Home Download Buy Blog Forum Support

Keybinding can't find command

Keybinding can't find command

Postby dutt on Sat Feb 02, 2013 12:32 pm

Hi,

I'm trying to write a little plugin to let me run my program with arguments taken from a popup text box, but I've run into problems.

I've added a keybinding
Code: Select all
{ "keys": ["f8"], "command" : "User.run_with_args" },

to Default(OSX).sublime-keymap and my little plugin located at Packages/User/run_with_args.py) currently looks like this:
Code: Select all
import sublime, sublime_plugin

class PromptRunWithArgsCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      sublime.message_dialog("testing")
      self.window.show_input_panel("Enter arguments: ", "", self.on_done, None, None)

   def on_done(self, text):
      parts = text.split(" ")
      self.window.active_view().run_command("run_with_args", {"args" : parts} )

class RunWithArgsCommand(sublime_plugin.TextCommand):
   def run(self, args):
      #get build system, run target program


Now I have two questions.
1) How do I make the keybinding find my command? If I switch from "run_with_args" to "build" it works fine. And should I split the two commands into two files? I assume that Sublime finds the commands by file name.
2) How do I make the current build system run the taget program?
dutt
 
Posts: 14
Joined: Sat Apr 28, 2012 10:09 am

Re: Keybinding can't find command

Postby sapphirehamster on Sat Feb 02, 2013 11:40 pm

First step, your keybinding does not need the "User" portion. It's not a package.
I would also assume you want it to run your "prompt" command since your run_with_args does nothing:
Code: Select all
{ "keys": ["f8"], "command" : "prompt_run_with_args" },


Additionally, TextCommand does not have a "window" attribute. You'll need to do:
Code: Select all
self.view.window().show_input_panel(...)


I'm not sure why you are executing another command from within your prompt command. Unless you have other plans, you could just put it all into one class. You'll also want to pass arguments by name when calling run_command, don't use {"args":...}, then use keyword arguments in your run method.
sapphirehamster
 
Posts: 83
Joined: Sun Jul 01, 2012 11:19 pm

Re: Keybinding can't find command

Postby dutt on Sun Feb 03, 2013 9:05 am

Thanks a lot for the help, it's running the plugin now.
dutt
 
Posts: 14
Joined: Sat Apr 28, 2012 10:09 am


Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests