Sublime Forum

Open folder in new window

#1

So, I’m developing the JRubyFX plugin, and I’m trying to add a “create new JRubyFX project” that will create a directory structure for the project, laid out according to a few conventions which will make it easier for me to add support for some of the other tools, like building and packaging. Got that part done, and now I want this folder to either open in a new window, or replace the project in the current window, but cannot seem to find the command for doing this. I seem to be dancing all around this, but not getting what I want. Thanks in advance for your help.

0 Likes

#2

So, for anyone searching for this in the future, I’ve spent all day poring over every bit of documentation on API, commands. looking through the default package, taking dozens of guesses at likely method names, and finally pouring over tons and tons of other plugins looking for something that might be useful. The only thing I’ve found is the the SideBarOpenInNewWindowCommand for the SideBarEnhancements Plugin, which shells out to the sublime text executable and fires up a new process. It seems like surely there would be some way to do this via sublime’s own API, since sublime itself does it when you open a project file or folder. But it is either something left unexposed, or it is completely undocumented. Fortunately, the SideBarEnhancements plugin which I mentioned will save me the trouble of having to figure out all these variations and whatnot on my own, so that’s a plus! http://www.sublimetext.com/forum/images/smilies/icon_mrgreen.gif

My hope is that I’ve missed something obvious, and someone will reply to my post telling me exactly how to do either of the things I desire, but if not, I wanted to come back and hopefully save someone else the hours of time spent looking.

EDIT: I had totally given up when I took a look at one more plugin SublimeFiles and what do you know, this guy’s found something that works. Apparently he’s come across it in the work of wbond, who, I believe, makes the package manager. It doesn’t open the project in a new window, but with it I can add the new project folder to the current window. Going to experiment a bit and see what all I can get it to do for me. Very happy. Wish I’d looked more closely at this one hours and hours ago, the first time my eyes brushed over it.

0 Likes

#3

You can try and do it like this

	def openInNewWindow(self, path):
		if sublime.platform() == 'osx':
			try:
				subprocess.Popen('subl', '.'], cwd=path)
			except:
				try:
					subprocess.Popen('sublime', '.'], cwd=path)
				except:
					subprocess.Popen('/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl', '.'], cwd=path)
		elif sublime.platform() == 'windows':
			try:
				subprocess.Popen('subl', '.'], cwd=path, shell=True)
			except:
				try:
					subprocess.Popen('sublime', '.'], cwd=path, shell=True)
				except:
					subprocess.Popen('/Program Files/Sublime Text 3/sublime_text.exe', '.'], cwd=path, shell=True)
		else:
			try:
				subprocess.Popen('subl', '.'], cwd=path)
			except:
				subprocess.Popen('sublime', '.'], cwd=path)
0 Likes

#4

github.com/titoBouzout/SideBarE … r.py#L1445

0 Likes

#5

I had to recognize that the magic line is this one there

for item in SideBarSelection(paths).getSelectedDirectoriesOrDirnames():
0 Likes

#6

Oh yeah, there was something strange there, is old code, the new one is much better

github.com/titoBouzout/SideBarE … r.py#L1447

0 Likes

#7

Thank you for the code, but there is a mistake, missing a parenthesis, I spend some time man researching Python

subprocess.Popen([‘subl’, ‘.’], cwd=path)

0 Likes