forked from WinMerge/winmerge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirFilterDlg.cpp
168 lines (146 loc) · 3.94 KB
/
DirFilterDlg.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
/**
* @file DirFilterDlg.cpp
*
* @brief Implementation file for DirCmpReport dialog
*
*/
#include "stdafx.h"
#include "Coretools.h"
#include "DirFilterDlg.h"
#include "DirReportTypes.h"
#include "paths.h"
#include "FileOrFolderSelect.h"
#include "Merge.h"
IMPLEMENT_DYNAMIC(DirFilterDlg, CDialog)
/**
* @brief Constructor.
*/
DirFilterDlg::DirFilterDlg(CWnd* pParent /*=NULL*/)
: CDialog(DirFilterDlg::IDD, pParent)
, m_bCopyToClipboard(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 DirFilterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::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);
}
BEGIN_MESSAGE_MAP(DirFilterDlg, CDialog)
ON_BN_CLICKED(IDC_REPORT_BROWSEFILE, OnBtnClickReportBrowse)
ON_BN_DOUBLECLICKED(IDC_REPORT_COPYCLIPBOARD, OnBtnDblclickCopyClipboard)
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 */
int idDisplay; /**< Resource-string ID (shown in file-selection dialog) */
int 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,
IDS_REPORT_COMMALIST,
IDS_TEXT_REPORT_FILES
},
{ REPORT_TYPE_TABLIST,
IDS_REPORT_TABLIST,
IDS_TEXT_REPORT_FILES
},
{ REPORT_TYPE_SIMPLEHTML,
IDS_REPORT_SIMPLEHTML,
IDS_HTML_REPORT_FILES
},
{ REPORT_TYPE_SIMPLEXML,
IDS_REPORT_SIMPLEXML,
IDS_XML_REPORT_FILES
},
};
/**
* @brief Dialog initializer function.
*/
BOOL DirFilterDlg::OnInitDialog()
{
theApp.TranslateDialog(m_hWnd);
CDialog::OnInitDialog();
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, theApp.LoadString(info.idDisplay).c_str());
m_ctlStyle.SetItemData(ind, info.reportType);
}
m_ctlStyle.SetCurSel(0);
// Set selected path to variable so file selection dialog shows
// correct filename and path.
m_ctlReportFile.GetWindowText(m_sReportFile);
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 DirFilterDlg::OnBtnClickReportBrowse()
{
UpdateData(TRUE);
CString folder = m_sReportFile;
int filterid = f_types[m_ctlStyle.GetCurSel()].browseFilter;
CString chosenFilepath;
if (SelectFile(GetSafeHwnd(), chosenFilepath, folder, IDS_SAVE_AS_TITLE,
filterid, FALSE))
{
m_sReportFile = chosenFilepath;
m_ctlReportFile.SetWindowText(chosenFilepath);
}
}
/**
* @brief Erase report file name.
*/
void DirFilterDlg::OnBtnDblclickCopyClipboard()
{
m_ctlReportFile.SetWindowText(_T(""));
}
/**
* @brief Close dialog.
*/
void DirFilterDlg::OnOK()
{
UpdateData(TRUE);
int sel = m_ctlStyle.GetCurSel();
m_nReportType = (REPORT_TYPE)m_ctlStyle.GetItemData(sel);
if (m_sReportFile.IsEmpty() && !m_bCopyToClipboard)
{
LangMessageBox(IDS_MUST_SPECIFY_OUTPUT, MB_ICONSTOP);
m_ctlReportFile.SetFocus();
return;
}
if (!m_sReportFile.IsEmpty())
{
if (paths_DoesPathExist(m_sReportFile) == IS_EXISTING_FILE)
{
int overWrite = LangMessageBox(IDS_REPORT_FILEOVERWRITE,
MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN,
IDS_DIFF_FILEOVERWRITE);
if (overWrite == IDNO)
return;
}
}
m_ctlReportFile.SaveState(_T("ReportFiles"));
CDialog::OnOK();
}