4 * @brief Implementation of PropEditor propertysheet
8 #include "PropEditor.h"
9 #include "OptionsDef.h"
10 #include "OptionsMgr.h"
11 #include "OptionsPanel.h"
17 /** @brief Maximum size for tabs in spaces. */
18 static const int MAX_TABSIZE = 64;
22 * @param [in] optionsMgr Pointer to options manager for handling options.
24 PropEditor::PropEditor(COptionsMgr *optionsMgr)
25 : OptionsPanel(optionsMgr, PropEditor::IDD)
26 , m_bHiliteSyntax(false)
29 , m_bAutomaticRescan(false)
30 , m_bAllowMixedEol(false)
31 , m_bViewLineDifferences(false)
32 , m_bBreakOnWords(false)
38 * @brief Function handling dialog data exchange between GUI and variables.
40 void PropEditor::DoDataExchange(CDataExchange* pDX)
42 CDialog::DoDataExchange(pDX);
43 //{{AFX_DATA_MAP(PropEditor)
44 DDX_Check(pDX, IDC_HILITE_CHECK, m_bHiliteSyntax);
45 DDX_Radio(pDX, IDC_PROP_INSERT_TABS, m_nTabType);
46 DDX_Text(pDX, IDC_TAB_EDIT, m_nTabSize);
47 DDV_MaxChars(pDX, std::to_string(m_nTabSize).c_str(), 2);
48 DDX_Check(pDX, IDC_AUTOMRESCAN_CHECK, m_bAutomaticRescan);
49 DDX_Check(pDX, IDC_MIXED_EOL, m_bAllowMixedEol);
50 DDX_Check(pDX, IDC_VIEW_LINE_DIFFERENCES, m_bViewLineDifferences);
51 DDX_Radio(pDX, IDC_EDITOR_CHARLEVEL, m_bBreakOnWords);
52 DDX_CBIndex(pDX, IDC_BREAK_TYPE, m_nBreakType);
53 DDX_Text(pDX, IDC_BREAK_CHARS, m_breakChars);
58 BEGIN_MESSAGE_MAP(PropEditor, CDialog)
59 //{{AFX_MSG_MAP(PropEditor)
60 ON_BN_CLICKED(IDC_VIEW_LINE_DIFFERENCES, OnLineDiffControlClicked)
61 ON_BN_CLICKED(IDC_EDITOR_CHARLEVEL, OnLineDiffControlClicked)
62 ON_BN_CLICKED(IDC_EDITOR_WORDLEVEL, OnLineDiffControlClicked)
63 ON_EN_KILLFOCUS(IDC_TAB_EDIT, OnEnKillfocusTabEdit)
68 * @brief Reads options values from storage to UI.
70 void PropEditor::ReadOptions()
72 m_nTabSize = GetOptionsMgr()->GetInt(OPT_TAB_SIZE);
73 m_nTabType = GetOptionsMgr()->GetInt(OPT_TAB_TYPE);
74 m_bAutomaticRescan = GetOptionsMgr()->GetBool(OPT_AUTOMATIC_RESCAN);
75 m_bHiliteSyntax = GetOptionsMgr()->GetBool(OPT_SYNTAX_HIGHLIGHT);
76 m_bAllowMixedEol = GetOptionsMgr()->GetBool(OPT_ALLOW_MIXED_EOL);
77 m_bViewLineDifferences = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
78 m_bBreakOnWords = GetOptionsMgr()->GetBool(OPT_BREAK_ON_WORDS);
79 m_nBreakType = GetOptionsMgr()->GetInt(OPT_BREAK_TYPE);
80 m_breakChars = GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS);
84 * @brief Writes options values from UI to storage.
86 void PropEditor::WriteOptions()
88 // Sanity check tabsize
91 if (m_nTabSize > MAX_TABSIZE)
92 m_nTabSize = MAX_TABSIZE;
93 GetOptionsMgr()->SaveOption(OPT_TAB_SIZE, (int)m_nTabSize);
94 GetOptionsMgr()->SaveOption(OPT_TAB_TYPE, (int)m_nTabType);
95 GetOptionsMgr()->SaveOption(OPT_AUTOMATIC_RESCAN, m_bAutomaticRescan);
96 GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, m_bAllowMixedEol);
97 GetOptionsMgr()->SaveOption(OPT_SYNTAX_HIGHLIGHT, m_bHiliteSyntax);
98 GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, !!m_bViewLineDifferences);
99 GetOptionsMgr()->SaveOption(OPT_BREAK_ON_WORDS, !!m_bBreakOnWords);
100 GetOptionsMgr()->SaveOption(OPT_BREAK_TYPE, m_nBreakType);
101 GetOptionsMgr()->SaveOption(OPT_BREAK_SEPARATORS, String(m_breakChars));
105 * @brief Called before propertysheet is drawn.
107 BOOL PropEditor::OnInitDialog()
109 OptionsPanel::OnInitDialog();
111 LoadBreakTypeStrings();
112 UpdateDataToWindow();
113 UpdateLineDiffControls();
115 return TRUE; // return TRUE unless you set the focus to a control
116 // EXCEPTION: OCX Property Pages should return FALSE
120 * @brief Load strings (from resource) into combobox for break type
122 void PropEditor::LoadBreakTypeStrings()
124 CComboBox * cbo = (CComboBox *)GetDlgItem(IDC_BREAK_TYPE);
125 cbo->AddString(_("Break at whitespace").c_str());
126 cbo->AddString(_("Break at whitespace or punctuation").c_str());
130 * @brief Handlers any clicks in any of the line differencing controls
132 void PropEditor::OnLineDiffControlClicked()
134 UpdateLineDiffControls();
138 * @brief Update availability of line difference controls
140 void PropEditor::UpdateLineDiffControls()
142 UpdateDataFromWindow();
143 // Can only choose char/word level if line differences are enabled
144 EnableDlgItem(IDC_EDITOR_CHARLEVEL, !!m_bViewLineDifferences);
145 EnableDlgItem(IDC_EDITOR_WORDLEVEL, !!m_bViewLineDifferences);
146 // Can only choose break type if line differences are enabled & we're breaking on words
147 EnableDlgItem(IDC_BREAK_TYPE, !!m_bViewLineDifferences);
151 * @brief Check tabsize value when control loses focus.
153 void PropEditor::OnEnKillfocusTabEdit()
155 unsigned value = GetDlgItemInt(IDC_TAB_EDIT);
156 if (value < 1 || value > MAX_TABSIZE)
158 String msg = string_format_string1(
159 _("Value in Tab size -field is not in range WinMerge accepts.\n\nPlease use values 1 - %1."),
160 string_to_str(MAX_TABSIZE));
161 AfxMessageBox(msg.c_str(), MB_ICONWARNING);