Sublime Forum

Menu item that gets caption dynamically from plugin [SOLVED]

#1

I would like to create dynamic menu items in Main.sublime-menu. They would either get their caption or checked/nonchecked value from the result of a plugin.

I know it must be possible, since it is already done in Main.sublime-menu to show the “Open Recent” file list. Somehow, the following menu entry shows as its caption the most recently opened file:

{ "command": "open_recent_file", "args": {"index": 0 } },

How does the File > Open Recent list show the filename as its caption in the menu? How can I do something similar to implement a return value from a plugin that will feed the value of the menu item caption? What about if I want a menu item to have its checked/nonchecked value as the result of a plugin return value? Thanks.

0 Likes

#2

sublimetext.com/docs/2/api_reference.html

description(<args>)	String	Returns a description of the command with the given arguments. Used in the menu, if no caption is provided. Return None to get the default description.

Implement description() and return what you want.

0 Likes

#3

Thanks, that works. I probably should have seen that, but it wouldn’t hurt adding a reference to it where I first looked here.

Perhaps in a future version, a method such as “is_checked()” could be added to sublime_plugin.ApplicationCommand? :smiley:

0 Likes

#4

Oups, this doc refer to SublimeText 1 :astonished:
Forget about it.

0 Likes

#5

UPDATE: The is_checked method is already there, though not documented.
Everything working now. Thanks.

0 Likes