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)
This commit is contained in:
Stefanos Anastasiou 2015-12-02 16:02:30 +01:00 committed by Don Ho
parent 1c84051d99
commit 624e5fa1ae
4 changed files with 30 additions and 0 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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) {