Sublime Forum

Setting the target folder and file name for the save dialog

#1

Executing

view.run_command("save")

in a plugin will trigger the save dialog on a tab that has never been saved before. Is there a way to also set the target folder and the filename in that dialog from the plugin so that the user only has to hit enter in case they are satisfied with both?

0 Likes

#2

See View.retarget and View.set_name

1 Like

#3

See also the default_dir setting, to control what directory is used as the default starting directory; e.g.

view.settings().set('default_dir', os.path.join(sublime.packages_path(), 'User'))
1 Like

#4

@bschaaf, @OdatNurd Thank you very much for your replies. I was unable to find retarget in the docs, but based on what I’ve seen how others were using it, I presume its job is to connect a view to an existing physical file. Perhaps that won’t be necessary here, I guess approving the path and file name in the save dialog will do that anyway.

set_name worked great and the save dialog had the file name pre-set upon opening. On the other hand, view.settings().set(‘default_dir’, my_path_variable_here) did not help. Re-reading that using view.settings().get(‘default_dir’) showed that the variable was changed, I’ve checked other posts and examples about how it should be used but the save dialog still pointed to the last folder used :slightly_frowning_face:

0 Likes

#5

view.settings().set("default_dir", <path>) seems to work fine for me on Build 4131 (Latest dev build) on Windows 11. What does my_path_variable_here point to ? If you are using this in some plugin, is that plugin sharable so that others can introspect what might be possible wrong ?

0 Likes

#6

I apologize @OdatNurd, I’m oofficially an idiot now. Earlier I set my_path_variable to a constant to check why default_dir does not get set, is it because the data does not get there or it does not work (as expected)? It turned out I made some mistakes, and when I corrected those I thought all was well. Except that “setting it to constant” was not reverted, the my_path_variable still contained the “I am the path here” string.

EDIT: also thanks to @UltraInstinct05, your post triggered the re-check that resulted in discovering the oversight.

0 Likes