From ba85977e6dcd31f6b185e2b07bf7ac0c0035ca28 Mon Sep 17 00:00:00 2001 From: donho Date: Sat, 22 Mar 2008 12:18:56 +0000 Subject: [PATCH] [BUG_FIXED] Enhance checking modification from outside feature. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@149 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 3 + PowerEditor/src/Notepad_plus.cpp | 172 ++++++++++-------- 2 files changed, 98 insertions(+), 77 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 43f21df2c..6f7d7d98b 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -191,6 +191,9 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // BOOL NPPM_ISTABBARHIDE(0, 0) // returned value : TRUE if tab bar is hidden, otherwise FALSE + #define NPPM_CHECKDOCSTATUS (NPPMSG + 53) + // VOID NPPM_CHECKDOCSTATUS(TRUE, 0) + #define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 1f4df81be..2fb3e39d7 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -4439,116 +4439,134 @@ void Notepad_plus::dropFiles(HDROP hdrop) void Notepad_plus::checkModifiedDocument() { const int NB_VIEW = 2; + /* ScintillaEditView * pScintillaArray[NB_VIEW]; DocTabView * pDocTabArray[NB_VIEW]; + int currentIndex[NB_VIEW] = {-1, -1}; + */ + struct ViewInfo { + int id; + ScintillaEditView * sv; + DocTabView * dtv; + int currentIndex; + bool toBeActivated; + }; - int currentView = getCurrentView(); - int currentIndex = _pEditView->getCurrentDocIndex(); - + ViewInfo viewInfoArray[NB_VIEW]; + // the oder (1.current view 2.non current view) is important // to synchronize with "hideCurrentView" function - pScintillaArray[0] = _pEditView; - pScintillaArray[1] = getNonCurrentEditView(); + viewInfoArray[0].id = getCurrentView(); + viewInfoArray[0].sv = _pEditView; + viewInfoArray[0].dtv = _pDocTab; + viewInfoArray[0].currentIndex = _pEditView->getCurrentDocIndex(); + viewInfoArray[0].toBeActivated = false; + viewInfoArray[1].id = getNonCurrentView(); + viewInfoArray[1].sv = getNonCurrentEditView(); + viewInfoArray[1].dtv = getNonCurrentDocTab(); + viewInfoArray[1].currentIndex = viewInfoArray[1].sv->getCurrentDocIndex(); + viewInfoArray[1].toBeActivated = false; + + /*pScintillaArray[0] = _pEditView; + pScintillaArray[1] = getNonCurrentEditView(); pDocTabArray[0] = _pDocTab; - pDocTabArray[1] = getNonCurrentDocTab(); + pDocTabArray[1] = getNonCurrentDocTab();*/ NppParameters *pNppParam = NppParameters::getInstance(); const NppGUI & nppGUI = pNppParam->getNppGUI(); bool autoUpdate = (nppGUI._fileAutoDetection == cdAutoUpdate) || (nppGUI._fileAutoDetection == cdAutoUpdateGo2end); + _subEditView.getCurrentDocIndex(); for (int j = 0 ; j < NB_VIEW ; j++) { - for (int i = (pScintillaArray[j]->getNbDoc()-1) ; i >= 0 ; i--) + ViewInfo & vi = viewInfoArray[j]; + if (vi.sv->isVisible()) { - Buffer & docBuf = pScintillaArray[j]->getBufferAt(i); - docFileStaus fStatus = docBuf.checkFileState(); - //pDocTabArray[j]->updateTabItem(i); - bool update = !docBuf.isDirty() && autoUpdate; - - if (fStatus == MODIFIED_FROM_OUTSIDE) + for (int i = ((vi.sv)->getNbDoc()-1) ; i >= 0 ; i--) { - // If npp is minimized, bring it up to the top - if (::IsIconic(_hSelf)) - ::ShowWindow(_hSelf, SW_SHOWNORMAL); + Buffer & docBuf = vi.sv->getBufferAt(i); + docFileStaus fStatus = docBuf.checkFileState(); + bool update = !docBuf.isDirty() && autoUpdate; - if (update) - docBuf._reloadOnSwitchBack = true; - else if (doReloadOrNot(docBuf.getFileName()) == IDYES) + if (fStatus == MODIFIED_FROM_OUTSIDE) { - docBuf._reloadOnSwitchBack = true; - setTitleWith(pDocTabArray[j]->activate(i)); - // if it's a non current view, make it as the current view - if (j == 1) - switchEditViewTo(getNonCurrentView()); + // If npp is minimized, bring it up to the top + if (::IsIconic(_hSelf)) + ::ShowWindow(_hSelf, SW_SHOWNORMAL); -/* - if (pScintillaArray[j]->isCurrentBufReadOnly()) - pScintillaArray[j]->execute(SCI_SETREADONLY, FALSE); - - reload(docBuf.getFileName()); - - //if (goToEOL) + if (update) { - int line = _pEditView->getNbLine(); - _pEditView->gotoLine(line); + docBuf._reloadOnSwitchBack = true; + // for 2 views, if it's current doc, then reload immediately + if (vi.currentIndex == i) + { + vi.toBeActivated = true; + } + } + else if (doReloadOrNot(docBuf.getFileName()) == IDYES) + { + docBuf._reloadOnSwitchBack = true; + setTitleWith(vi.dtv->activate(i)); + // if it's a non current view, make it as the current view + if (j == 1) + switchEditViewTo(getNonCurrentView()); } - if (pScintillaArray[j]->isCurrentBufReadOnly()) - pScintillaArray[j]->execute(SCI_SETREADONLY, TRUE); -*/ - } - - if (_activeAppInf._isActivated) - { - int curPos = _pEditView->execute(SCI_GETCURRENTPOS); - ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); - ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); - _activeAppInf._isActivated = false; - } - docBuf.updatTimeStamp(); - } - else if (fStatus == FILE_DELETED && !docBuf._dontBotherMeAnymore) - { - if (::IsIconic(_hSelf)) - ::ShowWindow(_hSelf, SW_SHOWNORMAL); - - if (doCloseOrNot(docBuf.getFileName()) == IDNO) - { - pDocTabArray[j]->activate(i); - if ((pScintillaArray[j]->getNbDoc() == 1) && (_mainWindowStatus & TWO_VIEWS_MASK)) + if (_activeAppInf._isActivated) { - setTitleWith(pDocTabArray[j]->closeCurrentDoc()); - hideCurrentView(); + int curPos = _pEditView->execute(SCI_GETCURRENTPOS); + ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); + ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); + _activeAppInf._isActivated = false; + } + docBuf.updatTimeStamp(); + } + else if (fStatus == FILE_DELETED && !docBuf._dontBotherMeAnymore) + { + if (::IsIconic(_hSelf)) + ::ShowWindow(_hSelf, SW_SHOWNORMAL); + + if (doCloseOrNot(docBuf.getFileName()) == IDNO) + { + vi.dtv->activate(i); + if ((vi.sv->getNbDoc() == 1) && (_mainWindowStatus & TWO_VIEWS_MASK)) + { + setTitleWith(vi.dtv->closeCurrentDoc()); + hideCurrentView(); + } + else + setTitleWith(vi.dtv->closeCurrentDoc()); } else - setTitleWith(pDocTabArray[j]->closeCurrentDoc()); - } - else - docBuf._dontBotherMeAnymore = true; + docBuf._dontBotherMeAnymore = true; - if (_activeAppInf._isActivated) - { - int curPos = _pEditView->execute(SCI_GETCURRENTPOS); - ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); - ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); - _activeAppInf._isActivated = false; + if (_activeAppInf._isActivated) + { + int curPos = _pEditView->execute(SCI_GETCURRENTPOS); + ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); + ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); + _activeAppInf._isActivated = false; + } } + + bool isReadOnly = vi.sv->isCurrentBufReadOnly(); + vi.sv->execute(SCI_SETREADONLY, isReadOnly); } - - bool isReadOnly = pScintillaArray[j]->isCurrentBufReadOnly(); - pScintillaArray[j]->execute(SCI_SETREADONLY, isReadOnly); - //_pDocTab->updateCurrentTabItem(); } } if (autoUpdate) { - switchEditViewTo(currentView); - int indexMax = _pEditView->getNbDoc() - 1; - if (currentIndex > indexMax) - currentIndex = indexMax; - _pDocTab->activate(currentIndex); + int iCur = getCurrentView(); + + if (viewInfoArray[0].toBeActivated) + switchEditViewTo(viewInfoArray[0].id); + + if (viewInfoArray[1].toBeActivated) + switchEditViewTo(viewInfoArray[1].id); + + switchEditViewTo(iCur); } }