Sublime Forum

Dynamic captions for menus

#1

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)?

0 Likes

#2

This isn’t exposed to Python yet, will add for the next dev build.

0 Likes

#3

Awesome, can’t wait! I’d imagine this could be used for labeling the file MRU list too :smiley:

0 Likes

#4

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!

0 Likes

#5

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

0 Likes

#6

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.

0 Likes

#7

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 :smile:

0 Likes