OSDN Git Service

Move a part of CMainFrame::OnToolsGeneratePatch() to DirView and MergeDoc
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 14 Feb 2016 08:30:15 +0000 (17:30 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 14 Feb 2016 08:30:15 +0000 (17:30 +0900)
Src/DirView.cpp
Src/DirView.h
Src/MainFrm.cpp
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/PatchTool.cpp
Src/PatchTool.h

index 86ccf58..39ccc83 100644 (file)
@@ -59,6 +59,7 @@
 #include "Merge7zFormatMergePluginImpl.h"
 #include "FileOrFolderSelect.h"
 #include "IntToIntMap.h"
+#include "PatchTool.h"
 #include <numeric>
 #include <functional>
 
@@ -217,6 +218,7 @@ BEGIN_MESSAGE_MAP(CDirView, CListView)
        ON_UPDATE_COMMAND_UI(ID_FILE_RIGHT_READONLY, OnUpdateReadOnly<SIDE_RIGHT>)
        ON_COMMAND(ID_TOOLS_CUSTOMIZECOLUMNS, OnCustomizeColumns)
        ON_COMMAND(ID_TOOLS_GENERATEREPORT, OnToolsGenerateReport)
+       ON_COMMAND(ID_TOOLS_GENERATEPATCH, OnToolsGeneratePatch)
        ON_COMMAND(ID_DIR_ZIP_LEFT, OnCtxtDirZip<DirItemEnumerator::Left>)
        ON_COMMAND(ID_DIR_ZIP_MIDDLE, OnCtxtDirZip<DirItemEnumerator::Middle>)
        ON_COMMAND(ID_DIR_ZIP_RIGHT, OnCtxtDirZip<DirItemEnumerator::Right>)
@@ -2485,6 +2487,62 @@ void CDirView::OnToolsGenerateReport()
 }
 
 /**
+ * @brief Generate patch from files selected.
+ *
+ * Creates a patch from selected files in active directory compare, or
+ * active file compare. Files in file compare must be saved before
+ * creating a patch.
+ */
+void CDirView::OnToolsGeneratePatch()
+{
+       CPatchTool patcher;
+       const CDiffContext& ctxt = GetDiffContext();
+
+       // Get selected items from folder compare
+       BOOL bValidFiles = TRUE;
+       for (DirItemIterator it = SelBegin(); bValidFiles && it != SelEnd(); ++it)
+       {
+               const DIFFITEM &item = *it;
+               if (item.diffcode.isBin())
+               {
+                       LangMessageBox(IDS_CANNOT_CREATE_BINARYPATCH, MB_ICONWARNING |
+                               MB_DONT_DISPLAY_AGAIN, IDS_CANNOT_CREATE_BINARYPATCH);
+                       bValidFiles = FALSE;
+               }
+               else if (item.diffcode.isDirectory())
+               {
+                       LangMessageBox(IDS_CANNOT_CREATE_DIRPATCH, MB_ICONWARNING |
+                               MB_DONT_DISPLAY_AGAIN, IDS_CANNOT_CREATE_DIRPATCH);
+                       bValidFiles = FALSE;
+               }
+
+               if (bValidFiles)
+               {
+                       // Format full paths to files (leftFile/rightFile)
+                       String leftFile = item.getFilepath(0, ctxt.GetNormalizedPath(0));
+                       if (!leftFile.empty())
+                               leftFile = paths_ConcatPath(leftFile, item.diffFileInfo[0].filename);
+                       String rightFile = item.getFilepath(1, ctxt.GetNormalizedPath(1));
+                       if (!rightFile.empty())
+                               rightFile = paths_ConcatPath(rightFile, item.diffFileInfo[1].filename);
+
+                       // Format relative paths to files in folder compare
+                       String leftpatch = item.diffFileInfo[0].path;
+                       if (!leftpatch.empty())
+                               leftpatch += _T("/");
+                       leftpatch += item.diffFileInfo[0].filename;
+                       String rightpatch = item.diffFileInfo[1].path;
+                       if (!rightpatch.empty())
+                               rightpatch += _T("/");
+                       rightpatch += item.diffFileInfo[1].filename;
+                       patcher.AddFiles(leftFile, leftpatch, rightFile, rightpatch);
+               }
+       }
+
+       patcher.CreatePatch();
+}
+
+/**
  * @brief Add special items for non-recursive compare
  * to directory view.
  *
index a3dc599..cfa510d 100644 (file)
@@ -290,6 +290,7 @@ protected:
        afx_msg void OnCtxtOpenWithUnpacker();
        afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
        afx_msg void OnToolsGenerateReport();
+       afx_msg void OnToolsGeneratePatch();
        template<int flag>
        afx_msg void OnCtxtDirZip();
        template<SIDE_TYPE stype>
index 0c9035c..337872d 100644 (file)
@@ -1402,91 +1402,7 @@ void CMainFrame::ClearStatusbarItemCount()
 void CMainFrame::OnToolsGeneratePatch()
 {
        CPatchTool patcher;
-       CFrameWnd * pFrame = GetActiveFrame();
-       FRAMETYPE frame = GetFrameType(pFrame);
-       BOOL bOpenDialog = TRUE;
-
-       // Mergedoc active?
-       if (frame == FRAME_FILE)
-       {
-               CMergeDoc * pMergeDoc = static_cast<CMergeDoc *>(pFrame->GetActiveDocument());
-               // If there are changes in files, tell user to save them first
-               BOOL bModified = FALSE;
-               for (int pane = 0; pane < pMergeDoc->m_nBuffers; pane++)
-               {
-                       if (pMergeDoc->m_ptBuf[pane]->IsModified())
-                               bModified = TRUE;
-               }
-               if (bModified)
-               {
-                       bOpenDialog = FALSE;
-                       LangMessageBox(IDS_SAVEFILES_FORPATCH, MB_ICONSTOP);
-               }
-               else
-               {
-                       patcher.AddFiles(pMergeDoc->m_filePaths.GetLeft(),
-                                       pMergeDoc->m_filePaths.GetRight());
-               }
-       }
-       // Dirview active
-       else if (frame == FRAME_FOLDER)
-       {
-               CDirDoc * pDoc = static_cast<CDirDoc*>(pFrame->GetActiveDocument());
-               const CDiffContext& ctxt = pDoc->GetDiffContext();
-               CDirView *pView = pDoc->GetMainView();
-
-               // Get selected items from folder compare
-               BOOL bValidFiles = TRUE;
-               for (DirItemIterator it = pView->SelBegin(); bValidFiles && it != pView->SelEnd(); ++it)
-               {
-                       const DIFFITEM &item = *it;
-                       if (item.diffcode.isBin())
-                       {
-                               LangMessageBox(IDS_CANNOT_CREATE_BINARYPATCH, MB_ICONWARNING |
-                                       MB_DONT_DISPLAY_AGAIN, IDS_CANNOT_CREATE_BINARYPATCH);
-                               bValidFiles = FALSE;
-                       }
-                       else if (item.diffcode.isDirectory())
-                       {
-                               LangMessageBox(IDS_CANNOT_CREATE_DIRPATCH, MB_ICONWARNING |
-                                       MB_DONT_DISPLAY_AGAIN, IDS_CANNOT_CREATE_DIRPATCH);
-                               bValidFiles = FALSE;
-                       }
-
-                       if (bValidFiles)
-                       {
-                               // Format full paths to files (leftFile/rightFile)
-                               String leftFile = item.getFilepath(0, ctxt.GetNormalizedPath(0));
-                               if (!leftFile.empty())
-                                       leftFile = paths_ConcatPath(leftFile, item.diffFileInfo[0].filename);
-                               String rightFile = item.getFilepath(1, ctxt.GetNormalizedPath(1));
-                               if (!rightFile.empty())
-                                       rightFile = paths_ConcatPath(rightFile, item.diffFileInfo[1].filename);
-
-                               // Format relative paths to files in folder compare
-                               String leftpatch = item.diffFileInfo[0].path;
-                               if (!leftpatch.empty())
-                                       leftpatch += _T("/");
-                               leftpatch += item.diffFileInfo[0].filename;
-                               String rightpatch = item.diffFileInfo[1].path;
-                               if (!rightpatch.empty())
-                                       rightpatch += _T("/");
-                               rightpatch += item.diffFileInfo[1].filename;
-                               patcher.AddFiles(leftFile, leftpatch, rightFile, rightpatch);
-                       }
-               }
-       }
-
-       if (bOpenDialog)
-       {
-               if (patcher.CreatePatch())
-               {
-                       if (patcher.GetOpenToEditor())
-                       {
-                               theApp.OpenFileToExternalEditor(patcher.GetPatchFile().c_str());
-                       }
-               }
-       }
+       patcher.CreatePatch();
 }
 
 void CMainFrame::OnDropFiles(const std::vector<String>& dropped_files)
index 5a5227f..a86a71f 100644 (file)
@@ -66,6 +66,7 @@
 #include "Constants.h"
 #include "Merge7zFormatMergePluginImpl.h"
 #include "7zCommon.h"
+#include "PatchTool.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -107,6 +108,7 @@ BEGIN_MESSAGE_MAP(CMergeDoc, CDocument)
        ON_UPDATE_COMMAND_UI(ID_STATUS_DIFFNUM, OnUpdateStatusNum)
        ON_UPDATE_COMMAND_UI(ID_STATUS_PLUGIN, OnUpdatePluginName)
        ON_COMMAND(ID_TOOLS_GENERATEREPORT, OnToolsGenerateReport)
+       ON_COMMAND(ID_TOOLS_GENERATEPATCH, OnToolsGeneratePatch)
        ON_COMMAND(ID_RESCAN, OnFileReload)
        ON_UPDATE_COMMAND_UI(ID_RESCAN, OnUpdateFileReload)
        ON_COMMAND(ID_FILE_ENCODING, OnFileEncoding)
@@ -3284,6 +3286,28 @@ void CMergeDoc::OnToolsGenerateReport()
 }
 
 /**
+ * @brief Generate patch from files selected.
+ *
+ * Creates a patch from selected files in active directory compare, or
+ * active file compare. Files in file compare must be saved before
+ * creating a patch.
+ */
+void CMergeDoc::OnToolsGeneratePatch()
+{
+       // If there are changes in files, tell user to save them first
+       if (IsModified())
+       {
+               LangMessageBox(IDS_SAVEFILES_FORPATCH, MB_ICONSTOP);
+               return;
+       }
+
+       CPatchTool patcher;
+       patcher.AddFiles(m_filePaths.GetLeft(),
+                       m_filePaths.GetRight());
+       patcher.CreatePatch();
+}
+
+/**
  * @brief Add synchronization point
  */
 void CMergeDoc::AddSyncPoint()
index 16c3282..8568c50 100644 (file)
@@ -347,6 +347,7 @@ protected:
        afx_msg void OnDiffContext(UINT nID);
        afx_msg void OnUpdateDiffContext(CCmdUI* pCmdUI);
        afx_msg void OnToolsGenerateReport();
+       afx_msg void OnToolsGeneratePatch();
        afx_msg void OnCtxtOpenWithUnpacker();
        afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
        afx_msg void OnBnClickedFileEncoding();
index 849a475..3343369 100644 (file)
@@ -27,6 +27,7 @@
 #include "PathContext.h"
 #include "PatchDlg.h"
 #include "paths.h"
+#include "Merge.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -170,6 +171,11 @@ int CPatchTool::CreatePatch()
                }
        }
        dlgPatch.ClearItems();
+       if (retVal)
+       {
+               if (m_bOpenToEditor)
+                       theApp.OpenFileToExternalEditor(m_sPatchFile);
+       }
        return retVal;
 }
 
@@ -214,20 +220,3 @@ bool CPatchTool::ShowDialog(CPatchDlg *pDlgPatch)
 
        return bRetVal;
 }
-
-/** 
- * @brief Returns filename and path for patch-file
- */
-String CPatchTool::GetPatchFile() const
-{
-       return m_sPatchFile;
-}
-
-/** 
- * @brief Returns TRUE if user wants to open patch file
- * to external editor (specified in WinMerge options).
- */
-bool CPatchTool::GetOpenToEditor() const
-{
-       return m_bOpenToEditor;
-}
index 054fdbd..9aa31bc 100644 (file)
@@ -67,8 +67,6 @@ public:
        void AddFiles(const String &file1, const String &altPath1,
                const String &file2, const String &altPath2);
        int CreatePatch();
-       String GetPatchFile() const;
-       bool GetOpenToEditor() const;
 
 protected:
        bool ShowDialog(CPatchDlg *pDlgPatch);