Sublime Forum

Select Directory dialog

#1

Is it possible for a plugin to ask the user to identify an existing file/directory for it to use? I do not want the directory to be a part of my sublime project or to be added to it as I don’t want it showing up in symbol searches etc. - I just want to request and store the name of a windows file/directory via some sort of file system browser.

0 Likes

#2

You could hack something with the ctypes module, but other than that there is no direct access to the OS’s file or folder picker dialog.

You’ll need to build your own picker using the command palette. I would link you to a package that does this, but I forgot its name and can’t find it anymore. I also haven’t used it in a long while.

0 Likes

#3

Thanks, I’ll look into it.

0 Likes

#4

Not “command palette” but “quick panel” of course.

0 Likes

#5

I’ve created a simple PlugIn for file/folder selection. I’ll post it in “Plugin Development”.

Here is the link: http://www.sublimetext.com/forum/viewtopic.php?f=6&t=18960#p69585

0 Likes

#6

Thanks, this is really helpful.
I will try to tweak it a little to :

  • replace _SELECT_THIS_FOLDER by “”

  • Add a CREATE_SUBDIRECTORY option

  • Replace full paths of sub-directories by relative (to ) names

(it may take me a while)

0 Likes

#7

[quote=“steveh4133”]
I will try to tweak it a little to :

  • replace _SELECT_THIS_FOLDER by “”

  • Add a CREATE_SUBDIRECTORY option

  • Replace full paths of sub-directories by relative (to ) names

(it may take me a while)[/quote]

I’ve done all this. Text changes are simple. At the beginning of the class definition you find all class-wide variables. There can you modify what you want.

0 Likes

#8

The service here is fantastic! Thanks again.

0 Likes

#9

But I think the plugin solution is not optimal. Taking over the selection in the calling script is not as easy as I thought. I’ll try if it works better with a module solution.
The insertion of the class in your script would be another way to gain direct access to the selection.
I’ll play around with it a little, in the hope of enlightenment. :bulb:

0 Likes

#10

I modified it a little so I could pass a callback command.

[code]import sublime, sublime_plugin

class ChooseDeliveryDirectoryCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.active_window().run_command(“user_select_file_folder”,
{“root”: “D:\development”,
“select_type”: “folder”,
“onchoose”: “set_delivery_directory”
})

class setDeliveryDirectoryCommand(sublime_plugin.TextCommand):
def run(self, edit, folder):
print("you chose ", folder )[/code]

0 Likes