forked from WinMerge/winmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirCmpReportDlg.cpp
197 lines (170 loc) · 5.33 KB
/
DirCmpReportDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* @file DirCmpReportDlg.cpp
*
* @brief Implementation file for DirCmpReport dialog
*
*/
#include "stdafx.h"
#include "DirCmpReportDlg.h"
#include "Coretools.h"
#include "DirReportTypes.h"
#include "paths.h"
#include "FileOrFolderSelect.h"
#include "OptionsMgr.h"
#include "OptionsDef.h"
IMPLEMENT_DYNAMIC(DirCmpReportDlg, CTrDialog)
/**
* @brief Constructor.
*/
DirCmpReportDlg::DirCmpReportDlg(CWnd* pParent /*= nullptr*/)
: CTrDialog(DirCmpReportDlg::IDD, pParent)
, m_bCopyToClipboard(false)
, m_bIncludeFileCmpReport(false)
, m_nReportType(REPORT_TYPE_COMMALIST)
{
}
/**
* @brief Map dialog controls to member variables.
* This function maps dialog controls with member variables so
* when UpdateData() is called controls and member variables
* get updated.
*/
void DirCmpReportDlg::DoDataExchange(CDataExchange* pDX)
{
CTrDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_REPORT_FILE, m_ctlReportFile);
DDX_Control(pDX, IDC_REPORT_STYLECOMBO, m_ctlStyle);
DDX_Text(pDX, IDC_REPORT_FILE, m_sReportFile);
DDX_Check(pDX, IDC_REPORT_COPYCLIPBOARD, m_bCopyToClipboard);
DDX_Check(pDX, IDC_REPORT_INCLUDEFILECMPREPORT, m_bIncludeFileCmpReport);
}
BEGIN_MESSAGE_MAP(DirCmpReportDlg, CTrDialog)
ON_BN_CLICKED(IDC_REPORT_BROWSEFILE, OnBtnClickReportBrowse)
ON_BN_DOUBLECLICKED(IDC_REPORT_COPYCLIPBOARD, OnBtnDblclickCopyClipboard)
ON_CBN_SELCHANGE(IDC_REPORT_STYLECOMBO, OnCbnSelchangeReportStylecombo)
END_MESSAGE_MAP()
/**
* @brief Definition for structure containing report types.
* This struct is used to form a report types list. This list
* can be then used to initialize the GUI for reports.
*/
struct ReportTypeInfo
{
REPORT_TYPE reportType; /**< Report-type ID */
const char *idDisplay; /**< Resource-string ID (shown in file-selection dialog) */
const char *browseFilter; /**< File-extension filter (resource-string ID) */
};
/**
* @brief List of report types.
* This list is used to initialize the GUI.
*/
static ReportTypeInfo f_types[] = {
{ REPORT_TYPE_COMMALIST,
"Comma-separated list",
"Text Files (*.csv;*.asc;*.rpt;*.txt)|*.csv;*.asc;*.rpt;*.txt|All Files (*.*)|*.*||"
},
{ REPORT_TYPE_TABLIST,
"Tab-separated list",
"Text Files (*.csv;*.asc;*.rpt;*.txt)|*.csv;*.asc;*.rpt;*.txt|All Files (*.*)|*.*||"
},
{ REPORT_TYPE_SIMPLEHTML,
"Simple HTML",
"HTML Files (*.htm,*.html)|*.htm;*.html|All Files (*.*)|*.*||"
},
{ REPORT_TYPE_SIMPLEXML,
"Simple XML",
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*||"
},
};
void DirCmpReportDlg::LoadSettings()
{
m_nReportType = static_cast<REPORT_TYPE>(GetOptionsMgr()->GetInt(OPT_REPORTFILES_REPORTTYPE));
m_bCopyToClipboard = GetOptionsMgr()->GetBool(OPT_REPORTFILES_COPYTOCLIPBOARD);
m_bIncludeFileCmpReport = GetOptionsMgr()->GetBool(OPT_REPORTFILES_INCLUDEFILECMPREPORT);
}
/**
* @brief Dialog initializer function.
*/
BOOL DirCmpReportDlg::OnInitDialog()
{
CTrDialog::OnInitDialog();
LoadSettings();
m_ctlReportFile.LoadState(_T("ReportFiles"));
for (int i = 0; i < sizeof(f_types) / sizeof(f_types[0]); ++i)
{
const ReportTypeInfo & info = f_types[i];
int ind = m_ctlStyle.InsertString(i, tr(info.idDisplay).c_str());
m_ctlStyle.SetItemData(ind, info.reportType);
if (info.reportType == m_nReportType)
m_ctlStyle.SetCurSel(m_nReportType);
}
if (m_ctlStyle.GetCurSel() < 0)
m_ctlStyle.SetCurSel(0);
OnCbnSelchangeReportStylecombo();
// Set selected path to variable so file selection dialog shows
// correct filename and path.
CString cstrReportFile;
m_ctlReportFile.GetWindowText(cstrReportFile);
m_sReportFile = cstrReportFile;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/**
* @brief Browse for report file.
*/
void DirCmpReportDlg::OnBtnClickReportBrowse()
{
UpdateData(TRUE);
String folder = m_sReportFile;
String filter = tr(f_types[m_ctlStyle.GetCurSel()].browseFilter);
String chosenFilepath;
if (SelectFile(GetSafeHwnd(), chosenFilepath, false, folder.c_str(), _T(""), filter))
{
m_sReportFile = chosenFilepath;
m_ctlReportFile.SetWindowText(chosenFilepath.c_str());
}
}
/**
* @brief Erase report file name.
*/
void DirCmpReportDlg::OnBtnDblclickCopyClipboard()
{
m_ctlReportFile.SetWindowText(_T(""));
}
void DirCmpReportDlg::OnCbnSelchangeReportStylecombo()
{
EnableDlgItem(IDC_REPORT_INCLUDEFILECMPREPORT,
m_ctlStyle.GetItemData(m_ctlStyle.GetCurSel()) == REPORT_TYPE_SIMPLEHTML);
}
/**
* @brief Close dialog.
*/
void DirCmpReportDlg::OnOK()
{
UpdateData(TRUE);
int sel = m_ctlStyle.GetCurSel();
m_nReportType = (REPORT_TYPE)m_ctlStyle.GetItemData(sel);
if (m_sReportFile.empty() && !m_bCopyToClipboard)
{
LangMessageBox(IDS_MUST_SPECIFY_OUTPUT, MB_ICONSTOP);
m_ctlReportFile.SetFocus();
return;
}
if (!m_sReportFile.empty())
{
if (paths::DoesPathExist(m_sReportFile) == paths::IS_EXISTING_FILE)
{
int overWrite = LangMessageBox(IDS_REPORT_FILEOVERWRITE,
MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN,
IDS_REPORT_FILEOVERWRITE);
if (overWrite == IDNO)
return;
}
}
m_ctlReportFile.SaveState(_T("ReportFiles"));
GetOptionsMgr()->SaveOption(OPT_REPORTFILES_REPORTTYPE, static_cast<int>(m_nReportType));
GetOptionsMgr()->SaveOption(OPT_REPORTFILES_COPYTOCLIPBOARD, m_bCopyToClipboard);
GetOptionsMgr()->SaveOption(OPT_REPORTFILES_INCLUDEFILECMPREPORT, m_bIncludeFileCmpReport);
CTrDialog::OnOK();
}