Home Download Buy Blog Forum Support

Project switch functionality, shortcut

Project switch functionality, shortcut

Postby tomaszdurka on Thu Jan 14, 2010 11:50 am

I love Sublime and using it, but (!) switching between projects could be really improved. Especially when in fullscreen where I need to quit it, change project, go back to it, etc.
It would be great to have some ability to change project quickly.
Easiest I can think about:
- "open project" key shortcut. Like open file one, best with predefined projects path activated
Bit more complex one
- "open project" key-shortcut simliar to ctrl+p (open in project) one, with all projects listed and text box active

Cheers,
Tomasz
tomaszdurka
 
Posts: 3
Joined: Thu Jan 14, 2010 11:42 am

Re: Project switch functionality, shortcut

Postby EJ12N on Fri Jan 15, 2010 5:45 pm

They are both easily doable :)


command for "Open Project..." is: openProject
so just bind it to whatever key u want...
Code: Select all
<binding key="ctrl+shift+p" command="openProject"/>

For specific directories/project then is the same command with the directory/project as paramater...

Code: Select all
<binding key="ctrl+shift+p" command="openProject 'c:/Documents and Settings/eb/Desktop/WORK/.SUBLIMEPROJECTS/bbcom.sublime-project'"/>

there's a few rules when passing the a directory/project path as parameter...
1st: directory separator has to be forward slash "/" not the backslash "\"
2nd: If it contains spaces you need to enclose it in quotes. (single or double, doesn't matter.)
---
Second request requires a little more code but still not really hard. Mainly because all *juicy* code is done for you already in the "open from current directory..." plugin. We just gonna modify it to make it work for projects :)

Code: Select all
"""Open project files from specific directory in quickPanel :)"""
class quickOpenProject(sublimeplugin.WindowCommand):
    allowedExtensions = ['.sublime-project']

    def wantFile(self, f):
        root, ext = os.path.splitext(f)
        return os.path.isfile(f) and ext in self.allowedExtensions

    def run(self, window, args):
        projectPath = str(args[0])
        displayFiles = [f for f in os.listdir(projectPath) if self.wantFile(projectPath+'/'+f)]
        displayFiles.sort()
        projectFilesPath = [projectPath+'/'+str(*displayFiles)]

        window.showQuickPanel("", "openProject", projectFilesPath, displayFiles,
            sublime.QUICK_PANEL_FILES | sublime.QUICK_PANEL_MULTI_SELECT)


Now just bind the command to any key you want and you have open project command with quickpanel with your specific directory! :)

Code: Select all
<binding key="ctrl+f8" command="quickOpenProject 'c:/Documents and Settings/eb/Desktop/WORK/.SUBLIMEPROJECTS'"/>


As you can see just pass the directory you keep your sublime-project files on as parameter and that's it :D
This allows you to have flexibility to have as many keybindings as you want to any specific directory in case you don't keep all your projects in one folder.

Anyways here is a nice example to let you see how powerful sublime is/can be if you get familiar with it ;) Enjoy it!
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Project switch functionality, shortcut

Postby tomaszdurka on Thu Jan 21, 2010 4:50 pm

I had some problems with the script. Made not best workaround as my Py knowledge is limited, but works.
Thanks a lot for that, showed me loads of possibilites. Was like quickest solution to desktop software request =)
tomaszdurka
 
Posts: 3
Joined: Thu Jan 14, 2010 11:42 am

Re: Project switch functionality, shortcut

Postby EJ12N on Thu Jan 21, 2010 4:53 pm

tomaszdurka wrote:I had some problems with the script. Made not best workaround as my Py knowledge is limited, but works.
Thanks a lot for that, showed me loads of possibilites. Was like quickest solution to desktop software request =)

Your welcome, what were the problems? Curious :D
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Project switch functionality, shortcut

Postby tomaszdurka on Mon Feb 01, 2010 12:02 pm

Code: Select all
projectFilesPath = [projectPath+'/'+str(*displayFiles)]

This line didn't worked for me. Don't remember exactly what was wrong (some syntax I believe).
I created new array and added each with projectPath added - via for ... in, like:
Code: Select all
filenames = []
for filename in displayFiles:
   filenames.append(projectPath + '/' + filename)


Cheers,
Tomasz
tomaszdurka
 
Posts: 3
Joined: Thu Jan 14, 2010 11:42 am


Return to Ideas and Feature Requests

Who is online

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