I want to create a menu for the user to select what file to use in my plugin. I’m hoping to create a menu that looks like the one in the SFTP plugin for selecting the server or the one that package control displays when you search for commands or install new packages. I was able to make something work using the show_popup_menu, but that’s not quite the style I want, since that seems to be attached to the editing point in the file, and I want this to be fixed at the top. Is there a command I can use, or an example I can look at to figure out how this has been done?
Designing a menu
OdatNurd
#2
Those packages use window.show_quick_panel()
to display their menu items. You provide a list
of strings (or for multiple lines of text in each item, a list
of list
s) and it does the work of letting the user select what they want, including the text filtering when text is entered.
A very brief example that uses them is available by using View Package File
from the command palette and opening Default/quick_panel.py
.
It implements the quick_panel
command; an example of using that command (via the console) would be:
window.run_command("quick_panel", {"items": [{"command": "echo", "args": {"first": True}, "caption": "First Item"}, {"command": "echo", "args": {"first": False}, "caption": "Second Item"}]})
It will open a panel that lets you pick between two items, and the console will show you if you picked the first or second item in the list.
2 Likes