How do we make a menu item “checkable,” as in, selected, and keep the state of that selection?
Checking selected menu items
You’ll need 2185 or later for this to work, although it’s not out yet. When it is, you’ll need to:
- Implement is_checked in your plugin
- Add “checkbox”: true to the corresponding entry in the .sublime-menu file
hi,
how exactly do I need to implement is_checked? I’ve looked around the docs, but it appears nowhere.
Thanks, mates
class MyCheckableCommand(sublime_plugin.WindowCommand):
def run(self):
pass # do something
def is_checked(self):
return True # or False
I couldn’t figure out how to get the current value from the menu entry! Really, really thank you! My problem was I tried that entry without a command, and it was behaving like a checkbox, and I expected I should grab the value, not override it with is_checked!
Thank you again =)
Just wanted to add that if the command requires an argument, is_checked
takes the same argument with the same name. This is how you can know whether or not to return True or False.
For example if one of your menu entries look like this:
{
"command": "some_command",
"caption": "Display Text",
"checkbox": true,
"args": {
"arg_name": "hello"
}
},
Then your is_checked
can look like this, taking the same argument
def is_checked(self, arg_name=None):
return arg_name is None