Home Download Buy Blog Forum Support

Dynamic menu caption?

Dynamic menu caption?

Postby jjabba on Mon Sep 09, 2013 11:18 am

I have a listing in a sub menu.
I would like to display different captions for the different items, all which are dynamically obtained. Much the same way 'Open recent' works.

I've implemented a
Code: Select all
def is_visible(self, index):


function to only show relevant menu items, and that works great.

How can I provide a custom caption?
Is there a function along the lines of
Code: Select all
has_caption(self, index):
that I could implement?
jjabba
 
Posts: 2
Joined: Mon Sep 09, 2013 10:47 am

Re: Dynamic menu caption?

Postby bizoo on Mon Sep 09, 2013 11:30 am

There's an API:
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.

So something like:
Code: Select all
def description(self, *args):
   return "DESCRIPTION"


Not sure exactly when it is called (once or each times ?)
bizoo
 
Posts: 888
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Dynamic menu caption?

Postby jjabba on Tue Sep 10, 2013 11:59 am

I tried implementing a function like
Code: Select all
def description(self, *args):
   return "DESCRIPTION"

but it is never called...
Do I need to put something special in my .sublime-menu file to trigger this callback?
I'm using sublime 2.
jjabba
 
Posts: 2
Joined: Mon Sep 09, 2013 10:47 am

Re: Dynamic menu caption?

Postby bizoo on Tue Sep 10, 2013 12:17 pm

Tried it right now and it works:
startup, version: 2221 windows x64 channel: stable

\Sublime Text 2\Packages\User\Main.sublime-menu
Code: Select all
[
    {
        "id": "view",
        "children":
        [
            {
                "command": "example"
            }
        ]
    }   
]


\Sublime Text 2\Packages\User\exemple.py
Code: Select all
class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        print 'Hello'

    def description(self, *args):
        return "DESCRIPTION"
bizoo
 
Posts: 888
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests