Skip to content

Commit

Permalink
[NEW_FEATURE] Automatic Backup System (in progress).
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1206 f5eea248-9336-0410-98b8-ebc06183d4e3
  • Loading branch information
donho committed Mar 31, 2014
1 parent 97c7395 commit 3318983
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 202 deletions.
14 changes: 9 additions & 5 deletions PowerEditor/src/Notepad_plus.cpp
Expand Up @@ -3201,6 +3201,10 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode)
bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
{
//scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED

// Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer();

Buffer * pBuf = MainFileManager->getBufferByID(id);
bool reload = pBuf->getNeedReload();
if (reload)
Expand Down Expand Up @@ -4275,7 +4279,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session)
generic_string languageName = getLangFromMenu(buf);
const TCHAR *langName = languageName.c_str();

sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(&_mainEditView));
sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(&_mainEditView), buf->getBackupFileName().c_str(), int(buf->getLastModifiedTimestamp()));

//_mainEditView.activateBuffer(buf->getID());
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
Expand Down Expand Up @@ -4319,7 +4323,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session)
generic_string languageName = getLangFromMenu( buf );
const TCHAR *langName = languageName.c_str();

sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(&_subEditView));
sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getEncoding(), buf->getPosition(&_subEditView), buf->getBackupFileName().c_str(), int(buf->getLastModifiedTimestamp()));

_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT);
Expand Down Expand Up @@ -4503,8 +4507,8 @@ 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());
doClose(buffer->getID(), currentView());
doClose(buffer->getID(), otherView(), true);
doClose(buffer->getID(), currentView(), true);
}
break;
}
Expand Down Expand Up @@ -5790,7 +5794,7 @@ DWORD WINAPI Notepad_plus::backupDocument(void *param)
//static int i = 0;
while (notepad_plus)
{
::Sleep(3000);
::Sleep(7000);
//printInt(i++);

MainFileManager->backupCurrentBuffer();
Expand Down
4 changes: 2 additions & 2 deletions PowerEditor/src/Notepad_plus.h
Expand Up @@ -223,7 +223,7 @@ friend class Notepad_plus_Window;
BufferID doOpen(const TCHAR *fileName, bool isRecursive = false, bool isReadOnly = false, int encoding = -1);
bool doReload(BufferID id, bool alert = true);
bool doSave(BufferID, const TCHAR * filename, bool isSaveCopy = false);
void doClose(BufferID, int whichOne);
void doClose(BufferID, int whichOne, bool doDeleteBackup = false);
//bool doDelete(const TCHAR *fileName) const {return ::DeleteFile(fileName) != 0;};

void fileOpen();
Expand All @@ -235,7 +235,7 @@ friend class Notepad_plus_Window;
};

bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from
bool fileCloseAll();
bool fileCloseAll(bool doDeleteBackup);
bool fileCloseAllButCurrent();
bool fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes);
bool fileCloseAllToLeft();
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/Notepad_plus_Window.cpp
Expand Up @@ -224,7 +224,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
}

// Lauch backup task
//_notepad_plus_plus_core.launchDocumentBackupTask();
_notepad_plus_plus_core.launchDocumentBackupTask();
}

bool Notepad_plus_Window::isDlgsMsg(MSG *msg, bool unicodeSupported) const
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/NppBigSwitch.cpp
Expand Up @@ -1407,7 +1407,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(); //try closing files before doing anything else
bool allClosed = fileCloseAll(false); //try closing files before doing anything else

if (nppgui._rememberLastSession)
{
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/NppCommands.cpp
Expand Up @@ -117,7 +117,7 @@ void Notepad_plus::command(int id)
break;

case IDM_FILE_CLOSEALL:
fileCloseAll();
fileCloseAll(true);
checkDocState();
break;

Expand Down
23 changes: 13 additions & 10 deletions PowerEditor/src/NppIO.cpp
Expand Up @@ -333,13 +333,16 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
return res;
}

void Notepad_plus::doClose(BufferID id, int whichOne)
void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
{
DocTabView *tabToClose = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
int i = tabToClose->getIndexByBuffer(id);
if (i == -1)
return;

if (doDeleteBackup)
MainFileManager->deleteCurrentBufferBackup();

Buffer * buf = MainFileManager->getBufferByID(id);

// Notify plugins that current file is about to be closed
Expand Down Expand Up @@ -575,11 +578,11 @@ 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);
doClose(bufferID, viewToClose, true);
return true;
}

bool Notepad_plus::fileCloseAll()
bool Notepad_plus::fileCloseAll(bool doDeleteBackup)
{
//closes all documents, makes the current view the only one visible

Expand Down Expand Up @@ -643,14 +646,14 @@ bool Notepad_plus::fileCloseAll()
//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());
doClose(_pNonDocTab->getBufferByIndex(i), otherView(), doDeleteBackup);
}
//hideView(otherView());
}

activateBuffer(_pDocTab->getBufferByIndex(0), currentView());
for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
doClose(_pDocTab->getBufferByIndex(i), currentView());
doClose(_pDocTab->getBufferByIndex(i), currentView(), doDeleteBackup);
}
return true;
}
Expand Down Expand Up @@ -697,7 +700,7 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)

// Now we close.
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView());
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), true);
}

return true;
Expand Down Expand Up @@ -794,7 +797,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
//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());
doClose(_pNonDocTab->getBufferByIndex(i), otherView(), true);
}
//hideView(otherView());
}
Expand All @@ -804,7 +807,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
if (i == active) { //dont close active index
continue;
}
doClose(_pDocTab->getBufferByIndex(i), currentView());
doClose(_pDocTab->getBufferByIndex(i), currentView(), true);
}
return true;
}
Expand Down Expand Up @@ -1019,8 +1022,8 @@ bool Notepad_plus::fileDelete(BufferID id)
MB_OK);
return false;
}
doClose(bufferID, MAIN_VIEW);
doClose(bufferID, SUB_VIEW);
doClose(bufferID, MAIN_VIEW, true);
doClose(bufferID, SUB_VIEW, true);
return true;
}
return false;
Expand Down
16 changes: 11 additions & 5 deletions PowerEditor/src/NppNotification.cpp
Expand Up @@ -109,12 +109,12 @@ BOOL Notepad_plus::notify(SCNotification *notification)
}
bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT;
buf->setDirty(isDirty);
/*

if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
{
MainFileManager->backupCurrentBuffer();
}
*/

break;
}

Expand Down Expand Up @@ -234,7 +234,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
int open = 1;
if (isFromPrimary || isFromSecondary)
open = notifyDocTab->nbItem();
doClose(bufferToClose, iView);
doClose(bufferToClose, iView, true);
//if (open == 1 && canHideView(iView))
// hideView(iView);
break;
Expand Down Expand Up @@ -277,12 +277,18 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_statusBar.setText((_pEditView->execute(SCI_GETOVERTYPE))?TEXT("OVR"):TEXT("INS"), STATUSBAR_TYPING_MODE);
}
}
else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf())
else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf() && _activeView == SUB_VIEW)
{
// Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer();
// Switch off
switchEditViewTo(MAIN_VIEW);
}
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf())
else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf() && _activeView == MAIN_VIEW)
{
// Before switching off, synchronize backup file
MainFileManager->backupCurrentBuffer();
// Switch off
switchEditViewTo(SUB_VIEW);
}

Expand Down

0 comments on commit 3318983

Please sign in to comment.