Code::Blocks  SVN r11506
editorconfigurationdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 11451 $
6  * $Id: editorconfigurationdlg.cpp 11451 2018-08-15 21:18:20Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/src/editorconfigurationdlg.cpp $
8  */
9 
10 #include "sdk.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/button.h>
14  #include <wx/checkbox.h>
15  #include <wx/choice.h>
16  #include <wx/colordlg.h>
17  #include <wx/imaglist.h>
18  #include <wx/listbox.h>
19  #include <wx/listctrl.h>
20  #include <wx/menu.h>
21  #include <wx/radiobox.h>
22  #include <wx/regex.h>
23  #include <wx/settings.h>
24  #include <wx/slider.h>
25  #include <wx/spinctrl.h>
26  #include <wx/stattext.h>
27  #include <wx/textdlg.h>
28  #include <wx/xrc/xmlres.h>
29 
30  #include "manager.h"
31  #include "cbauibook.h"
32  #include "cbeditor.h"
33  #include "cbplugin.h" // cgEditor
34  #include "configmanager.h"
35  #include "editormanager.h"
36  #include "globals.h"
37  #include "pluginmanager.h"
38 #endif
39 #include "cbstyledtextctrl.h"
40 #include "cbcolourmanager.h"
41 
42 #include <wx/fontdlg.h>
43 #include <wx/fontutil.h>
44 #include <wx/fontmap.h>
45 #include <wx/listbook.h>
46 
47 #include "configurationpanel.h"
48 #include "editkeywordsdlg.h"
49 #include "editorcolourset.h"
50 #include "editorconfigurationdlg.h"
51 
52 // images by order of pages
53 const wxString base_imgs[] =
54 {
55  _T("editor"),
56  _T("folding"),
57  _T("gutter-margin"),
58  _T("syntax-highlight"),
59  _T("default-code"),
60 };
61 const int IMAGES_COUNT = sizeof(base_imgs) / sizeof(wxString);
62 
63 // map cmbDefCodeFileType indexes to FileType values
64 // if more entries are added to cmbDefCodeFileType, edit the mapping here
66 
67 BEGIN_EVENT_TABLE(EditorConfigurationDlg, wxScrollingDialog)
68  EVT_BUTTON(XRCID("btnChooseEditorFont"), EditorConfigurationDlg::OnChooseFont)
69  EVT_BUTTON(XRCID("btnKeywords"), EditorConfigurationDlg::OnEditKeywords)
70  EVT_BUTTON(XRCID("btnFilemasks"), EditorConfigurationDlg::OnEditFilemasks)
71  EVT_BUTTON(XRCID("btnColoursReset"), EditorConfigurationDlg::OnColoursReset)
72  EVT_BUTTON(XRCID("btnColoursCopy"), EditorConfigurationDlg::OnColoursCopyFrom)
73  EVT_BUTTON(XRCID("btnColoursCopyAll"), EditorConfigurationDlg::OnColoursCopyAllFrom)
74  EVT_BUTTON(XRCID("btnCaretColour"), EditorConfigurationDlg::OnChooseColour)
75  EVT_BUTTON(XRCID("btnGutterColour"), EditorConfigurationDlg::OnChooseColour)
76  EVT_BUTTON(XRCID("btnColoursFore"), EditorConfigurationDlg::OnChooseColour)
77  EVT_BUTTON(XRCID("btnColoursBack"), EditorConfigurationDlg::OnChooseColour)
78  EVT_BUTTON(XRCID("btnForeSetDefault"), EditorConfigurationDlg::OnSetDefaultColour)
79  EVT_BUTTON(XRCID("btnBackSetDefault"), EditorConfigurationDlg::OnSetDefaultColour)
80  EVT_BUTTON(XRCID("btnColoursAddTheme"), EditorConfigurationDlg::OnAddColourTheme)
81  EVT_BUTTON(XRCID("btnColoursDeleteTheme"), EditorConfigurationDlg::OnDeleteColourTheme)
82  EVT_BUTTON(XRCID("btnColoursRenameTheme"), EditorConfigurationDlg::OnRenameColourTheme)
83  EVT_CHECKBOX(XRCID("chkColoursBold"), EditorConfigurationDlg::OnBoldItalicUline)
84  EVT_CHECKBOX(XRCID("chkColoursItalics"), EditorConfigurationDlg::OnBoldItalicUline)
85  EVT_CHECKBOX(XRCID("chkColoursUnderlined"), EditorConfigurationDlg::OnBoldItalicUline)
86  EVT_LISTBOX(XRCID("lstComponents"), EditorConfigurationDlg::OnColourComponent)
87  EVT_CHOICE(XRCID("cmbLangs"), EditorConfigurationDlg::OnChangeLang)
88  EVT_CHOICE(XRCID("cmbDefCodeFileType"), EditorConfigurationDlg::OnChangeDefCodeFileType)
89  EVT_CHOICE(XRCID("cmbThemes"), EditorConfigurationDlg::OnColourTheme)
90  EVT_CHECKBOX(XRCID("chkDynamicWidth"), EditorConfigurationDlg::OnDynamicCheck)
91  EVT_CHECKBOX(XRCID("chkEnableMultipleSelections"), EditorConfigurationDlg::OnMultipleSelections)
92  EVT_CHOICE(XRCID("lstCaretStyle"), EditorConfigurationDlg::OnCaretStyle)
93 
94  EVT_LISTBOOK_PAGE_CHANGED(XRCID("nbMain"), EditorConfigurationDlg::OnPageChanged)
95  EVT_BUTTON(XRCID("btnWSColour"), EditorConfigurationDlg::OnChooseColour)
96 END_EVENT_TABLE()
97 
99  : m_TextColourControl(nullptr),
100  m_Theme(nullptr),
101  m_Lang(HL_NONE),
102  m_DefCodeFileType(0),
103  m_ThemeModified(false),
104  m_EnableChangebar(false),
105  m_pImageList(nullptr)
106 {
107  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfigureEditor"),_T("wxScrollingDialog"));
108  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
109 
110  XRCCTRL(*this, "lblEditorFont", wxStaticText)->SetLabel(_("This is sample text"));
111  m_FontString = Manager::Get()->GetConfigManager(_T("editor"))->Read(_T("/font"), wxEmptyString);
112  UpdateSampleFont(false);
113 
114  ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("editor"));
115 
116  XRCCTRL(*this, "chkAutoIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/auto_indent"), true));
117  XRCCTRL(*this, "chkSmartIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/smart_indent"), true));
118  XRCCTRL(*this, "chkBraceCompletion", wxCheckBox)->SetValue(cfg->ReadBool(_T("/brace_completion"), true));
119  XRCCTRL(*this, "chkDetectIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/detect_indent"), false));
120  XRCCTRL(*this, "chkUseTab", wxCheckBox)->SetValue(cfg->ReadBool(_T("/use_tab"), false));
121  m_EnableScrollWidthTracking = cfg->ReadBool(_T("/margin/scroll_width_tracking"), false);
122  XRCCTRL(*this, "chkScrollWidthTracking", wxCheckBox)->SetValue(m_EnableScrollWidthTracking);
123  m_EnableChangebar = cfg->ReadBool(_T("/margin/use_changebar"), true);
124  XRCCTRL(*this, "chkUseChangebar", wxCheckBox)->SetValue(m_EnableChangebar);
125  XRCCTRL(*this, "chkShowIndentGuides", wxCheckBox)->SetValue(cfg->ReadBool(_T("/show_indent_guides"), false));
126  XRCCTRL(*this, "chkBraceSmartIndent", wxCheckBox)->SetValue(cfg->ReadBool(_T("/brace_smart_indent"), true));
127  XRCCTRL(*this, "chkSelectionBraceCompletion", wxCheckBox)->SetValue(cfg->ReadBool(_T("/selection_brace_completion"), false));
128  XRCCTRL(*this, "chkTabIndents", wxCheckBox)->SetValue(cfg->ReadBool(_T("/tab_indents"), true));
129  XRCCTRL(*this, "chkBackspaceUnindents", wxCheckBox)->SetValue(cfg->ReadBool(_T("/backspace_unindents"), true));
130  XRCCTRL(*this, "chkWordWrap", wxCheckBox)->SetValue(cfg->ReadBool(_T("/word_wrap"), false));
131  XRCCTRL(*this, "chkWordWrapStyleHomeEnd", wxCheckBox)->SetValue(cfg->ReadBool(_T("/word_wrap_style_home_end"), true));
132  XRCCTRL(*this, "chkPosixRegex", wxCheckBox)->SetValue(cfg->ReadBool(_T("/use_posix_style_regexes"), false));
133  #ifdef wxHAS_REGEX_ADVANCED
134  XRCCTRL(*this, "chkAdvancedRegex", wxCheckBox)->SetValue(cfg->ReadBool(_T("/use_advanced_regexes"), false));
135  #else
136  XRCCTRL(*this, "chkAdvancedRegex", wxCheckBox)->SetValue(false);
137  XRCCTRL(*this, "chkAdvancedRegex", wxCheckBox)->Enable(false);
138  #endif
139  XRCCTRL(*this, "chkShowLineNumbers", wxCheckBox)->SetValue(cfg->ReadBool(_T("/show_line_numbers"), true));
140  XRCCTRL(*this, "chkHighlightCaretLine", wxCheckBox)->SetValue(cfg->ReadBool(_T("/highlight_caret_line"), false));
141  XRCCTRL(*this, "chkSimplifiedHome", wxCheckBox)->SetValue(cfg->ReadBool(_T("/simplified_home"), false));
142  XRCCTRL(*this, "chkCamelCase", wxCheckBox)->SetValue(cfg->ReadBool(_T("/camel_case"), false));
143  XRCCTRL(*this, "chkResetZoom", wxCheckBox)->SetValue(cfg->ReadBool(_T("/reset_zoom"), false));
144  XRCCTRL(*this, "chkZoomAll", wxCheckBox)->SetValue(cfg->ReadBool(_T("/zoom_all"), false));
145  XRCCTRL(*this, "chkSyncEditorWithProjectManager", wxCheckBox)->SetValue(cfg->ReadBool(_T("/sync_editor_with_project_manager"), false));
146  XRCCTRL(*this, "spnTabSize", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/tab_size"), 4));
147  XRCCTRL(*this, "cmbViewWS", wxChoice)->SetSelection(cfg->ReadInt(_T("/view_whitespace"), 0));
148  XRCCTRL(*this, "cmbCaretBuffer", wxChoice)->SetSelection(cfg->ReadInt(wxT("/caret_buffer"), 2));
149  XRCCTRL(*this, "rbTabText", wxRadioBox)->SetSelection(cfg->ReadBool(_T("/tab_text_relative"), false)? 1 : 0);
150 
151  XRCCTRL(*this, "chkTrackPreprocessor", wxCheckBox)->SetValue(cfg->ReadBool(_T("/track_preprocessor"), true));
152  XRCCTRL(*this, "chkCollectPrjDefines", wxCheckBox)->SetValue(cfg->ReadBool(_T("/collect_prj_defines"), true));
153  XRCCTRL(*this, "chkPlatDefines", wxCheckBox)->SetValue(cfg->ReadBool(_T("/platform_defines"), false));
154  XRCCTRL(*this, "chkColoursWxSmith", wxCheckBox)->SetValue(cfg->ReadBool(_T("/highlight_wxsmith"), true));
155  XRCCTRL(*this, "chkNoStlC", wxCheckBox)->SetValue(cfg->ReadBool(_T("/no_stl_in_c"), true));
156 
157  XRCCTRL(*this, "chkShowEOL", wxCheckBox)->SetValue(cfg->ReadBool(_T("/show_eol"), false));
158  XRCCTRL(*this, "chkStripTrailings", wxCheckBox)->SetValue(cfg->ReadBool(_T("/eol/strip_trailing_spaces"), true));
159  XRCCTRL(*this, "chkEnsureFinalEOL", wxCheckBox)->SetValue(cfg->ReadBool(_T("/eol/ensure_final_line_end"), true));
160  XRCCTRL(*this, "chkEnsureConsistentEOL", wxCheckBox)->SetValue(cfg->ReadBool(_T("/eol/ensure_consistent_line_ends"), false));
161  // NOTE: duplicate line in cbeditor.cpp (CreateEditor)
162  XRCCTRL(*this, "cmbEOLMode", wxChoice)->SetSelection(cfg->ReadInt(_T("/eol/eolmode"), platform::windows ? wxSCI_EOL_CRLF : wxSCI_EOL_LF)); // Windows takes CR+LF, other platforms LF only
163 
164  //caret
165  wxColour caretColour = Manager::Get()->GetColourManager()->GetColour(wxT("editor_caret"));
166  int caretStyle = cfg->ReadInt(_T("/caret/style"), wxSCI_CARETSTYLE_LINE);
167  XRCCTRL(*this, "lstCaretStyle", wxChoice)->SetSelection(caretStyle);
168  XRCCTRL(*this, "spnCaretWidth", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/caret/width"), 1));
169  XRCCTRL(*this, "spnCaretWidth", wxSpinCtrl)->Enable(caretStyle == wxSCI_CARETSTYLE_LINE);
170  XRCCTRL(*this, "btnCaretColour", wxButton)->SetBackgroundColour(caretColour);
171  XRCCTRL(*this, "slCaretPeriod", wxSlider)->SetValue(cfg->ReadInt(_T("/caret/period"), 500));
172 
173  // whitespace colour
174  wxColour whiteSpaceColour = Manager::Get()->GetColourManager()->GetColour(wxT("editor_whitespace"));
175  XRCCTRL(*this, "btnWSColour", wxButton)->SetBackgroundColour(whiteSpaceColour);
176 
177  //selections
178  XRCCTRL(*this, "chkEnableVirtualSpace", wxCheckBox)->SetValue(cfg->ReadBool(_T("/selection/use_vspace"), false));
179  XRCCTRL(*this, "chkEnableRectVirtualSpace", wxCheckBox)->SetValue(cfg->ReadBool(_T("/selection/use_rect_vspace"), false));
180  bool multiSelectEnabled = cfg->ReadBool(_T("/selection/multi_select"), false);
181  XRCCTRL(*this, "chkEnableMultipleSelections", wxCheckBox)->SetValue(multiSelectEnabled);
182  XRCCTRL(*this, "chkEnableAdditionalSelectionTyping", wxCheckBox)->SetValue(cfg->ReadBool(_T("/selection/multi_typing"), false));
183  XRCCTRL(*this, "chkEnableAdditionalSelectionTyping", wxCheckBox)->Enable(multiSelectEnabled);
184 
185  //folding
186  XRCCTRL(*this, "chkEnableFolding", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/show_folds"), true));
187  XRCCTRL(*this, "chkFoldOnOpen", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/fold_all_on_open"), false));
188  XRCCTRL(*this, "chkFoldPreprocessor", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/fold_preprocessor"), false));
189  XRCCTRL(*this, "chkFoldComments", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/fold_comments"), true));
190  XRCCTRL(*this, "chkFoldXml", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/fold_xml"), true));
191  XRCCTRL(*this, "chkUnderlineFoldedLine", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/underline_folded_line"), true));
192  XRCCTRL(*this, "lstIndicators", wxChoice)->SetSelection(cfg->ReadInt(_T("/folding/indicator"), 2));
193  XRCCTRL(*this, "chkFoldLimit", wxCheckBox)->SetValue(cfg->ReadBool(_T("/folding/limit"), false));
194  XRCCTRL(*this, "spnFoldLimitLevel", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/folding/limit_level"), 1));
195 
196  //gutter
197  wxColour gutterColour = Manager::Get()->GetColourManager()->GetColour(wxT("editor_gutter"));
198  XRCCTRL(*this, "lstGutterMode", wxChoice)->SetSelection(cfg->ReadInt(_T("/gutter/mode"), 0));
199  XRCCTRL(*this, "btnGutterColour", wxButton)->SetBackgroundColour(gutterColour);
200  XRCCTRL(*this, "spnGutterColumn", wxSpinCtrl)->SetRange(1, 500);
201  XRCCTRL(*this, "spnGutterColumn", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/gutter/column"), 80));
202 
203  //margin
204  XRCCTRL(*this, "spnMarginWidth", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/margin/width_chars"), 6));
205  XRCCTRL(*this, "chkDynamicWidth", wxCheckBox)->SetValue(cfg->ReadBool(_T("/margin/dynamic_width"), false));
206  XRCCTRL(*this, "spnMarginWidth", wxSpinCtrl)->Enable(!cfg->ReadBool(_T("/margin/dynamic_width"), false));
207  XRCCTRL(*this, "chkAddBPByLeftClick", wxCheckBox)->SetValue(cfg->ReadBool(_T("/margin_1_sensitive"), true));
208  XRCCTRL(*this, "chkImageBP", wxCheckBox)->SetValue(cfg->ReadBool(_T("/margin_1_image_bp"), true));
209 
210  // colour set
211  LoadThemes();
212 
213  // fill encodings
214  wxChoice* cmbEnc = XRCCTRL(*this, "cmbEncoding", wxChoice);
215  if (cmbEnc)
216  {
217  cmbEnc->Clear();
218  wxString def_enc_name = cfg->Read(_T("/default_encoding"), wxLocale::GetSystemEncodingName());
219  int sel = 0;
221  for (size_t i = 0; i < count; ++i)
222  {
224  wxString enc_name = wxFontMapper::GetEncodingName(enc);
225  cmbEnc->Append(enc_name);
226  if (enc_name.CmpNoCase(def_enc_name) == 0)
227  sel = i;
228  }
229  cmbEnc->SetSelection(sel);
230  }
231  XRCCTRL(*this, "rbEncodingUseOption", wxRadioBox)->SetSelection(cfg->ReadInt(_T("/default_encoding/use_option"), 0));
232  XRCCTRL(*this, "chkEncodingFindLatin2", wxCheckBox)->SetValue(cfg->ReadBool(_T("/default_encoding/find_latin2"), false));
233  XRCCTRL(*this, "chkEncodingUseSystem", wxCheckBox)->SetValue(cfg->ReadBool(_T("/default_encoding/use_system"), true));
234 
235  // default code
236  XRCCTRL(*this, "cmbDefCodeFileType", wxChoice)->SetSelection(m_DefCodeFileType);
237  wxString key;
238  key.Printf(_T("/default_code/set%d"), IdxToFileType[m_DefCodeFileType]);
239  XRCCTRL(*this, "txtDefCode", wxTextCtrl)->SetValue(cfg->Read(key, wxEmptyString));
240 
241  // setting the default editor font size to 10 point
243 
244  XRCCTRL(*this, "txtDefCode", wxTextCtrl)->SetFont(tmpFont);
245  // read them all in the array
246  for(size_t idx = 0; idx < sizeof(IdxToFileType)/sizeof(*IdxToFileType); ++ idx)
247  {
248  key.Printf(_T("/default_code/set%d"), IdxToFileType[idx]);
249  m_DefaultCode.Add(cfg->Read(key, wxEmptyString));
250  }// end for : idx
251 
252  // code completion
253  cfg = Manager::Get()->GetConfigManager(_T("ccmanager"));
254  XRCCTRL(*this, "chkCodeCompletion", wxCheckBox)->SetValue(cfg->ReadBool(_T("/code_completion"), true));
255  XRCCTRL(*this, "chkCCCaseSensitive", wxCheckBox)->SetValue(cfg->ReadBool(_T("/case_sensitive"), false));
256  XRCCTRL(*this, "chkAutoselectSingle", wxCheckBox)->SetValue(cfg->ReadBool(_T("/auto_select_single"), false));
257  XRCCTRL(*this, "spnAutolaunchCount", wxSpinCtrl)->SetValue(cfg->ReadInt(_T("/auto_launch_count"), 3));
258  XRCCTRL(*this, "chkDocumentationPopup", wxCheckBox)->SetValue(cfg->ReadBool(_T("/documentation_popup"), true));
259  XRCCTRL(*this, "cmbTooltipMode", wxChoice)->SetSelection(cfg->ReadInt(_T("/tooltip_mode"), 1));
260 
261  LoadListbookImages();
262 
263  // add all plugins configuration panels
264  AddPluginPanels();
265 
266  // the following code causes a huge dialog to be created with wx2.8.4
267  // commenting it out fixes the problem (along with some XRC surgery)
268  // if this causes problems with earlier wx versions we might need to
269  // add a platform/version #ifdef...
270  // the former commented out code leads to problems with wxGTK (parts of long static texts not shown)
271  // seems to work without the comments on wx2.8.9 on linux and windows
272 
273  // make sure everything is laid out properly
274  GetSizer()->SetSizeHints(this);
275  CentreOnParent();
276  Layout();
277 }
278 
280 {
281  if (m_Theme)
282  delete m_Theme;
283 
285  delete m_TextColourControl;
286 
287  delete m_pImageList;
288 }
289 
291 {
292  const wxString base = _T("images/settings/");
293  // for plugins who do not supply icons, use common generic icons
294  const wxString noimg = _T("images/settings/generic-plugin");
295 
296  wxListbook* lb = XRCCTRL(*this, "nbMain", wxListbook);
297  // get all configuration panels which are about the editor.
299 
300  for (size_t i = 0; i < m_PluginPanels.GetCount(); ++i)
301  {
303  panel->SetParentDialog(this);
304  lb->AddPage(panel, panel->GetTitle());
305 
306  wxString onFile = ConfigManager::LocateDataFile(base + panel->GetBitmapBaseName() + _T(".png"), sdDataGlobal | sdDataUser);
307  if (onFile.IsEmpty())
308  onFile = ConfigManager::LocateDataFile(noimg + _T(".png"), sdDataGlobal | sdDataUser);
309  wxString offFile = ConfigManager::LocateDataFile(base + panel->GetBitmapBaseName() + _T("-off.png"), sdDataGlobal | sdDataUser);
310  if (offFile.IsEmpty())
311  offFile = ConfigManager::LocateDataFile(noimg + _T("-off.png"), sdDataGlobal | sdDataUser);
312 
313  m_pImageList->Add(cbLoadBitmap(onFile));
314  m_pImageList->Add(cbLoadBitmap(offFile));
315  lb->SetPageImage(lb->GetPageCount() - 1, m_pImageList->GetImageCount() - 2);
316  }
317 
319 }
320 
322 {
323  const wxString base = ConfigManager::GetDataFolder() + _T("/images/settings/");
324 
325  m_pImageList = new wxImageList(80, 80);
326  wxBitmap bmp;
327  for (int i = 0; i < IMAGES_COUNT; ++i)
328  {
329  bmp = cbLoadBitmap(base + base_imgs[i] + _T(".png"));
330  m_pImageList->Add(bmp);
331  bmp = cbLoadBitmap(base + base_imgs[i] + _T("-off.png"));
332  m_pImageList->Add(bmp);
333  }
334 }
335 
337 {
338  wxListbook* lb = XRCCTRL(*this, "nbMain", wxListbook);
339  int sel = lb->GetSelection();
340 
341  if (SettingsIconsStyle(Manager::Get()->GetConfigManager(_T("app"))->ReadInt(_T("/environment/settings_size"), 0)))
342  {
344  lb->SetImageList(nullptr);
345  }
346  else
347  {
348  lb->SetImageList(m_pImageList);
349  // set page images according to their on/off status
350  for (size_t i = 0; i < IMAGES_COUNT + m_PluginPanels.GetCount(); ++i)
351  lb->SetPageImage(i, (i * 2) + (sel == (int)i ? 0 : 1));
353  }
354 
355  // update the page title
356  wxString label = lb->GetPageText(sel);
357  // replace any stray & with && because label makes it an underscore
358  while (label.Replace(_T(" & "), _T(" && ")))
359  ;
360  XRCCTRL(*this, "lblBigTitle", wxStaticText)->SetLabel(label);
361  XRCCTRL(*this, "pnlTitleInfo", wxPanel)->Layout();
362 }
363 
364 void EditorConfigurationDlg::OnPageChanged(wxListbookEvent& event)
365 {
366  // update only on real change, not on dialog creation
367  if (event.GetOldSelection() != -1 && event.GetSelection() != -1)
369 }
370 
372 {
373  if (!m_TextColourControl)
374  {
376 
380  m_TextColourControl->SetMinSize(wxSize(50,50));
382 
384  }
385 
386  int breakLine = -1;
387  int debugLine = -1;
388  int errorLine = -1;
389  wxString code = m_Theme->GetSampleCode(m_Lang, &breakLine, &debugLine, &errorLine);
390  if (!code.IsEmpty())
391  {
393  }
394 
395  const bool hightlightCaretLine = XRCCTRL(*this, "chkHighlightCaretLine", wxCheckBox)->GetValue();
396  m_TextColourControl->SetCaretLineVisible(hightlightCaretLine);
397 
398  const bool showIndentGuides = XRCCTRL(*this, "chkShowIndentGuides", wxCheckBox)->GetValue();
400 
404  if (breakLine != -1) m_TextColourControl->MarkerAdd(breakLine, 2); // breakpoint line
405  if (debugLine != -1) m_TextColourControl->MarkerAdd(debugLine, 3); // active line
406  if (errorLine != -1) m_TextColourControl->MarkerAdd(errorLine, 4); // error line
407 
408  ApplyColours();
410 }
411 
413 {
414  wxListBox* colours = XRCCTRL(*this, "lstComponents", wxListBox);
415  colours->Clear();
416  int count = m_Theme->GetOptionCount(m_Lang);
417  if (count == 0)
418  return;
419 
420  for (int i = 0; i < count; ++i)
421  {
423  if (colours->FindString(opt->name) == -1)
424  colours->Append(opt->name);
425  }
426  if (colours->GetCount() > 0)
427  colours->SetSelection(0);
428  ReadColours();
429 }
430 
432 {
434  {
435  wxFont fnt = XRCCTRL(*this, "lblEditorFont", wxStaticText)->GetFont();
436 
438  m_Theme->Apply(m_Lang, m_TextColourControl, false, true);
439  }
440 }
441 
443 {
444  if (m_Theme)
445  {
446  wxListBox* colours = XRCCTRL(*this, "lstComponents", wxListBox);
447 /* TODO (mandrav#1#): FIXME!!! */
448  OptionColour* opt = m_Theme->GetOptionByName(m_Lang, colours->GetStringSelection());
450  }
451 }
452 
454 {
455  if (opt)
456  {
457  wxColour c = opt->fore;
458  if (c == wxNullColour)
459  {
460  XRCCTRL(*this, "btnColoursFore", wxButton)->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
461  XRCCTRL(*this, "btnColoursFore", wxButton)->SetLabel(_("\"Default\""));
462  }
463  else
464  {
465  XRCCTRL(*this, "btnColoursFore", wxButton)->SetBackgroundColour(c);
466  XRCCTRL(*this, "btnColoursFore", wxButton)->SetLabel(_T(""));
467  }
468 
469  c = opt->back;
470  if (c == wxNullColour)
471  {
472  XRCCTRL(*this, "btnColoursBack", wxButton)->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
473  XRCCTRL(*this, "btnColoursBack", wxButton)->SetLabel(_("\"Default\""));
474  }
475  else
476  {
477  XRCCTRL(*this, "btnColoursBack", wxButton)->SetBackgroundColour(c);
478  XRCCTRL(*this, "btnColoursBack", wxButton)->SetLabel(_T(""));
479  }
480 
481  XRCCTRL(*this, "chkColoursBold", wxCheckBox)->SetValue(opt->bold);
482  XRCCTRL(*this, "chkColoursItalics", wxCheckBox)->SetValue(opt->italics);
483  XRCCTRL(*this, "chkColoursUnderlined", wxCheckBox)->SetValue(opt->underlined);
484 
485 // XRCCTRL(*this, "btnColorsFore", wxButton)->Enable(opt->isStyle);
486  XRCCTRL(*this, "chkColoursBold", wxCheckBox)->Enable(opt->isStyle);
487  XRCCTRL(*this, "chkColoursItalics", wxCheckBox)->Enable(opt->isStyle);
488  XRCCTRL(*this, "chkColoursUnderlined", wxCheckBox)->Enable(opt->isStyle);
489  bool isDefault = (opt->name == _("Default"));
490  XRCCTRL(*this, "btnForeSetDefault", wxButton)->Enable(!isDefault);
491  XRCCTRL(*this, "btnBackSetDefault", wxButton)->Enable(!isDefault);
492  }
493 }
494 
496 {
497  if (m_Theme)
498  {
499  wxListBox* colours = XRCCTRL(*this, "lstComponents", wxListBox);
500 /* TODO (mandrav#1#): FIXME!!! */
501  OptionColour* opt = m_Theme->GetOptionByName(m_Lang, colours->GetStringSelection());
502  if (opt)
503  {
504  wxColour c = XRCCTRL(*this, "btnColoursFore", wxButton)->GetBackgroundColour();
506  opt->fore = c;
507  else
508  opt->fore = wxNullColour;
509  c = XRCCTRL(*this, "btnColoursBack", wxButton)->GetBackgroundColour();
511  opt->back = c;
512  else
513  opt->back = wxNullColour;
514  opt->bold = XRCCTRL(*this, "chkColoursBold", wxCheckBox)->GetValue();
515  opt->italics = XRCCTRL(*this, "chkColoursItalics", wxCheckBox)->GetValue();
516  opt->underlined = XRCCTRL(*this, "chkColoursUnderlined", wxCheckBox)->GetValue();
518  }
519  }
520  ApplyColours();
521  m_ThemeModified = true;
522 }
523 
525 {
526  // setting the default editor font size to 10 point
528 
529  if (!m_FontString.IsEmpty())
530  {
531  wxNativeFontInfo nfi;
533  tmpFont.SetNativeFontInfo(nfi);
534  }
535 
536  XRCCTRL(*this, "lblEditorFont", wxStaticText)->SetFont(tmpFont);
537  if (!askForNewFont)
538  return;
539 
540  wxFontData data;
541  data.SetInitialFont(tmpFont);
542 
543  wxFontDialog dlg(this, data);
544  PlaceWindow(&dlg);
545  if (dlg.ShowModal() == wxID_OK)
546  {
547  wxFont font = dlg.GetFontData().GetChosenFont();
548  XRCCTRL(*this, "lblEditorFont", wxStaticText)->SetFont(font);
550  ApplyColours();
551  }
552 }
553 
555 {
556  XRCCTRL(*this, "spnCaretWidth", wxSpinCtrl)->Enable(XRCCTRL(*this, "lstCaretStyle", wxChoice)->GetSelection() == wxSCI_CARETSTYLE_LINE);
557 }
558 
560 {
561  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
562  cmbThemes->Clear();
563  ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("editor"));
564  wxArrayString list = cfg->EnumerateSubPaths(_T("/colour_sets"));
565  list.Sort();
566  for (unsigned int i = 0; i < list.GetCount(); ++i)
567  {
568  cmbThemes->Append(cfg->Read(_T("/colour_sets/") + list[i] + _T("/name"), list[i]));
569  }
570  if (cmbThemes->GetCount() == 0)
571  cmbThemes->Append(COLORSET_DEFAULT);
572  wxString group = cfg->Read(_T("/colour_sets/active_colour_set"), COLORSET_DEFAULT);
573  long int cookie = cmbThemes->FindString(group);
574  if (cookie == wxNOT_FOUND)
575  cookie = 0;
576  cmbThemes->SetSelection(cookie);
577  ChangeTheme();
578 }
579 
581 {
582  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
583  if (m_Theme && m_ThemeModified)
584  {
585  wxString msg;
586  msg.Printf(_("The colour theme \"%s\" is modified.\nDo you want to save the changes?"), m_Theme->GetName().c_str());
587  int ret = cbMessageBox(msg, _("Save"), wxYES_NO | wxCANCEL, this);
588  switch (ret)
589  {
590  case wxID_YES: m_Theme->Save(); break;
591  case wxID_CANCEL:
592  {
593  int idx = cmbThemes->FindString(m_Theme->GetName());
594  cmbThemes->SetSelection(idx);
595  return false;
596  }
597  default: break;
598  }
599  }
600  return true;
601 }
602 
604 {
605  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
606  if (cmbThemes->GetSelection() == wxNOT_FOUND)
607  cmbThemes->SetSelection(0);
608  wxString key = cmbThemes->GetStringSelection();
609  XRCCTRL(*this, "btnColoursRenameTheme", wxButton)->Enable(key != COLORSET_DEFAULT);
610  XRCCTRL(*this, "btnColoursDeleteTheme", wxButton)->Enable(key != COLORSET_DEFAULT);
611 
612  if (m_Theme)
613  delete m_Theme;
614 
615  // If the theme is the same one used by EditorManager,
616  // skip the creation of new EditorColourSet class to avoid lengthy loading times.
617  // Instead, use the copy constructor...
619  if (colour_set && key == colour_set->GetName())
620  m_Theme = new EditorColourSet(*colour_set);
621  else
622  m_Theme = new EditorColourSet(key);
623 
624  XRCCTRL(*this, "btnKeywords", wxButton)->Enable(m_Theme);
625  XRCCTRL(*this, "btnFilemasks", wxButton)->Enable(m_Theme);
626 
627  wxChoice* cmbLangs = XRCCTRL(*this, "cmbLangs", wxChoice);
628  int sel = cmbLangs->GetSelection();
629  cmbLangs->Clear();
630  cmbLangs->Append(_("Plain text"));
632  for (unsigned int i = 0; i < langs.GetCount(); ++i)
633  {
634  cmbLangs->Append(langs[i]);
635  }
636  if (sel == -1)
637  {
638  wxString lang = Manager::Get()->GetConfigManager(_T("editor"))->Read(_T("/colour_sets/active_lang"), _T("C/C++"));
639  sel = cmbLangs->FindString(lang);
640  }
641  cmbLangs->SetSelection(sel != -1 ? sel : 0);
642  cmbLangs->Enable(langs.GetCount() != 0);
643  if (m_Theme)
644  {
645  wxString str_sel = cmbLangs->GetStringSelection();
646  m_Lang = m_Theme->GetHighlightLanguage(str_sel);
647  }
648 
650  m_ThemeModified = false;
651 }
652 
653 // events
654 
656 {
657  // theme has changed
658  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
659  if (m_Theme && m_Theme->GetName() != cmbThemes->GetStringSelection())
660  {
661  if (AskToSaveTheme())
662  ChangeTheme();
663  }
664 }
665 
666 namespace
667 {
668 bool CheckColourThemeName(const wxString &name, wxWindow *parent)
669 {
670  wxRegEx regex(wxT("^[A-Za-z][A-Za-z_0-9]*$"));
671  if (regex.Matches(name))
672  return true;
673  else
674  {
675  cbMessageBox(_("You've entered invalid characters for the name of the theme. "
676  "Only alphanumeric characters and '_' are allowed! The first character should be a letter. "
677  "Please try again."),
678  _("Error"),
679  wxOK,
680  parent);
681  return false;
682  }
683 }
684 
685 } // anonymous namespace
686 
688 {
689  wxTextEntryDialog dlg(this, _("Please enter the name of the new colour theme:"), _("New theme name"));
690  PlaceWindow(&dlg);
691  if (dlg.ShowModal() != wxID_OK)
692  return;
693 
694  wxString name = dlg.GetValue();
695  if (!CheckColourThemeName(name, this))
696  return;
697 
698  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
699  cmbThemes->Append(name);
700  cmbThemes->SetSelection(cmbThemes->GetCount() - 1);
701  ChangeTheme();
702 }
703 
705 {
706  if (cbMessageBox(_("Are you sure you want to delete this theme?"), _("Confirmation"), wxYES_NO, this) == wxID_YES)
707  {
708  Manager::Get()->GetConfigManager(_T("editor"))->DeleteSubPath(_T("/colour_sets/") + m_Theme->GetName());
709  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
710  int idx = cmbThemes->FindString(m_Theme->GetName());
711  if (idx != wxNOT_FOUND)
712  cmbThemes->Delete(idx);
713  cmbThemes->SetSelection(wxNOT_FOUND);
714  ChangeTheme();
715  }
716 }
717 
719 {
720  wxTextEntryDialog dlg(this, _("Please enter the new name of the new colour theme:"), _("New theme name"), m_Theme->GetName());
721  PlaceWindow(&dlg);
722  if (dlg.ShowModal() != wxID_OK)
723  return;
724 
725  wxString name = dlg.GetValue();
726  if (!CheckColourThemeName(name, this))
727  return;
728 
729  wxString oldName = m_Theme->GetName();
730  wxChoice* cmbThemes = XRCCTRL(*this, "cmbThemes", wxChoice);
731  int idx = cmbThemes->GetSelection();
732  if (idx != wxNOT_FOUND)
733  cmbThemes->SetString(idx, name);
734  m_Theme->SetName(name);
735  m_Theme->Save();
736  Manager::Get()->GetConfigManager(_T("editor"))->DeleteSubPath(_T("/colour_sets/") + oldName);
737 
738  cmbThemes->SetSelection(cmbThemes->FindString(name));
739  ChangeTheme();
740 }
741 
743 {
744  if (m_Theme && m_Lang != HL_NONE)
745  {
746  wxArrayString descriptions;
749  EditKeywordsDlg dlg(nullptr, m_Theme, m_Lang, descriptions);
750  PlaceWindow(&dlg);
751  dlg.ShowModal();
752 
753  dlg.m_pTheme->SetKeywords(dlg.m_Lang, dlg.m_LastSet, dlg.txtKeywords->GetValue());
754  }
755 }
756 
758 {
759  if (m_Theme && m_Lang != HL_NONE)
760  {
761  wxString masks = cbGetTextFromUser(_("Edit filemasks (use commas to separate them - case insensitive):"),
764  if (!masks.IsEmpty())
765  m_Theme->SetFileMasks(m_Lang, masks);
766  }
767 }
768 
770 {
771  if (m_Theme && m_Lang != HL_NONE)
772  {
773  wxString tmp;
774  tmp.Printf(_("Are you sure you want to reset all settings to defaults for \"%s\"?"),
776  if (cbMessageBox(tmp, _("Confirmation"), wxICON_QUESTION | wxYES_NO, this) == wxID_YES)
777  {
778  m_Theme->Reset(m_Lang);
779  ApplyColours();
780  ReadColours();
781  m_ThemeModified = true;
782  }
783  }
784 }
785 
787 {
788  const wxArrayString &listLang = m_Theme->GetAllHighlightLanguages();
789 
790  wxMenu menu;
791  for (size_t ii = 0; ii < listLang.GetCount(); ++ii)
792  {
793  wxMenu *optionsMenu = new wxMenu;
794  const wxString &langID = m_Theme->GetHighlightLanguage(listLang[ii]);
795  for (int optIndex = 0; optIndex < m_Theme->GetOptionCount(langID); ++optIndex)
796  {
797  const OptionColour* opt = m_Theme->GetOptionByIndex(langID, optIndex);
798  if (optionsMenu->FindItem(opt->name) == wxNOT_FOUND)
799  {
801  id.index = optIndex;
802  id.langID = langID;
803 
804  long menuID = wxNewId();
805 
806  optionsMenu->Append(menuID, opt->name);
807  Connect(menuID, wxEVT_COMMAND_MENU_SELECTED,
808  wxCommandEventHandler(EditorConfigurationDlg::OnMenuColoursCopyFrom));
809  m_MenuIDToLanguageOption.insert(MenuIDToLanguageOption::value_type(menuID, id));
810  }
811  }
812  menu.AppendSubMenu(optionsMenu, listLang[ii]);
813  }
814 
815  PopupMenu(&menu);
816 
817  for (MenuIDToLanguageOption::const_iterator it = m_MenuIDToLanguageOption.begin();
818  it != m_MenuIDToLanguageOption.end();
819  ++it)
820  {
821  Disconnect(it->first, wxEVT_COMMAND_MENU_SELECTED,
822  wxCommandEventHandler(EditorConfigurationDlg::OnMenuColoursCopyFrom));
823  }
824  m_MenuIDToLanguageOption.clear();
825 }
826 
828 {
829  if (!m_Theme)
830  return;
831  long id = event.GetId();
832  MenuIDToLanguageOption::const_iterator it = m_MenuIDToLanguageOption.find(id);
833  if (it == m_MenuIDToLanguageOption.end())
834  return;
835 
836  MenuItemLanguageOptionID option = it->second;
837  const OptionColour* optSource = m_Theme->GetOptionByIndex(option.langID, option.index);
838 
839  wxListBox* colours = XRCCTRL(*this, "lstComponents", wxListBox);
840  OptionColour* optDest = m_Theme->GetOptionByName(m_Lang, colours->GetStringSelection());
841  if (optSource && optDest)
842  {
843  optDest->back = optSource->back;
844  optDest->fore = optSource->fore;
845  optDest->bold = optSource->bold;
846  optDest->italics = optSource->italics;
847  optDest->underlined = optSource->underlined;
848 
849  UpdateColourControls(optDest);
850  ApplyColours();
851  }
852 }
853 
855 {
856  const wxArrayString &listLang = m_Theme->GetAllHighlightLanguages();
857 
858  wxMenu menu;
859  for (size_t ii = 0; ii < listLang.GetCount(); ++ii)
860  {
862  id.index = -1;
863  id.langID = m_Theme->GetHighlightLanguage(listLang[ii]);;
864 
865  long menuID = wxNewId();
866 
867  menu.Append(menuID, listLang[ii]);
868  Connect(menuID, wxEVT_COMMAND_MENU_SELECTED,
869  wxCommandEventHandler(EditorConfigurationDlg::OnMenuColoursCopyAllFrom));
870  m_MenuIDToLanguageOption.insert(MenuIDToLanguageOption::value_type(menuID, id));
871  }
872 
873  PopupMenu(&menu);
874 
875  for (MenuIDToLanguageOption::const_iterator it = m_MenuIDToLanguageOption.begin();
876  it != m_MenuIDToLanguageOption.end();
877  ++it)
878  {
879  Disconnect(it->first, wxEVT_COMMAND_MENU_SELECTED,
880  wxCommandEventHandler(EditorConfigurationDlg::OnMenuColoursCopyAllFrom));
881  }
882  m_MenuIDToLanguageOption.clear();
883 }
884 
886 {
887  if (!m_Theme)
888  return;
889  long id = event.GetId();
890  MenuIDToLanguageOption::const_iterator it = m_MenuIDToLanguageOption.find(id);
891  if (it == m_MenuIDToLanguageOption.end())
892  return;
893  const wxString &srcLang = it->second.langID;
894  for (int destIndex = 0; destIndex < m_Theme->GetOptionCount(m_Lang); ++destIndex)
895  {
896  OptionColour *optDest = m_Theme->GetOptionByIndex(m_Lang, destIndex);
897  if (!optDest)
898  continue;
899  OptionColour *optSource = m_Theme->GetOptionByName(srcLang, optDest->name);
900  // if the option is not found and we are looking for comment,
901  // then try to get the C/C++ option for comments.
902  if (!optSource && optDest->name == wxT("Comment"))
903  optSource = m_Theme->GetOptionByName(srcLang, wxT("Comment (normal)"));
904  if (optSource)
905  {
906  optDest->back = optSource->back;
907  optDest->fore = optSource->fore;
908  optDest->bold = optSource->bold;
909  optDest->italics = optSource->italics;
910  optDest->underlined = optSource->underlined;
911  }
912  }
913  ApplyColours();
914  ReadColours();
915 }
916 
918 {
919  if (m_Theme)
920  {
921  wxString sel = XRCCTRL(*this, "cmbLangs", wxChoice)->GetStringSelection();
923  }
926 }
927 
929 {
930  int sel = XRCCTRL(*this, "cmbDefCodeFileType", wxChoice)->GetSelection();
931  if (sel != m_DefCodeFileType)
932  { // update array for previous selected and show the code for the newly selected
933  m_DefaultCode[m_DefCodeFileType] = XRCCTRL(*this, "txtDefCode", wxTextCtrl)->GetValue();
934  m_DefCodeFileType = sel;
935  XRCCTRL(*this, "txtDefCode", wxTextCtrl)->SetValue(m_DefaultCode[m_DefCodeFileType]);
936  }
937 }
938 
940 {
941  wxColourData data;
942  wxWindow* sender = FindWindowById(event.GetId());
943  data.SetColour(sender->GetBackgroundColour());
944 
945  wxColourDialog dlg(this, &data);
946  PlaceWindow(&dlg);
947  if (dlg.ShowModal() == wxID_OK)
948  {
949  wxColour colour = dlg.GetColourData().GetColour();
950  sender->SetBackgroundColour(colour);
951  sender->SetLabel(wxEmptyString);
952  }
953 
954  if (event.GetId() == XRCID("btnColoursFore") ||
955  event.GetId() == XRCID("btnColoursBack"))
956  WriteColours();
957 }
958 
960 {
961  wxWindow *button = nullptr;
962  if (event.GetId() == XRCID("btnForeSetDefault"))
963  button = FindWindowById(XRCID("btnColoursFore"));
964  else if (event.GetId() == XRCID("btnBackSetDefault"))
965  button = FindWindowById(XRCID("btnColoursBack"));
966  if (!button)
967  return;
968  button->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
969  button->SetLabel(_("\"Default\""));
970  WriteColours();
971 }
972 
974 {
975  UpdateSampleFont(true);
976 }
977 
979 {
980  ReadColours();
981 }
982 
984 {
985  WriteColours();
986 }
987 
989 {
990  XRCCTRL(*this, "spnMarginWidth", wxSpinCtrl)->Enable(!event.IsChecked());
991 }
992 
994 {
995  if (retCode == wxID_OK)
996  {
997  ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("editor"));
998 
999  cfg->Write(_T("/font"), XRCCTRL(*this, "lblEditorFont", wxStaticText)->GetFont().GetNativeFontInfoDesc());
1000 
1001  cfg->Write(_T("/auto_indent"), XRCCTRL(*this, "chkAutoIndent", wxCheckBox)->GetValue());
1002  cfg->Write(_T("/smart_indent"), XRCCTRL(*this, "chkSmartIndent", wxCheckBox)->GetValue());
1003  cfg->Write(_T("/brace_completion"), XRCCTRL(*this, "chkBraceCompletion", wxCheckBox)->GetValue());
1004  cfg->Write(_T("/detect_indent"), XRCCTRL(*this, "chkDetectIndent", wxCheckBox)->GetValue());
1005  cfg->Write(_T("/use_tab"), XRCCTRL(*this, "chkUseTab", wxCheckBox)->GetValue());
1006  cfg->Write(_T("/show_indent_guides"), XRCCTRL(*this, "chkShowIndentGuides", wxCheckBox)->GetValue());
1007  cfg->Write(_T("/brace_smart_indent"), XRCCTRL(*this, "chkBraceSmartIndent", wxCheckBox)->GetValue());
1008  cfg->Write(_T("/selection_brace_completion"), XRCCTRL(*this, "chkSelectionBraceCompletion", wxCheckBox)->GetValue());
1009  cfg->Write(_T("/tab_indents"), XRCCTRL(*this, "chkTabIndents", wxCheckBox)->GetValue());
1010  cfg->Write(_T("/backspace_unindents"), XRCCTRL(*this, "chkBackspaceUnindents", wxCheckBox)->GetValue());
1011  cfg->Write(_T("/word_wrap"), XRCCTRL(*this, "chkWordWrap", wxCheckBox)->GetValue());
1012  cfg->Write(_T("/word_wrap_style_home_end"), XRCCTRL(*this, "chkWordWrapStyleHomeEnd", wxCheckBox)->GetValue());
1013  cfg->Write(_T("/use_posix_style_regexes"), XRCCTRL(*this, "chkPosixRegex", wxCheckBox)->GetValue());
1014  #ifdef wxHAS_REGEX_ADVANCED
1015  cfg->Write(_T("/use_advanced_regexes"), XRCCTRL(*this, "chkAdvancedRegex", wxCheckBox)->GetValue());
1016  #endif
1017 
1018  cfg->Write(_T("/show_line_numbers"), XRCCTRL(*this, "chkShowLineNumbers", wxCheckBox)->GetValue());
1019  cfg->Write(_T("/highlight_caret_line"), XRCCTRL(*this, "chkHighlightCaretLine", wxCheckBox)->GetValue());
1020  cfg->Write(_T("/simplified_home"), XRCCTRL(*this, "chkSimplifiedHome", wxCheckBox)->GetValue());
1021  cfg->Write(_T("/camel_case"), XRCCTRL(*this, "chkCamelCase", wxCheckBox)->GetValue());
1022 
1023  cfg->Write(_T("/track_preprocessor"), XRCCTRL(*this, "chkTrackPreprocessor", wxCheckBox)->GetValue());
1024  cfg->Write(_T("/collect_prj_defines"), XRCCTRL(*this, "chkCollectPrjDefines", wxCheckBox)->GetValue());
1025  cfg->Write(_T("/platform_defines"), XRCCTRL(*this, "chkPlatDefines", wxCheckBox)->GetValue());
1026  cfg->Write(_T("/highlight_wxsmith"), XRCCTRL(*this, "chkColoursWxSmith", wxCheckBox)->GetValue());
1027  cfg->Write(_T("/no_stl_in_c"), XRCCTRL(*this, "chkNoStlC", wxCheckBox)->GetValue());
1028 
1029  bool resetZoom = XRCCTRL(*this, "chkResetZoom", wxCheckBox)->GetValue();
1030  bool zoomAll = XRCCTRL(*this, "chkZoomAll", wxCheckBox)->GetValue();
1031  if (zoomAll || resetZoom)
1032  {
1034  if (resetZoom)
1035  em->SetZoom(0);
1036  em->GetNotebook()->SetZoom(em->GetZoom());
1037  }
1038  cfg->Write(_T("/reset_zoom"), resetZoom);
1039  cfg->Write(_T("/zoom_all"), zoomAll);
1040  cfg->Write(_T("/sync_editor_with_project_manager"), XRCCTRL(*this, "chkSyncEditorWithProjectManager", wxCheckBox)->GetValue());
1041 
1042  cfg->Write(_T("/tab_size"), XRCCTRL(*this, "spnTabSize", wxSpinCtrl)->GetValue());
1043  cfg->Write(_T("/view_whitespace"), XRCCTRL(*this, "cmbViewWS", wxChoice)->GetSelection());
1044  cfg->Write(_T("/caret_buffer"), XRCCTRL(*this, "cmbCaretBuffer", wxChoice)->GetSelection());
1045  cfg->Write(_T("/tab_text_relative"), XRCCTRL(*this, "rbTabText", wxRadioBox)->GetSelection() ? true : false);
1046  // find & replace, regex searches
1047 
1048  //caret
1049  cfg->Write(_T("/caret/style"), XRCCTRL(*this, "lstCaretStyle", wxChoice)->GetSelection());
1050  cfg->Write(_T("/caret/width"), XRCCTRL(*this, "spnCaretWidth", wxSpinCtrl)->GetValue());
1051  wxColour caretColour = XRCCTRL(*this, "btnCaretColour", wxButton)->GetBackgroundColour();
1052  Manager::Get()->GetColourManager()->SetColour(wxT("editor_caret"), caretColour);
1053  cfg->Write(_T("/caret/period"), XRCCTRL(*this, "slCaretPeriod", wxSlider)->GetValue());
1054 
1055  // whitespace colour
1056  wxColour wsColour = XRCCTRL(*this, "btnWSColour", wxButton)->GetBackgroundColour();
1057  Manager::Get()->GetColourManager()->SetColour(wxT("editor_whitespace"), wsColour);
1058 
1059  //folding
1060  bool enableFolding = XRCCTRL(*this, "chkEnableFolding", wxCheckBox)->GetValue();
1061  if (!enableFolding)
1062  {
1063  //if the folding has been disabled, first unfold
1064  //all blocks in all editors
1066  for (int idx = 0; idx<em->GetEditorsCount(); ++idx)
1067  {
1068  cbEditor *ed = em->GetBuiltinEditor(em->GetEditor(idx));
1069  if(ed)
1070  ed->UnfoldAll();
1071  }
1072  }
1073 
1074  cfg->Write(_T("/folding/show_folds"), enableFolding);
1075  cfg->Write(_T("/folding/fold_all_on_open"), XRCCTRL(*this, "chkFoldOnOpen", wxCheckBox)->GetValue());
1076  cfg->Write(_T("/folding/fold_preprocessor"), XRCCTRL(*this, "chkFoldPreprocessor", wxCheckBox)->GetValue());
1077  cfg->Write(_T("/folding/fold_comments"), XRCCTRL(*this, "chkFoldComments", wxCheckBox)->GetValue());
1078  cfg->Write(_T("/folding/fold_xml"), XRCCTRL(*this, "chkFoldXml", wxCheckBox)->GetValue());
1079  cfg->Write(_T("/folding/underline_folded_line"), XRCCTRL(*this, "chkUnderlineFoldedLine", wxCheckBox)->GetValue());
1080  cfg->Write(_T("/folding/indicator"), XRCCTRL(*this, "lstIndicators", wxChoice)->GetSelection());
1081  cfg->Write(_T("/folding/limit"), XRCCTRL(*this, "chkFoldLimit", wxCheckBox)->GetValue());
1082  cfg->Write(_T("/folding/limit_level"), XRCCTRL(*this, "spnFoldLimitLevel", wxSpinCtrl)->GetValue());
1083 
1084  //eol
1085  cfg->Write(_T("/show_eol"), XRCCTRL(*this, "chkShowEOL", wxCheckBox)->GetValue());
1086  cfg->Write(_T("/eol/strip_trailing_spaces"), XRCCTRL(*this, "chkStripTrailings", wxCheckBox)->GetValue());
1087  cfg->Write(_T("/eol/ensure_final_line_end"), XRCCTRL(*this, "chkEnsureFinalEOL", wxCheckBox)->GetValue());
1088  cfg->Write(_T("/eol/ensure_consistent_line_ends"), XRCCTRL(*this, "chkEnsureConsistentEOL", wxCheckBox)->GetValue());
1089  cfg->Write(_T("/eol/eolmode"), (int)XRCCTRL(*this, "cmbEOLMode", wxChoice)->GetSelection());
1090 
1091  //gutter
1092  cfg->Write(_T("/gutter/mode"), XRCCTRL(*this, "lstGutterMode", wxChoice)->GetSelection());
1093  wxColour gutterColour = XRCCTRL(*this, "btnGutterColour", wxButton)->GetBackgroundColour();
1094  Manager::Get()->GetColourManager()->SetColour(wxT("editor_gutter"), gutterColour);
1095  cfg->Write(_T("/gutter/column"), XRCCTRL(*this, "spnGutterColumn", wxSpinCtrl)->GetValue());
1096 
1097  //margin
1098  cfg->Write(_T("/margin/width_chars"), XRCCTRL(*this, "spnMarginWidth", wxSpinCtrl)->GetValue());
1099  cfg->Write(_T("/margin/dynamic_width"), XRCCTRL(*this, "chkDynamicWidth", wxCheckBox)->GetValue());
1100  cfg->Write(_T("/margin_1_sensitive"), (bool)XRCCTRL(*this, "chkAddBPByLeftClick", wxCheckBox)->GetValue());
1101  cfg->Write(_T("/margin_1_image_bp"), (bool)XRCCTRL(*this, "chkImageBP", wxCheckBox)->GetValue());
1102 
1103  //selections
1104  cfg->Write(_T("/selection/use_vspace"), (bool)XRCCTRL(*this, "chkEnableVirtualSpace", wxCheckBox)->GetValue());
1105  cfg->Write(_T("/selection/use_rect_vspace"), (bool)XRCCTRL(*this, "chkEnableRectVirtualSpace", wxCheckBox)->GetValue());
1106  cfg->Write(_T("/selection/multi_select"), (bool)XRCCTRL(*this, "chkEnableMultipleSelections", wxCheckBox)->GetValue());
1107  cfg->Write(_T("/selection/multi_typing"), (bool)XRCCTRL(*this, "chkEnableAdditionalSelectionTyping", wxCheckBox)->GetValue());
1108 
1109  //scrollbar
1110  cfg->Write(_T("/margin/scroll_width_tracking"), XRCCTRL(*this, "chkScrollWidthTracking", wxCheckBox)->GetValue());
1111 
1112  //changebar
1113  bool enableChangebar = XRCCTRL(*this, "chkUseChangebar", wxCheckBox)->GetValue();
1114  cfg->Write(_T("/margin/use_changebar"), enableChangebar);
1115  if (enableChangebar != m_EnableChangebar)
1116  {
1118  for (int idx = 0; idx<em->GetEditorsCount(); ++idx)
1119  {
1120  cbEditor *ed = em->GetBuiltinEditor(em->GetEditor(idx));
1121  if(ed)
1122  {
1123  // if we enable changeCollection, we also have to empty Undo-Buffer, to avoid inconsistences,
1124  // if we disable it, there is no need to do that
1125  enableChangebar?
1126  ed->ClearHistory():
1127  ed->SetChangeCollection(false);
1128  }
1129  }
1130  }
1131  // default code : first update what's in the current txtCtrl,
1132  // and then write them all to the config file (even if unmodified)
1133  int sel = XRCCTRL(*this, "cmbDefCodeFileType", wxChoice)->GetSelection();
1134  m_DefaultCode[sel] = XRCCTRL(*this, "txtDefCode", wxTextCtrl)->GetValue();
1135  for(size_t idx = 0; idx < sizeof(IdxToFileType)/sizeof(*IdxToFileType); ++ idx)
1136  {
1137  wxString key;
1138  key.Printf(_T("/default_code/set%d"), IdxToFileType[idx]);
1139  m_DefaultCode.Add(cfg->Read(key, wxEmptyString));
1140  cfg->Write(key, m_DefaultCode[idx]);
1141  }// end for : idx
1142 
1143 
1144  if (m_Theme)
1145  {
1146  m_Theme->Save();
1148  cfg->Write(_T("/colour_sets/active_colour_set"), m_Theme->GetName());
1149  }
1150  cfg->Write(_T("/colour_sets/active_lang"), XRCCTRL(*this, "cmbLangs", wxChoice)->GetStringSelection());
1151 
1152  // encoding
1153  wxChoice* cmbEnc = XRCCTRL(*this, "cmbEncoding", wxChoice);
1154  if (cmbEnc)
1155  {
1156  cfg->Write(_T("/default_encoding"), cmbEnc->GetStringSelection());
1157  }
1158  cfg->Write(_T("/default_encoding/use_option"), XRCCTRL(*this, "rbEncodingUseOption", wxRadioBox)->GetSelection());
1159  cfg->Write(_T("/default_encoding/find_latin2"), XRCCTRL(*this, "chkEncodingFindLatin2", wxCheckBox)->GetValue());
1160  cfg->Write(_T("/default_encoding/use_system"), XRCCTRL(*this, "chkEncodingUseSystem", wxCheckBox)->GetValue());
1161 
1162  // code completion
1163  cfg = Manager::Get()->GetConfigManager(_T("ccmanager"));
1164  cfg->Write(_T("/code_completion"), XRCCTRL(*this, "chkCodeCompletion", wxCheckBox)->GetValue());
1165  cfg->Write(_T("/case_sensitive"), XRCCTRL(*this, "chkCCCaseSensitive", wxCheckBox)->GetValue());
1166  cfg->Write(_T("/auto_select_single"), XRCCTRL(*this, "chkAutoselectSingle", wxCheckBox)->GetValue());
1167  cfg->Write(_T("/auto_launch_count"), XRCCTRL(*this, "spnAutolaunchCount", wxSpinCtrl)->GetValue());
1168  cfg->Write(_T("/documentation_popup"), XRCCTRL(*this, "chkDocumentationPopup", wxCheckBox)->GetValue());
1169  cfg->Write(_T("/tooltip_mode"), XRCCTRL(*this, "cmbTooltipMode", wxChoice)->GetSelection());
1170 
1171  // finally, apply settings in all plugins' panels
1172  for (size_t i = 0; i < m_PluginPanels.GetCount(); ++i)
1173  {
1175  panel->OnApply();
1176  }
1177 
1178  // save the colours manager here, just in case there are duplicate colour controls
1180  }
1181  else
1182  {
1183  // finally, cancel settings in all plugins' panels
1184  for (size_t i = 0; i < m_PluginPanels.GetCount(); ++i)
1185  {
1187  panel->OnCancel();
1188  }
1189  }
1190  wxScrollingDialog::EndModal(retCode);
1191 }
1192 
1194 {
1195  XRCCTRL(*this, "chkEnableAdditionalSelectionTyping", wxCheckBox)->Enable( event.IsChecked() );
1196 }
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
Definition: globals.cpp:134
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
virtual bool AddPage(wxWindow *page, const wxString &text, bool select=false, int imageId=NO_IMAGE)
wxString GetLanguageName(HighlightLanguage lang)
void UpdateColourControls(const OptionColour *opt)
#define wxSCI_MARGIN_NUMBER
Definition: wxscintilla.h:151
int wxNewId()
PluginManager * GetPluginManager() const
Definition: manager.cpp:444
#define wxICON_QUESTION
void OnMenuColoursCopyFrom(wxCommandEvent &event)
void OnColoursCopyAllFrom(wxCommandEvent &event)
virtual bool SetPageImage(size_t page, int image)=0
virtual int GetSelection() const=0
Data folder in user&#39;s dir.
Definition: configmanager.h:75
Large icons (default)
Definition: globals.h:299
void OnChooseColour(wxCommandEvent &event)
bool FromString(const wxString &s)
void OnSetDefaultColour(wxCommandEvent &event)
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
void OnCaretStyle(wxCommandEvent &event)
#define COLORSET_DEFAULT
int ReadInt(const wxString &name, int defaultVal=0)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
SettingsIconsStyle
Icons styles for settings dialogs.
Definition: globals.h:297
void OnChooseFont(wxCommandEvent &event)
void SetIndentationGuides(int indentView)
Show or hide indentation guides.
virtual int GetSelection() const
void SetColourSet(EditorColourSet *theme)
DLLIMPORT wxBitmap cbLoadBitmap(const wxString &filename, wxBitmapType bitmapType=wxBITMAP_TYPE_PNG)
This function loads a bitmap from disk.
Definition: globals.cpp:1102
void GetConfigurationPanels(int group, wxWindow *parent, ConfigurationPanelsArray &arrayToFill)
DLLIMPORT wxString cbGetTextFromUser(const wxString &message, const wxString &caption=cbGetTextFromUserPromptStr, const wxString &default_value=wxEmptyString, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord, bool centre=true)
Definition: globals.cpp:1465
wxColour & GetColour()
#define wxSCI_EOL_LF
Definition: wxscintilla.h:85
MenuIDToLanguageOption m_MenuIDToLanguageOption
wxColour wxNullColour
void OnChangeDefCodeFileType(wxCommandEvent &event)
void SetMarginType(int margin, int marginType)
Set a margin to be either numeric or symbolic.
bool ReadBool(const wxString &name, bool defaultVal=false)
void UnfoldAll()
Unfold all editor folds (shows blocks of code).
Definition: cbeditor.cpp:2142
static size_t GetSupportedEncodingsCount()
virtual wxString GetTitle() const =0
#define wxCANCEL
void OnColourComponent(wxCommandEvent &event)
int GetZoom() const
wxCStrData c_str() const
void OnAddColourTheme(wxCommandEvent &event)
virtual size_t GetPageCount() const
wxMenuItem * Append(int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
bool Matches(const wxString &text, int flags=0) const
virtual void OnApply()=0
Called when the user chooses to apply the configuration.
#define _T(string)
virtual void OnCancel()=0
Called when the user chooses to cancel the configuration.
static wxString GetEncodingName(wxFontEncoding encoding)
FileType
Known file types.
Definition: globals.h:49
const wxArrayString & GetFileMasks(HighlightLanguage lang)
#define wxYES_NO
DLLIMPORT wxString GetStringFromArray(const wxArrayString &array, const wxString &separator=DEFAULT_ARRAY_SEP, bool SeparatorAtEnd=true)
Definition: globals.cpp:122
static const int cgEditor
Editor related.
Definition: cbplugin.h:69
wxString GetName()
void OnDeleteColourTheme(wxCommandEvent &event)
virtual unsigned int GetCount() const
wxFontEncoding
const wxString base_imgs[]
#define wxT(string)
#define wxNOT_FOUND
int CmpNoCase(const wxString &s) const
static wxString LocateDataFile(const wxString &filename, int search_dirs=sdAllKnown)
Locate a file in an installation- and platform-independent way.
void SetName(const wxString &name)
wxFont GetChosenFont() const
void SetZoom(int zoom)
Set zoomfactor for builtin editors.
Definition: cbauibook.cpp:228
const FileType IdxToFileType[]
EditorManager * GetEditorManager() const
Definition: manager.cpp:434
No icons, just text.
Definition: globals.h:300
void SetCaretLineVisible(bool show)
Display the background of the line containing the caret in a different colour.
virtual void SetString(unsigned int pos, const wxString &s)
wxArrayString m_DefaultCode
will store the default code during configuration for each type
void SetChangeCollection(bool collectChange) override
Definition: cbeditor.cpp:2516
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
virtual int GetImageCount() const
void SetMarginWidth(int margin, int pixelWidth)
Set the width of a margin to a width expressed in pixels.
void OnRenameColourTheme(wxCommandEvent &event)
void SetInitialFont(const wxFont &font)
#define wxSCI_IV_LOOKBOTH
Definition: wxscintilla.h:241
wxMenuItem * AppendSubMenu(wxMenu *submenu, const wxString &text, const wxString &help=wxEmptyString)
wxColour GetColour(const wxString &id) const
wxArrayString EnumerateSubPaths(const wxString &path)
bool SetNativeFontInfo(const wxString &info)
wxString GetSampleCode(HighlightLanguage lang, int *breakLine, int *debugLine, int *errorLine)
static wxString GetSystemEncodingName()
void UpdateSampleFont(bool askForNewFont)
void SetFileMasks(HighlightLanguage lang, const wxString &masks, const wxString &=_(","))
void MarkerDeleteAll(int markerNumber)
Delete all markers with a particular number from all lines.
#define HL_NONE
Definition: globals.h:167
wxString DescribeKeyWordSets() const
Retrieve a &#39;\n&#39; separated list of descriptions of the keyword sets understood by the current lexer...
virtual int ShowModal()
void OnEditFilemasks(wxCommandEvent &event)
static wxColour GetColour(wxSystemColour index)
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
void OnBoldItalicUline(wxCommandEvent &event)
wxArrayString GetAllHighlightLanguages()
void StyleSetFont(int styleNum, const wxFont &font)
Set style size, face, bold, italic, and underline attributes from a wxFont&#39;s attributes.
virtual int ShowModal()
int GetOptionCount(HighlightLanguage lang)
wxString wxEmptyString
#define wxOK
#define wxSCI_IV_NONE
Definition: wxscintilla.h:238
void SetZoom(int zoom)
const wxString & _(const wxString &string)
OptionColour * GetOptionByName(HighlightLanguage lang, const wxString &name)
EditorBase * GetEditor(int index)
Base class for plugin configuration panels.
cbEditor * GetBuiltinEditor(EditorBase *eb)
#define wxSCI_STYLE_DEFAULT
Styles in range 32..38 are predefined for parts of the UI and are not used as normal styles...
Definition: wxscintilla.h:163
virtual wxString GetBitmapBaseName() const =0
bool LoadFile(const wxString &filename)
Load the contents of filename into the editor.
static wxString GetDataFolder(bool global=true)
ColourManager * GetColourManager() const
Definition: manager.cpp:489
void SetTabWidth(int tabWidth)
Change the visible size of a tab to be a multiple of the width of a space character.
EditorColourSet * GetColourSet()
void Reset(HighlightLanguage lang)
A file editor.
Definition: cbeditor.h:43
virtual int FindItem(const wxString &itemString) const
void DeleteSubPath(const wxString &strPath)
bool IsEmpty() const
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
cbAuiNotebook * GetNotebook()
Definition: editormanager.h:73
bool AttachUnknownControl(const wxString &name, wxWindow *control, wxWindow *parent=NULL)
OptionColour * GetOptionByIndex(HighlightLanguage lang, int index)
void OnPageChanged(wxListbookEvent &event)
void OnMultipleSelections(wxCommandEvent &event)
void OnDynamicCheck(wxCommandEvent &event)
void UpdateOptionsWithSameName(HighlightLanguage lang, OptionColour *base)
static wxFontEncoding GetEncoding(size_t n)
void ClearHistory() override
Clear Undo- (and Changebar-) history.
Definition: cbeditor.cpp:2472
DLLIMPORT void SetSettingsIconsStyle(wxListCtrl *lc, SettingsIconsStyle style)
Set the icons style for the supplied list control.
Definition: globals.cpp:1125
int MarkerAdd(int line, int markerNumber)
Add a marker to a line, returning an ID which can be used to find or delete the marker.
void OnColoursCopyFrom(wxCommandEvent &event)
const int IMAGES_COUNT
size_t Add(const wxString &str, size_t copies=1)
void OnChangeLang(wxCommandEvent &event)
#define wxSCI_EOL_CRLF
Definition: wxscintilla.h:83
void Sort(bool reverseOrder=false)
#define wxSCI_CARETSTYLE_LINE
Definition: wxscintilla.h:381
int Add(const wxBitmap &bitmap, const wxBitmap &mask=wxNullBitmap)
virtual wxString GetPageText(size_t nPage) const=0
size_t GetCount() const
void SetColour(const wxString &id, const wxColour &colour)
static wxXmlResource * Get()
HighlightLanguage Apply(cbEditor *editor, HighlightLanguage lang, bool colourise)
void OnEditKeywords(wxCommandEvent &event)
Data folder in base dir.
Definition: configmanager.h:81
wxColourData & GetColourData()
int Printf(const wxString &pszFormat,...)
ConfigurationPanelsArray m_PluginPanels
void SetColour(const wxColour &colour)
void OnColourTheme(wxCommandEvent &event)
virtual void SetSelection(int n)
void SetParentDialog(wxWindow *dialog)
Sets the panel&#39;s parent dialog.
wxListView * GetListView() const
void OnColoursReset(wxCommandEvent &event)
cbStyledTextCtrl * m_TextColourControl
wxString GetNativeFontInfoDesc() const
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395
void OnMenuColoursCopyAllFrom(wxCommandEvent &event)
HighlightLanguage GetHighlightLanguage(int lexer)
const wxFontData & GetFontData() const
virtual int FindString(const wxString &s, bool bCase=false) const