[BUG_FIXED] Enhance checking modification from outside feature.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@149 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-03-22 12:18:56 +00:00
parent e7e3be93b8
commit ba85977e6d
2 changed files with 98 additions and 77 deletions

View File

@ -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) // BOOL NPPM_ISTABBARHIDE(0, 0)
// returned value : TRUE if tab bar is hidden, otherwise FALSE // 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 RUNCOMMAND_USER (WM_USER + 3000)
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
#define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY)

View File

@ -4439,116 +4439,134 @@ void Notepad_plus::dropFiles(HDROP hdrop)
void Notepad_plus::checkModifiedDocument() void Notepad_plus::checkModifiedDocument()
{ {
const int NB_VIEW = 2; const int NB_VIEW = 2;
/*
ScintillaEditView * pScintillaArray[NB_VIEW]; ScintillaEditView * pScintillaArray[NB_VIEW];
DocTabView * pDocTabArray[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(); ViewInfo viewInfoArray[NB_VIEW];
int currentIndex = _pEditView->getCurrentDocIndex();
// the oder (1.current view 2.non current view) is important // the oder (1.current view 2.non current view) is important
// to synchronize with "hideCurrentView" function // to synchronize with "hideCurrentView" function
pScintillaArray[0] = _pEditView; viewInfoArray[0].id = getCurrentView();
pScintillaArray[1] = getNonCurrentEditView(); 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[0] = _pDocTab;
pDocTabArray[1] = getNonCurrentDocTab(); pDocTabArray[1] = getNonCurrentDocTab();*/
NppParameters *pNppParam = NppParameters::getInstance(); NppParameters *pNppParam = NppParameters::getInstance();
const NppGUI & nppGUI = pNppParam->getNppGUI(); const NppGUI & nppGUI = pNppParam->getNppGUI();
bool autoUpdate = (nppGUI._fileAutoDetection == cdAutoUpdate) || (nppGUI._fileAutoDetection == cdAutoUpdateGo2end); bool autoUpdate = (nppGUI._fileAutoDetection == cdAutoUpdate) || (nppGUI._fileAutoDetection == cdAutoUpdateGo2end);
_subEditView.getCurrentDocIndex();
for (int j = 0 ; j < NB_VIEW ; j++) 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); for (int i = ((vi.sv)->getNbDoc()-1) ; i >= 0 ; i--)
docFileStaus fStatus = docBuf.checkFileState();
//pDocTabArray[j]->updateTabItem(i);
bool update = !docBuf.isDirty() && autoUpdate;
if (fStatus == MODIFIED_FROM_OUTSIDE)
{ {
// If npp is minimized, bring it up to the top Buffer & docBuf = vi.sv->getBufferAt(i);
if (::IsIconic(_hSelf)) docFileStaus fStatus = docBuf.checkFileState();
::ShowWindow(_hSelf, SW_SHOWNORMAL); bool update = !docBuf.isDirty() && autoUpdate;
if (update) if (fStatus == MODIFIED_FROM_OUTSIDE)
docBuf._reloadOnSwitchBack = true;
else if (doReloadOrNot(docBuf.getFileName()) == IDYES)
{ {
docBuf._reloadOnSwitchBack = true; // If npp is minimized, bring it up to the top
setTitleWith(pDocTabArray[j]->activate(i)); if (::IsIconic(_hSelf))
// if it's a non current view, make it as the current view ::ShowWindow(_hSelf, SW_SHOWNORMAL);
if (j == 1)
switchEditViewTo(getNonCurrentView());
/* if (update)
if (pScintillaArray[j]->isCurrentBufReadOnly())
pScintillaArray[j]->execute(SCI_SETREADONLY, FALSE);
reload(docBuf.getFileName());
//if (goToEOL)
{ {
int line = _pEditView->getNbLine(); docBuf._reloadOnSwitchBack = true;
_pEditView->gotoLine(line); // 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()) if (_activeAppInf._isActivated)
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))
{ {
setTitleWith(pDocTabArray[j]->closeCurrentDoc()); int curPos = _pEditView->execute(SCI_GETCURRENTPOS);
hideCurrentView(); ::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 else
setTitleWith(pDocTabArray[j]->closeCurrentDoc()); docBuf._dontBotherMeAnymore = true;
}
else
docBuf._dontBotherMeAnymore = true;
if (_activeAppInf._isActivated) if (_activeAppInf._isActivated)
{ {
int curPos = _pEditView->execute(SCI_GETCURRENTPOS); int curPos = _pEditView->execute(SCI_GETCURRENTPOS);
::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0);
::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos);
_activeAppInf._isActivated = false; _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) if (autoUpdate)
{ {
switchEditViewTo(currentView); int iCur = getCurrentView();
int indexMax = _pEditView->getNbDoc() - 1;
if (currentIndex > indexMax) if (viewInfoArray[0].toBeActivated)
currentIndex = indexMax; switchEditViewTo(viewInfoArray[0].id);
_pDocTab->activate(currentIndex);
if (viewInfoArray[1].toBeActivated)
switchEditViewTo(viewInfoArray[1].id);
switchEditViewTo(iCur);
} }
} }