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)?
Dynamic captions for menus
Awesome, can’t wait! I’d imagine this could be used for labeling the file MRU list too
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:
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!
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
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
{ "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.
Could the open_recent_file command be changed so it has a description(self) implementation that returns " - ", where N is the index + 1? Then change the menu file to have corresponding mnemonics? “alt+f,r,” is a handy key combo