SaveAs event - get new file Name
-
Hi all,
I am currently working on a plugin that triggers certain actions when files are opened/saved with a specific fileEnding. For this, I have made a
switch
inbeNotified
checking forNPPN_FILEOPENED
orNPPN_FILEBEFORESAVE
and then I useNPPM_GETFULLPATHFROMBUFFERID
to get the full path of the file and check if the path/extension match certain criteria that trigger my action.I have noticed though, that when I use
saveAs
in notepad++, thenNPPM_GETFULLPATHFROMBUFFERID
in theNPPN_FILEBEFORESAVE
will return the old filename, but not the one that was chosen in the saveAs menu. Is there anyway I can get ahold of that?As an example, I want to trigger my action wehn saving a file with the extension
.special
. When I open a filelog.txt
and selectsaveAs
and enterlog.special
, then I still get the Filenamelog.txt
fromNPPN_FILEBEFORESAVE
, hence my action will not trigger -
@Florian-Jochheim said in SaveAs event - get new file Name:
I have noticed though, that when I use saveAs in notepad++, then NPPM_GETFULLPATHFROMBUFFERID in the NPPN_FILEBEFORESAVE will return the old filename, but not the one that was chosen in the saveAs menu. Is there anyway I can get ahold of that?
Looking at the code, it appears that Notepad++ updates the file name in the buffer after a successful save; and doing my best to follow the processing for IDM_FILE_SAVEAS, I don’t see any messages sent that would help. You could use NPPN_FILESAVED to be notified after the fact and then check if the name was changed from what you captured in NPPN_FILEBEFORESAVE.
If what you need to do is to intercept processing before the save, probably the best you can do is create your own Save As… command, display and process the dialog to get the filename yourself, and then use NPPM_SAVECURRENTFILEAS to perform the requested action. You could, if you were brave, use SetWindowSubclass to subclass the main Notepad++ window, intercept IDM_FILE_SAVEAS, and call your own routine instead.
-
As an example, I want to trigger my action wehn saving a file with the extension .special. When I open a file log.txt and select saveAs and enter log.special, then I still get the Filename log.txt from NPPN_FILEBEFORESAVE, hence my action will not trigger
As @Coises said,
NPPN_FILESAVED
should be used to listen for when a file is finished saving. As the name implies,NPPN_FILEBEFORESAVE
fires before the file is saved, so you should not be too surprised that you get the old name of the buffer when you respond to this notification.To respond to a file being renamed, use
NPPN_FILEBEFORERENAME
,NPPN_FILERENAMED
andNPPN_FILERENAMECANCEL
.You need a global variable, the name of a file that is being renamed. Let’s call it
fileToRename
.- When you receive an
scNotification
with codeNPPN_FILEBEFORERENAME
, setfileToRename
, to the name of the buffer to be renamed (useNPPM_GETFULLPATHFROMBUFFERID
withWPARAM
=scNotification->Header.idFrom
) - When you receive an
scNotification
with codeNPPN_FILERENAMECANCEL
, setfileToRename
toNULL
, because the file rename operation was cancelled. - When you receive an
scNotification
with codeNPPN_FILERENAMED
, you can setfileToRename
to the name of the file after being renamed (useNPPM_GETFULLPATHFROMBUFFERID
withWPARAM
=scNotification->Header.idFrom
)
If you don’t care about what the name of the file was
beforeafter it was renamed, you can also only listen toNPPN_FILERENAMED
. - When you receive an