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_bCopyFullLine(false)
32 , m_bViewLineDifferences(false)
33 , m_bBreakOnWords(false)
40 * @brief Function handling dialog data exchange between GUI and variables.
42 void PropEditor::DoDataExchange(CDataExchange* pDX)
44 CDialog::DoDataExchange(pDX);
45 //{{AFX_DATA_MAP(PropEditor)
46 DDX_Check(pDX, IDC_HILITE_CHECK, m_bHiliteSyntax);
47 DDX_Radio(pDX, IDC_PROP_INSERT_TABS, m_nTabType);
48 DDX_Text(pDX, IDC_TAB_EDIT, m_nTabSize);
49 DDV_MaxChars(pDX, std::to_string(m_nTabSize).c_str(), 2);
50 DDX_Check(pDX, IDC_AUTOMRESCAN_CHECK, m_bAutomaticRescan);
51 DDX_Check(pDX, IDC_MIXED_EOL, m_bAllowMixedEol);
52 // m_bCopyFullLine currently is only a hidden option
53 // > it is used here in PropEditor.cpp, because otherwise it doesn't get saved to the registry
54 DDX_Check(pDX, IDC_VIEW_LINE_DIFFERENCES, m_bViewLineDifferences);
55 DDX_Radio(pDX, IDC_EDITOR_CHARLEVEL, m_bBreakOnWords);
56 DDX_CBIndex(pDX, IDC_BREAK_TYPE, m_nBreakType);
57 DDX_Text(pDX, IDC_BREAK_CHARS, m_breakChars);
58 DDX_CBIndex(pDX, IDC_RENDERING_MODE, m_nRenderingMode);
63 BEGIN_MESSAGE_MAP(PropEditor, OptionsPanel)
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_bCopyFullLine = GetOptionsMgr()->GetBool(OPT_COPY_FULL_LINE);
83 m_bViewLineDifferences = GetOptionsMgr()->GetBool(OPT_WORDDIFF_HIGHLIGHT);
84 m_bBreakOnWords = GetOptionsMgr()->GetBool(OPT_BREAK_ON_WORDS);
85 m_nBreakType = GetOptionsMgr()->GetInt(OPT_BREAK_TYPE);
86 m_breakChars = GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS);
87 m_nRenderingMode = GetOptionsMgr()->GetInt(OPT_RENDERING_MODE) + 1;
91 * @brief Writes options values from UI to storage.
93 void PropEditor::WriteOptions()
95 // Sanity check tabsize
98 if (m_nTabSize > MAX_TABSIZE)
99 m_nTabSize = MAX_TABSIZE;
100 GetOptionsMgr()->SaveOption(OPT_TAB_SIZE, (int)m_nTabSize);
101 GetOptionsMgr()->SaveOption(OPT_TAB_TYPE, (int)m_nTabType);
102 GetOptionsMgr()->SaveOption(OPT_AUTOMATIC_RESCAN, m_bAutomaticRescan);
103 GetOptionsMgr()->SaveOption(OPT_ALLOW_MIXED_EOL, m_bAllowMixedEol);
104 GetOptionsMgr()->SaveOption(OPT_COPY_FULL_LINE, m_bCopyFullLine);
105 GetOptionsMgr()->SaveOption(OPT_SYNTAX_HIGHLIGHT, m_bHiliteSyntax);
106 GetOptionsMgr()->SaveOption(OPT_WORDDIFF_HIGHLIGHT, m_bViewLineDifferences);
107 GetOptionsMgr()->SaveOption(OPT_BREAK_ON_WORDS, m_bBreakOnWords);
108 GetOptionsMgr()->SaveOption(OPT_BREAK_TYPE, m_nBreakType);
109 GetOptionsMgr()->SaveOption(OPT_BREAK_SEPARATORS, String(m_breakChars));
110 GetOptionsMgr()->SaveOption(OPT_RENDERING_MODE, m_nRenderingMode - 1);
114 * @brief Called before propertysheet is drawn.
116 BOOL PropEditor::OnInitDialog()
118 OptionsPanel::OnInitDialog();
120 LoadComboBoxStrings();
121 UpdateDataToWindow();
122 UpdateLineDiffControls();
124 EnableDlgItem(IDC_RENDERING_MODE, false);
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::LoadComboBoxStrings()
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());
139 cbo = (CComboBox *)GetDlgItem(IDC_RENDERING_MODE);
140 cbo->AddString(_("GDI").c_str());
141 cbo->AddString(_("DirectWrite Default").c_str());
142 cbo->AddString(_("DirectWrite Aliased").c_str());
143 cbo->AddString(_("DirectWrite GDI Classic").c_str());
144 cbo->AddString(_("DirectWrite GDI Natural").c_str());
145 cbo->AddString(_("DirectWrite Natural").c_str());
146 cbo->AddString(_("DirectWrite Natural Symmetric").c_str());
150 * @brief Handlers any clicks in any of the line differencing controls
152 void PropEditor::OnLineDiffControlClicked()
154 UpdateLineDiffControls();
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 unsigned value = GetDlgItemInt(IDC_TAB_EDIT);
176 if (value < 1 || value > MAX_TABSIZE)
178 String msg = strutils::format_string1(
179 _("Value in Tab size -field is not in range WinMerge accepts.\n\nPlease use values 1 - %1."),
180 strutils::to_str(MAX_TABSIZE));
181 AfxMessageBox(msg.c_str(), MB_ICONWARNING);