Hello everyone,
I created a plugin that has a single command which accepts a single argument. The available argument values are stored in a .sublime-settings file and users can add and change them as they wish. Currently I manually add an entry in the context menu for each argument but it would be nice if this was done dynamically. However, I couldn’t find any way to do this through the API.
I’d rather not have Sublime edit the plugin’s Context.sublime-menu file each time it loads the plugin but at the moment I think this is the only solution. Any ideas how to do this in a nice way (dynamically, through the API)?
To make things clear, here’s an example:
my_plugin.py
import sublime, sublime_plugin
settings = sublime.load_settings('MySettings.sublime-settings')
class MyPluginActionCommand(sublime_plugin.TextCommand):
def run(self, edit, argument):
current_argument = settings.get(argument)
# do stuff based on current_argument
MySettings.sublime-settings
{
"first_argument": "this is the first available argument",
"second_argument": "this is the second available argument"
}
Right now, I have to manually create a Context.sublime-menu file but I want the menu items to automatically appear in the context menu:
{ "id": "end" },
{ "caption": "-" },
{
"caption": "My Plugin",
"id": "my_plugin",
"children":
{
"caption": "First action",
"command": "my_plugin_action", "args": { "argument" : "first_argument" }
},
{
"caption": "Second action",
"command": "my_plugin_action", "args": { "argument" : "second_argument" }
}
]
}
]