Howto close current file / editor witout savequestion
-
Hello,
i programming a litle plugin on C#.
How can i close the current file / editor without question for save changing?
regards Mario
-
do you want to discard the changes or to always save it?
-
Being a Pythonscript programmer, and having wanted to do the same type of thing in the past, I didn’t really find that it is possible in P.S., but maybe with a true plugin it IS possible?
Anyway, what I do in a P.S. is, since you are discarding changes anyway, is execute repetitive “undo” operations until you get the file back to an unmodified state. Then it can be closed without Notepad++ prompting for anything.
Of course, if you want to save the changes, what I do via P.S. is a “save” and then the “close” on the file. There should be something mimicing that for true plugins.
-
@Alan-Kilborn said in Howto close current file / editor witout savequestion:
Anyway, what I do in a P.S. is, since you are discarding changes anyway, is execute repetitive “undo” operations until you get the file back to an unmodified state.
Maybe I’m wrong but shouldn’t this work to discard the changes?
editor.setSavePoint() notepad.close()
-
-
Hello,
do you want to discard the changes or to always save it?
yes i want discard all changes and close only the file, not the notepad.
-
Then I would say use the c# equivalent messages to my pythonscript example.
-
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); editor.SetSavePoint();
works and set the document ans unchanged.
but how close the document “notepad.close” dosnt exist.
-
Oh, ok - you need to use SendMessage and menuCommand enums.
From python this is likedef close(self) -> None: # done ''' Closes the currently active document ''' self.menuCommand(MENUCOMMAND.FILE_CLOSE) def menuCommand(self, commandID: int) -> None: # done ''' Runs a Notepad++ menu command - just pass the commandID ''' self.__npp_send(NPPM_MENUCOMMAND, 0, commandID) def __npp_send(self, message: int, wparam: int=0, lparam: int=0) -> int: # done ''' internal function used to send npp messages to npp ''' result = user32.SendMessageW(self.hwnd, message, wparam, lparam) return result
WM_USER = 1024
NPPMSG = WM_USER + 1000
NPPM_MENUCOMMAND = NPPMSG + 48IDM = 40000
FILE = IDM + 1000
FILE_NEW = FILE + 1
FILE_OPEN = FILE + 2
FILE_CLOSE = FILE + 3MENUCOMMAND.FILE_CLOSE = IDM + FILE +3
self.hwnd is the handle from npp that you get via setInfo callback
-
@ all
i have found a solution:
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); editor.SetSavePoint(); Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_CLOSE);
work wit current tab.
thanks for inspiration