2015-07-07 10:01:17 -04:00
|
|
|
#include "src/widgets/PrefPane.h"
|
|
|
|
#include "src/widgets/MainFrame.h"
|
2015-05-26 15:46:55 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
extern wxConfigBase *Glob_config;
|
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
class GeneralPrefPanePage : public wxPanel {
|
|
|
|
public:
|
|
|
|
GeneralPrefPanePage(wxWindow *parent)
|
|
|
|
: wxPanel(parent)
|
|
|
|
{
|
2015-05-27 11:37:02 -04:00
|
|
|
this->frame = (MainFrame *) parent;
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-06-12 16:50:27 -04:00
|
|
|
this->showLineNumbers = new wxCheckBox(this, myID_PREFS_LINE_NUMBERS, "Show line numbers");
|
|
|
|
this->showIndentGuides = new wxCheckBox(this, myID_PREFS_IDENT_GUIDES, "Show indent guides");
|
|
|
|
this->showCodeFolding = new wxCheckBox(this, myID_PREFS_CODE_FOLDING, "Show code folding");
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
|
2015-06-12 16:50:27 -04:00
|
|
|
sizer->Add(this->showLineNumbers, wxSizerFlags().Border());
|
|
|
|
sizer->Add(this->showIndentGuides, wxSizerFlags().Border());
|
|
|
|
sizer->Add(this->showCodeFolding, wxSizerFlags().Border());
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
this->SetSizerAndFit(sizer);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
// Change settings on selection, rather than on apply button
|
|
|
|
// On supported platforms
|
|
|
|
if (wxPreferencesEditor::ShouldApplyChangesImmediately())
|
|
|
|
{
|
2015-06-12 16:50:27 -04:00
|
|
|
this->showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
|
2015-06-05 16:50:52 -04:00
|
|
|
Glob_config->Write("show_line_numbers", event.IsChecked());
|
|
|
|
this->frame->OnPrefsChanged(event);
|
|
|
|
Glob_config->Flush();
|
|
|
|
}, myID_PREFS_LINE_NUMBERS);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-06-12 16:50:27 -04:00
|
|
|
this->showIndentGuides->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
|
2015-06-05 16:50:52 -04:00
|
|
|
Glob_config->Write("show_indent_guides", event.IsChecked());
|
|
|
|
this->frame->OnPrefsChanged(event);
|
|
|
|
Glob_config->Flush();
|
|
|
|
}, myID_PREFS_IDENT_GUIDES);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-06-12 16:50:27 -04:00
|
|
|
this->showCodeFolding->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
|
2015-06-05 16:50:52 -04:00
|
|
|
Glob_config->Write("show_code_folding", event.IsChecked());
|
|
|
|
this->frame->OnPrefsChanged(event);
|
|
|
|
Glob_config->Flush();
|
|
|
|
}, myID_PREFS_CODE_FOLDING);
|
2015-05-26 15:46:55 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
~GeneralPrefPanePage()
|
|
|
|
{
|
2019-05-30 15:09:42 -04:00
|
|
|
wxDELETE(this->showLineNumbers);
|
|
|
|
wxDELETE(this->showIndentGuides);
|
|
|
|
wxDELETE(this->showCodeFolding);
|
2015-05-27 11:37:02 -04:00
|
|
|
}
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
/**
|
|
|
|
* Apply current settings to the pref window
|
2015-10-29 13:55:01 -04:00
|
|
|
*
|
2019-05-16 15:21:32 -04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-05-26 15:46:55 -04:00
|
|
|
virtual bool TransferDataToWindow()
|
|
|
|
{
|
2015-06-12 16:50:27 -04:00
|
|
|
this->showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true));
|
|
|
|
this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false));
|
|
|
|
this->showCodeFolding->SetValue(Glob_config->ReadBool("show_code_folding", false));
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2019-05-30 15:09:42 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on platforms with modal preferences dialog to save
|
|
|
|
* and apply the changes
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
virtual bool TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
Glob_config->Write("show_line_numbers", this->showLineNumbers->IsChecked());
|
|
|
|
Glob_config->Write("show_indent_guides", this->showIndentGuides->IsChecked());
|
|
|
|
Glob_config->Write("show_code_folding", this->showCodeFolding->IsChecked());
|
|
|
|
|
|
|
|
wxCommandEvent evt = wxCommandEvent();
|
|
|
|
this->frame->OnPrefsChanged(evt);
|
|
|
|
|
|
|
|
Glob_config->Flush();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MainFrame *frame;
|
|
|
|
wxCheckBox *showLineNumbers = nullptr;
|
|
|
|
wxCheckBox *showIndentGuides = nullptr;
|
|
|
|
wxCheckBox *showCodeFolding = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FontPrefPanePage : public wxPanel{
|
|
|
|
public:
|
|
|
|
FontPrefPanePage(wxWindow *parent): wxPanel(parent)
|
|
|
|
{
|
|
|
|
this->frame = (MainFrame *) parent;
|
|
|
|
|
|
|
|
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
2019-05-31 14:17:30 -04:00
|
|
|
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
|
|
|
|
Glob_config->Read("global_font", &globalFont);
|
|
|
|
|
2019-05-30 15:09:42 -04:00
|
|
|
this->fontPicker = new wxFontPickerCtrl(
|
2019-05-31 14:17:30 -04:00
|
|
|
this,
|
|
|
|
myID_PREFS_FONT,
|
|
|
|
globalFont,
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
|
|
|
wxFNTP_FONTDESC_AS_LABEL
|
2019-05-30 15:09:42 -04:00
|
|
|
);
|
|
|
|
this->fontPicker->SetLabelText("Editor Font");
|
|
|
|
wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
fontSizer->AddSpacer(50);
|
|
|
|
fontSizer->Add(this->fontPicker, wxSizerFlags().Border());
|
|
|
|
fontSizer->AddSpacer(50);
|
|
|
|
sizer->Add(fontSizer, wxSizerFlags().Border());
|
|
|
|
|
|
|
|
this->SetSizerAndFit(sizer);
|
|
|
|
|
|
|
|
// Change settings on selection, rather than on apply button
|
|
|
|
// On supported platforms
|
|
|
|
if (wxPreferencesEditor::ShouldApplyChangesImmediately())
|
|
|
|
{
|
|
|
|
this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) {
|
|
|
|
Glob_config->Write("global_font", event.GetFont());
|
|
|
|
this->frame->OnPrefsChanged(event);
|
|
|
|
Glob_config->Flush();
|
|
|
|
}, myID_PREFS_FONT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~FontPrefPanePage()
|
|
|
|
{
|
|
|
|
wxDELETE(this->fontPicker);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply current settings to the pref window
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
virtual bool TransferDataToWindow()
|
|
|
|
{
|
2019-05-31 14:17:30 -04:00
|
|
|
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
|
2019-05-16 15:21:32 -04:00
|
|
|
Glob_config->Read("global_font", &globalFont);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2019-05-16 15:21:32 -04:00
|
|
|
this->fontPicker->SetSelectedFont(globalFont);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
/**
|
2015-10-29 13:55:01 -04:00
|
|
|
* Called on platforms with modal preferences dialog to save
|
2015-05-26 15:46:55 -04:00
|
|
|
* and apply the changes
|
2015-10-29 13:55:01 -04:00
|
|
|
*
|
2019-05-16 15:21:32 -04:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-05-26 15:46:55 -04:00
|
|
|
virtual bool TransferDataFromWindow()
|
|
|
|
{
|
2019-05-16 15:21:32 -04:00
|
|
|
Glob_config->Write("global_font", this->fontPicker->GetSelectedFont());
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
wxCommandEvent evt = wxCommandEvent();
|
|
|
|
this->frame->OnPrefsChanged(evt);
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-27 11:37:02 -04:00
|
|
|
Glob_config->Flush();
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-29 13:55:01 -04:00
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
private:
|
2015-05-27 11:37:02 -04:00
|
|
|
MainFrame *frame;
|
2015-06-12 16:50:27 -04:00
|
|
|
wxFontPickerCtrl *fontPicker = nullptr;
|
2015-05-26 15:46:55 -04:00
|
|
|
};
|
|
|
|
|
2019-05-30 15:09:42 -04:00
|
|
|
/*
|
|
|
|
* Creates the "General" pane on the pref window
|
|
|
|
* */
|
2015-05-26 15:46:55 -04:00
|
|
|
class GeneralPrefPane: public wxStockPreferencesPage {
|
|
|
|
public:
|
|
|
|
GeneralPrefPane() : wxStockPreferencesPage(Kind_General) {}
|
|
|
|
virtual wxWindow *CreateWindow(wxWindow *parent)
|
|
|
|
{
|
|
|
|
return new GeneralPrefPanePage(parent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-30 15:09:42 -04:00
|
|
|
class FontPrefPane: public wxStockPreferencesPage {
|
|
|
|
public:
|
|
|
|
FontPrefPane() : wxStockPreferencesPage(Kind_Advanced) {}
|
|
|
|
virtual wxWindow *CreateWindow(wxWindow *parent)
|
|
|
|
{
|
|
|
|
return new FontPrefPanePage(parent);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-26 15:46:55 -04:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// ! Implementation of PrefPane Class
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
PrefPane::PrefPane()
|
|
|
|
{
|
|
|
|
this->pref_window = new wxPreferencesEditor();
|
2015-05-27 11:37:02 -04:00
|
|
|
this->pref_window->AddPage(new GeneralPrefPane());
|
2019-05-31 14:17:30 -04:00
|
|
|
this->pref_window->AddPage(new FontPrefPane());
|
2015-05-26 15:46:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PrefPane::~PrefPane()
|
|
|
|
{
|
2015-06-18 13:34:54 -04:00
|
|
|
//delete this->pref_window;
|
2015-05-26 15:46:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrefPane::Show(wxWindow *parent)
|
|
|
|
{
|
|
|
|
this->pref_window->Show(parent);
|
|
|
|
}
|