Home Download Buy Blog Forum Support

[SOLVED]run_command in mulitple files?

[SOLVED]run_command in mulitple files?

Postby jtwebb on Wed Jul 24, 2013 12:41 pm

Is it possible to have classes the respond to the run_command spread across multiple files?

For example, if I had a directory structure like this:
Code: Select all
    - commands_dir/
          - __init__.py
          - bootstrap.py      # import all files into this file so plugin.py only has one import statement
          - command_1.py
          - command_2.py
          - etc...
    - plugin.py
    - menus & settings...

Could I, somehow, still call view.run_command('command_1')? I'm still new to Sublime plugins and Python in general so if I'm missing something obvious, please let me know.

An alternative that I thought of was to have the commands in the command_dir just be standard classes and then (again, somehow) call a command in the plugin.py file that would use that class based on the input from the menu item. Is that a better route?

The reason I want to structure the plugin this way is because the plugin could, potentially, have a hundred commands and I don't want the plugin.py littered with command classes.
Last edited by jtwebb on Wed Jul 24, 2013 7:37 pm, edited 1 time in total.
Posts: 14
Joined: Sat Jul 20, 2013 5:19 am

Re: run_command in mulitple files?

Postby sapphirehamster on Wed Jul 24, 2013 6:25 pm

Take a look at how Package Control is implemented. Essentially you have
Code: Select all
from myplugin.commands import *
and each command in a separate file in the commands subpackage. It'll be slightly different if you are supporting ST3 or ST3.
Posts: 99
Joined: Sun Jul 01, 2012 11:19 pm

Re: run_command in mulitple files?

Postby jtwebb on Wed Jul 24, 2013 7:34 pm

Thanks for the response. That's exactly what I needed! I probably looked through 20 different packages looking for someone that did something similar, but couldn't find anything. I should have known that Package Control would have what I needed :)
Posts: 14
Joined: Sat Jul 20, 2013 5:19 am

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests