Getting Started
Plugins
- List of plugins
- Installing plugins
- Writing plugins
- Architecture
- Sharing plugins
- Core plugin
- Caveats
- API
Configuration
Context menus in fman
As explained in this blog post, fman offers a minimalistic but very configurable context menu. This page shows how you can customize it.
The context menu is configured through simple JSON files. For example,
the following file called
File Context Menu (Windows).json
defines fman's context menu on Windows:
[ { "caption": "-", "id": "open" }, { "caption": "&Open", "command": "open_selected_files" }, { "caption": "Open wit&h...", "command": "open_with" }, { "caption": "-", "id": "clipboard" }, { "caption": "Cu&t", "command": "cut" }, { "caption": "&Copy", "command": "copy_to_clipboard" }, { "caption": "-", "id": "file_operations" }, { "caption": "&Delete", "command": "move_to_trash"}, { "caption": "Rena&me", "command": "rename" }, { "caption": "-", "id": "archive" }, { "caption": "Add to archive...", "command": "pack"}, { "caption": "-", "id": "properties" }, { "caption": "P&roperties", "command": "show_explorer_properties"} ]
This is what the context menu looks like:
Every entry in the JSON file can have the following attributes:
- caption
-
The text displayed for the item in the context menu. If the caption
contains an ampersand
&
, then the character after it is used as the mnemonic for the item. For example,P&roperties
has mnemonic r. So when the context menu is open and you press r, then the Properties item is immediately selected.
If the caption is a dash-
, then the item is just a visual separator and can't have an associated command. See the JSON and the screenshot above for examples. Separators at the beginning and end of the context menu are not displayed but may still serve a purpose via theid
attribute described below.
The caption is optional if you supply thecommand
parameter. - command
-
The command that is executed when the context menu entry is clicked.
For a complete list of commands, please see the
core/commands
directory in the Core plugin. As explained here, a command calledDoSomething
in the Core plugin is referenced asdo_something
in the JSON file. - args
-
Commands in fman can have arguments. This optional attribute lets
you specify the parameters with which
command
should be invoked. It should be a dictionary{...}
. For example:{ "caption": "Select", "command": "move_cursor_down", "args": {"toggle_selection": true} }
- id
-
Ids are useful to let you specify where a new item should be
inserted in the context menu. For example, if you recall this
section from the JSON file above:
{ "caption": "-", "id": "clipboard" }, { "caption": "Cu&t", "command": "cut" }, { "caption": "&Copy", "command": "copy_to_clipboard" },
To append an item at the end of this section, you would create the following new JSON file:[ { "caption": "-", "id": "clipboard" }, { "command": "about" } ]
The"id": "clipboard"
parts in your JSON file and the original would be matched to determine the point of insertion. The new context menu then looks as follows:
Extending the context menu
To extend the context menu, create the file
Plugins/User/Settings/File Context Menu.json
in your data directory.
Add entries to it as in the id
example above. To apply your
changes, open the Command Palette with Ctrl+Shift+P
(or
Cmd+Shift+P
on Mac) and enter Reload plugins
:
- Reload plugins
Once you have done this, the new entries in your context menu should start to appear.
Clicking inside a folder
The previous section mentioned File Context Menu.json
.
It defines the context menu when you click on a file. But there is also
a (different) menu when you rightclick inside a directory (ie. not on a
file):
The entries of this context menu are defined by the file
Folder Context Menu.json
.
Hidden entries
JSON files describe which commands make up the context menu. The
commands themselves are implemented in plugins such as
Core. Some commands
use the method
is_visible()
to define whether the command can currently be executed. For
instance, the Paste
command is only visible when there is
a file on the clipboard. The context menu implementation uses this as
well to selectively hide items.
P.S.
fman is optimized to be used with the keyboard. You will often be significantly faster using the Command Palette than the context menu. If you can, try not to use the mouse. You will likely get much more out of fman this way.