OSDN Git Service

Update TranslationsStatus
[winmerge-jp/winmerge-jp.git] / Src / DirDoc.cpp
index ecfc677..44bf016 100644 (file)
@@ -109,6 +109,10 @@ BOOL CDirDoc::OnNewDocument()
 BEGIN_MESSAGE_MAP(CDirDoc, CDocument)
        //{{AFX_MSG_MAP(CDirDoc)
                // NOTE - the ClassWizard will add and remove mapping macros here.
+       // Progress dialog
+       ON_BN_CLICKED(IDC_COMPARISON_STOP, OnBnClickedComparisonStop)
+       ON_BN_CLICKED(IDC_COMPARISON_PAUSE, OnBnClickedComparisonPause)
+       ON_BN_CLICKED(IDC_COMPARISON_CONTINUE, OnBnClickedComparisonContinue)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -281,6 +285,17 @@ void CDirDoc::Rescan()
                m_pCompareStats->Reset();
        m_pDirView->StartCompare(m_pCompareStats.get());
 
+       if (m_pCmpProgressBar == nullptr)
+               m_pCmpProgressBar.reset(new DirCompProgressBar());
+
+       if (!::IsWindow(m_pCmpProgressBar->GetSafeHwnd()))
+               m_pCmpProgressBar->Create(m_pDirView->GetParentFrame());
+
+       m_pCmpProgressBar->SetCompareStat(m_pCompareStats.get());
+       m_pCmpProgressBar->StartUpdating();
+
+       m_pDirView->GetParentFrame()->ShowControlBar(m_pCmpProgressBar.get(), TRUE, FALSE);
+
        if (!m_bGeneratingReport)
                m_pDirView->DeleteAllDisplayItems();
        // Don't clear if only scanning selected items
@@ -292,11 +307,23 @@ void CDirDoc::Rescan()
 
        InitDiffContext(m_pCtxt.get());
 
-       pf->GetHeaderInterface()->SetPaneCount(m_nDirs);
-       pf->GetHeaderInterface()->SetOnSetFocusCallback([&](int pane) {
+       auto* pHeaderBar = pf->GetHeaderInterface();
+       pHeaderBar->SetPaneCount(m_nDirs);
+       pHeaderBar->SetOnSetFocusCallback([&](int pane) {
                m_pDirView->SetActivePane(pane);
                GetOptionsMgr()->SaveOption(OPT_ACTIVE_PANE, pane);
        });
+       pHeaderBar->SetOnCaptionChangedCallback([&](int pane, const String& sText) {
+               m_strDesc[pane] = sText;
+               UpdateHeaderPath(pane);
+       });
+       pHeaderBar->SetOnFolderSelectedCallback([&](int pane, const String& sFolderpath) {
+               PathContext paths = m_pCtxt->GetNormalizedPaths();
+               paths.SetPath(pane, sFolderpath);
+               m_strDesc[pane].clear();
+               InitCompare(paths, m_pCtxt->m_bRecursive, nullptr);
+               Rescan();
+       });
        for (int nIndex = 0; nIndex < m_nDirs; nIndex++)
        {
                UpdateHeaderPath(nIndex);
@@ -352,15 +379,18 @@ void CDirDoc::Rescan()
                        SetGeneratingReport(false);
                        SetReport(nullptr);
                });
+               m_diffThread.SetMarkedRescan(false);
        }
        else if (m_bMarkedRescan)
        {
-               m_diffThread.SetCollectFunction(nullptr);
-               m_diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) {
+               m_diffThread.SetCollectFunction([](DiffFuncStruct* myStruct) {
                        int nItems = DirScan_UpdateMarkedItems(myStruct, nullptr);
                        myStruct->context->m_pCompareStats->IncreaseTotalItems(nItems);
+                       });
+               m_diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) {
                        DirScan_CompareRequestedItems(myStruct, nullptr);
-               });
+                       });
+               m_diffThread.SetMarkedRescan(true);
        }
        else
        {
@@ -376,6 +406,7 @@ void CDirDoc::Rescan()
                m_diffThread.SetCompareFunction([](DiffFuncStruct* myStruct) {
                        DirScan_CompareItems(myStruct, nullptr);
                });
+               m_diffThread.SetMarkedRescan(false);
        }
        m_diffThread.CompareDirectories();
        m_bMarkedRescan = false;
@@ -457,8 +488,7 @@ void CDirDoc::SetDirView(CDirView * newView)
        m_pDirView = newView;
        // MFC has a view list for us, so lets check against it
        POSITION pos = GetFirstViewPosition();
-       CDirView * temp = static_cast<CDirView *>(GetNextView(pos));
-       ASSERT(temp == m_pDirView); // verify that our stashed pointer is the same as MFC's
+       ASSERT(m_pDirView == static_cast<CDirView *>(GetNextView(pos))); // verify that our stashed pointer is the same as MFC's
 }
 
 /**
@@ -563,6 +593,10 @@ void CDirDoc::UpdateChangedItem(const PathContext &paths,
  */
 void CDirDoc::CompareReady()
 {
+       // Close and destroy the dialog after compare
+       if (m_pCmpProgressBar != nullptr)
+               m_pDirView->GetParentFrame()->ShowControlBar(m_pCmpProgressBar.get(), FALSE, FALSE);
+       m_pCmpProgressBar.reset();
 }
 
 /**
@@ -615,6 +649,7 @@ BOOL CDirDoc::SaveModified()
                m_diffThread.Abort();
                while (m_diffThread.GetThreadState() == CDiffThread::THREAD_COMPARING)
                        Sleep(50);
+               CompareReady();
        }
        
        return CDocument::SaveModified();
@@ -734,6 +769,13 @@ void CDirDoc::SetTitle(LPCTSTR lpszTitle)
        }       
 }
 
+/**
+ * @brief A string to display as a tooltip for MDITabbar
+ */
+CString CDirDoc::GetTooltipString() const
+{
+       return CMergeFrameCommon::GetTooltipString(m_pCtxt->GetNormalizedPaths(), m_strDesc, nullptr, nullptr).c_str();
+}
 
 /**
  * @brief Checks if current folders are opened from archive file.
@@ -949,8 +991,38 @@ bool CDirDoc::CompareFilesIfFilesAreLarge(int nFiles, const FileLocation ifilelo
        FolderCmp cmp(&ctxt);
        CWaitCursor waitstatus;
        di.diffcode.diffcode |= cmp.prepAndCompareFiles(di);
-       AfxMessageBox(ci.ColGetTextToDisplay(&ctxt, 2, di).c_str(), MB_OK | MB_ICONINFORMATION);
+       if (di.diffcode.isResultSame())
+       {
+               ctxt.GetComparePaths(di, paths);
+               CMergeFrameCommon::ShowIdenticalMessage(paths, true,
+                       [](LPCTSTR msg, UINT flags, UINT id) -> int { return AfxMessageBox(msg, flags, id); });
+       }
+       else
+       {
+               AfxMessageBox(ci.ColGetTextToDisplay(&ctxt, 2, di).c_str(), MB_OK | MB_ICONINFORMATION);
+       }
        theApp.SetLastCompareResult(di.diffcode.isResultDiff() ? 1 : 0);
        return true;
 }
 
+void CDirDoc::OnBnClickedComparisonStop()
+{
+       if (m_pCmpProgressBar != nullptr)
+               m_pCmpProgressBar->EndUpdating();
+       AbortCurrentScan();
+}
+
+void CDirDoc::OnBnClickedComparisonPause()
+{
+       if (m_pCmpProgressBar != nullptr)
+               m_pCmpProgressBar->SetPaused(true);
+       PauseCurrentScan();
+}
+
+void CDirDoc::OnBnClickedComparisonContinue()
+{
+       if (m_pCmpProgressBar != nullptr)
+               m_pCmpProgressBar->SetPaused(false);
+       ContinueCurrentScan();
+}
+