OSDN Git Service

Delay calling InitialUpdateFrame() to reduce unnecessary drawing
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 20 Jan 2019 11:38:50 +0000 (20:38 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 20 Jan 2019 11:38:50 +0000 (20:38 +0900)
--HG--
branch : stable

Externals/crystaledit/editlib/ccrystaltextview.cpp
Src/ChildFrm.h
Src/MainFrm.cpp
Src/MergeDoc.cpp
Src/MergeDoc.h

index 4d60e34..f5297b0 100644 (file)
@@ -516,6 +516,7 @@ SaveSettings ()
 CCrystalTextView::CCrystalTextView ()
 : m_nScreenChars(-1)
 , m_pFindTextDlg(nullptr)
+, m_CurSourceDef(nullptr)
 {
   memset(((CView*)this)+1, 0, sizeof(*this) - sizeof(class CView)); // AFX_ZERO_INIT_OBJECT (CView)
   m_rxnode = nullptr;
@@ -2837,7 +2838,8 @@ OnInitialUpdate ()
 {
   CView::OnInitialUpdate ();
   CString sDoc = GetDocument ()->GetPathName (), sExt = GetExt (sDoc);
-  SetTextType (sExt);
+  if (m_CurSourceDef == nullptr)
+      SetTextType (sExt);
   AttachToBuffer (nullptr);
 
   CSplitterWnd *pSplitter = GetParentSplitter (this, false);
@@ -2869,7 +2871,6 @@ OnInitialUpdate ()
             }
         }
     }
-  SetTextType (sExt);
   SetFont (m_LogFont);
   if (m_bRememberLastPos && !sDoc.IsEmpty ())
     {
index 3463d51..18f7568 100644 (file)
@@ -55,6 +55,7 @@ public:
        void UpdateAutoPaneResize();
        void UpdateSplitter();
        CSplitterWndEx& GetSplitter() { return m_wndSplitter; };
+       bool IsActivated() const { return m_bActivated; }
 
 // Attributes
 protected:
index e1d89f5..498ba7d 100644 (file)
@@ -85,7 +85,7 @@ using boost::end;
 static void LoadToolbarImageList(int imageWidth, UINT nIDResource, UINT nIDResourceMask, bool bGrayscale, CImageList& ImgList);
 static CPtrList &GetDocList(CMultiDocTemplate *pTemplate);
 template<class DocClass>
-DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles);
+DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles, bool bMakeVisible = true);
 
 /**
  * @brief A table associating menuitem id, icon and menus to apply.
@@ -657,7 +657,7 @@ bool CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc,
 {
        if (m_pMenus[MENU_MERGEVIEW] == nullptr)
                theApp.m_pDiffTemplate->m_hMenuShared = NewMergeViewMenu();
-       CMergeDoc * pMergeDoc = GetMergeDocForDiff<CMergeDoc>(theApp.m_pDiffTemplate, pDirDoc, nFiles);
+       CMergeDoc * pMergeDoc = GetMergeDocForDiff<CMergeDoc>(theApp.m_pDiffTemplate, pDirDoc, nFiles, false);
 
        // Make local copies, so we can change encoding if we guess it below
        FileLocation fileloc[3];
@@ -711,7 +711,15 @@ bool CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc,
        }
 
        // Note that OpenDocs() takes care of closing compare window when needed.
-       if (!pMergeDoc->OpenDocs(nFiles, fileloc, GetROFromFlags(nFiles, dwFlags).data(), strDesc, GetActivePaneFromFlags(nFiles, dwFlags)))
+       bool bResult = pMergeDoc->OpenDocs(nFiles, fileloc, GetROFromFlags(nFiles, dwFlags).data(), strDesc, GetActivePaneFromFlags(nFiles, dwFlags));
+
+       if (CChildFrame *pFrame = pMergeDoc->GetParentFrame())
+       {
+               if (!pFrame->IsActivated())
+                       pFrame->InitialUpdateFrame(pMergeDoc, true);
+       }
+
+       if (!bResult)
                return false;
 
        for (int pane = 0; pane < nFiles; pane++)
@@ -1303,11 +1311,11 @@ HexMergeDocList &CMainFrame::GetAllHexMergeDocs()
  * @return Pointer to CMergeDoc to use. 
  */
 template<class DocClass>
-DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles)
+DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles, bool bMakeVisible)
 {
        // Create a new merge doc
        DocClass::m_nBuffersTemp = nFiles;
-       DocClass *pMergeDoc = static_cast<DocClass*>(pTemplate->OpenDocumentFile(nullptr));
+       DocClass *pMergeDoc = static_cast<DocClass*>(pTemplate->OpenDocumentFile(nullptr, bMakeVisible));
        if (pMergeDoc != nullptr)
        {
                pDirDoc->AddMergeDoc(pMergeDoc);
index 19d2b59..5e3f800 100644 (file)
@@ -357,7 +357,7 @@ int CMergeDoc::Rescan(bool &bBinary, IDENTLEVEL &identical,
                if (FileChanged[nBuffer] == FileRemoved)
                {
                        String msg = strutils::format_string1(_("The file\n%1\nhas disappeared. Please save a copy of the file to continue."), m_filePaths[nBuffer]);
-                       AfxMessageBox(msg.c_str(), MB_ICONWARNING);
+                       ShowMessageBox(msg, MB_ICONWARNING);
                        bool bSaveResult = false;
                        bool ok = DoSaveAs(m_filePaths[nBuffer].c_str(), bSaveResult, nBuffer);
                        if (!ok || !bSaveResult)
@@ -571,7 +571,7 @@ void CMergeDoc::CheckFileChanged(void)
                if (FileChange[nBuffer] == FileChanged)
                {
                        String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge scanned it last time.\n\nDo you want to reload the file?"), m_filePaths[nBuffer]);
-                       if (AfxMessageBox(msg.c_str(), MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN) == IDYES)
+                       if (ShowMessageBox(msg, MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN) == IDYES)
                        {
                                OnFileReload();
                        }
@@ -697,6 +697,16 @@ void CMergeDoc::FlagMovedLines(void)
        // todo: Need to record actual moved information
 }
 
+int CMergeDoc::ShowMessageBox(const String& sText, unsigned nType, unsigned nIDHelp)
+{
+       if (!GetParentFrame()->IsActivated())
+       {
+               GetParentFrame()->InitialUpdateFrame(this, true);
+               GetParentFrame()->SendMessage(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0);
+       }
+       return AfxMessageBox(sText.c_str(), nType, nIDHelp);
+}
+
 /**
  * @brief Prints (error) message by rescan status.
  *
@@ -716,7 +726,7 @@ void CMergeDoc::ShowRescanError(int nRescanResult, IDENTLEVEL identical)
        {
                s = _("An error occurred while comparing the files.");
                LogErrorString(s);
-               AfxMessageBox(s.c_str(), MB_ICONSTOP);
+               ShowMessageBox(s, MB_ICONSTOP);
                return;
        }
 
@@ -724,7 +734,7 @@ void CMergeDoc::ShowRescanError(int nRescanResult, IDENTLEVEL identical)
        {
                s = _("Temporary files could not be created. Check your temporary path settings.");
                LogErrorString(s);
-               AfxMessageBox(s.c_str(), MB_ICONSTOP);
+               ShowMessageBox(s, MB_ICONSTOP);
                return;
        }
 
@@ -736,7 +746,7 @@ void CMergeDoc::ShowRescanError(int nRescanResult, IDENTLEVEL identical)
                {
                        // compare file to itself, a custom message so user may hide the message in this case only
                        s = _("The same file is opened in both panels.");
-                       AfxMessageBox(s.c_str(), MB_ICONINFORMATION | MB_DONT_DISPLAY_AGAIN, IDS_FILE_TO_ITSELF);
+                       ShowMessageBox(s, MB_ICONINFORMATION | MB_DONT_DISPLAY_AGAIN, IDS_FILE_TO_ITSELF);
                }
                else if (identical == IDENTLEVEL_ALL)
                {
@@ -752,7 +762,8 @@ void CMergeDoc::ShowRescanError(int nRescanResult, IDENTLEVEL identical)
 
                        if (theApp.m_bExitIfNoDiff != MergeCmdLineInfo::ExitQuiet)
                        {
-                               LangMessageBox(IDS_FILESSAME, nFlags);
+                               s = _("The selected files are identical.");
+                               ShowMessageBox(s, nFlags);
                        }
 
                        // Exit application if files are identical.
@@ -956,21 +967,21 @@ void CMergeDoc::DoAutoMerge(int dstPane)
                DoMergeValue(m_ptBuf[0]->getEncoding(), m_ptBuf[1]->getEncoding(), m_ptBuf[2]->getEncoding(), dstPane);
        if (mergedEncoding.first == Merged)
        {
-               LangMessageBox(IDS_CODEPAGE_MERGED, MB_ICONINFORMATION);
+               ShowMessageBox(_("The change of codepage has been merged"), MB_ICONINFORMATION);
                m_ptBuf[dstPane]->setEncoding(mergedEncoding.second);
        }
        else if (mergedEncoding.first == Conflict)
-               LangMessageBox(IDS_CODEPAGE_CONFLICT, MB_ICONINFORMATION);
+               ShowMessageBox(_("The changes of codepage are conflicting"), MB_ICONINFORMATION);
 
        std::pair<MergeResult, CRLFSTYLE> mergedEOLStyle = 
                DoMergeValue(m_ptBuf[0]->GetCRLFMode(), m_ptBuf[1]->GetCRLFMode(), m_ptBuf[2]->GetCRLFMode(), dstPane);
        if (mergedEOLStyle.first == Merged)
        {
-               LangMessageBox(IDS_EOL_MERGED, MB_ICONINFORMATION);
+               ShowMessageBox(_("The change of EOL has been merged"), MB_ICONINFORMATION);
                m_ptBuf[dstPane]->SetCRLFMode(mergedEOLStyle.second);
        }
        else if (mergedEOLStyle.first == Conflict)
-               LangMessageBox(IDS_EOL_CONFLICT, MB_ICONINFORMATION);
+               ShowMessageBox(_("The changes of EOL are conflicting"), MB_ICONINFORMATION);
 
        RescanSuppress suppressRescan(*this);
 
@@ -1035,11 +1046,11 @@ void CMergeDoc::DoAutoMerge(int dstPane)
        if (nDiff != -1)
                pViewDst->SelectDiff(nDiff, true, false);
 
-       AfxMessageBox(
+       ShowMessageBox(
                strutils::format_string2(
                        _T("The number of automatically merged changes: %1\nThe number of unresolved conflicts: %2"), 
                        strutils::format(_T("%d"), autoMergedCount),
-                       strutils::format(_T("%d"), unresolvedConflictCount)).c_str(),
+                       strutils::format(_T("%d"), unresolvedConflictCount)),
                MB_ICONINFORMATION);
 }
 
@@ -1389,7 +1400,7 @@ bool CMergeDoc::TrySaveAs(String &strPath, int &nSaveResult, String & sError,
        // SAVE_NO_FILENAME is temporarily used for scratchpad.
        // So don't ask about saving in that case.
        if (nSaveResult != SAVE_NO_FILENAME)
-               answer = AfxMessageBox(str.c_str(), MB_OKCANCEL | MB_ICONWARNING);
+               answer = ShowMessageBox(str, MB_OKCANCEL | MB_ICONWARNING);
 
        switch (answer)
        {
@@ -1467,7 +1478,7 @@ bool CMergeDoc::DoSave(LPCTSTR szPath, bool &bSaveSuccess, int nBuffer)
        if (fileChanged == FileChanged)
        {
                String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge loaded it.\n\nOverwrite changed file?"), szPath);
-               if (AfxMessageBox(msg.c_str(), MB_ICONWARNING | MB_YESNO) == IDNO)
+               if (ShowMessageBox(msg, MB_ICONWARNING | MB_YESNO) == IDNO)
                {
                        bSaveSuccess = true;
                        return true;
@@ -2502,12 +2513,12 @@ int CMergeDoc::LoadFile(CString sFileName, int nBuffer, bool & readOnly, const F
                        sError = strutils::format_string2(_("Cannot open file\n%1\n\n%2"), (LPCTSTR)sFileName, (LPCTSTR)sOpenError);
                else
                        sError = strutils::format_string1(_("File not found: %1"), (LPCTSTR)sFileName);
-               AfxMessageBox(sError.c_str(), MB_OK | MB_ICONSTOP | MB_MODELESS);
+               ShowMessageBox(sError, MB_OK | MB_ICONSTOP | MB_MODELESS);
        }
        else if (FileLoadResult::IsErrorUnpack(retVal))
        {
                sError = strutils::format_string1(_("File not unpacked: %1"), (LPCTSTR)sFileName);
-               AfxMessageBox(sError.c_str(), MB_OK | MB_ICONSTOP | MB_MODELESS);
+               ShowMessageBox(sError, MB_OK | MB_ICONSTOP | MB_MODELESS);
        }
        return retVal;
 }
@@ -2720,7 +2731,7 @@ bool CMergeDoc::OpenDocs(int nFiles, const FileLocation ifileloc[],
                        // All lines will differ, that is not very interesting and probably not wanted.
                        // Propose to turn off the option 'sensitive to EOL'
                        String s = theApp.LoadString(IDS_SUGGEST_IGNOREEOL);
-                       if (AfxMessageBox(s.c_str(), MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN | MB_IGNORE_IF_SILENCED, IDS_SUGGEST_IGNOREEOL) == IDYES)
+                       if (ShowMessageBox(s, MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN | MB_IGNORE_IF_SILENCED, IDS_SUGGEST_IGNOREEOL) == IDYES)
                        {
                                diffOptions.bIgnoreEol = true;
                                m_diffWrapper.SetOptions(&diffOptions);
index fad1510..e16614a 100644 (file)
@@ -185,6 +185,7 @@ public:
        void RescanIfNeeded(float timeOutInSecond);
        int Rescan(bool &bBinary, IDENTLEVEL &identical, bool bForced = false);
        void CheckFileChanged(void);
+       int ShowMessageBox(const String& sText, unsigned nType = MB_OK, unsigned nIDHelp = 0);
        void ShowRescanError(int nRescanResult, IDENTLEVEL identical);
        bool Undo();
        void CopyAllList(int srcPane, int dstPane);