aziz / SublimeFileBrowser

Ditch sidebar and browse your files in a normal tab with keyboard, like a pro!
MIT License
394 stars 46 forks source link

Ability to customize status bar help message #129

Open kentliau opened 8 years ago

kentliau commented 8 years ago

I use different shortcut for rename mode to commit and discard changes due to I want esc to clear out multiple cursors not to undo.

I do by adding these shortcut to my user key binding

/* the command with "noop" is to disable the default behavior*/
  {
    "keys" : ["enter"],
    "command": "noop",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.dired" },
        { "key": "setting.dired_rename_mode", "operand": true }
    ]
  },
  {
    "keys" : ["escape"],
    "command": "noop",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.dired" },
        { "key": "setting.dired_rename_mode", "operand": true }
    ]
  },
  {
    "keys" : ["escape"],
    "command": "single_selection",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.dired" },
        { "key": "setting.dired_rename_mode", "operand": true },
        { "key": "num_selections", "operator": "not_equal", "operand": 1 }
    ]
  },
  {
    "keys" : ["ctrl+x"],
    "command": "dired_rename_commit",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.dired" },
        { "key": "setting.dired_rename_mode", "operand": true }
    ]
  },
  {
    "keys" : ["ctrl+z"],
    "command": "dired_rename_cancel",
    "context": [
        { "key": "selector", "operator": "equal", "operand": "text.dired" },
        { "key": "setting.dired_rename_mode", "operand": true }
    ]
  },

So now I want to customize the help file when press ? and the status bar help message down it the bottom of the windows. Can it like have another setting field to specify the custom shortcuts.md?

aziz commented 8 years ago

I don't think it's possible in an easy and elegant way using the current API. We need an API to be able to read keybindings programmatically to find the bound keys, which as far as I know is not provided by SublimeText. You can ask SublimeHQ to add this feature.

vovkkk commented 8 years ago

If you install via Package Control on ST3 you can create Packages/FileBrowser/shortcuts.md with your own content.

I think we should at least set correct keybindings in status-bar when renaming dynamically.

aziz commented 8 years ago

I think we should at least set correct keybindings in status-bar when renaming dynamically.

The Question is, can we?

kentliau commented 8 years ago

@vovkkk thanks, just learned this.

@aziz reading dynamically from the key binding file is cool, for the time being I am good for just having a customized shortcuts.md in my user package dir, and I just learned that I can do that. But why not read from the shortcuts.md as well for the status bar message?

aziz commented 8 years ago

It feels very hacky. I want a more robust and reliable solution, not just a hack!

kentliau commented 8 years ago

i stumble upon this FindKeyConflicts, it go through all the binding files. But for a specific package, is it only have to go through the package's default and user's key binding file right?

vovkkk commented 8 years ago

only have to go through the package's default and user's key binding file right?

No, keybinding can be anywhere.

I thought command has info about keybinding since ST show keys in menus dynamically, but apparently it does not.

kentliau commented 8 years ago

some of the commands in command palette show the key binding even third party one

screen shot 2016-10-01 at 12 27 59 am
vovkkk commented 8 years ago

That is what I meant menu and command palette, but this info is not available programmatically it seems.

You can get all text command as list with sublime_plugin.text_command_classes you can init command with c = sublime_plugin.text_command_classes[105](view) (105 is an index i.e. the 106th command in the list) you can print attributes of command pprint.pprint([(a, getattr(c, a)) for a in dir(c)]) All these steps can be done in console ViewShow Consoleimport sublime_plugin, pprint

You can look at sublime.py and sublime_plugin.py in the same directory as ST executable.

You will see that there is no any way in API to get keys for command.

You can create menu Packages/User/Main.sublime-menu:

[
  {
    "id": "filebrowser",
    "caption": "FileBrowser",
    "children":
    [
      { "command": "dired_rename_commit" },
      { "command": "dired_rename_cancel" },
      { "command": "dired_expand" }
    ]
  }
]

2016-10-01_05-44-07