4 * @brief Implementation of PropEditor propertysheet
8 #include "PropEditor.h"
10 #include "OptionsDef.h"
11 #include "OptionsMgr.h"
12 #include "OptionsPanel.h"
13 #include "DDXHelper.h"
18 static char THIS_FILE[] = __FILE__;
21 /** @brief Maximum size for tabs in spaces. */
22 static const int MAX_TABSIZE = 64;
26 * @param [in] optionsMgr Pointer to options manager for handling options.
28 PropEditor::PropEditor(COptionsMgr *optionsMgr)
29 : OptionsPanel(optionsMgr, PropEditor::IDD)
30 , m_bHiliteSyntax(false)
33 , m_bAutomaticRescan(false)
34 , m_bAllowMixedEol(false)
35 , m_bViewLineDifferences(false)
36 , m_bBreakOnWords(false)
42 * @brief Function handling dialog data exchange between GUI and variables.
44 void PropEditor::DoDataExchange(CDataExchange* pDX)
46 CDialog::DoDataExchange(pDX);
47 //{{AFX_DATA_MAP(PropEditor)
48 DDX_Check(pDX, IDC_HILITE_CHECK, m_bHiliteSyntax);
49 DDX_Radio(pDX, IDC_PROP_INSERT_TABS, m_nTabType);
50 DDX_Text(pDX, IDC_TAB_EDIT, m_nTabSize);
51 DDX_Check(pDX, IDC_AUTOMRESCAN_CHECK, m_bAutomaticRescan);
52 DDX_Check(pDX, IDC_MIXED_EOL, m_bAllowMixedEol);
53 DDX_Check(pDX, IDC_VIEW_LINE_DIFFERENCES, m_bViewLineDifferences);
54 DDX_Radio(pDX, IDC_EDITOR_CHARLEVEL, m_bBreakOnWords);
55 DDX_CBIndex(pDX, IDC_BREAK_TYPE, m_nBreakType);
56 DDX_Text(pDX, IDC_BREAK_CHARS, m_breakChars);
61 BEGIN_MESSAGE_MAP(PropEditor, CDialog)
62 //{{AFX_MSG_MAP(PropEditor)
63 ON_BN_CLICKED(IDC_VIEW_LINE_DIFFERENCES, OnLineDiffControlClicked)
64 ON_BN_CLICKED(IDC_EDITOR_CHARLEVEL, OnLineDiffControlClicked)
65 ON_BN_CLICKED(IDC_EDITOR_WORDLEVEL, OnLineDiffControlClicked)
66 ON_EN_KILLFOCUS(IDC_TAB_EDIT, OnEnKillfocusTabEdit)
71 * @brief Reads options values from storage to UI.
73 void PropEditor::ReadOptions()
75 m_nTabSize = GetOptionsMgr()->GetInt(OPT_TAB_SIZE);
76 m_nTabType = GetOptionsMgr()->GetInt(OPT_TAB_TYPE);
77 m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
78 m_bHiliteSyntax = GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT);
79 m_bAllowMixedEol = GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL);
80 m_bViewLineDifferences = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
81 m_bBreakOnWords = GetOptionsMgr()->GetBool(OPT_BREAK_ON_WORDS);
82 m_nBreakType = GetOptionsMgr()->GetInt(OPT_BREAK_TYPE);
83 m_breakChars = GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS).c_str();
87 * @brief Writes options values from UI to storage.
89 void PropEditor::WriteOptions()
91 // Sanity check tabsize
94 if (m_nTabSize > MAX_TABSIZE)
95 m_nTabSize = MAX_TABSIZE;
96 GetOptionsMgr()->SaveOption(OPT_TAB_SIZE, (int)m_nTabSize);
97 GetOptionsMgr()->SaveOption(OPT_TAB_TYPE, (int)m_nTabType);
98 GetOptionsMgr()->SaveOption(OPT_AUTOMATIC_RESCAN, m_bAutomaticRescan);
99 GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, m_bAllowMixedEol);
100 GetOptionsMgr()->SaveOption(OPT_SYNTAX_HIGHLIGHT, m_bHiliteSyntax);
101 GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, !!m_bViewLineDifferences);
102 GetOptionsMgr()->SaveOption(OPT_BREAK_ON_WORDS, !!m_bBreakOnWords);
103 GetOptionsMgr()->SaveOption(OPT_BREAK_TYPE, m_nBreakType);
104 GetOptionsMgr()->SaveOption(OPT_BREAK_SEPARATORS, String(m_breakChars));
108 * @brief Called before propertysheet is drawn.
110 BOOL PropEditor::OnInitDialog()
112 theApp.TranslateDialog(m_hWnd);
113 CPropertyPage::OnInitDialog();
115 CEdit * pEdit = (CEdit *) GetDlgItem(IDC_TAB_EDIT);
117 // Limit max text of tabsize to 2 chars
119 pEdit->SetLimitText(2);
121 LoadBreakTypeStrings();
122 UpdateDataToWindow();
123 UpdateLineDiffControls();
125 return TRUE; // return TRUE unless you set the focus to a control
126 // EXCEPTION: OCX Property Pages should return FALSE
130 * @brief Load strings (from resource) into combobox for break type
132 void PropEditor::LoadBreakTypeStrings()
134 CComboBox * cbo = (CComboBox *)GetDlgItem(IDC_BREAK_TYPE);
135 cbo->AddString(_("Break at whitespace").c_str());
136 cbo->AddString(_("Break at whitespace or punctuation").c_str());
140 * @brief Handlers any clicks in any of the line differencing controls
142 void PropEditor::OnLineDiffControlClicked()
144 UpdateLineDiffControls();
148 * @brief Shortcut to enable or disable a control
149 * @param [in] item ID of dialog control to enable/disable.
150 * @param [in] enable if true control is enabled, else disabled.
152 void PropEditor::EnableDlgItem(int item, bool enable)
154 GetDlgItem(item)->EnableWindow(!!enable);
158 * @brief Update availability of line difference controls
160 void PropEditor::UpdateLineDiffControls()
162 UpdateDataFromWindow();
163 // Can only choose char/word level if line differences are enabled
164 EnableDlgItem(IDC_EDITOR_CHARLEVEL, !!m_bViewLineDifferences);
165 EnableDlgItem(IDC_EDITOR_WORDLEVEL, !!m_bViewLineDifferences);
166 // Can only choose break type if line differences are enabled & we're breaking on words
167 EnableDlgItem(IDC_BREAK_TYPE, !!m_bViewLineDifferences);
171 * @brief Check tabsize value when control loses focus.
173 void PropEditor::OnEnKillfocusTabEdit()
175 CEdit * pEdit = (CEdit *)GetDlgItem(IDC_TAB_EDIT);
177 pEdit->GetWindowText(PopString(valueAsText));
179 try { value = string_stoi(valueAsText); } catch (...) {};
180 if (value < 1 || value > MAX_TABSIZE)
182 String msg = string_format_string1(
183 _("Value in Tab size -field is not in range WinMerge accepts.\n\nPlease use values 1 - %1."),
184 string_to_str(MAX_TABSIZE));
185 AfxMessageBox(msg.c_str(), MB_ICONWARNING);