Sublime Forum

Project switch functionality, shortcut

#1

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

1 Like

#2

They are both easily doable :smile:

command for “Open Project…” is: openProject
so just bind it to whatever key u want…

<binding key="ctrl+shift+p" command="openProject"/>

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

<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 :smile:

[code]""“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)[/code]

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

<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 :smiley:
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 :wink: Enjoy it!

1 Like

Easier Way to Open Project
#3

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 =)

0 Likes

#4

[quote=“tomaszdurka”]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 =)[/quote]

Your welcome, what were the problems? Curious :smiley:

0 Likes

#5
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:

filenames = ]
for filename in displayFiles:
	filenames.append(projectPath + '/' + filename)

Cheers,
Tomasz

0 Likes