PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

[Feature request] Provide an API to set the directory for the next FileOpen / FileSave

Open fml2 opened this issue 1 month ago • 8 comments

This issue stems from the discussion on the forum: https://community.notepad-plus-plus.org/topic/27270/set-current-directory-to-default-if-no-real-file-is-open

I'd like to have an API to set the directory that will be used on the next launch of the "Open File" or "Save File" dialog. This should overwrite the value that is internally tracked and set by Notepad++ because e.g. of the setting "Default Open/Save file Directory".

This should allow for me to better handle the following situation:

  1. The setting "Default Open/Save file Directory" is set to "Follow current document"
  2. I have a tab with new contents (not yet saved as a file)
  3. In another tab, I have a file from a network folder, which is the active tab now.
  4. I close the tab with the network file. Only the untitled tab remains
  5. Now I want to save this untitled tab to a "standard" folder. The standard folder is the one used after Notepad++ is started without any files. It's "Desktop" for me.

As of now, when I press Ctrl+S in the step 5, the dialog opens in the network directory. I'd like it to open in the "Standard" directory. But this should only be for untitled tabs. For real files, the dialog should still open in the directory of the file.


Disclaimer: I also submitted this as an issue in Notepad++ for the case that this feature is better implemented there.

fml2 avatar Nov 28 '25 20:11 fml2

Not a reasonable feature for PythonScript, IMO.

alankilborn avatar Nov 28 '25 22:11 alankilborn

Maybe just an API for opening the dialog in the folder passed in as a parameter?

fml2 avatar Nov 29 '25 07:11 fml2

Maybe just an API for opening the dialog in the folder passed in as a parameter?

Not needed. You can do your own "save" dialog in Python code, customizing it however you want.

alankilborn avatar Nov 29 '25 11:11 alankilborn

I thought that all the GUI actions have to happen under the umbrella of the main application (Notepad++) so that the GUI does not get confused. I'm not a GUI expert but heard that there are some gotchas.

Do you have an example of a Python script opening dialogs from within NP++ by any chance? If that works, I agree that exxtending the plugin or NP++ is not necessary.

fml2 avatar Nov 29 '25 14:11 fml2

Do you have an example of a Python script opening dialogs from within NP++ by any chance?

THIS library can do it.

alankilborn avatar Nov 29 '25 14:11 alankilborn

I think to work on this it would require an extension of N++ plugin API. Unlikely that this feature gets implemented by me but if someone volunteers I would be open to integrate it.

chcg avatar Dec 01 '25 08:12 chcg

@chcg No need for that; I'll write this person a script to show how to do it.

alankilborn avatar Dec 01 '25 12:12 alankilborn

There's actually already a script I wrote for something like this, HERE.

alankilborn avatar Dec 05 '25 12:12 alankilborn