From 624e5fa1aef00184ba2134956910e37171c76c8e Mon Sep 17 00:00:00 2001 From: Stefanos Anastasiou Date: Wed, 2 Dec 2015 16:02:30 +0100 Subject: [PATCH] Add new API NPPM_SAVEFILE to save any file. Close #1214, closes #817 This API saves a file without having to actually focus on the file. // VOID NPPM_SAVEFILE(0, const TCHAR *fileNameToSave) --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 3 +++ PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/NppBigSwitch.cpp | 5 +++++ PowerEditor/src/NppIO.cpp | 21 +++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 924f8b34..0645cc85 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -413,6 +413,9 @@ enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, W #define NPPM_SETEDITORBORDEREDGE (NPPMSG + 93) // VOID NPPM_SETEDITORBORDEREDGE(0, BOOL withEditorBorderEdgeOrNot) + #define NPPM_SAVEFILE (NPPMSG + 94) + // VOID NPPM_SAVEFILE(0, const TCHAR *fileNameToSave) + #define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 1d4a6659..abf2c148 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -240,6 +240,7 @@ public: bool fileCloseAllToRight(); bool fileSave(BufferID id = BUFFER_INVALID); bool fileSaveAll(); + bool fileSaveSpecific(const generic_string& fileNameToSave); bool fileSaveAs(BufferID id = BUFFER_INVALID, bool isSaveCopy = false); bool fileDelete(BufferID id = BUFFER_INVALID); bool fileRename(BufferID id = BUFFER_INVALID); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 72cc09fb..d4bbd78f 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -406,6 +406,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return fileSaveAll(); } + case NPPM_SAVEFILE: + { + return fileSaveSpecific((const TCHAR *)lParam); + } + case NPPM_GETCURRENTNATIVELANGENCODING: { return _nativeLangSpeaker.getLangEncoding(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index c20d7f60..d5190957 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1125,6 +1125,27 @@ bool Notepad_plus::fileSave(BufferID id) return false; } +bool Notepad_plus::fileSaveSpecific(const generic_string& fileNameToSave) +{ + BufferID idToSave = _mainDocTab.findBufferByName(fileNameToSave.c_str()); + if (idToSave == BUFFER_INVALID) + { + idToSave = _subDocTab.findBufferByName(fileNameToSave.c_str()); + } + //do not use else syntax, id might be taken from sub doc tab, + //in which case fileSave needs to be executed also + if (idToSave != BUFFER_INVALID) + { + fileSave(idToSave); + checkDocState(); + return true; + } + else + { + return false; + } +} + bool Notepad_plus::fileSaveAll() { if (viewVisible(MAIN_VIEW)) { for(int i = 0; i < _mainDocTab.nbItem(); ++i) {