Home Download Buy Blog Forum Support

Dynamic captions for menus

Dynamic captions for menus

Postby jburnett on Tue Aug 02, 2011 9:03 am

I just wrote a command intended to go in the context menu. Is it possible to make the caption dynamic (not animated, just custom each time the menu is built for display)?
jburnett
 
Posts: 89
Joined: Wed Jul 27, 2011 9:23 pm

Re: Dynamic captions for menus

Postby jps on Tue Aug 02, 2011 9:56 am

This isn't exposed to Python yet, will add for the next dev build.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Dynamic captions for menus

Postby jburnett on Wed Aug 03, 2011 4:31 am

Awesome, can't wait! I'd imagine this could be used for labeling the file MRU list too :D
jburnett
 
Posts: 89
Joined: Wed Jul 27, 2011 9:23 pm

Re: Dynamic captions for menus

Postby jburnett on Thu Aug 04, 2011 9:39 am

Tried it, it works great. There's a small issue with it when using it on the main menus on Windows though - the flyout menu width grows to fit the text, but never shrinks again. e.g. try this in a menu:

Code: Select all
import sublime, sublime_plugin
foo = True
class test(sublime_plugin.TextCommand):
    def description(self):
        global foo
        foo = not foo
        return "*" * 120 if foo else "i'm small"


It works properly for context menus though. Thanks again!
jburnett
 
Posts: 89
Joined: Wed Jul 27, 2011 9:23 pm

Re: Dynamic captions for menus

Postby Judah on Thu Aug 25, 2011 5:28 pm

What about dynamic content for a menu? It would be great if we could supply a builder that would generate menu items when the menu is posted, similar to how the recent files list is generated, etc.

thanks,
-Judah
Judah
 
Posts: 3
Joined: Tue Aug 09, 2011 12:37 am

Re: Dynamic captions for menus

Postby jps on Thu Aug 25, 2011 10:57 pm

The recent files menu isn't actually dynamically generated, some of the items are just hidden, and you can do the same thing from Python. The menu looks like

Code: Select all
{ "command": "open_recent_file", "args": {"index": 0 } },
{ "command": "open_recent_file", "args": {"index": 1 } },
{ "command": "open_recent_file", "args": {"index": 2 } },
...

The open_recent_file command implements is_visible(self, index) (which plugins can also do), and uses this to give the appearance of a dynamic menu.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Dynamic captions for menus

Postby jburnett on Mon Aug 29, 2011 7:31 am

jps wrote:The open_recent_file command implements is_visible(self, index) (which plugins can also do), and uses this to give the appearance of a dynamic menu.


Could the open_recent_file command be changed so it has a description(self) implementation that returns "<N> - <filepath>", where N is the index + 1? Then change the menu file to have corresponding mnemonics? "alt+f,r,<number>" is a handy key combo :)
jburnett
 
Posts: 89
Joined: Wed Jul 27, 2011 9:23 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 8 guests