From 4c49b023ca73ddcb91b72d6e88c547b2b71363a3 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 13 Apr 2014 01:31:02 +0000 Subject: [PATCH] [NEW_FEATURE] Automatic Backup System (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1220 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 30 +++++++----- PowerEditor/src/Notepad_plus.h | 8 ++-- PowerEditor/src/Notepad_plus_Window.cpp | 4 +- PowerEditor/src/NppBigSwitch.cpp | 6 +-- PowerEditor/src/NppCommands.cpp | 4 +- PowerEditor/src/NppIO.cpp | 48 +++++++++---------- PowerEditor/src/NppNotification.cpp | 12 ++--- PowerEditor/src/Parameters.cpp | 17 +++---- PowerEditor/src/Parameters.h | 14 +++--- PowerEditor/src/ScitillaComponent/Buffer.cpp | 4 +- .../src/WinControls/Preference/preference.rc | 23 +++++---- .../WinControls/Preference/preferenceDlg.cpp | 44 ++++++++++++++--- .../WinControls/Preference/preference_rc.h | 5 ++ 13 files changed, 135 insertions(+), 84 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 6e3aac410..e64d79bf5 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3209,8 +3209,8 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne) { //scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + if (isSnapshotMode) { // Before switching off, synchronize backup file MainFileManager->backupCurrentBuffer(); @@ -4474,9 +4474,9 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) if (doCloseOrNot(buffer->getFullPathName()) == IDNO) { //close in both views, doing current view last since that has to remain opened - bool isBackupMode = nppGUI._isBackupMode; - doClose(buffer->getID(), otherView(), isBackupMode); - doClose(buffer->getID(), currentView(), isBackupMode); + bool isSnapshotMode = nppGUI._isSnapshotMode; + doClose(buffer->getID(), otherView(), isSnapshotMode); + doClose(buffer->getID(), currentView(), isSnapshotMode); } break; } @@ -5755,17 +5755,25 @@ void Notepad_plus::showQuoteFromIndex(int index) const void Notepad_plus::launchDocumentBackupTask() { - size_t timer = NppParameters::getInstance()->getNppGUI()._backupTiming; - HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, &timer, 0, NULL); + HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, NULL, 0, NULL); ::CloseHandle(hThread); } -DWORD WINAPI Notepad_plus::backupDocument(void *param) +DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/) { - size_t *timer = (size_t *)param; - while (*timer) + bool isSnapshotMode = true; + while (isSnapshotMode) { - ::Sleep(*timer); + size_t timer = NppParameters::getInstance()->getNppGUI()._snapshotBackupTiming; + if (timer < 1000) + timer = 1000; + + ::Sleep(timer); + + isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + if (!isSnapshotMode) + break; + MainFileManager->backupCurrentBuffer(); } return TRUE; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index f28bc659d..a706279ea 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -235,7 +235,7 @@ public: }; bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from - bool fileCloseAll(bool doDeleteBackup, bool isBackupMode = false); + bool fileCloseAll(bool doDeleteBackup, bool isSnapshotMode = false); bool fileCloseAllButCurrent(); bool fileCloseAllGiven(const std::vector &krvecBufferIndexes); bool fileCloseAllToLeft(); @@ -290,11 +290,11 @@ public: void loadLastSession(){ Session lastSession = (NppParameters::getInstance())->getSession(); - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - loadSession(lastSession, isBackupMode); + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + loadSession(lastSession, isSnapshotMode); }; - bool loadSession(Session & session, bool isBackupMode = false); + bool loadSession(Session & session, bool isSnapshotMode = false); void notifyBufferChanged(Buffer * buffer, int mask); bool findInFiles(); diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index e838725dc..e25cb0840 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -223,8 +223,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin ::MessageBoxA(NULL, dest, "", MB_OK); } - bool isBackupMode = nppGUI._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = nppGUI._isSnapshotMode; + if (isSnapshotMode) { _notepad_plus_plus_core.checkModifiedDocument(); // Lauch backup task diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 84bd17b25..72d794842 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1398,8 +1398,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa if (_pTrayIco) _pTrayIco->doTrayIcon(REMOVE); - bool isBackupMode = pNppParam->getNppGUI()._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = pNppParam->getNppGUI()._isSnapshotMode; + if (isSnapshotMode) MainFileManager->backupCurrentBuffer(); const NppGUI & nppgui = pNppParam->getNppGUI(); @@ -1411,7 +1411,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa //Causing them to show on restart even though they are loaded by session _lastRecentFileList.setLock(true); //only lock when the session is remembered } - bool allClosed = fileCloseAll(false, isBackupMode); //try closing files before doing anything else + bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else if (nppgui._rememberLastSession) { diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index a2d366ce3..341c03a87 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -118,8 +118,8 @@ void Notepad_plus::command(int id) case IDM_FILE_CLOSEALL: { - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - fileCloseAll(isBackupMode, false); + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + fileCloseAll(isSnapshotMode, false); checkDocState(); break; } diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index e716ab83d..9ca133458 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -43,8 +43,8 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe ::GetFullPathName(fileName, MAX_PATH, longFileName, NULL); ::GetLongPathName(longFileName, longFileName, MAX_PATH); - bool isBackupMode = backupFileName != NULL && PathFileExists(backupFileName); - if (isBackupMode && !PathFileExists(longFileName)) // UNTITLED + bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName); + if (isSnapshotMode && !PathFileExists(longFileName)) // UNTITLED { lstrcpy(longFileName, fileName); } @@ -98,7 +98,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe bool globbing = wcsrchr(longFileName, TCHAR('*')) || wcsrchr(longFileName, TCHAR('?')); - if (!isBackupMode) // if not backup mode, or backupfile path is invalid + if (!isSnapshotMode) // if not backup mode, or backupfile path is invalid { if (!PathFileExists(longFileName) && !globbing) { @@ -151,7 +151,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isRecursive, bool isRe } BufferID buffer; - if (isBackupMode) + if (isSnapshotMode) { buffer = MainFileManager->loadFile(longFileName, NULL, encoding, backupFileName, fileNameTimestamp); } @@ -597,12 +597,12 @@ bool Notepad_plus::fileClose(BufferID id, int curView) viewToClose = curView; //first check amount of documents, we dont want the view to hide if we closed a secondary doc with primary being empty //int nrDocs = _pDocTab->nbItem(); - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - doClose(bufferID, viewToClose, isBackupMode); + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + doClose(bufferID, viewToClose, isSnapshotMode); return true; } -bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isBackupMode) +bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode) { //closes all documents, makes the current view the only one visible @@ -617,7 +617,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isBackupMode) } else if (buf->isDirty()) { - if (isBackupMode) + if (isSnapshotMode) { } @@ -650,7 +650,7 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isBackupMode) } else if (buf->isDirty()) { - if (isBackupMode) + if (isSnapshotMode) { } @@ -733,9 +733,9 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector &krvecBufferIndexes) } // Now we close. - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; for(std::vector::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) { - doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isBackupMode); + doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isSnapshotMode); } return true; @@ -826,7 +826,7 @@ bool Notepad_plus::fileCloseAllButCurrent() } } - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; //Then start closing, inactive view first so the active is left open if (bothActive()) { //first close all docs in non-current view, which gets closed automatically @@ -834,7 +834,7 @@ bool Notepad_plus::fileCloseAllButCurrent() activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView()); for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left - doClose(_pNonDocTab->getBufferByIndex(i), otherView(), isBackupMode); + doClose(_pNonDocTab->getBufferByIndex(i), otherView(), isSnapshotMode); } //hideView(otherView()); } @@ -844,7 +844,7 @@ bool Notepad_plus::fileCloseAllButCurrent() if (i == active) { //dont close active index continue; } - doClose(_pDocTab->getBufferByIndex(i), currentView(), isBackupMode); + doClose(_pDocTab->getBufferByIndex(i), currentView(), isSnapshotMode); } return true; } @@ -1059,9 +1059,9 @@ bool Notepad_plus::fileDelete(BufferID id) MB_OK); return false; } - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - doClose(bufferID, MAIN_VIEW, isBackupMode); - doClose(bufferID, SUB_VIEW, isBackupMode); + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + doClose(bufferID, MAIN_VIEW, isSnapshotMode); + doClose(bufferID, SUB_VIEW, isSnapshotMode); return true; } return false; @@ -1332,7 +1332,7 @@ bool Notepad_plus::loadSession(Session & session) } */ -bool Notepad_plus::loadSession(Session & session, bool isBackupMode) +bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode) { NppParameters *pNppParam = NppParameters::getInstance(); bool allSessionFilesLoaded = true; @@ -1362,12 +1362,12 @@ bool Notepad_plus::loadSession(Session & session, bool isBackupMode) } if (PathFileExists(pFn)) { - if (isBackupMode && session._mainViewFiles[i]._backupFilePath != TEXT("")) + if (isSnapshotMode && session._mainViewFiles[i]._backupFilePath != TEXT("")) lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding, session._mainViewFiles[i]._backupFilePath.c_str(), session._mainViewFiles[i]._originalFileLastModifTimestamp); else lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding); } - else if (isBackupMode && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) + else if (isSnapshotMode && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) { lastOpened = doOpen(pFn, false, false, session._mainViewFiles[i]._encoding, session._mainViewFiles[i]._backupFilePath.c_str(), session._mainViewFiles[i]._originalFileLastModifTimestamp); } @@ -1409,7 +1409,7 @@ bool Notepad_plus::loadSession(Session & session, bool isBackupMode) if (session._mainViewFiles[i]._encoding != -1) buf->setEncoding(session._mainViewFiles[i]._encoding); - if (isBackupMode && session._mainViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) + if (isSnapshotMode && session._mainViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str())) buf->setDirty(true); //Force in the document so we can add the markers @@ -1456,7 +1456,7 @@ bool Notepad_plus::loadSession(Session & session, bool isBackupMode) } if (PathFileExists(pFn)) { - if (isBackupMode && session._subViewFiles[i]._backupFilePath != TEXT("")) + if (isSnapshotMode && session._subViewFiles[i]._backupFilePath != TEXT("")) lastOpened = doOpen(pFn, false, false, session._subViewFiles[i]._encoding, session._subViewFiles[i]._backupFilePath.c_str(), session._subViewFiles[i]._originalFileLastModifTimestamp); else lastOpened = doOpen(pFn, false, false, session._subViewFiles[i]._encoding); @@ -1466,7 +1466,7 @@ bool Notepad_plus::loadSession(Session & session, bool isBackupMode) loadBufferIntoView(lastOpened, SUB_VIEW); } } - else if (isBackupMode && PathFileExists(session._subViewFiles[i]._backupFilePath.c_str())) + else if (isSnapshotMode && PathFileExists(session._subViewFiles[i]._backupFilePath.c_str())) { lastOpened = doOpen(pFn, false, false, session._subViewFiles[i]._encoding, session._subViewFiles[i]._backupFilePath.c_str(), session._subViewFiles[i]._originalFileLastModifTimestamp); } @@ -1516,7 +1516,7 @@ bool Notepad_plus::loadSession(Session & session, bool isBackupMode) buf->setLangType(typeToSet, pLn); buf->setEncoding(session._subViewFiles[k]._encoding); - if (isBackupMode && session._subViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._subViewFiles[i]._backupFilePath.c_str())) + if (isSnapshotMode && session._subViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._subViewFiles[i]._backupFilePath.c_str())) buf->setDirty(true); //Force in the document so we can add the markers diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 53883ad9a..f50402ce9 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -112,8 +112,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (notification->nmhdr.code == SCN_SAVEPOINTREACHED) { - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + if (isSnapshotMode) { MainFileManager->backupCurrentBuffer(); } @@ -276,8 +276,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) } else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf() && _activeView == SUB_VIEW) { - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + if (isSnapshotMode) { // Before switching off, synchronize backup file MainFileManager->backupCurrentBuffer(); @@ -287,8 +287,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) } else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf() && _activeView == MAIN_VIEW) { - bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode; - if (isBackupMode) + bool isSnapshotMode = NppParameters::getInstance()->getNppGUI()._isSnapshotMode; + if (isSnapshotMode) { // Before switching off, synchronize backup file MainFileManager->backupCurrentBuffer(); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index fd97c5b5b..52f21a596 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -3860,12 +3860,13 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) if (pDir) _nppGUI._backupDir = pDir; - const TCHAR *isBackupMode = element->Attribute(TEXT("isBackupMode")); - _nppGUI._isBackupMode = (isBackupMode && !lstrcmp(isBackupMode, TEXT("yes"))); + const TCHAR *isSnapshotModeStr = element->Attribute(TEXT("isSnapshotMode")); + if (isSnapshotModeStr && !lstrcmp(isSnapshotModeStr, TEXT("no"))) + _nppGUI._isSnapshotMode = false; int timing; - if (element->Attribute(TEXT("backupTiming"), &timing)) - _nppGUI._backupTiming = timing; + if (element->Attribute(TEXT("snapshotBackupTiming"), &timing)) + _nppGUI._snapshotBackupTiming = timing; } else if (!lstrcmp(nm, TEXT("DockingManager"))) @@ -4719,8 +4720,8 @@ bool NppParameters::writeGUIParams() element->SetAttribute(TEXT("useCustumDir"), _nppGUI._useDir?TEXT("yes"):TEXT("no")); element->SetAttribute(TEXT("dir"), _nppGUI._backupDir.c_str()); - element->SetAttribute(TEXT("isBackupMode"), _nppGUI._isBackupMode?TEXT("yes"):TEXT("no")); - element->SetAttribute(TEXT("backupTiming"), _nppGUI._backupTiming); + element->SetAttribute(TEXT("isSnapshotMode"), _nppGUI._isSnapshotMode?TEXT("yes"):TEXT("no")); + element->SetAttribute(TEXT("snapshotBackupTiming"), _nppGUI._snapshotBackupTiming); backExist = true; } else if (!lstrcmp(nm, TEXT("MRU"))) @@ -4997,8 +4998,8 @@ bool NppParameters::writeGUIParams() GUIConfigElement->SetAttribute(TEXT("useCustumDir"), _nppGUI._useDir?TEXT("yes"):TEXT("no")); GUIConfigElement->SetAttribute(TEXT("dir"), _nppGUI._backupDir.c_str()); - GUIConfigElement->SetAttribute(TEXT("isBackupMode"), _nppGUI._isBackupMode?TEXT("yes"):TEXT("no")); - GUIConfigElement->SetAttribute(TEXT("backupTiming"), _nppGUI._backupTiming); + GUIConfigElement->SetAttribute(TEXT("isSnapshotMode"), _nppGUI._isSnapshotMode?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("snapshotBackupTiming"), _nppGUI._snapshotBackupTiming); } if (!doTaskListExist) diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index df7e1f9c4..ff5e0ae8e 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -714,7 +714,7 @@ struct NppGUI _autocStatus(autoc_both), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")),\ _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _enableMultiSelection(false), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false),\ _smartHiliteCaseSensitive(false), _leftmostDelimiter('('), _rightmostDelimiter(')'), _delimiterSelectionOnEntireDocument(false), _multiInstSetting(monoInst),\ - _fileSwitcherWithoutExtColumn(false), _isBackupMode(false), _backupTiming(7000) { + _fileSwitcherWithoutExtColumn(false), _isSnapshotMode(true), _snapshotBackupTiming(7000) { _appPos.left = 0; _appPos.top = 0; _appPos.right = 700; @@ -815,13 +815,13 @@ struct NppGUI MultiInstSetting _multiInstSetting; bool _fileSwitcherWithoutExtColumn; /* - bool isBackupMode() const {return _isBackupMode;}; - void setBackupMode(bool doBackup) {_isBackupMode = doBackup;}; - size_t getBackupTiming() const {return _backupTiming;}; - void setBackupTiming(size_t timing) {_backupTiming = timing;}; + bool isSnapshotMode() const {return _isSnapshotMode;}; + void setBackupMode(bool doBackup) {_isSnapshotMode = doBackup;}; + size_t getBackupTiming() const {return _snapshotBackupTiming;}; + void setBackupTiming(size_t timing) {_snapshotBackupTiming = timing;}; */ - bool _isBackupMode; - size_t _backupTiming; + bool _isSnapshotMode; + size_t _snapshotBackupTiming; }; struct ScintillaViewParams diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 834953233..99bcc10df 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -470,8 +470,8 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin ::GetFullPathName(filename, MAX_PATH, fullpath, NULL); ::GetLongPathName(fullpath, fullpath, MAX_PATH); - bool isBackupMode = backupFileName != NULL && PathFileExists(backupFileName); - if (isBackupMode && !PathFileExists(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED + bool isSnapshotMode = backupFileName != NULL && PathFileExists(backupFileName); + if (isSnapshotMode && !PathFileExists(fullpath)) // if backup mode and fullpath doesn't exist, we guess is UNTITLED { lstrcpy(fullpath, filename); // we restore fullpath with filename, in our case is "new #" } diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 840f68afe..4ca385c42 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -289,15 +289,20 @@ IDD_PREFERENCE_BACKUP_BOX DIALOGEX 0, 0, 455, 185 STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - GROUPBOX "Backup",IDC_BACKUPDIR_GRP_STATIC,79,19,289,128,BS_CENTER - CONTROL "None",IDC_RADIO_BKNONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,104,32,87,10 - CONTROL "Simple backup",IDC_RADIO_BKSIMPLE,"Button",BS_AUTORADIOBUTTON,104,46,111,10 - CONTROL "Verbose backup",IDC_RADIO_BKVERBOSE,"Button",BS_AUTORADIOBUTTON,104,60,111,10 - GROUPBOX "Custom Backup Directory",IDC_BACKUPDIR_USERCUSTOMDIR_GRPSTATIC,95,87,260,40 - CONTROL "",IDC_BACKUPDIR_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,87,8,10 - RTEXT "Directory :",IDD_BACKUPDIR_STATIC,99,98,40,8 - EDITTEXT IDC_BACKUPDIR_EDIT,146,102,179,14,ES_AUTOHSCROLL - PUSHBUTTON "...",IDD_BACKUPDIR_BROWSE_BUTTON,332,102,16,14 + GROUPBOX "Backup on save",IDC_BACKUPDIR_GRP_STATIC,79,69,289,110,BS_CENTER + CONTROL "None",IDC_RADIO_BKNONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,104,80,87,10 + CONTROL "Simple backup",IDC_RADIO_BKSIMPLE,"Button",BS_AUTORADIOBUTTON,104,94,111,10 + CONTROL "Verbose backup",IDC_RADIO_BKVERBOSE,"Button",BS_AUTORADIOBUTTON,104,108,111,10 + GROUPBOX "Custom Backup Directory",IDC_BLINKRATE_STATIC,95,129,260,40 + CONTROL "",IDC_BACKUPDIR_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,91,129,8,10 + RTEXT "Directory :",IDD_BACKUPDIR_STATIC,99,146,40,8 + EDITTEXT IDC_BACKUPDIR_EDIT,146,144,179,14,ES_AUTOHSCROLL + PUSHBUTTON "...",IDD_BACKUPDIR_BROWSE_BUTTON,332,144,16,14 + GROUPBOX "Snapshot and periodic backup",IDC_BACKUPDIR_RESTORESESSION_GRP_STATIC,79,1,289,59,BS_CENTER + CONTROL "Enable",IDC_BACKUPDIR_RESTORESESSION_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,105,17,101,10 + EDITTEXT IDC_BACKUPDIR_RESTORESESSION_EDIT,164,35,21,14,ES_NUMBER + RTEXT "Backup in every",IDD_BACKUPDIR_RESTORESESSION_STATIC1,82,37,78,8 + LTEXT "seconds",IDD_BACKUPDIR_RESTORESESSION_STATIC2,190,37,66,8 END IDD_PREFERENCE_AUTOCOMPLETION_BOX DIALOGEX 0, 0, 455, 185 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index febbbf072..3eb379a97 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -2163,7 +2163,6 @@ BOOL CALLBACK PrintSettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) } - BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) { NppParameters *pNppParam = NppParameters::getInstance(); @@ -2172,21 +2171,26 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) { case WM_INITDIALOG : { - int ID2Check = 0; + bool snapshotCheck = nppGUI._isSnapshotMode; + ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_RESTORESESSION_CHECK, BM_SETCHECK, snapshotCheck?BST_CHECKED:BST_UNCHECKED, 0); + int periodicBackupInSec = nppGUI._snapshotBackupTiming/1000; + ::SetDlgItemInt(_hSelf, IDC_BACKUPDIR_RESTORESESSION_EDIT, periodicBackupInSec, FALSE); + + int ID2CheckBackupOnSave = 0; switch (nppGUI._backup) { case bak_simple : - ID2Check = IDC_RADIO_BKSIMPLE; + ID2CheckBackupOnSave = IDC_RADIO_BKSIMPLE; break; case bak_verbose : - ID2Check = IDC_RADIO_BKVERBOSE; + ID2CheckBackupOnSave = IDC_RADIO_BKVERBOSE; break; default : //bak_none - ID2Check = IDC_RADIO_BKNONE; + ID2CheckBackupOnSave = IDC_RADIO_BKNONE; } - ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, ID2CheckBackupOnSave, BM_SETCHECK, BST_CHECKED, 0); if (nppGUI._useDir) ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_CHECK, BM_SETCHECK, BST_CHECKED, 0); @@ -2209,11 +2213,34 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) nppGUI._backupDir = inputDir; return TRUE; } + + case IDC_BACKUPDIR_RESTORESESSION_EDIT: + { + nppGUI._snapshotBackupTiming = ::GetDlgItemInt(_hSelf, IDC_BACKUPDIR_RESTORESESSION_EDIT, NULL, FALSE) * 1000; + if (!nppGUI._snapshotBackupTiming) + { + nppGUI._snapshotBackupTiming = 1000; + ::SetDlgItemInt(_hSelf, IDC_BACKUPDIR_RESTORESESSION_EDIT, 1, FALSE); + } + return TRUE; + } } } switch (wParam) { + case IDC_BACKUPDIR_RESTORESESSION_CHECK: + { + nppGUI._isSnapshotMode = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_RESTORESESSION_CHECK, BM_GETCHECK, 0, 0); + updateBackupGUI(); + + if (nppGUI._isSnapshotMode) + { + // Launch thread + } + return TRUE; + } + case IDC_RADIO_BKSIMPLE: { nppGUI._backup = bak_simple; @@ -2259,6 +2286,11 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) void BackupDlg::updateBackupGUI() { + bool isSnapshot = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_RESTORESESSION_CHECK, BM_GETCHECK, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_RESTORESESSION_STATIC1), isSnapshot); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_RESTORESESSION_EDIT), isSnapshot); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_RESTORESESSION_STATIC2), isSnapshot); + bool noBackup = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIO_BKNONE, BM_GETCHECK, 0, 0); bool isEnableGlobableCheck = false; bool isEnableLocalCheck = false; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index 97e78a56e..0edd1470c 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -280,6 +280,11 @@ #define IDD_AUTOC_STATIC_NOTE (IDD_PREFERENCE_BACKUP_BOX + 14) #define IDD_FUNC_CHECK (IDD_PREFERENCE_BACKUP_BOX + 15) #define IDD_AUTOC_BOTHRADIO (IDD_PREFERENCE_BACKUP_BOX + 16) + #define IDC_BACKUPDIR_RESTORESESSION_GRP_STATIC (IDD_PREFERENCE_BACKUP_BOX + 17) + #define IDC_BACKUPDIR_RESTORESESSION_CHECK (IDD_PREFERENCE_BACKUP_BOX + 18) + #define IDD_BACKUPDIR_RESTORESESSION_STATIC1 (IDD_PREFERENCE_BACKUP_BOX + 19) + #define IDC_BACKUPDIR_RESTORESESSION_EDIT (IDD_PREFERENCE_BACKUP_BOX + 20) + #define IDD_BACKUPDIR_RESTORESESSION_STATIC2 (IDD_PREFERENCE_BACKUP_BOX + 21) #define IDD_PREFERENCE_AUTOCOMPLETION_BOX 6850 //(IDD_PREFERENCE_BOX + 850) #define IDD_AUTOCINSERT_GRPSTATIC (IDD_PREFERENCE_AUTOCOMPLETION_BOX + 1)