From 4a794ac8b18f8a28ddf28d4ceba7d4fdfde6f3fe Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 1 Apr 2014 22:52:12 +0000 Subject: [PATCH] [NEW_FEATURE] Automatic Backup System (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1209 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 2 +- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/ScitillaComponent/Buffer.cpp | 42 +++++--------------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 4284b263..04761fa1 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) +void Notepad_plus::getCurrentOpenedFiles(Session & session, bool /*includUntitledDoc*/) { _mainEditView.saveCurrentPos(); //save position so itll be correct in the session _subEditView.saveCurrentPos(); //both views diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 9634c668..7c574f4d 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -271,7 +271,7 @@ public: (NppParameters::getInstance())->writeFindHistory(); }; - void getCurrentOpenedFiles(Session & session); + void getCurrentOpenedFiles(Session & session, bool includUntitledDoc = false); bool fileLoadSession(const TCHAR *fn = NULL); const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 2a08eea5..e7d6c9f4 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -621,23 +621,8 @@ bool FileManager::backupCurrentBuffer() Buffer * buffer = _pNotepadPlus->getCurrentBuffer(); bool result = false; + bool hasModifForSession = false; -/* - time_t currentBakModifTimestamp = buffer->getBackupModifiedTimeStamp(); - time_t lastBakModifTimestamp = 0; - - if (PathFileExists(fullpath)) - { - struct _stat statBuf; - if (!generic_stat(fullpath, &statBuf)) - { - if (currentBakModifTimestamp == statBuf.st_mtime) - return true; - - lastBakModifTimestamp = statBuf.st_mtime; - } - } -*/ if (buffer->isDirty()) { if (buffer->isModified()) // buffer dirty and modified, write the backup file @@ -724,23 +709,9 @@ bool FileManager::backupCurrentBuffer() // Note that fwrite() doesn't return the number of bytes written, but rather the number of ITEMS. if(items_written == 1) { - _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); - /* - if (lastBakModifTimestamp != 0) - buffer->setBackupModifiedTimeStamp(lastBakModifTimestamp); - else - { - struct _stat statBuf; - if (!generic_stat(fullpath, &statBuf)) - { - buffer->setBackupModifiedTimeStamp(statBuf.st_mtime); - } - } - */ - buffer->setModifiedStatus(false); - + hasModifForSession = true; result = true; //all done } } @@ -759,11 +730,20 @@ bool FileManager::backupCurrentBuffer() generic_string file2Delete = buffer->getBackupFileName(); buffer->setBackupFileName(TEXT("")); result = (::DeleteFile(file2Delete.c_str()) != 0); + hasModifForSession = true; } //printStr(TEXT("backup deleted in backupCurrentBuffer")); result = true; // no backup file to delete } //printStr(TEXT("backup sync")); +/* + if (hasModifForSession && nppgui._rememberLastSession && _rememberThisSession) +{ + Session currentSession; + getCurrentOpenedFiles(currentSession); + saveSession(currentSession); +} + */ ::ReleaseMutex(mutex); return result; }