OSDN Git Service

Avoid an assertion failure when loading settings from winmerge.ini
[winmerge-jp/winmerge-jp.git] / Src / PropCompareTable.cpp
1 /** 
2  * @file  PropCompareTable.cpp
3  *
4  * @brief Implementation of PropCompareTable propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropCompareTable.h"
9 #include "WildcardDropList.h"
10 #include "OptionsDef.h"
11 #include "OptionsMgr.h"
12 #include "OptionsPanel.h"
13
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #endif
17
18 /** 
19  * @brief Constructor.
20  * @param [in] optionsMgr Pointer to COptionsMgr.
21  */
22 PropCompareTable::PropCompareTable(COptionsMgr *optionsMgr) 
23  : OptionsPanel(optionsMgr, PropCompareTable::IDD)
24 , m_bAllowNewlinesInQuotes(true)
25 , m_sDSVDelimiterChar(_T(";"))
26 , m_sQuoteChar(_T("\""))
27 {
28 }
29
30 void PropCompareTable::DoDataExchange(CDataExchange* pDX)
31 {
32         CPropertyPage::DoDataExchange(pDX);
33         //{{AFX_DATA_MAP(PropCompareTable)
34         DDX_Control(pDX, IDC_COMPARETABLE_CSV_PATTERNS, m_comboCSVPatterns);
35         DDX_Text(pDX, IDC_COMPARETABLE_CSV_PATTERNS, m_sCSVFilePatterns);
36         DDX_Control(pDX, IDC_COMPARETABLE_TSV_PATTERNS, m_comboTSVPatterns);
37         DDX_Text(pDX, IDC_COMPARETABLE_TSV_PATTERNS, m_sTSVFilePatterns);
38         DDX_Control(pDX, IDC_COMPARETABLE_DSV_PATTERNS, m_comboDSVPatterns);
39         DDX_Text(pDX, IDC_COMPARETABLE_DSV_PATTERNS, m_sDSVFilePatterns);
40         DDX_Text(pDX, IDC_COMPARETABLE_DSV_DELIM_CHAR, m_sDSVDelimiterChar);
41         DDX_Check(pDX, IDC_COMPARETABLE_ALLOWNEWLINE, m_bAllowNewlinesInQuotes);
42         DDX_Text(pDX, IDC_COMPARETABLE_QUOTE_CHAR, m_sQuoteChar);
43         //}}AFX_DATA_MAP
44 }
45
46
47 BEGIN_MESSAGE_MAP(PropCompareTable, OptionsPanel)
48         //{{AFX_MSG_MAP(PropCompareTable)
49         ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults)
50         ON_CBN_DROPDOWN(IDC_COMPARETABLE_CSV_PATTERNS, OnDropDownCSVPatterns)
51         ON_CBN_CLOSEUP(IDC_COMPARETABLE_CSV_PATTERNS, OnCloseUpCSVPatterns)
52         ON_CBN_DROPDOWN(IDC_COMPARETABLE_TSV_PATTERNS, OnDropDownTSVPatterns)
53         ON_CBN_CLOSEUP(IDC_COMPARETABLE_TSV_PATTERNS, OnCloseUpTSVPatterns)
54         ON_CBN_DROPDOWN(IDC_COMPARETABLE_DSV_PATTERNS, OnDropDownDSVPatterns)
55         ON_CBN_CLOSEUP(IDC_COMPARETABLE_DSV_PATTERNS, OnCloseUpDSVPatterns)
56         //}}AFX_MSG_MAP
57 END_MESSAGE_MAP()
58
59 /** 
60  * @brief Reads options values from storage to UI.
61  * Property sheet calls this before displaying GUI to load values
62  * into members.
63  */
64 void PropCompareTable::ReadOptions()
65 {
66         m_sCSVFilePatterns = GetOptionsMgr()->GetString(OPT_CMP_CSV_FILEPATTERNS);
67         m_sTSVFilePatterns = GetOptionsMgr()->GetString(OPT_CMP_TSV_FILEPATTERNS);
68         m_sDSVFilePatterns = GetOptionsMgr()->GetString(OPT_CMP_DSV_FILEPATTERNS);
69         m_sDSVDelimiterChar = GetOptionsMgr()->GetString(OPT_CMP_DSV_DELIM_CHAR).substr(0, 1);
70         m_bAllowNewlinesInQuotes = GetOptionsMgr()->GetBool(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES);
71         m_sQuoteChar = GetOptionsMgr()->GetString(OPT_CMP_TBL_QUOTE_CHAR).substr(0, 1);
72 }
73
74 /** 
75  * @brief Writes options values from UI to storage.
76  * Property sheet calls this after dialog is closed with OK button to
77  * store values in member variables.
78  */
79 void PropCompareTable::WriteOptions()
80 {
81         WildcardRemoveDuplicatePatterns(m_sCSVFilePatterns);
82         GetOptionsMgr()->SaveOption(OPT_CMP_CSV_FILEPATTERNS, m_sCSVFilePatterns);
83         WildcardRemoveDuplicatePatterns(m_sTSVFilePatterns);
84         GetOptionsMgr()->SaveOption(OPT_CMP_TSV_FILEPATTERNS, m_sTSVFilePatterns);
85         WildcardRemoveDuplicatePatterns(m_sDSVFilePatterns);
86         GetOptionsMgr()->SaveOption(OPT_CMP_DSV_FILEPATTERNS, m_sDSVFilePatterns);
87         GetOptionsMgr()->SaveOption(OPT_CMP_DSV_DELIM_CHAR, m_sDSVDelimiterChar.substr(0, 1));
88         GetOptionsMgr()->SaveOption(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES, m_bAllowNewlinesInQuotes);
89         GetOptionsMgr()->SaveOption(OPT_CMP_TBL_QUOTE_CHAR, m_sQuoteChar.substr(0, 1));
90 }
91
92 /** 
93  * @brief Sets options to defaults
94  */
95 void PropCompareTable::OnDefaults()
96 {
97         m_sCSVFilePatterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_CSV_FILEPATTERNS);
98         m_sTSVFilePatterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_TSV_FILEPATTERNS);
99         m_sDSVFilePatterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_DSV_FILEPATTERNS);
100         m_sDSVDelimiterChar = GetOptionsMgr()->GetDefault<String>(OPT_CMP_DSV_DELIM_CHAR);
101         m_bAllowNewlinesInQuotes = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_TBL_ALLOW_NEWLINES_IN_QUOTES);
102         m_sQuoteChar = GetOptionsMgr()->GetDefault<String>(OPT_CMP_TBL_QUOTE_CHAR);
103         UpdateData(FALSE);
104 }
105
106 /**
107  * @brief Prepares multi-selection drop list 
108  */
109 void PropCompareTable::OnDropDownCSVPatterns()
110 {
111         String patterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_CSV_FILEPATTERNS);
112         WildcardDropList::OnDropDown(m_comboCSVPatterns, 6, patterns.c_str());
113 }
114
115 /**
116  * @brief Finishes drop list multi-selection
117  */
118 void PropCompareTable::OnCloseUpCSVPatterns()
119 {
120         WildcardDropList::OnCloseUp(m_comboCSVPatterns);
121 }
122
123 /**
124  * @brief Prepares multi-selection drop list 
125  */
126 void PropCompareTable::OnDropDownTSVPatterns()
127 {
128         String patterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_TSV_FILEPATTERNS);
129         WildcardDropList::OnDropDown(m_comboTSVPatterns, 6, patterns.c_str());
130 }
131
132 /**
133  * @brief Finishes drop list multi-selection
134  */
135 void PropCompareTable::OnCloseUpTSVPatterns()
136 {
137         WildcardDropList::OnCloseUp(m_comboTSVPatterns);
138 }
139
140 /**
141  * @brief Prepares multi-selection drop list 
142  */
143 void PropCompareTable::OnDropDownDSVPatterns()
144 {
145         String patterns = GetOptionsMgr()->GetDefault<String>(OPT_CMP_DSV_FILEPATTERNS);
146         WildcardDropList::OnDropDown(m_comboDSVPatterns, 6, patterns.c_str());
147 }
148
149 /**
150  * @brief Finishes drop list multi-selection
151  */
152 void PropCompareTable::OnCloseUpDSVPatterns()
153 {
154         WildcardDropList::OnCloseUp(m_comboDSVPatterns);
155 }