[NEW_FEATURE] Automatic Backup System (in progress).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1218 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
7ec6d51d8f
commit
b30c3246d4
@ -3209,9 +3209,12 @@ 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)
|
||||
{
|
||||
// Before switching off, synchronize backup file
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
|
||||
}
|
||||
Buffer * pBuf = MainFileManager->getBufferByID(id);
|
||||
bool reload = pBuf->getNeedReload();
|
||||
if (reload)
|
||||
@ -4471,8 +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
|
||||
doClose(buffer->getID(), otherView(), true);
|
||||
doClose(buffer->getID(), currentView(), true);
|
||||
bool isBackupMode = nppGUI._isBackupMode;
|
||||
doClose(buffer->getID(), otherView(), isBackupMode);
|
||||
doClose(buffer->getID(), currentView(), isBackupMode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -5750,19 +5754,17 @@ void Notepad_plus::showQuoteFromIndex(int index) const
|
||||
|
||||
void Notepad_plus::launchDocumentBackupTask()
|
||||
{
|
||||
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, this, 0, NULL);
|
||||
size_t timer = NppParameters::getInstance()->getNppGUI()._backupTiming;
|
||||
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, &timer, 0, NULL);
|
||||
::CloseHandle(hThread);
|
||||
}
|
||||
|
||||
DWORD WINAPI Notepad_plus::backupDocument(void *param)
|
||||
{
|
||||
Notepad_plus *notepad_plus = static_cast<Notepad_plus *>(param);
|
||||
//static int i = 0;
|
||||
while (notepad_plus)
|
||||
size_t *timer = (size_t *)param;
|
||||
while (*timer)
|
||||
{
|
||||
::Sleep(7000);
|
||||
//printInt(i++);
|
||||
|
||||
::Sleep(*timer);
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -290,7 +290,8 @@ public:
|
||||
|
||||
void loadLastSession(){
|
||||
Session lastSession = (NppParameters::getInstance())->getSession();
|
||||
loadSession(lastSession, true);
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
loadSession(lastSession, isBackupMode);
|
||||
};
|
||||
|
||||
bool loadSession(Session & session, bool isBackupMode = false);
|
||||
|
@ -223,8 +223,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||
::MessageBoxA(NULL, dest, "", MB_OK);
|
||||
}
|
||||
|
||||
bool doBackup = true;
|
||||
if (doBackup)
|
||||
bool isBackupMode = nppGUI._isBackupMode;
|
||||
if (isBackupMode)
|
||||
{
|
||||
_notepad_plus_plus_core.checkModifiedDocument();
|
||||
// Lauch backup task
|
||||
|
@ -1398,6 +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)
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
|
||||
const NppGUI & nppgui = pNppParam->getNppGUI();
|
||||
@ -1409,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, true); //try closing files before doing anything else
|
||||
bool allClosed = fileCloseAll(false, isBackupMode); //try closing files before doing anything else
|
||||
|
||||
if (nppgui._rememberLastSession)
|
||||
{
|
||||
|
@ -117,9 +117,12 @@ void Notepad_plus::command(int id)
|
||||
break;
|
||||
|
||||
case IDM_FILE_CLOSEALL:
|
||||
fileCloseAll(true, false);
|
||||
{
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
fileCloseAll(isBackupMode, false);
|
||||
checkDocState();
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_FILE_CLOSEALL_BUT_CURRENT :
|
||||
fileCloseAllButCurrent();
|
||||
|
@ -597,7 +597,8 @@ 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();
|
||||
doClose(bufferID, viewToClose, true);
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
doClose(bufferID, viewToClose, isBackupMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -732,8 +733,9 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
|
||||
}
|
||||
|
||||
// Now we close.
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
|
||||
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), true);
|
||||
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isBackupMode);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -824,13 +826,15 @@ bool Notepad_plus::fileCloseAllButCurrent()
|
||||
}
|
||||
}
|
||||
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
//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
|
||||
//Set active tab to the last one closed.
|
||||
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(), true);
|
||||
doClose(_pNonDocTab->getBufferByIndex(i), otherView(), isBackupMode);
|
||||
}
|
||||
//hideView(otherView());
|
||||
}
|
||||
@ -840,7 +844,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
|
||||
if (i == active) { //dont close active index
|
||||
continue;
|
||||
}
|
||||
doClose(_pDocTab->getBufferByIndex(i), currentView(), true);
|
||||
doClose(_pDocTab->getBufferByIndex(i), currentView(), isBackupMode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1055,8 +1059,9 @@ bool Notepad_plus::fileDelete(BufferID id)
|
||||
MB_OK);
|
||||
return false;
|
||||
}
|
||||
doClose(bufferID, MAIN_VIEW, true);
|
||||
doClose(bufferID, SUB_VIEW, true);
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
doClose(bufferID, MAIN_VIEW, isBackupMode);
|
||||
doClose(bufferID, SUB_VIEW, isBackupMode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -111,9 +111,13 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
||||
buf->setDirty(isDirty);
|
||||
|
||||
if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
|
||||
{
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
if (isBackupMode)
|
||||
{
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@ -271,16 +275,24 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
||||
}
|
||||
}
|
||||
else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf() && _activeView == SUB_VIEW)
|
||||
{
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
if (isBackupMode)
|
||||
{
|
||||
// Before switching off, synchronize backup file
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
}
|
||||
// Switch off
|
||||
switchEditViewTo(MAIN_VIEW);
|
||||
}
|
||||
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf() && _activeView == MAIN_VIEW)
|
||||
{
|
||||
bool isBackupMode = NppParameters::getInstance()->getNppGUI()._isBackupMode;
|
||||
if (isBackupMode)
|
||||
{
|
||||
// Before switching off, synchronize backup file
|
||||
MainFileManager->backupCurrentBuffer();
|
||||
}
|
||||
// Switch off
|
||||
switchEditViewTo(SUB_VIEW);
|
||||
}
|
||||
|
@ -648,7 +648,7 @@ NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserSty
|
||||
_pXmlSessionDoc(NULL), _pXmlBlacklistDoc(NULL), _nbUserLang(0), _nbExternalLang(0),\
|
||||
_hUser32(NULL), _hUXTheme(NULL), _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\
|
||||
_pNativeLangSpeaker(NULL), _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1),\
|
||||
_asNotepadStyle(false), _isFindReplacing(false)/*, _forceLoadingSession(false)*/
|
||||
_asNotepadStyle(false), _isFindReplacing(false)
|
||||
{
|
||||
// init import UDL array
|
||||
_nbImportedULD = 0;
|
||||
@ -3859,6 +3859,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
|
||||
const TCHAR *pDir = element->Attribute(TEXT("dir"));
|
||||
if (pDir)
|
||||
_nppGUI._backupDir = pDir;
|
||||
|
||||
}
|
||||
else if (!lstrcmp(nm, TEXT("DockingManager")))
|
||||
{
|
||||
|
@ -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) {
|
||||
_fileSwitcherWithoutExtColumn(false), _isBackupMode(false), _backupTiming(7000) {
|
||||
_appPos.left = 0;
|
||||
_appPos.top = 0;
|
||||
_appPos.right = 700;
|
||||
@ -814,6 +814,15 @@ struct NppGUI
|
||||
generic_string _themeName;
|
||||
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 _isBackupMode;
|
||||
size_t _backupTiming;
|
||||
};
|
||||
|
||||
struct ScintillaViewParams
|
||||
@ -1492,6 +1501,7 @@ public:
|
||||
bool _isFindReplacing; // an on the fly variable for find/replace functions
|
||||
void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection);
|
||||
|
||||
|
||||
#ifdef UNICODE
|
||||
LocalizationSwitcher & getLocalizationSwitcher() {
|
||||
return _localizationSwitcher;
|
||||
|
@ -774,7 +774,6 @@ bool FileManager::deleteCurrentBufferBackup()
|
||||
buffer->setBackupFileName(TEXT(""));
|
||||
result = (::DeleteFile(file2Delete.c_str()) != 0);
|
||||
}
|
||||
//printStr(TEXT("backup deleted in deleteCurrentBufferBackup"));
|
||||
::ReleaseMutex(mutex);
|
||||
return result;
|
||||
}
|
||||
|
@ -321,8 +321,6 @@ public :
|
||||
|
||||
Lang * getCurrentLang() const;
|
||||
|
||||
//time_t getBackupModifiedTimeStamp() const {return _backupModifiedTimeStamp;};
|
||||
//void setBackupModifiedTimeStamp(time_t timestamp2Set) {_backupModifiedTimeStamp = timestamp2Set;};
|
||||
bool isModified() const {return _isModified;};
|
||||
void setModifiedStatus(bool isModified) {_isModified = isModified;};
|
||||
generic_string getBackupFileName() const {return _backupFileName;};
|
||||
|
Loading…
Reference in New Issue
Block a user