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