[NEW_FEATURE] Automatic Backup System (in progress).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1206 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
97c7395059
commit
33189832ba
@ -3201,6 +3201,10 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode)
|
|||||||
bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
|
bool Notepad_plus::activateBuffer(BufferID id, int whichOne)
|
||||||
{
|
{
|
||||||
//scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED
|
//scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED
|
||||||
|
|
||||||
|
// Before switching off, synchronize backup file
|
||||||
|
MainFileManager->backupCurrentBuffer();
|
||||||
|
|
||||||
Buffer * pBuf = MainFileManager->getBufferByID(id);
|
Buffer * pBuf = MainFileManager->getBufferByID(id);
|
||||||
bool reload = pBuf->getNeedReload();
|
bool reload = pBuf->getNeedReload();
|
||||||
if (reload)
|
if (reload)
|
||||||
@ -4275,7 +4279,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session)
|
|||||||
generic_string languageName = getLangFromMenu(buf);
|
generic_string languageName = getLangFromMenu(buf);
|
||||||
const TCHAR *langName = languageName.c_str();
|
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());
|
//_mainEditView.activateBuffer(buf->getID());
|
||||||
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
||||||
@ -4319,7 +4323,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session)
|
|||||||
generic_string languageName = getLangFromMenu( buf );
|
generic_string languageName = getLangFromMenu( buf );
|
||||||
const TCHAR *langName = languageName.c_str();
|
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());
|
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
|
||||||
int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT);
|
int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT);
|
||||||
@ -4503,8 +4507,8 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
|
|||||||
if (doCloseOrNot(buffer->getFullPathName()) == IDNO)
|
if (doCloseOrNot(buffer->getFullPathName()) == IDNO)
|
||||||
{
|
{
|
||||||
//close in both views, doing current view last since that has to remain opened
|
//close in both views, doing current view last since that has to remain opened
|
||||||
doClose(buffer->getID(), otherView());
|
doClose(buffer->getID(), otherView(), true);
|
||||||
doClose(buffer->getID(), currentView());
|
doClose(buffer->getID(), currentView(), true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -5790,7 +5794,7 @@ DWORD WINAPI Notepad_plus::backupDocument(void *param)
|
|||||||
//static int i = 0;
|
//static int i = 0;
|
||||||
while (notepad_plus)
|
while (notepad_plus)
|
||||||
{
|
{
|
||||||
::Sleep(3000);
|
::Sleep(7000);
|
||||||
//printInt(i++);
|
//printInt(i++);
|
||||||
|
|
||||||
MainFileManager->backupCurrentBuffer();
|
MainFileManager->backupCurrentBuffer();
|
||||||
|
@ -223,7 +223,7 @@ public:
|
|||||||
BufferID doOpen(const TCHAR *fileName, bool isRecursive = false, bool isReadOnly = false, int encoding = -1);
|
BufferID doOpen(const TCHAR *fileName, bool isRecursive = false, bool isReadOnly = false, int encoding = -1);
|
||||||
bool doReload(BufferID id, bool alert = true);
|
bool doReload(BufferID id, bool alert = true);
|
||||||
bool doSave(BufferID, const TCHAR * filename, bool isSaveCopy = false);
|
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;};
|
//bool doDelete(const TCHAR *fileName) const {return ::DeleteFile(fileName) != 0;};
|
||||||
|
|
||||||
void fileOpen();
|
void fileOpen();
|
||||||
@ -235,7 +235,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from
|
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 fileCloseAllButCurrent();
|
||||||
bool fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes);
|
bool fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes);
|
||||||
bool fileCloseAllToLeft();
|
bool fileCloseAllToLeft();
|
||||||
|
@ -224,7 +224,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lauch backup task
|
// Lauch backup task
|
||||||
//_notepad_plus_plus_core.launchDocumentBackupTask();
|
_notepad_plus_plus_core.launchDocumentBackupTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notepad_plus_Window::isDlgsMsg(MSG *msg, bool unicodeSupported) const
|
bool Notepad_plus_Window::isDlgsMsg(MSG *msg, bool unicodeSupported) const
|
||||||
|
@ -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
|
//Causing them to show on restart even though they are loaded by session
|
||||||
_lastRecentFileList.setLock(true); //only lock when the session is remembered
|
_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)
|
if (nppgui._rememberLastSession)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ void Notepad_plus::command(int id)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IDM_FILE_CLOSEALL:
|
case IDM_FILE_CLOSEALL:
|
||||||
fileCloseAll();
|
fileCloseAll(true);
|
||||||
checkDocState();
|
checkDocState();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -333,13 +333,16 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
|
|||||||
return res;
|
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;
|
DocTabView *tabToClose = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
|
||||||
int i = tabToClose->getIndexByBuffer(id);
|
int i = tabToClose->getIndexByBuffer(id);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (doDeleteBackup)
|
||||||
|
MainFileManager->deleteCurrentBufferBackup();
|
||||||
|
|
||||||
Buffer * buf = MainFileManager->getBufferByID(id);
|
Buffer * buf = MainFileManager->getBufferByID(id);
|
||||||
|
|
||||||
// Notify plugins that current file is about to be closed
|
// Notify plugins that current file is about to be closed
|
||||||
@ -575,11 +578,11 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
|
|||||||
viewToClose = 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
|
//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();
|
//int nrDocs = _pDocTab->nbItem();
|
||||||
doClose(bufferID, viewToClose);
|
doClose(bufferID, viewToClose, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notepad_plus::fileCloseAll()
|
bool Notepad_plus::fileCloseAll(bool doDeleteBackup)
|
||||||
{
|
{
|
||||||
//closes all documents, makes the current view the only one visible
|
//closes all documents, makes the current view the only one visible
|
||||||
|
|
||||||
@ -643,14 +646,14 @@ bool Notepad_plus::fileCloseAll()
|
|||||||
//Set active tab to the last one closed.
|
//Set active tab to the last one closed.
|
||||||
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
||||||
for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
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());
|
//hideView(otherView());
|
||||||
}
|
}
|
||||||
|
|
||||||
activateBuffer(_pDocTab->getBufferByIndex(0), currentView());
|
activateBuffer(_pDocTab->getBufferByIndex(0), currentView());
|
||||||
for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -697,7 +700,7 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
|
|||||||
|
|
||||||
// Now we close.
|
// Now we close.
|
||||||
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
|
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;
|
return true;
|
||||||
@ -794,7 +797,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
|
|||||||
//Set active tab to the last one closed.
|
//Set active tab to the last one closed.
|
||||||
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView());
|
||||||
for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left
|
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());
|
//hideView(otherView());
|
||||||
}
|
}
|
||||||
@ -804,7 +807,7 @@ bool Notepad_plus::fileCloseAllButCurrent()
|
|||||||
if (i == active) { //dont close active index
|
if (i == active) { //dont close active index
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
doClose(_pDocTab->getBufferByIndex(i), currentView());
|
doClose(_pDocTab->getBufferByIndex(i), currentView(), true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1019,8 +1022,8 @@ bool Notepad_plus::fileDelete(BufferID id)
|
|||||||
MB_OK);
|
MB_OK);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
doClose(bufferID, MAIN_VIEW);
|
doClose(bufferID, MAIN_VIEW, true);
|
||||||
doClose(bufferID, SUB_VIEW);
|
doClose(bufferID, SUB_VIEW, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -109,12 +109,12 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||||||
}
|
}
|
||||||
bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT;
|
bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT;
|
||||||
buf->setDirty(isDirty);
|
buf->setDirty(isDirty);
|
||||||
/*
|
|
||||||
if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
|
if (notification->nmhdr.code == SCN_SAVEPOINTREACHED)
|
||||||
{
|
{
|
||||||
MainFileManager->backupCurrentBuffer();
|
MainFileManager->backupCurrentBuffer();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||||||
int open = 1;
|
int open = 1;
|
||||||
if (isFromPrimary || isFromSecondary)
|
if (isFromPrimary || isFromSecondary)
|
||||||
open = notifyDocTab->nbItem();
|
open = notifyDocTab->nbItem();
|
||||||
doClose(bufferToClose, iView);
|
doClose(bufferToClose, iView, true);
|
||||||
//if (open == 1 && canHideView(iView))
|
//if (open == 1 && canHideView(iView))
|
||||||
// hideView(iView);
|
// hideView(iView);
|
||||||
break;
|
break;
|
||||||
@ -277,12 +277,18 @@ BOOL Notepad_plus::notify(SCNotification *notification)
|
|||||||
_statusBar.setText((_pEditView->execute(SCI_GETOVERTYPE))?TEXT("OVR"):TEXT("INS"), STATUSBAR_TYPING_MODE);
|
_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);
|
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);
|
switchEditViewTo(SUB_VIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1628,7 +1628,6 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
|
|||||||
if (!sessionRoot)
|
if (!sessionRoot)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
TiXmlElement *actView = sessionRoot->ToElement();
|
TiXmlElement *actView = sessionRoot->ToElement();
|
||||||
size_t index;
|
size_t index;
|
||||||
const TCHAR *str = actView->Attribute(TEXT("activeView"), (int *)&index);
|
const TCHAR *str = actView->Attribute(TEXT("activeView"), (int *)&index);
|
||||||
@ -1637,17 +1636,24 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
|
|||||||
(*ptrSession)._activeView = index;
|
(*ptrSession)._activeView = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const size_t nbView = 2;
|
||||||
TiXmlNode *mainviewRoot = sessionRoot->FirstChildElement(TEXT("mainView"));
|
TiXmlNode *viewRoots[nbView];
|
||||||
if (mainviewRoot)
|
viewRoots[0] = sessionRoot->FirstChildElement(TEXT("mainView"));
|
||||||
|
viewRoots[1] = sessionRoot->FirstChildElement(TEXT("subView"));
|
||||||
|
for (size_t k = 0; k < nbView; ++k)
|
||||||
{
|
{
|
||||||
TiXmlElement *actIndex = mainviewRoot->ToElement();
|
if (viewRoots[k])
|
||||||
|
{
|
||||||
|
TiXmlElement *actIndex = viewRoots[k]->ToElement();
|
||||||
str = actIndex->Attribute(TEXT("activeIndex"), (int *)&index);
|
str = actIndex->Attribute(TEXT("activeIndex"), (int *)&index);
|
||||||
if (str)
|
if (str)
|
||||||
{
|
{
|
||||||
|
if (k == 0)
|
||||||
(*ptrSession)._activeMainIndex = index;
|
(*ptrSession)._activeMainIndex = index;
|
||||||
|
else // k == 1
|
||||||
|
(*ptrSession)._activeSubIndex = index;
|
||||||
}
|
}
|
||||||
for (TiXmlNode *childNode = mainviewRoot->FirstChildElement(TEXT("File"));
|
for (TiXmlNode *childNode = viewRoots[k]->FirstChildElement(TEXT("File"));
|
||||||
childNode ;
|
childNode ;
|
||||||
childNode = childNode->NextSibling(TEXT("File")) )
|
childNode = childNode->NextSibling(TEXT("File")) )
|
||||||
{
|
{
|
||||||
@ -1666,7 +1672,12 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
|
|||||||
langName = (childNode->ToElement())->Attribute(TEXT("lang"));
|
langName = (childNode->ToElement())->Attribute(TEXT("lang"));
|
||||||
int encoding = -1;
|
int encoding = -1;
|
||||||
const TCHAR *encStr = (childNode->ToElement())->Attribute(TEXT("encoding"), &encoding);
|
const TCHAR *encStr = (childNode->ToElement())->Attribute(TEXT("encoding"), &encoding);
|
||||||
sessionFileInfo sfi(fileName, langName, encStr?encoding:-1, position);
|
const TCHAR *backupFilePath = (childNode->ToElement())->Attribute(TEXT("backupFilePath"));
|
||||||
|
|
||||||
|
int fileModifiedTimestamp = 0;
|
||||||
|
(childNode->ToElement())->Attribute(TEXT("originalFileLastModifTimestamp"), &fileModifiedTimestamp);
|
||||||
|
|
||||||
|
sessionFileInfo sfi(fileName, langName, encStr?encoding:-1, position, backupFilePath, fileModifiedTimestamp);
|
||||||
|
|
||||||
for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
|
for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
|
||||||
markNode ;
|
markNode ;
|
||||||
@ -1691,71 +1702,14 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
|
|||||||
sfi._foldStates.push_back(lineNumber);
|
sfi._foldStates.push_back(lineNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (k == 0)
|
||||||
(*ptrSession)._mainViewFiles.push_back(sfi);
|
(*ptrSession)._mainViewFiles.push_back(sfi);
|
||||||
}
|
else // k == 1
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TiXmlNode *subviewRoot = sessionRoot->FirstChildElement(TEXT("subView"));
|
|
||||||
if (subviewRoot)
|
|
||||||
{
|
|
||||||
TiXmlElement *actIndex = subviewRoot->ToElement();
|
|
||||||
str = actIndex->Attribute(TEXT("activeIndex"), (int *)&index);
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
(*ptrSession)._activeSubIndex = index;
|
|
||||||
}
|
|
||||||
for (TiXmlNode *childNode = subviewRoot->FirstChildElement(TEXT("File"));
|
|
||||||
childNode ;
|
|
||||||
childNode = childNode->NextSibling(TEXT("File")) )
|
|
||||||
{
|
|
||||||
const TCHAR *fileName = (childNode->ToElement())->Attribute(TEXT("filename"));
|
|
||||||
if (fileName)
|
|
||||||
{
|
|
||||||
|
|
||||||
Position position;
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("firstVisibleLine"), &position._firstVisibleLine);
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("xOffset"), &position._xOffset);
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("startPos"), &position._startPos);
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("endPos"), &position._endPos);
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("selMode"), &position._selMode);
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("scrollWidth"), &position._scrollWidth);
|
|
||||||
|
|
||||||
const TCHAR *langName;
|
|
||||||
langName = (childNode->ToElement())->Attribute(TEXT("lang"));
|
|
||||||
int encoding = -1;
|
|
||||||
(childNode->ToElement())->Attribute(TEXT("encoding"), &encoding);
|
|
||||||
|
|
||||||
sessionFileInfo sfi(fileName, langName, encoding, position);
|
|
||||||
|
|
||||||
for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
|
|
||||||
markNode ;
|
|
||||||
markNode = markNode->NextSibling(TEXT("Mark")))
|
|
||||||
{
|
|
||||||
int lineNumber;
|
|
||||||
const TCHAR *lineNumberStr = (markNode->ToElement())->Attribute(TEXT("line"), &lineNumber);
|
|
||||||
if (lineNumberStr)
|
|
||||||
{
|
|
||||||
sfi.marks.push_back(lineNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TiXmlNode *foldNode = childNode->FirstChildElement(TEXT("Fold"));
|
|
||||||
foldNode ;
|
|
||||||
foldNode = foldNode->NextSibling(TEXT("Fold")))
|
|
||||||
{
|
|
||||||
int lineNumber;
|
|
||||||
const TCHAR *lineNumberStr = (foldNode->ToElement())->Attribute(TEXT("line"), &lineNumber);
|
|
||||||
if (lineNumberStr)
|
|
||||||
{
|
|
||||||
sfi._foldStates.push_back(lineNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(*ptrSession)._subViewFiles.push_back(sfi);
|
(*ptrSession)._subViewFiles.push_back(sfi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -2443,66 +2397,55 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
|
|||||||
TiXmlNode *sessionNode = root->InsertEndChild(TiXmlElement(TEXT("Session")));
|
TiXmlNode *sessionNode = root->InsertEndChild(TiXmlElement(TEXT("Session")));
|
||||||
(sessionNode->ToElement())->SetAttribute(TEXT("activeView"), (int)session._activeView);
|
(sessionNode->ToElement())->SetAttribute(TEXT("activeView"), (int)session._activeView);
|
||||||
|
|
||||||
TiXmlNode *mainViewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("mainView")));
|
struct ViewElem {
|
||||||
(mainViewNode->ToElement())->SetAttribute(TEXT("activeIndex"), (int)session._activeMainIndex);
|
TiXmlNode *viewNode;
|
||||||
for (size_t i = 0, len = session._mainViewFiles.size(); i < len ; ++i)
|
vector<sessionFileInfo> *viewFiles;
|
||||||
{
|
size_t activeIndex;
|
||||||
TiXmlNode *fileNameNode = mainViewNode->InsertEndChild(TiXmlElement(TEXT("File")));
|
};
|
||||||
|
const int nbElem = 2;
|
||||||
|
ViewElem viewElems[nbElem];
|
||||||
|
viewElems[0].viewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("mainView")));
|
||||||
|
viewElems[1].viewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("subView")));
|
||||||
|
viewElems[0].viewFiles = (vector<sessionFileInfo> *)(&(session._mainViewFiles));
|
||||||
|
viewElems[1].viewFiles = (vector<sessionFileInfo> *)(&(session._subViewFiles));
|
||||||
|
viewElems[0].activeIndex = session._activeMainIndex;
|
||||||
|
viewElems[1].activeIndex = session._activeSubIndex;
|
||||||
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), session._mainViewFiles[i]._firstVisibleLine);
|
for (size_t k = 0; k < nbElem ; ++k)
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), session._mainViewFiles[i]._xOffset);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), session._mainViewFiles[i]._scrollWidth);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), session._mainViewFiles[i]._startPos);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), session._mainViewFiles[i]._endPos);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), session._mainViewFiles[i]._selMode);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("lang"), session._mainViewFiles[i]._langName.c_str());
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("encoding"), session._mainViewFiles[i]._encoding);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("filename"), session._mainViewFiles[i]._fileName.c_str());
|
|
||||||
|
|
||||||
for (size_t j = 0, len = session._mainViewFiles[i].marks.size() ; j < len ; ++j)
|
|
||||||
{
|
{
|
||||||
size_t markLine = session._mainViewFiles[i].marks[j];
|
(viewElems[k].viewNode->ToElement())->SetAttribute(TEXT("activeIndex"), (int)viewElems[k].activeIndex);
|
||||||
|
vector<sessionFileInfo> & viewSessionFiles = *(viewElems[k].viewFiles);
|
||||||
|
|
||||||
|
for (size_t i = 0, len = viewElems[k].viewFiles->size(); i < len ; ++i)
|
||||||
|
{
|
||||||
|
TiXmlNode *fileNameNode = viewElems[k].viewNode->InsertEndChild(TiXmlElement(TEXT("File")));
|
||||||
|
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), viewSessionFiles[i]._firstVisibleLine);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), viewSessionFiles[i]._xOffset);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), viewSessionFiles[i]._scrollWidth);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), viewSessionFiles[i]._startPos);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), viewSessionFiles[i]._endPos);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), viewSessionFiles[i]._selMode);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("lang"), viewSessionFiles[i]._langName.c_str());
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("encoding"), viewSessionFiles[i]._encoding);
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("filename"), viewSessionFiles[i]._fileName.c_str());
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("backupFilePath"), viewSessionFiles[i]._backupFilePath.c_str());
|
||||||
|
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestamp"), int(viewSessionFiles[i]._originalFileLastModifTimestamp));
|
||||||
|
|
||||||
|
for (size_t j = 0, len = viewSessionFiles[i].marks.size() ; j < len ; ++j)
|
||||||
|
{
|
||||||
|
size_t markLine = viewSessionFiles[i].marks[j];
|
||||||
TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark")));
|
TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark")));
|
||||||
markNode->ToElement()->SetAttribute(TEXT("line"), markLine);
|
markNode->ToElement()->SetAttribute(TEXT("line"), markLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0, len = session._mainViewFiles[i]._foldStates.size() ; j < len ; ++j)
|
for (size_t j = 0, len = viewSessionFiles[i]._foldStates.size() ; j < len ; ++j)
|
||||||
{
|
{
|
||||||
size_t foldLine = session._mainViewFiles[i]._foldStates[j];
|
size_t foldLine = viewSessionFiles[i]._foldStates[j];
|
||||||
TiXmlNode *foldNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Fold")));
|
TiXmlNode *foldNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Fold")));
|
||||||
foldNode->ToElement()->SetAttribute(TEXT("line"), foldLine);
|
foldNode->ToElement()->SetAttribute(TEXT("line"), foldLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TiXmlNode *subViewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("subView")));
|
|
||||||
(subViewNode->ToElement())->SetAttribute(TEXT("activeIndex"), (int)session._activeSubIndex);
|
|
||||||
for (size_t i = 0, len = session._subViewFiles.size(); i < len ; ++i)
|
|
||||||
{
|
|
||||||
TiXmlNode *fileNameNode = subViewNode->InsertEndChild(TiXmlElement(TEXT("File")));
|
|
||||||
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), session._subViewFiles[i]._firstVisibleLine);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), session._subViewFiles[i]._xOffset);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), session._subViewFiles[i]._scrollWidth);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), session._subViewFiles[i]._startPos);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), session._subViewFiles[i]._endPos);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), session._subViewFiles[i]._selMode);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("lang"), session._subViewFiles[i]._langName.c_str());
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("encoding"), session._subViewFiles[i]._encoding);
|
|
||||||
(fileNameNode->ToElement())->SetAttribute(TEXT("filename"), session._subViewFiles[i]._fileName.c_str());
|
|
||||||
|
|
||||||
for (size_t j = 0, len = session._subViewFiles[i].marks.size(); j < len; ++j)
|
|
||||||
{
|
|
||||||
size_t markLine = session._subViewFiles[i].marks[j];
|
|
||||||
TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark")));
|
|
||||||
markNode->ToElement()->SetAttribute(TEXT("line"), markLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t j = 0, len = session._subViewFiles[i]._foldStates.size() ; j < len ; ++j)
|
|
||||||
{
|
|
||||||
size_t foldLine = session._subViewFiles[i]._foldStates[j];
|
|
||||||
TiXmlNode *foldNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Fold")));
|
|
||||||
foldNode->ToElement()->SetAttribute(TEXT("line"), foldLine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pXmlSessionDoc->SaveFile();
|
_pXmlSessionDoc->SaveFile();
|
||||||
|
@ -145,9 +145,11 @@ struct Position
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sessionFileInfo : public Position {
|
struct sessionFileInfo : public Position {
|
||||||
sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, Position pos) : _encoding(encoding), Position(pos) {
|
sessionFileInfo(const TCHAR *fn, const TCHAR *ln, int encoding, Position pos, const TCHAR *backupFilePath, int originalFileLastModifTimestamp) :
|
||||||
|
_encoding(encoding), Position(pos), _originalFileLastModifTimestamp(originalFileLastModifTimestamp) {
|
||||||
if (fn) _fileName = fn;
|
if (fn) _fileName = fn;
|
||||||
if (ln) _langName = ln;
|
if (ln) _langName = ln;
|
||||||
|
if (backupFilePath) _backupFilePath = backupFilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
sessionFileInfo(generic_string fn) : _fileName(fn), _encoding(-1){};
|
sessionFileInfo(generic_string fn) : _fileName(fn), _encoding(-1){};
|
||||||
@ -157,6 +159,9 @@ struct sessionFileInfo : public Position {
|
|||||||
vector<size_t> marks;
|
vector<size_t> marks;
|
||||||
vector<size_t> _foldStates;
|
vector<size_t> _foldStates;
|
||||||
int _encoding;
|
int _encoding;
|
||||||
|
|
||||||
|
generic_string _backupFilePath;
|
||||||
|
time_t _originalFileLastModifTimestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Session {
|
struct Session {
|
||||||
|
@ -648,25 +648,36 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
|
|
||||||
Utf8_16_Write UnicodeConvertor;
|
Utf8_16_Write UnicodeConvertor;
|
||||||
UnicodeConvertor.setEncoding(mode);
|
UnicodeConvertor.setEncoding(mode);
|
||||||
|
|
||||||
int encoding = buffer->getEncoding();
|
int encoding = buffer->getEncoding();
|
||||||
|
|
||||||
|
generic_string backupFilePath = buffer->getBackupFileName();
|
||||||
generic_string backupFilePath = NppParameters::getInstance()->getUserPath();
|
if (backupFilePath == TEXT(""))
|
||||||
if (buffer->getBackupFileName() == TEXT(""))
|
|
||||||
{
|
|
||||||
// Create file name
|
|
||||||
if (buffer->isUntitled())
|
|
||||||
{
|
{
|
||||||
|
// Create file
|
||||||
|
backupFilePath = NppParameters::getInstance()->getUserPath();
|
||||||
|
backupFilePath += TEXT("\\backup\\");
|
||||||
|
|
||||||
|
// if "backup" folder doesn't exist, create it.
|
||||||
|
if (!PathFileExists(backupFilePath.c_str()))
|
||||||
|
{
|
||||||
|
::CreateDirectory(backupFilePath.c_str(), NULL);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
backupFilePath += buffer->getFileName();
|
||||||
|
|
||||||
|
const int temBufLen = 32;
|
||||||
|
TCHAR tmpbuf[temBufLen];
|
||||||
|
time_t ltime = time(0);
|
||||||
|
struct tm *today;
|
||||||
|
|
||||||
|
today = localtime(<ime);
|
||||||
|
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
|
||||||
|
|
||||||
|
backupFilePath += TEXT("@");
|
||||||
|
backupFilePath += tmpbuf;
|
||||||
|
|
||||||
// Set created file name in buffer
|
// Set created file name in buffer
|
||||||
//backupFilePath +=
|
buffer->setBackupFileName(backupFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -745,11 +756,34 @@ bool FileManager::backupCurrentBuffer()
|
|||||||
if (backupFilePath != TEXT(""))
|
if (backupFilePath != TEXT(""))
|
||||||
{
|
{
|
||||||
// delete backup file
|
// delete backup file
|
||||||
|
generic_string file2Delete = buffer->getBackupFileName();
|
||||||
|
buffer->setBackupFileName(TEXT(""));
|
||||||
|
result = (::DeleteFile(file2Delete.c_str()) != 0);
|
||||||
}
|
}
|
||||||
|
//printStr(TEXT("backup deleted in backupCurrentBuffer"));
|
||||||
result = true; // no backup file to delete
|
result = true; // no backup file to delete
|
||||||
}
|
}
|
||||||
|
//printStr(TEXT("backup sync"));
|
||||||
|
::ReleaseMutex(mutex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileManager::deleteCurrentBufferBackup()
|
||||||
|
{
|
||||||
|
HANDLE mutex = ::CreateMutex(NULL, false, TEXT("nppBackupSystem"));
|
||||||
|
::WaitForSingleObject(mutex, INFINITE);
|
||||||
|
|
||||||
|
Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
|
||||||
|
bool result = true;
|
||||||
|
generic_string backupFilePath = buffer->getBackupFileName();
|
||||||
|
if (backupFilePath != TEXT(""))
|
||||||
|
{
|
||||||
|
// delete backup file
|
||||||
|
generic_string file2Delete = buffer->getBackupFileName();
|
||||||
|
buffer->setBackupFileName(TEXT(""));
|
||||||
|
result = (::DeleteFile(file2Delete.c_str()) != 0);
|
||||||
|
}
|
||||||
|
//printStr(TEXT("backup deleted in deleteCurrentBufferBackup"));
|
||||||
::ReleaseMutex(mutex);
|
::ReleaseMutex(mutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ public:
|
|||||||
bool reloadBufferDeferred(BufferID id);
|
bool reloadBufferDeferred(BufferID id);
|
||||||
bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false, generic_string * error_msg = NULL);
|
bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false, generic_string * error_msg = NULL);
|
||||||
bool backupCurrentBuffer();
|
bool backupCurrentBuffer();
|
||||||
|
bool deleteCurrentBufferBackup();
|
||||||
bool deleteFile(BufferID id);
|
bool deleteFile(BufferID id);
|
||||||
bool moveFile(BufferID id, const TCHAR * newFilename);
|
bool moveFile(BufferID id, const TCHAR * newFilename);
|
||||||
bool createEmptyFile(const TCHAR * path);
|
bool createEmptyFile(const TCHAR * path);
|
||||||
@ -325,6 +326,8 @@ public :
|
|||||||
bool isModified() const {return _isModified;};
|
bool isModified() const {return _isModified;};
|
||||||
void setModifiedStatus(bool isModified) {_isModified = isModified;};
|
void setModifiedStatus(bool isModified) {_isModified = isModified;};
|
||||||
generic_string getBackupFileName() const {return _backupFileName;};
|
generic_string getBackupFileName() const {return _backupFileName;};
|
||||||
|
void setBackupFileName(generic_string fileName) {_backupFileName = fileName;};
|
||||||
|
time_t getLastModifiedTimestamp() const {return _timeStamp;};
|
||||||
|
|
||||||
private :
|
private :
|
||||||
FileManager * _pManager;
|
FileManager * _pManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user