From ac4b7ea8dbb598910e19316af1bb496b795971d5 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 2 Apr 2014 22:02:10 +0000 Subject: [PATCH] [NEW_FEATURE] Automatic Backup System (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1211 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 49 ++++++++++---------- PowerEditor/src/Notepad_plus.h | 2 + PowerEditor/src/NppIO.cpp | 12 +++++ PowerEditor/src/ScitillaComponent/Buffer.cpp | 12 ++--- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 6cc682829..59dabbe7e 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -4245,7 +4245,7 @@ bool Notepad_plus::getIntegralDockingData(tTbData & dockData, int & iCont, bool } -void Notepad_plus::getCurrentOpenedFiles(Session & session, bool /*includUntitledDoc*/) +void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledDoc) { _mainEditView.saveCurrentPos(); //save position so itll be correct in the session _subEditView.saveCurrentPos(); //both views @@ -4270,33 +4270,34 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool /*includUntitle Buffer * buf = MainFileManager->getBufferByID(bufID); - if (PathFileExists(buf->getFullPathName())) + if (!includUntitledDoc) + if (!PathFileExists(buf->getFullPathName())) + continue; + + generic_string languageName = getLangFromMenu(buf); + const TCHAR *langName = languageName.c_str(); + sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(editView), buf->getBackupFileName().c_str(), int(buf->getLastModifiedTimestamp())); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); + int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT); + + for (int j = 0 ; j < maxLine ; ++j) { - generic_string languageName = getLangFromMenu(buf); - const TCHAR *langName = languageName.c_str(); - sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(editView), buf->getBackupFileName().c_str(), int(buf->getLastModifiedTimestamp())); - - _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); - int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT); - - for (int j = 0 ; j < maxLine ; ++j) + if ((_invisibleEditView.execute(SCI_MARKERGET, j)&(1 << MARK_BOOKMARK)) != 0) { - if ((_invisibleEditView.execute(SCI_MARKERGET, j)&(1 << MARK_BOOKMARK)) != 0) - { - sfi.marks.push_back(j); - } + sfi.marks.push_back(j); } - - if (i == activeIndex) - { - editView->getCurrentFoldStates(sfi._foldStates); - } - else - { - sfi._foldStates = buf->getHeaderLineState(editView); - } - viewFiles->push_back(sfi); } + + if (i == activeIndex) + { + editView->getCurrentFoldStates(sfi._foldStates); + } + else + { + sfi._foldStates = buf->getHeaderLineState(editView); + } + viewFiles->push_back(sfi); } } _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 7c574f4d6..57336a441 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -266,6 +266,8 @@ public: NppParameters::getInstance()->writeShortcuts(); }; void saveSession(const Session & session); + void saveCurrentSession(); + void saveFindHistory(){ _findReplaceDlg.saveFindHistory(); (NppParameters::getInstance())->writeFindHistory(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index c77cefc10..ca60f73a2 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1408,3 +1408,15 @@ void Notepad_plus::saveSession(const Session & session) { (NppParameters::getInstance())->writeSession(session); } + + +void Notepad_plus::saveCurrentSession() +{ + NppParameters *nppParam = NppParameters::getInstance(); + if (nppParam->getNppGUI()._rememberLastSession && _rememberThisSession) + { + Session currentSession; + getCurrentOpenedFiles(currentSession, true); + nppParam->writeSession(currentSession); + } +} \ No newline at end of file diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index e7d6c9f42..7f0af9a63 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -736,14 +736,10 @@ bool FileManager::backupCurrentBuffer() result = true; // no backup file to delete } //printStr(TEXT("backup sync")); -/* - if (hasModifForSession && nppgui._rememberLastSession && _rememberThisSession) -{ - Session currentSession; - getCurrentOpenedFiles(currentSession); - saveSession(currentSession); -} - */ + + if (hasModifForSession) + _pNotepadPlus->saveCurrentSession(); + ::ReleaseMutex(mutex); return result; }