diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 13dc24f6a..ad4e074b6 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -501,6 +501,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } case WM_COMMAND: + { if (HIWORD(wParam) == SCEN_SETFOCUS) { HWND hMain = _mainEditView.getHSelf(), hSec = _subEditView.getHSelf(); @@ -523,7 +524,20 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa else command(LOWORD(wParam)); } - return TRUE; + } + return TRUE; + + case NPPM_INTERNAL_SAVECURRENTSESSION: + { + NppParameters *nppParam = NppParameters::getInstance(); + if (nppParam->getNppGUI()._rememberLastSession && _rememberThisSession) + { + Session currentSession; + getCurrentOpenedFiles(currentSession, true); + nppParam->writeSession(currentSession); + } + } + return TRUE; case NPPM_INTERNAL_RELOADNATIVELANG: { diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 9ca133458..811dfbfe6 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1680,11 +1680,5 @@ void Notepad_plus::saveSession(const Session & session) void Notepad_plus::saveCurrentSession() { - NppParameters *nppParam = NppParameters::getInstance(); - if (nppParam->getNppGUI()._rememberLastSession && _rememberThisSession) - { - Session currentSession; - getCurrentOpenedFiles(currentSession, true); - nppParam->writeSession(currentSession); - } + ::PostMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_SAVECURRENTSESSION, 0, 0); } \ No newline at end of file diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index a5eb32b72..e2fd2bb8e 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -696,6 +696,9 @@ bool FileManager::backupCurrentBuffer() // Set created file name in buffer buffer->setBackupFileName(backupFilePath); + + // Session changes, save it + hasModifForSession = true; } @@ -743,7 +746,6 @@ bool FileManager::backupCurrentBuffer() { _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); buffer->setModifiedStatus(false); - hasModifForSession = true; result = true; //all done ::SetEvent(writeEvent); @@ -767,17 +769,20 @@ bool FileManager::backupCurrentBuffer() generic_string file2Delete = buffer->getBackupFileName(); buffer->setBackupFileName(TEXT("")); result = (::DeleteFile(file2Delete.c_str()) != 0); + + // Session changes, save it hasModifForSession = true; } //printStr(TEXT("backup deleted in backupCurrentBuffer")); result = true; // no backup file to delete } //printStr(TEXT("backup sync")); -/* - if (hasModifForSession) - _pNotepadPlus->saveCurrentSession(); -*/ + if (result && hasModifForSession) + { + //printStr(buffer->getBackupFileName().c_str()); + _pNotepadPlus->saveCurrentSession(); + } return result; } @@ -794,7 +799,7 @@ bool FileManager::deleteCurrentBufferBackup() if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0) { // problem!!! - printStr(TEXT("pb!!!")); + printStr(TEXT("WaitForSingleObject problem in deleteCurrentBufferBackup()!")); return false; } @@ -832,7 +837,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0) { // problem!!! - printStr(TEXT("pb!!!")); + printStr(TEXT("WaitForSingleObject problem in saveBuffer()!")); return false; } diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 7dfeaf8b9..ae417c88b 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -394,7 +394,9 @@ #define NPPM_INTERNAL_RECENTFILELIST_UPDATE (NOTEPADPLUS_USER_INTERNAL + 35) #define NPPM_INTERNAL_RECENTFILELIST_SWITCH (NOTEPADPLUS_USER_INTERNAL + 36) #define NPPM_INTERNAL_GETSCINTEDTVIEW (NOTEPADPLUS_USER_INTERNAL + 37) - #define NPPM_INTERNAL_ENABLESNAPSHOT (NOTEPADPLUS_USER_INTERNAL + 38) + #define NPPM_INTERNAL_ENABLESNAPSHOT (NOTEPADPLUS_USER_INTERNAL + 38) + #define NPPM_INTERNAL_SAVECURRENTSESSION (NOTEPADPLUS_USER_INTERNAL + 39) + //wParam: 0 //lParam: document new index