Home Download Buy Blog Forum Support

Menu item that gets caption dynamically from plugin [SOLVED]

Menu item that gets caption dynamically from plugin [SOLVED]

Postby robertcollier4 on Thu Feb 28, 2013 12:28 pm

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:
Code: Select all
{ "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.
Last edited by robertcollier4 on Wed Mar 06, 2013 9:32 am, edited 1 time in total.
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: How make menu item that gets caption dynamically from plugin

Postby bizoo on Thu Feb 28, 2013 12:45 pm

http://www.sublimetext.com/docs/2/api_reference.html
Code: Select all
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.
bizoo
 
Posts: 880
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How make menu item that gets caption dynamically from plugin

Postby robertcollier4 on Thu Feb 28, 2013 1:20 pm

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(<args>)" could be added to sublime_plugin.ApplicationCommand? :D
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm

Re: How make menu item that gets caption dynamically from plugin

Postby bizoo on Thu Feb 28, 2013 1:34 pm

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

Oups, this doc refer to SublimeText 1 :o
Forget about it.
bizoo
 
Posts: 880
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: How make menu item that gets caption dynamically from plugin

Postby robertcollier4 on Wed Mar 06, 2013 9:28 am

robertcollier4 wrote:Perhaps in a future version, a method such as "is_checked(<args>)" could be added to sublime_plugin.ApplicationCommand? :D

UPDATE: The is_checked method is already there, though not documented.
Everything working now. Thanks.
robertcollier4
 
Posts: 154
Joined: Sun Feb 24, 2013 5:37 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests