#include "Merge7zFormatMergePluginImpl.h"
#include "FileOrFolderSelect.h"
#include "IntToIntMap.h"
+#include "PatchTool.h"
#include <numeric>
#include <functional>
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>)
}
/**
+ * @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.
*
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>
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)
#include "Constants.h"
#include "Merge7zFormatMergePluginImpl.h"
#include "7zCommon.h"
+#include "PatchTool.h"
#ifdef _DEBUG
#define new DEBUG_NEW
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)
}
/**
+ * @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()
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();
#include "PathContext.h"
#include "PatchDlg.h"
#include "paths.h"
+#include "Merge.h"
#ifdef _DEBUG
#define new DEBUG_NEW
}
}
dlgPatch.ClearItems();
+ if (retVal)
+ {
+ if (m_bOpenToEditor)
+ theApp.OpenFileToExternalEditor(m_sPatchFile);
+ }
return retVal;
}
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;
-}
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);