[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,31 +4439,54 @@ 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--)
{
Buffer & docBuf = vi.sv->getBufferAt(i);
docFileStaus fStatus = docBuf.checkFileState(); docFileStaus fStatus = docBuf.checkFileState();
//pDocTabArray[j]->updateTabItem(i);
bool update = !docBuf.isDirty() && autoUpdate; bool update = !docBuf.isDirty() && autoUpdate;
if (fStatus == MODIFIED_FROM_OUTSIDE) if (fStatus == MODIFIED_FROM_OUTSIDE)
@ -4473,30 +4496,21 @@ void Notepad_plus::checkModifiedDocument()
::ShowWindow(_hSelf, SW_SHOWNORMAL); ::ShowWindow(_hSelf, SW_SHOWNORMAL);
if (update) if (update)
{
docBuf._reloadOnSwitchBack = true; 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) else if (doReloadOrNot(docBuf.getFileName()) == IDYES)
{ {
docBuf._reloadOnSwitchBack = true; docBuf._reloadOnSwitchBack = true;
setTitleWith(pDocTabArray[j]->activate(i)); setTitleWith(vi.dtv->activate(i));
// if it's a non current view, make it as the current view // if it's a non current view, make it as the current view
if (j == 1) if (j == 1)
switchEditViewTo(getNonCurrentView()); switchEditViewTo(getNonCurrentView());
/*
if (pScintillaArray[j]->isCurrentBufReadOnly())
pScintillaArray[j]->execute(SCI_SETREADONLY, FALSE);
reload(docBuf.getFileName());
//if (goToEOL)
{
int line = _pEditView->getNbLine();
_pEditView->gotoLine(line);
}
if (pScintillaArray[j]->isCurrentBufReadOnly())
pScintillaArray[j]->execute(SCI_SETREADONLY, TRUE);
*/
} }
if (_activeAppInf._isActivated) if (_activeAppInf._isActivated)
@ -4515,14 +4529,14 @@ void Notepad_plus::checkModifiedDocument()
if (doCloseOrNot(docBuf.getFileName()) == IDNO) if (doCloseOrNot(docBuf.getFileName()) == IDNO)
{ {
pDocTabArray[j]->activate(i); vi.dtv->activate(i);
if ((pScintillaArray[j]->getNbDoc() == 1) && (_mainWindowStatus & TWO_VIEWS_MASK)) if ((vi.sv->getNbDoc() == 1) && (_mainWindowStatus & TWO_VIEWS_MASK))
{ {
setTitleWith(pDocTabArray[j]->closeCurrentDoc()); setTitleWith(vi.dtv->closeCurrentDoc());
hideCurrentView(); hideCurrentView();
} }
else else
setTitleWith(pDocTabArray[j]->closeCurrentDoc()); setTitleWith(vi.dtv->closeCurrentDoc());
} }
else else
docBuf._dontBotherMeAnymore = true; docBuf._dontBotherMeAnymore = true;
@ -4536,19 +4550,23 @@ void Notepad_plus::checkModifiedDocument()
} }
} }
bool isReadOnly = pScintillaArray[j]->isCurrentBufReadOnly(); bool isReadOnly = vi.sv->isCurrentBufReadOnly();
pScintillaArray[j]->execute(SCI_SETREADONLY, isReadOnly); vi.sv->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);
} }
} }