Home Download Buy Blog Forum Support

Add a Folder to Sidebar via API?

Add a Folder to Sidebar via API?

Postby C0D312 on Fri Jan 13, 2012 3:10 am

Is it possible to add a folder to the sidebar from a plugin? If I pass a folder to the open_file command, will it open in the sidebar?

Thanks.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Add a Folder to Sidebar via API?

Postby weslly on Tue Jan 31, 2012 12:26 am

+1, it would be really useful for some plugins
weslly
 
Posts: 203
Joined: Sun Aug 28, 2011 3:57 am
Location: Brazil

Re: Add a Folder to Sidebar via API?

Postby Navaru on Tue Jan 31, 2012 5:28 am

+1, I would like this too :)
Navaru
 
Posts: 10
Joined: Wed Sep 07, 2011 12:16 pm

Re: Add a Folder to Sidebar via API?

Postby wbond on Thu Feb 09, 2012 4:23 am

I just spent a few minutes digging through the Default package looking for a solution to this. I would also approve of such a feature! :-)

Alternatively a way to open a folder without a prompt, or opening a project without a prompt would work also.
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Add a Folder to Sidebar via API?

Postby impeached on Thu Feb 09, 2012 1:35 pm

You can kind of cheat by running this system command. This is how I always do it, i just keep a terminal open and add stuff through that.
Code: Select all
/path/to/sublime_text.exe -a /path/to/file_or_folder
impeached
 
Posts: 20
Joined: Mon Nov 14, 2011 11:18 pm

Re: Add a Folder to Sidebar via API?

Postby wbond on Fri Feb 10, 2012 3:14 am

impeached wrote:You can kind of cheat by running this system command. This is how I always do it, i just keep a terminal open and add stuff through that.
Code: Select all
/path/to/sublime_text.exe -a /path/to/file_or_folder


I was going to attempt this, however with the limited amount of time I spent on it, I could not think of a good way to programatically determine the path to the command line program. Perhaps I am overlooking a simple solution?
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Re: Add a Folder to Sidebar via API?

Postby sublimator on Fri Feb 10, 2012 3:24 am

>>> import sys
>>> sys.executable
'C:\\Program Files\\Sublime Text 2\\sublime_text.exe'
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Add a Folder to Sidebar via API?

Postby sublimator on Fri Feb 10, 2012 3:26 am

Though, now I think about it, iirc that won't work on OSX as you'll get the system python executable.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Add a Folder to Sidebar via API?

Postby sublimator on Fri Feb 10, 2012 4:29 am

>>> open('/proc/self/cmdline').read().split(chr(0))[0]
'/usr/lib/sublime-text-2/sublime_text'

For *nix ( not osx it seems)
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Add a Folder to Sidebar via API?

Postby wbond on Fri Feb 10, 2012 2:31 pm

I think sys.executable may be good enough since OS X users are unlikely to install Sublime in a non-standard location, whereas Linux users have no standard and Windows users could be using the portable installation.

So, I think the best solution (until we get an API method) is:

Code: Select all
import sublime
import sys
import subprocess

def get_sublime_path():
    if sublime.platform() == 'osx':
        return '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'
    if sublime.platform() == 'linux':
        return open('/proc/self/cmdline').read().split(chr(0))[0]
    return sys.executable

def sublime_command_line(args):
    args.insert(0, get_sublime_path())
    return subprocess.Popen(args)


Usage for adding a folder to the sidebar would be:

Code: Select all
sublime_command_line(['-a', '/path/to/folder'])
wbond
 
Posts: 528
Joined: Mon Feb 28, 2011 5:33 am

Next

Return to Plugin Development

Who is online

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