Skip to content

Commit

Permalink
Fix issus #923: Put the diff patch to the clipboard rather than to files
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Nov 21, 2021
1 parent 58dae9d commit f374eca
Show file tree
Hide file tree
Showing 48 changed files with 363 additions and 523 deletions.
14 changes: 3 additions & 11 deletions Src/Merge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ BEGIN
COMBOBOX IDC_DIFF_FILE2,48,24,230,96,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Br&owse...",IDC_DIFF_BROWSE_FILE2,283,24,52,14
PUSHBUTTON "&Swap",IDC_DIFF_SWAPFILES,283,41,52,14
CONTROL "&Copy to Clipboard",IDC_DIFF_COPYCLIPBOARD,"Button",BS_AUTOCHECKBOX | BS_NOTIFY | WS_TABSTOP,48,40,230,10
CONTROL "&Append to existing file",IDC_DIFF_APPENDFILE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,48,51,230,10
LTEXT "&Result:",IDC_STATIC,7,66,37,10
COMBOBOX IDC_DIFF_FILERESULT,48,63,230,96,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
Expand All @@ -1440,17 +1441,8 @@ BEGIN
COMBOBOX IDC_DIFF_STYLE,63,92,80,68,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&Context:",IDC_STATIC,13,109,46,10
COMBOBOX IDC_DIFF_CONTEXT,63,108,80,65,CBS_DROPDOWN | CBS_SORT | WS_DISABLED | WS_VSCROLL | WS_TABSTOP
GROUPBOX "W&hitespaces",IDC_STATIC,155,81,123,46
CONTROL "Com&pare",IDC_DIFF_WHITESPACE_COMPARE,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,162,92,110,10
CONTROL "I&gnore changes",IDC_DIFF_WHITESPACE_IGNORE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,162,102,110,10
CONTROL "Ig&nore all",IDC_DIFF_WHITESPACE_IGNOREALL,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,162,112,110,10
CONTROL "Ignor&e blank lines",IDC_DIFF_WHITESPACE_IGNOREBLANKS,
"Button",BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,7,134,142,10
CONTROL "Ignore &case",IDC_DIFF_IGNORECASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,145,142,10
CONTROL "Igno&re carriage return differences (Windows/Unix/Mac)",IDC_DIFF_IGNOREEOL,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,156,281,10
CONTROL "Inclu&de command line",IDC_DIFF_INCLCMDLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,155,134,170,10
CONTROL "Open to e&xternal editor",IDC_DIFF_OPENTOEDITOR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,155,145,170,10
CONTROL "Inclu&de command line",IDC_DIFF_INCLCMDLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,134,170,10
CONTROL "Open to e&xternal editor",IDC_DIFF_OPENTOEDITOR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,145,170,10
PUSHBUTTON "Defaults",IDC_DIFF_DEFAULTS,7,170,70,14
DEFPUSHBUTTON "OK",IDOK,230,170,52,14
PUSHBUTTON "Cancel",IDCANCEL,283,170,52,14
Expand Down
5 changes: 1 addition & 4 deletions Src/OptionsDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,9 @@ inline const String OPT_ARCHIVE_FILTER_INDEX {_T("Merge7z/FilterIndex"s)};
// Patch Creator
inline const String OPT_PATCHCREATOR_PATCH_STYLE {_T("PatchCreator/PatchStyle"s)};
inline const String OPT_PATCHCREATOR_CONTEXT_LINES {_T("PatchCreator/ContextLines"s)};
inline const String OPT_PATCHCREATOR_CASE_SENSITIVE {_T("PatchCreator/CaseSensitive"s)};
inline const String OPT_PATCHCREATOR_EOL_SENSITIVE {_T("PatchCreator/EOLSensitive"s)};
inline const String OPT_PATCHCREATOR_IGNORE_BLANK_LINES {_T("PatchCreator/IgnoreBlankLines"s)};
inline const String OPT_PATCHCREATOR_WHITESPACE {_T("PatchCreator/Whitespace"s)};
inline const String OPT_PATCHCREATOR_OPEN_TO_EDITOR {_T("PatchCreator/OpenToEditor"s)};
inline const String OPT_PATCHCREATOR_INCLUDE_CMD_LINE {_T("PatchCreator/IncludeCmdLine"s)};
inline const String OPT_PATCHCREATOR_COPY_TO_CLIPBOARD {_T("PatchCreator/CopyToClipboard"s)};

// Plugins
inline const String OPT_PLUGINS_ENABLED {_T("Settings/PluginsEnabled"s)};
Expand Down
5 changes: 1 addition & 4 deletions Src/OptionsInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,9 @@ void Init(COptionsMgr *pOptions)

pOptions->InitOption(OPT_PATCHCREATOR_PATCH_STYLE, 0, 0, 3);
pOptions->InitOption(OPT_PATCHCREATOR_CONTEXT_LINES, 0);
pOptions->InitOption(OPT_PATCHCREATOR_CASE_SENSITIVE, true);
pOptions->InitOption(OPT_PATCHCREATOR_EOL_SENSITIVE, true);
pOptions->InitOption(OPT_PATCHCREATOR_IGNORE_BLANK_LINES, false);
pOptions->InitOption(OPT_PATCHCREATOR_WHITESPACE, WHITESPACE_COMPARE_ALL, WHITESPACE_COMPARE_ALL, WHITESPACE_IGNORE_ALL);
pOptions->InitOption(OPT_PATCHCREATOR_OPEN_TO_EDITOR, false);
pOptions->InitOption(OPT_PATCHCREATOR_INCLUDE_CMD_LINE, false);
pOptions->InitOption(OPT_PATCHCREATOR_COPY_TO_CLIPBOARD, false);

pOptions->InitOption(OPT_TABBAR_AUTO_MAXWIDTH, true);
pOptions->InitOption(OPT_ACTIVE_FRAME_MAX, true);
Expand Down
36 changes: 5 additions & 31 deletions Src/PatchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ using std::swap;
*/
CPatchDlg::CPatchDlg(CWnd* pParent /*= nullptr*/)
: CTrDialog(CPatchDlg::IDD, pParent)
, m_ignoreCase(false)
, m_ignoreBlanks(false)
, m_ignoreEOLDifference(false)
, m_whitespaceCompare(0)
, m_copyToClipboard(false)
, m_appendFile(false)
, m_openToEditor(false)
, m_includeCmdLine(false)
, m_outputStyle(OUTPUT_NORMAL)
, m_contextLines(0)
, m_diffAlgorithm(DIFF_ALGORITHM_DEFAULT)
, m_indentHeuristic(true)
{
}

Expand All @@ -53,10 +48,7 @@ void CPatchDlg::DoDataExchange(CDataExchange* pDX)
//{{AFX_DATA_MAP(CPatchDlg)
DDX_Control(pDX, IDC_DIFF_STYLE, m_comboStyle);
DDX_Control(pDX, IDC_DIFF_CONTEXT, m_comboContext);
DDX_Check(pDX, IDC_DIFF_IGNORECASE, m_ignoreCase);
DDX_Check(pDX, IDC_DIFF_WHITESPACE_IGNOREBLANKS, m_ignoreBlanks);
DDX_Radio(pDX, IDC_DIFF_WHITESPACE_COMPARE, m_whitespaceCompare);
DDX_Check(pDX, IDC_DIFF_IGNOREEOL, m_ignoreEOLDifference);
DDX_Check(pDX, IDC_DIFF_COPYCLIPBOARD, m_copyToClipboard);
DDX_Check(pDX, IDC_DIFF_APPENDFILE, m_appendFile);
DDX_Control(pDX, IDC_DIFF_FILE1, m_ctlFile1);
DDX_Control(pDX, IDC_DIFF_FILE2, m_ctlFile2);
Expand Down Expand Up @@ -178,8 +170,6 @@ void CPatchDlg::OnOK()
}

m_contextLines = GetDlgItemInt(IDC_DIFF_CONTEXT);
m_diffAlgorithm = static_cast<DiffAlgorithm>(GetOptionsMgr()->GetInt(OPT_CMP_DIFF_ALGORITHM));
m_indentHeuristic = GetOptionsMgr()->GetBool(OPT_CMP_INDENT_HEURISTIC);

SaveSettings();

Expand Down Expand Up @@ -397,19 +387,9 @@ void CPatchDlg::LoadSettings()
if (m_contextLines < 0 || m_contextLines > 50)
m_contextLines = 0;

m_ignoreCase = !GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_CASE_SENSITIVE);
m_ignoreEOLDifference = GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_EOL_SENSITIVE);
m_ignoreBlanks = GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_IGNORE_BLANK_LINES);

m_whitespaceCompare = GetOptionsMgr()->GetInt(OPT_PATCHCREATOR_WHITESPACE);
if (m_whitespaceCompare < WHITESPACE_COMPARE_ALL ||
m_whitespaceCompare > WHITESPACE_IGNORE_ALL)
{
m_whitespaceCompare = WHITESPACE_COMPARE_ALL;
}

m_openToEditor = GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_OPEN_TO_EDITOR);
m_includeCmdLine = GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_INCLUDE_CMD_LINE);
m_copyToClipboard = GetOptionsMgr()->GetBool(OPT_PATCHCREATOR_COPY_TO_CLIPBOARD);

UpdateSettings();
}
Expand All @@ -422,12 +402,9 @@ void CPatchDlg::SaveSettings()
COptionsMgr *pOptions = GetOptionsMgr();
pOptions->SaveOption(OPT_PATCHCREATOR_PATCH_STYLE, m_outputStyle);
pOptions->SaveOption(OPT_PATCHCREATOR_CONTEXT_LINES, m_contextLines);
pOptions->SaveOption(OPT_PATCHCREATOR_CASE_SENSITIVE, !m_ignoreCase);
pOptions->SaveOption(OPT_PATCHCREATOR_EOL_SENSITIVE, m_ignoreEOLDifference);
pOptions->SaveOption(OPT_PATCHCREATOR_IGNORE_BLANK_LINES, m_ignoreBlanks);
pOptions->SaveOption(OPT_PATCHCREATOR_WHITESPACE, m_whitespaceCompare);
pOptions->SaveOption(OPT_PATCHCREATOR_OPEN_TO_EDITOR, m_openToEditor);
pOptions->SaveOption(OPT_PATCHCREATOR_INCLUDE_CMD_LINE, m_includeCmdLine);
pOptions->SaveOption(OPT_PATCHCREATOR_COPY_TO_CLIPBOARD, m_copyToClipboard);
}

/**
Expand All @@ -437,12 +414,9 @@ void CPatchDlg::OnDefaultSettings()
{
m_outputStyle = (enum output_style) DIFF_OUTPUT_NORMAL;
m_contextLines = 0;
m_ignoreCase = false;
m_ignoreEOLDifference = false;
m_ignoreBlanks = false;
m_whitespaceCompare = WHITESPACE_COMPARE_ALL;
m_openToEditor = false;
m_includeCmdLine = false;
m_copyToClipboard = false;

UpdateSettings();
}
Expand Down
7 changes: 1 addition & 6 deletions Src/PatchDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,20 @@ class CPatchDlg : public CTrDialog
enum { IDD = IDD_GENERATE_PATCH };
CComboBox m_comboStyle;
CSuperComboBox m_comboContext;
bool m_ignoreCase;
CSuperComboBox m_ctlFile1;
CSuperComboBox m_ctlFile2;
CSuperComboBox m_ctlResult;
String m_file1;
String m_file2;
String m_fileResult;
bool m_ignoreBlanks;
bool m_ignoreEOLDifference;
int m_whitespaceCompare;
bool m_copyToClipboard;
bool m_appendFile;
bool m_openToEditor;
bool m_includeCmdLine;
//}}AFX_DATA

enum output_style m_outputStyle; /**< Patch style (context, unified etc.) */
int m_contextLines; /**< How many context lines are added. */
enum DiffAlgorithm m_diffAlgorithm;
bool m_indentHeuristic;

// Overrides
// ClassWizard generated virtual function overrides
Expand Down
38 changes: 27 additions & 11 deletions Src/PatchTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include "paths.h"
#include "Merge.h"
#include "DirTravel.h"
#include "OptionsDiffOptions.h"
#include "UniFile.h"
#include "codepage_detect.h"
#include "OptionsMgr.h"
#include "OptionsDef.h"
#include "ClipBoard.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand All @@ -22,7 +28,7 @@
/**
* @brief Default constructor.
*/
CPatchTool::CPatchTool() : m_bOpenToEditor(false)
CPatchTool::CPatchTool() : m_bOpenToEditor(false), m_bCopyToClipbard(false)
{
}

Expand Down Expand Up @@ -186,6 +192,7 @@ int CPatchTool::CreatePatch()

m_sPatchFile = dlgPatch.m_fileResult;
m_bOpenToEditor = dlgPatch.m_openToEditor;
m_bCopyToClipbard = dlgPatch.m_copyToClipboard;
retVal = 1;
}
}
Expand All @@ -194,6 +201,24 @@ int CPatchTool::CreatePatch()
{
if (m_bOpenToEditor)
CMergeApp::OpenFileToExternalEditor(m_sPatchFile);
if (m_bCopyToClipbard)
{
UniMemFile file;
if (file.OpenReadOnly(m_sPatchFile))
{
int iGuessEncodingType = GetOptionsMgr()->GetInt(OPT_CP_DETECT);
FileTextEncoding encoding = codepage_detect::Guess(m_sPatchFile, iGuessEncodingType);
file.SetUnicoding(encoding.m_unicoding);
file.SetCodepage(encoding.m_codepage);
file.SetBom(encoding.m_bom);
if (encoding.m_bom)
file.ReadBom();
String lines;
file.ReadStringAll(lines);
file.Close();
PutToClipboard(lines, AfxGetMainWnd()->m_hWnd);
}
}
}
return retVal;
}
Expand Down Expand Up @@ -223,17 +248,8 @@ bool CPatchTool::ShowDialog(CPatchDlg *pDlgPatch)
m_diffWrapper.SetPatchOptions(&patchOptions);

// These are from checkboxes and radiobuttons - can't be wrong
diffOptions.nIgnoreWhitespace = pDlgPatch->m_whitespaceCompare;
diffOptions.bIgnoreBlankLines = pDlgPatch->m_ignoreBlanks;
m_diffWrapper.SetAppendFiles(pDlgPatch->m_appendFile);

// Use this because non-sensitive setting can't write
// patch file EOLs correctly
diffOptions.bIgnoreEol = pDlgPatch->m_ignoreEOLDifference;

diffOptions.bIgnoreCase = pDlgPatch->m_ignoreCase;
diffOptions.nDiffAlgorithm = pDlgPatch->m_diffAlgorithm;
diffOptions.bIndentHeuristic = pDlgPatch->m_indentHeuristic;
Options::DiffOptions::Load(GetOptionsMgr(), diffOptions);
m_diffWrapper.SetOptions(&diffOptions);
}
else
Expand Down
1 change: 1 addition & 0 deletions Src/PatchTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ class CPatchTool
CDiffWrapper m_diffWrapper; /**< DiffWrapper instance we use to create patch. */
String m_sPatchFile; /**< Patch file path and filename. */
bool m_bOpenToEditor; /**< Is patch file opened to external editor? */
bool m_bCopyToClipbard; /**< Is patch file copied to clipboard? */
};
7 changes: 1 addition & 6 deletions Src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,11 @@
#define IDC_DIFF_FILERESULT 1067
#define IDC_DIFF_STYLE 1068
#define IDC_DIFF_CONTEXT 1069
#define IDC_DIFF_IGNORECASE 1070
#define IDC_DIFF_WHITESPACE_IGNOREBLANKS 1071
#define IDC_DIFF_WHITESPACE_COMPARE 1072
#define IDC_DIFF_WHITESPACE_IGNORE 1073
#define IDC_DIFF_WHITESPACE_IGNOREALL 1074
#define IDC_DIFF_BROWSE_FILE1 1075
#define IDC_DIFF_BROWSE_FILE2 1076
#define IDC_DIFF_BROWSE_RESULT 1077
#define IDC_DIFF_APPENDFILE 1078
#define IDC_DIFF_IGNOREEOL 1079
#define IDC_DIFF_COPYCLIPBOARD 1079
#define IDC_TRIVIAL_DIFF_COLOR 1080
#define IDC_TRIVIAL_DIFF_DELETED_COLOR 1081
#define IDC_FILES_DIRS_GROUP0 1082
Expand Down
5 changes: 1 addition & 4 deletions Testing/GoogleTest/GUITests/ConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,9 @@ namespace
// Patch Creator
{ OPT_PATCHCREATOR_PATCH_STYLE, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_CONTEXT_LINES, varprop::VT_INT, {0, 1, 2, 3, 5, 7}, {}},
{ OPT_PATCHCREATOR_CASE_SENSITIVE, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_EOL_SENSITIVE, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_IGNORE_BLANK_LINES, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_WHITESPACE, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_OPEN_TO_EDITOR, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_INCLUDE_CMD_LINE, varprop::VT_BOOL, {}, {}},
{ OPT_PATCHCREATOR_COPY_TO_CLIPBOARD, varprop::VT_BOOL, {}, {}},
// Plugins
{ OPT_PLUGINS_ENABLED, varprop::VT_BOOL, {}, {}},
{ OPT_PLUGINS_CUSTOM_SETTINGS_LIST, varprop::VT_STRING, {}, {L"EDITOR_SCRIPT.PrettifyHTML=arguments:-indent --tab-size 1 --indent-spaces 1 -wrap 0 --sort-attributes alpha \tFILE_PACK_UNPACK.PrettifyHTML=arguments:-indent --indent-attributes yes --tab-size 2 --indent-spaces 2 -wrap 0 --sort-attributes alpha FILE_PACK_UNPACK.PrettifyXML=arguments:-xml -indent --indent-attributes yes --tab-size 2 --indent-spaces 2 -wrap 0 --sort-attributes alpha|automatic:true FILE_PACK_UNPACK.PrettifyJSON=automatic:true"}},
Expand Down
Loading

0 comments on commit f374eca

Please sign in to comment.