Home Download Buy Blog Forum Support

using window.showQuickPanel to choose a command

using window.showQuickPanel to choose a command

Postby SteveCooperOrg on Sun Feb 15, 2009 8:18 am

If, like me, you have plugins with a lot of commands, and far too many key bindings, consider this little snippet. It pops up the quickpanel, and lets you choose a command to execute.

Code: Select all
class ChooseOutputFormatCommand(sublimeplugin.WindowCommand):
  def run(self, window, args):
    items = [
      ("Article (pdf)", "compileToPdf"),
      ("Filofax Pages (pdf)","compileToFilofaxPagePdf"),
      ("Index Cards (pdf)","compileToIndexCardPdf"),
      ("Standard Manuscript Format (pdf)", "compileToSmfPdf"),
      ("Web Page (html)", "compileToHtml"),
      ("Rich Text Format (rtf)", "compileToRtf"),
      ("S5 slideshow (html)", "compileToS5"),
      ("Screenplay (pdf)","compileToScreenplayPdf"),
      ("Book (pdf)","compileToBookPdf"),
      ("Book with pagebreaks (pdf)","compileToBookPbPdf"),
      ("Booklet (pdf)","compileToBookletPdf"),
    ]
    commands = [x for x,y in items]
    names =    [y for x,y in items]
    window.showQuickPanel("", "onOutputChosen", names, commands)
 
class OnOutputChosenCommand(sublimeplugin.WindowCommand):
  def run(self, window, args):
    if len(args) != 1:
      print "%s items selected; expected 1" % len(args)
      return
    command = args[0]
    print "selected %s" % command
    window.activeView().runCommand(command)
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: using window.showQuickPanel to choose a command

Postby SteveCooperOrg on Sun Feb 15, 2009 8:25 am

Anyone know if there is a way to test if a command is enabled? I'd like to improve that snippet so that it didn't show disabled commands.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: using window.showQuickPanel to choose a command

Postby jps on Sun Feb 15, 2009 12:13 pm

There isn't; I'll expose an API function for it in the next beta.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: using window.showQuickPanel to choose a command

Postby SteveCooperOrg on Sun Feb 15, 2009 3:53 pm

You, sir, are a god.
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am

Re: using window.showQuickPanel to choose a command

Postby SteveCooperOrg on Tue Feb 17, 2009 5:36 pm

The canRunCommand method works perfectly. I now have the ability to select a build command based on the current extension. Neat!
Maybe what you're looking for is at the http://www.sublimetextwiki.com
SteveCooperOrg
 
Posts: 193
Joined: Thu Mar 20, 2008 9:53 am


Return to Plugin Announcements

Who is online

Users browsing this forum: niyyou and 11 guests