OSDN Git Service

Add "Swap Panes" menu item to Folder Compare window
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 Jan 2016 06:53:27 +0000 (15:53 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 Jan 2016 06:53:27 +0000 (15:53 +0900)
14 files changed:
Src/CompareStats.cpp
Src/CompareStats.h
Src/DiffContext.h
Src/DiffItem.cpp
Src/DiffItem.h
Src/DiffItemList.cpp
Src/DiffItemList.h
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/DirView.h
Src/Merge.rc
Testing/GoogleTest/UnitTests/UnitTests.vcxproj
Testing/GoogleTest/UnitTests/UnitTests.vcxproj.filters

index 426e5a1..9bda045 100644 (file)
@@ -238,3 +238,12 @@ CompareStats::RESULT CompareStats::GetResultFromCode(unsigned diffcode) const
                }
        }
 }
+
+void CompareStats::Swap(int idx1, int idx2)
+{
+       idx2 = m_nDirs < 3 ? idx2 + 1 : idx2;
+       std::swap(m_counts[RESULT_LUNIQUE + idx1], m_counts[RESULT_LUNIQUE + idx2]);
+       std::swap(m_counts[RESULT_LMISSING + idx1], m_counts[RESULT_LMISSING + idx2]);
+       std::swap(m_counts[RESULT_LDIRUNIQUE + idx1], m_counts[RESULT_LDIRUNIQUE + idx2]);
+       std::swap(m_counts[RESULT_LDIRMISSING + idx1], m_counts[RESULT_LDIRMISSING + idx2]);
+}
index d81b5b8..49a0b46 100644 (file)
@@ -90,8 +90,8 @@ public:
        CompareStats::CMP_STATE GetCompareState() const;
        void SetCurrentDiffItem(const DIFFITEM *di);
        bool IsCompareDone() const { return m_bCompareDone; }
-
        CompareStats::RESULT GetResultFromCode(unsigned diffcode) const;
+       void Swap(int idx1, int idx2);
 
 private:
        int m_counts[RESULT_COUNT]; /**< Table storing result counts */
index 15c092e..e7096b5 100644 (file)
@@ -144,6 +144,15 @@ public:
 
        int GetCompareDirs() const { return m_paths.GetSize(); }
 
+       void Swap(int idx1, int idx2)
+       {
+               String tmp;
+               tmp = m_paths.GetPath(idx1);
+               m_paths.SetPath(idx1, m_paths.GetPath(idx2));
+               m_paths.SetPath(idx2, tmp);
+               DiffItemList::Swap(idx1, idx2);
+       }
+
        IDiffFilter * m_piFilterGlobal; /**< Interface for file filtering. */
        IPluginInfos * m_piPluginInfos;
        int m_iGuessEncodingType;
index a1d70a1..0acdcbd 100644 (file)
@@ -65,3 +65,14 @@ void DIFFITEM::RemoveChildren()
                delete p;
        }
 }
+
+void DIFFITEM::Swap(int idx1, int idx2)
+{
+       std::swap(diffFileInfo[idx1], diffFileInfo[idx2]);
+       diffcode.swap(idx1, idx2);
+       if (HasChildren())
+       {
+               for (ListEntry *p = children.IsSibling(children.Flink); p; p = children.IsSibling(p->Flink))
+                       static_cast<DIFFITEM *>(p)->Swap(idx1, idx2);
+       }
+}
index 3b6a685..b2cf0a1 100644 (file)
@@ -162,6 +162,16 @@ public:
        // rescan
        bool isScanNeeded() const { return ((diffcode & DIFFCODE::SCANFLAGS) == DIFFCODE::NEEDSCAN); }
 
+       void swap(int idx1, int idx2)
+       {
+               bool e[3] = { false, false, false };
+               for (int i = 0; i < 3; ++i)
+                       e[i] = exists(i);
+               std::swap(e[idx1], e[idx2]);
+               setSideNone();
+               for (int i = 0; i < 3; ++i)
+                       if (e[i]) setSideFlag(i);
+       }
 };
 
 /**
@@ -199,4 +209,5 @@ struct DIFFITEM : ListEntry
        bool IsAncestor(const DIFFITEM *pdi) const;
        bool HasChildren() const;
        void RemoveChildren();
+       void Swap(int idx1, int idx2);
 };
index c7d352a..f30a568 100644 (file)
@@ -198,3 +198,9 @@ void DiffItemList::SetCustomFlags1(uintptr_t diffpos, unsigned flag)
        DIFFITEM & di = GetDiffRefAt(diffpos);
        di.customFlags1 = flag;
 }
+
+void DiffItemList::Swap(int idx1, int idx2)
+{
+       for (ListEntry *p = m_root.IsSibling(m_root.Flink); p; p = m_root.IsSibling(p->Flink))
+               static_cast<DIFFITEM *>(p)->Swap(idx1, idx2);
+}
index a26172e..bef2e2e 100644 (file)
@@ -40,6 +40,8 @@ public:
        unsigned GetCustomFlags1(uintptr_t diffpos) const;
        void SetCustomFlags1(uintptr_t diffpos, unsigned flag);
 
+       void Swap(int idx1, int idx2);
+
 protected:
        ListEntry m_root; /**< Root of list of diffitems */
 };
index dfd9451..43fed2d 100644 (file)
@@ -634,3 +634,13 @@ bool CDirDoc::IsArchiveFolders() const
        else
                return false;
 }
+
+void CDirDoc::Swap(int idx1, int idx2)
+{
+       std::swap(m_bRO[idx1], m_bRO[idx2]);
+       std::swap(m_strDesc[idx1], m_strDesc[idx2]);
+       m_pCtxt->Swap(idx1, idx2);
+       m_pCompareStats->Swap(idx1, idx2);
+       for (int nIndex = 0; nIndex < m_nDirs; nIndex++)
+               UpdateHeaderPath(nIndex);
+}
index 1002e87..d23efbb 100644 (file)
@@ -112,6 +112,7 @@ public:
        const CompareStats * GetCompareStats() const { return m_pCompareStats.get(); };
        bool IsArchiveFolders() const;
        PluginManager& GetPluginManager() { return m_pluginman; };
+       void Swap(int idx1, int idx2);
 
 protected:
        void LoadLineFilterList();
index 57cbfad..d846c08 100644 (file)
@@ -297,6 +297,7 @@ BEGIN_MESSAGE_MAP(CDirView, CListView)
        ON_UPDATE_COMMAND_UI(ID_VIEW_EXPAND_ALLSUBDIRS, OnUpdateViewExpandAllSubdirs)
        ON_COMMAND(ID_VIEW_COLLAPSE_ALLSUBDIRS, OnViewCollapseAllSubdirs)
        ON_UPDATE_COMMAND_UI(ID_VIEW_COLLAPSE_ALLSUBDIRS, OnUpdateViewCollapseAllSubdirs)
+       ON_COMMAND(ID_VIEW_SWAPPANES, OnViewSwapPanes)
        ON_COMMAND(ID_VIEW_DIR_STATISTICS, OnViewCompareStatistics)
        ON_COMMAND(ID_OPTIONS_SHOWDIFFERENT, OnOptionsShowDifferent)
        ON_COMMAND(ID_OPTIONS_SHOWIDENTICAL, OnOptionsShowIdentical)
@@ -2407,7 +2408,7 @@ struct FileCmpReport: public IFileCmpReport
                        return false;
                }
 
-               sLinkPath = di.diffFileInfo[0].GetFile();\r
+               sLinkPath = di.diffFileInfo[0].GetFile();
 
                string_replace(sLinkPath, _T("\\"), _T("_"));
                sLinkPath += _T(".html");
@@ -3024,6 +3025,12 @@ void CDirView::OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI)
        pCmdUI->Enable(m_bTreeMode && GetDiffContext().m_bRecursive);
 }
 
+void CDirView::OnViewSwapPanes()
+{
+       GetDocument()->Swap(0, GetDocument()->m_nDirs - 1);
+       Redisplay();
+}
+
 /**
  * @brief Show/Hide different files/directories
  */
index 546a456..b2521bc 100644 (file)
@@ -328,6 +328,7 @@ protected:
        afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
        afx_msg void OnViewCollapseAllSubdirs();
        afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
+       afx_msg void OnViewSwapPanes();
        afx_msg void OnOptionsShowDifferent();
        afx_msg void OnOptionsShowIdentical();
        afx_msg void OnOptionsShowUniqueLeft();
index 35b9f14..fa1246e 100644 (file)
@@ -278,6 +278,8 @@ BEGIN
         MENUITEM "Select &Font...",             ID_VIEW_SELECTFONT
         MENUITEM "Use Default F&ont",           ID_VIEW_USEDEFAULTFONT
         MENUITEM SEPARATOR
+        MENUITEM "Sw&ap Panes",                 ID_VIEW_SWAPPANES
+        MENUITEM SEPARATOR
         POPUP "&Toolbar"
         BEGIN
             MENUITEM "&None",                       ID_TOOLBAR_NONE
index 6dd0993..234717e 100644 (file)
     <ClCompile Include="..\..\..\Src\CompareEngines\TimeSizeCompare.cpp" />\r
     <ClCompile Include="..\..\..\Src\CompareOptions.cpp" />\r
     <ClCompile Include="..\..\..\Src\Common\coretools.cpp" />\r
+    <ClCompile Include="..\..\..\Src\DiffFileInfo.cpp" />\r
     <ClCompile Include="..\..\..\Src\DiffItem.cpp" />\r
     <ClCompile Include="..\..\..\Src\diffutils\src\Diff.cpp" />\r
     <ClCompile Include="..\..\..\Src\DirItem.cpp" />\r
index 845666c..914e4f7 100644 (file)
     <ClCompile Include="..\..\..\Src\OptionsDef.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\Src\DiffFileInfo.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\Src\CompareEngines\ByteComparator.h">\r