OSDN Git Service

Rename "Ignored Substitutions" to "Substitution Filters"
[winmerge-jp/winmerge-jp.git] / Src / PropCompare.cpp
1 /** 
2  * @file  PropCompare.cpp
3  *
4  * @brief Implementation of PropCompare propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropCompare.h"
9 #include "OptionsDef.h"
10 #include "OptionsMgr.h"
11 #include "OptionsPanel.h"
12
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #endif
16
17 /** 
18  * @brief Constructor.
19  * @param [in] optionsMgr Pointer to COptionsMgr.
20  */
21 PropCompare::PropCompare(COptionsMgr *optionsMgr) 
22  : OptionsPanel(optionsMgr, PropCompare::IDD)
23  , m_bIgnoreCase(false)
24  , m_bIgnoreBlankLines(false)
25  , m_bIgnoreEol(true)
26  , m_bIgnoreCodepage(true)
27  , m_nIgnoreWhite(-1)
28  , m_bMovedBlocks(false)
29  , m_bMatchSimilarLines(false)
30  , m_bFilterCommentsLines(false)
31  , m_nDiffAlgorithm(0)
32  , m_bIndentHeuristic(true)
33  , m_bCompleteBlankOutIgnoredChanges(false)
34 {
35 }
36
37 void PropCompare::DoDataExchange(CDataExchange* pDX)
38 {
39         CPropertyPage::DoDataExchange(pDX);
40         //{{AFX_DATA_MAP(PropCompare)
41         DDX_CBIndex(pDX, IDC_DIFF_ALGORITHM, m_nDiffAlgorithm);
42         DDX_Check(pDX, IDC_INDENT_HEURISTIC, m_bIndentHeuristic);
43         DDX_Check(pDX, IDC_IGNCASE_CHECK, m_bIgnoreCase);
44         DDX_Check(pDX, IDC_IGNBLANKS_CHECK, m_bIgnoreBlankLines);
45         DDX_Check(pDX, IDC_FILTERCOMMENTS_CHECK, m_bFilterCommentsLines);
46         DDX_Check(pDX, IDC_CP_SENSITIVE, m_bIgnoreCodepage);
47         DDX_Check(pDX, IDC_EOL_SENSITIVE, m_bIgnoreEol);
48         DDX_Radio(pDX, IDC_WHITESPACE, m_nIgnoreWhite);
49         DDX_Check(pDX, IDC_MOVED_BLOCKS, m_bMovedBlocks);
50         DDX_Check(pDX, IDC_MATCH_SIMILAR_LINES, m_bMatchSimilarLines);
51         DDX_Check(pDX, IDC_COMPLETELY_BLANK_OUT_IGNORED_DIFFERENCES, m_bCompleteBlankOutIgnoredChanges);
52         //}}AFX_DATA_MAP
53         UpdateControls();
54 }
55
56
57 BEGIN_MESSAGE_MAP(PropCompare, OptionsPanel)
58         //{{AFX_MSG_MAP(PropCompare)
59         ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults)
60         ON_CBN_SELCHANGE(IDC_DIFF_ALGORITHM, OnCbnSelchangeDiffAlgorithm)
61         //}}AFX_MSG_MAP
62 END_MESSAGE_MAP()
63
64 /** 
65  * @brief Reads options values from storage to UI.
66  * Property sheet calls this before displaying GUI to load values
67  * into members.
68  */
69 void PropCompare::ReadOptions()
70 {
71         m_nIgnoreWhite = GetOptionsMgr()->GetInt(OPT_CMP_IGNORE_WHITESPACE);
72         m_bIgnoreBlankLines = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_BLANKLINES);
73         m_bFilterCommentsLines = GetOptionsMgr()->GetBool(OPT_CMP_FILTER_COMMENTLINES);
74         m_bIgnoreCase = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_CASE);
75         m_bIgnoreEol = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_EOL);
76         m_bIgnoreCodepage = GetOptionsMgr()->GetBool(OPT_CMP_IGNORE_CODEPAGE);
77         m_bMovedBlocks = GetOptionsMgr()->GetBool(OPT_CMP_MOVED_BLOCKS);
78         m_bMatchSimilarLines = GetOptionsMgr()->GetBool(OPT_CMP_MATCH_SIMILAR_LINES);
79         m_nDiffAlgorithm = GetOptionsMgr()->GetInt(OPT_CMP_DIFF_ALGORITHM);
80         m_bIndentHeuristic = GetOptionsMgr()->GetBool(OPT_CMP_INDENT_HEURISTIC);
81         m_bCompleteBlankOutIgnoredChanges = GetOptionsMgr()->GetBool(OPT_CMP_COMPLETELY_BLANK_OUT_IGNORED_CHANGES);
82 }
83
84 /** 
85  * @brief Writes options values from UI to storage.
86  * Property sheet calls this after dialog is closed with OK button to
87  * store values in member variables.
88  */
89 void PropCompare::WriteOptions()
90 {
91         GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_WHITESPACE, m_nIgnoreWhite);
92         GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_BLANKLINES, m_bIgnoreBlankLines);
93         GetOptionsMgr()->SaveOption(OPT_CMP_FILTER_COMMENTLINES, m_bFilterCommentsLines);
94         GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_CODEPAGE, m_bIgnoreCodepage);
95         GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_EOL, m_bIgnoreEol);
96         GetOptionsMgr()->SaveOption(OPT_CMP_IGNORE_CASE, m_bIgnoreCase);
97         GetOptionsMgr()->SaveOption(OPT_CMP_MOVED_BLOCKS, m_bMovedBlocks);
98         GetOptionsMgr()->SaveOption(OPT_CMP_MATCH_SIMILAR_LINES, m_bMatchSimilarLines);
99         GetOptionsMgr()->SaveOption(OPT_CMP_DIFF_ALGORITHM, m_nDiffAlgorithm);
100         GetOptionsMgr()->SaveOption(OPT_CMP_INDENT_HEURISTIC, m_bIndentHeuristic);
101         GetOptionsMgr()->SaveOption(OPT_CMP_COMPLETELY_BLANK_OUT_IGNORED_CHANGES, m_bCompleteBlankOutIgnoredChanges);
102 }
103
104 /** 
105  * @brief Called before propertysheet is drawn.
106  */
107 BOOL PropCompare::OnInitDialog()
108 {
109         CComboBox * combo = (CComboBox*) GetDlgItem(IDC_DIFF_ALGORITHM);
110
111         combo->AddString(_("default").c_str());
112         combo->AddString(_("minimal").c_str());
113         combo->AddString(_("patience").c_str());
114         combo->AddString(_("histogram").c_str());
115         combo->SetCurSel(m_nDiffAlgorithm);
116
117         OptionsPanel::OnInitDialog();
118         return TRUE;  // return TRUE unless you set the focus to a control
119 }
120
121 /** 
122  * @brief Sets options to defaults
123  */
124 void PropCompare::OnDefaults()
125 {
126         m_nIgnoreWhite = GetOptionsMgr()->GetDefault<unsigned>(OPT_CMP_IGNORE_WHITESPACE);
127         m_bIgnoreEol = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_IGNORE_EOL);
128         m_bIgnoreCodepage = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_IGNORE_CODEPAGE);
129         m_bIgnoreBlankLines = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_IGNORE_BLANKLINES);
130         m_bFilterCommentsLines = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_FILTER_COMMENTLINES);
131         m_bIgnoreCase = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_IGNORE_CASE);
132         m_bMovedBlocks = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_MOVED_BLOCKS);
133         m_bMatchSimilarLines = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_MATCH_SIMILAR_LINES);
134         m_nDiffAlgorithm = GetOptionsMgr()->GetDefault<unsigned>(OPT_CMP_DIFF_ALGORITHM);
135         m_bIndentHeuristic = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_INDENT_HEURISTIC);
136         m_bCompleteBlankOutIgnoredChanges = GetOptionsMgr()->GetDefault<bool>(OPT_CMP_COMPLETELY_BLANK_OUT_IGNORED_CHANGES);
137         UpdateData(FALSE);
138 }
139
140 void PropCompare::OnCbnSelchangeDiffAlgorithm()
141 {
142         UpdateControls();
143 }
144
145 void PropCompare::UpdateControls()
146 {
147         CComboBox * pCombo = (CComboBox*)GetDlgItem(IDC_DIFF_ALGORITHM);
148         EnableDlgItem(IDC_INDENT_HEURISTIC, pCombo->GetCurSel() != 0);
149 }