2 * @file DirCmpReportDlg.cpp
4 * @brief Implementation file for DirCmpReport dialog
9 #include "DirCmpReportDlg.h"
10 #include "Coretools.h"
11 #include "DirReportTypes.h"
13 #include "FileOrFolderSelect.h"
14 #include "OptionsMgr.h"
15 #include "OptionsDef.h"
17 IMPLEMENT_DYNAMIC(DirCmpReportDlg, CTrDialog)
22 DirCmpReportDlg::DirCmpReportDlg(CWnd* pParent /*= nullptr*/)
23 : CTrDialog(DirCmpReportDlg::IDD, pParent)
24 , m_bCopyToClipboard(false)
25 , m_bIncludeFileCmpReport(false)
26 , m_nReportType(REPORT_TYPE_COMMALIST)
31 * @brief Map dialog controls to member variables.
32 * This function maps dialog controls with member variables so
33 * when UpdateData() is called controls and member variables
36 void DirCmpReportDlg::DoDataExchange(CDataExchange* pDX)
38 CTrDialog::DoDataExchange(pDX);
39 DDX_Control(pDX, IDC_REPORT_FILE, m_ctlReportFile);
40 DDX_Control(pDX, IDC_REPORT_STYLECOMBO, m_ctlStyle);
41 DDX_Text(pDX, IDC_REPORT_FILE, m_sReportFile);
42 DDX_Check(pDX, IDC_REPORT_COPYCLIPBOARD, m_bCopyToClipboard);
43 DDX_Check(pDX, IDC_REPORT_INCLUDEFILECMPREPORT, m_bIncludeFileCmpReport);
46 BEGIN_MESSAGE_MAP(DirCmpReportDlg, CTrDialog)
47 ON_BN_CLICKED(IDC_REPORT_BROWSEFILE, OnBtnClickReportBrowse)
48 ON_BN_DOUBLECLICKED(IDC_REPORT_COPYCLIPBOARD, OnBtnDblclickCopyClipboard)
49 ON_CBN_SELCHANGE(IDC_REPORT_STYLECOMBO, OnCbnSelchangeReportStylecombo)
53 * @brief Definition for structure containing report types.
54 * This struct is used to form a report types list. This list
55 * can be then used to initialize the GUI for reports.
59 REPORT_TYPE reportType; /**< Report-type ID */
60 const char *idDisplay; /**< Resource-string ID (shown in file-selection dialog) */
61 const char *browseFilter; /**< File-extension filter (resource-string ID) */
65 * @brief List of report types.
66 * This list is used to initialize the GUI.
68 static ReportTypeInfo f_types[] = {
69 { REPORT_TYPE_COMMALIST,
70 "Comma-separated list",
71 "Text Files (*.csv;*.asc;*.rpt;*.txt)|*.csv;*.asc;*.rpt;*.txt|All Files (*.*)|*.*||"
73 { REPORT_TYPE_TABLIST,
75 "Text Files (*.csv;*.asc;*.rpt;*.txt)|*.csv;*.asc;*.rpt;*.txt|All Files (*.*)|*.*||"
77 { REPORT_TYPE_SIMPLEHTML,
79 "HTML Files (*.htm,*.html)|*.htm;*.html|All Files (*.*)|*.*||"
81 { REPORT_TYPE_SIMPLEXML,
83 "XML Files (*.xml)|*.xml|All Files (*.*)|*.*||"
87 void DirCmpReportDlg::LoadSettings()
89 m_nReportType = static_cast<REPORT_TYPE>(GetOptionsMgr()->GetInt(OPT_REPORTFILES_REPORTTYPE));
90 m_bCopyToClipboard = GetOptionsMgr()->GetBool(OPT_REPORTFILES_COPYTOCLIPBOARD);
91 m_bIncludeFileCmpReport = GetOptionsMgr()->GetBool(OPT_REPORTFILES_INCLUDEFILECMPREPORT);
95 * @brief Dialog initializer function.
97 BOOL DirCmpReportDlg::OnInitDialog()
99 CTrDialog::OnInitDialog();
103 m_ctlReportFile.LoadState(_T("ReportFiles"));
105 for (int i = 0; i < sizeof(f_types) / sizeof(f_types[0]); ++i)
107 const ReportTypeInfo & info = f_types[i];
108 int ind = m_ctlStyle.InsertString(i, tr(info.idDisplay).c_str());
109 m_ctlStyle.SetItemData(ind, info.reportType);
110 if (info.reportType == m_nReportType)
111 m_ctlStyle.SetCurSel(m_nReportType);
113 if (m_ctlStyle.GetCurSel() < 0)
114 m_ctlStyle.SetCurSel(0);
116 OnCbnSelchangeReportStylecombo();
118 // Set selected path to variable so file selection dialog shows
119 // correct filename and path.
120 CString cstrReportFile;
121 m_ctlReportFile.GetWindowText(cstrReportFile);
122 m_sReportFile = cstrReportFile;
126 return TRUE; // return TRUE unless you set the focus to a control
127 // EXCEPTION: OCX Property Pages should return FALSE
131 * @brief Browse for report file.
133 void DirCmpReportDlg::OnBtnClickReportBrowse()
137 String folder = m_sReportFile;
138 String filter = tr(f_types[m_ctlStyle.GetCurSel()].browseFilter);
140 String chosenFilepath;
141 if (SelectFile(GetSafeHwnd(), chosenFilepath, false, folder.c_str(), _T(""), filter))
143 m_sReportFile = chosenFilepath;
144 m_ctlReportFile.SetWindowText(chosenFilepath.c_str());
149 * @brief Erase report file name.
151 void DirCmpReportDlg::OnBtnDblclickCopyClipboard()
153 m_ctlReportFile.SetWindowText(_T(""));
156 void DirCmpReportDlg::OnCbnSelchangeReportStylecombo()
158 EnableDlgItem(IDC_REPORT_INCLUDEFILECMPREPORT,
159 m_ctlStyle.GetItemData(m_ctlStyle.GetCurSel()) == REPORT_TYPE_SIMPLEHTML);
163 * @brief Close dialog.
165 void DirCmpReportDlg::OnOK()
169 int sel = m_ctlStyle.GetCurSel();
170 m_nReportType = (REPORT_TYPE)m_ctlStyle.GetItemData(sel);
172 if (m_sReportFile.empty() && !m_bCopyToClipboard)
174 LangMessageBox(IDS_MUST_SPECIFY_OUTPUT, MB_ICONSTOP);
175 m_ctlReportFile.SetFocus();
179 if (!m_sReportFile.empty())
181 if (paths::DoesPathExist(m_sReportFile) == paths::IS_EXISTING_FILE)
183 int overWrite = LangMessageBox(IDS_REPORT_FILEOVERWRITE,
184 MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN,
185 IDS_REPORT_FILEOVERWRITE);
186 if (overWrite == IDNO)
191 m_ctlReportFile.SaveState(_T("ReportFiles"));
192 GetOptionsMgr()->SaveOption(OPT_REPORTFILES_REPORTTYPE, static_cast<int>(m_nReportType));
193 GetOptionsMgr()->SaveOption(OPT_REPORTFILES_COPYTOCLIPBOARD, m_bCopyToClipboard);
194 GetOptionsMgr()->SaveOption(OPT_REPORTFILES_INCLUDEFILECMPREPORT, m_bIncludeFileCmpReport);