Rework style of pref pane

This commit is contained in:
Timothy Warren 2019-05-31 16:34:31 -04:00
parent ee64ae24c4
commit 6028925475
3 changed files with 56 additions and 117 deletions

View File

@ -20,8 +20,8 @@ EditPane::EditPane(
) : wxStyledTextCtrl (parent, id, pos, size, wxBORDER_NONE)
{
Glob_config = (wxConfig *) wxConfigBase::Get();
lang_config = new LangConfig();
theme_config = new ThemeConfig();
this->lang_config = new LangConfig();
this->theme_config = new ThemeConfig();
this->BindEvents();
@ -49,8 +49,8 @@ EditPane::EditPane(
EditPane::~EditPane()
{
wxLogDebug("Called EditPane Destructor");
delete lang_config;
delete theme_config;
delete this->lang_config;
delete this->theme_config;
}
/**
@ -65,7 +65,7 @@ void EditPane::Highlight(const wxString &filePath)
this->fileName.Assign(filePath);
// Get the configuration name for the selected language
string lang = lang_config->GetLangByFile(this->fileName);
string lang = this->lang_config->GetLangByFile(this->fileName);
// Apply the theme
this->ApplyTheme(lang);
@ -99,12 +99,12 @@ void EditPane::ApplyTheme(const string &lang, const string &theme)
if ( ! theme.empty())
{
theme_config->SetTheme(theme);
this->theme_config->SetTheme(theme);
}
// Get the keywords and mapping for the selected language
JsonValue lexer_map = lang_config->GetLexerMap(lang);
JsonValue keywords_array = lang_config->GetKeywordList(lang);
JsonValue lexer_map = this->lang_config->GetLexerMap(lang);
JsonValue keywords_array = this->lang_config->GetKeywordList(lang);
if (keywords_array.isArray())
{
@ -140,7 +140,7 @@ void EditPane::ApplyTheme(const string &lang, const string &theme)
*/
void EditPane::ReApplyTheme(const string &theme)
{
this->ApplyTheme(lang_config->GetLangByName(this->GetCurrentLang()), theme);
this->ApplyTheme(this->lang_config->GetLangByName(this->GetCurrentLang()), theme);
}
/**
@ -393,33 +393,33 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
string key = lexer_map[i].asString();
// Set the foreground color, if it exists
if ( ! theme_config->GetThemeValue("foreground", key).isNull())
if ( ! this->theme_config->GetThemeValue("foreground", key).isNull())
{
this->StyleSetForeground(i, theme_config->GetThemeColor("foreground", key));
this->StyleSetForeground(i, this->theme_config->GetThemeColor("foreground", key));
}
// Set the background color, if it exists
if ( ! theme_config->GetThemeValue("background", key).isNull())
if ( ! this->theme_config->GetThemeValue("background", key).isNull())
{
this->StyleSetBackground(i, theme_config->GetThemeColor("background", key));
this->StyleSetBackground(i, this->theme_config->GetThemeColor("background", key));
}
// Set bold, if it applies
if (theme_config->GetThemeValue("bold", key).isBool())
if this->theme_config->GetThemeValue("bold", key).isBool())
{
this->StyleSetBold(i, theme_config->GetThemeValue("bold", key).asBool());
this->StyleSetBold(i, this->theme_config->GetThemeValue("bold", key).asBool());
}
// Italic
if (theme_config->GetThemeValue("italic", key).isBool())
if this->theme_config->GetThemeValue("italic", key).isBool())
{
this->StyleSetItalic(i, theme_config->GetThemeValue("italic", key).asBool());
this->StyleSetItalic(i, this->theme_config->GetThemeValue("italic", key).asBool());
}
// Underline
if (theme_config->GetThemeValue("underline", key).isBool())
if this->theme_config->GetThemeValue("underline", key).isBool())
{
this->StyleSetUnderline(i, theme_config->GetThemeValue("underline", key).asBool());
this->StyleSetUnderline(i, this->theme_config->GetThemeValue("underline", key).asBool());
}
}
}

View File

@ -39,7 +39,6 @@ FilePane::FilePane(
wxCOL_RESIZABLE | wxCOL_SORTABLE);
this->SetSortColumn(0);
}
FilePane::~FilePane()

View File

@ -8,18 +8,43 @@ public:
GeneralPrefPanePage(wxWindow *parent)
: wxPanel(parent)
{
auto BASE_MARGIN = 30;
this->frame = (MainFrame *) parent;
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
Glob_config->Read("global_font", &globalFont);
this->fontPicker = new wxFontPickerCtrl(
this,
myID_PREFS_FONT,
globalFont,
wxDefaultPosition,
wxDefaultSize,
wxFNTP_FONTDESC_AS_LABEL
);
this->fontPicker->SetLabelText("Editor Font");
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");
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(this->showLineNumbers, wxSizerFlags().Border());
sizer->Add(this->showIndentGuides, wxSizerFlags().Border());
sizer->Add(this->showCodeFolding, wxSizerFlags().Border());
wxSizer *hSizer = new wxBoxSizer(wxHORIZONTAL);
hSizer->AddSpacer(BASE_MARGIN);
this->SetSizerAndFit(sizer);
wxSizer *vSizer = new wxBoxSizer(wxVERTICAL);
vSizer->AddSpacer(BASE_MARGIN);
vSizer->Add(this->fontPicker, wxSizerFlags().Border());
vSizer->AddSpacer(10);
vSizer->Add(this->showLineNumbers, wxSizerFlags().Border());
vSizer->Add(this->showIndentGuides, wxSizerFlags().Border());
vSizer->Add(this->showCodeFolding, wxSizerFlags().Border());
vSizer->AddSpacer(BASE_MARGIN);
hSizer->Add(vSizer);
hSizer->AddSpacer(BASE_MARGIN);
this->SetSizerAndFit(hSizer);
// Change settings on selection, rather than on apply button
// On supported platforms
@ -50,6 +75,7 @@ public:
wxDELETE(this->showLineNumbers);
wxDELETE(this->showIndentGuides);
wxDELETE(this->showCodeFolding);
wxDELETE(this->fontPicker);
}
/**
@ -63,88 +89,6 @@ public:
this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false));
this->showCodeFolding->SetValue(Glob_config->ReadBool("show_code_folding", false));
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);
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
Glob_config->Read("global_font", &globalFont);
this->fontPicker = new wxFontPickerCtrl(
this,
myID_PREFS_FONT,
globalFont,
wxDefaultPosition,
wxDefaultSize,
wxFNTP_FONTDESC_AS_LABEL
);
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()
{
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
Glob_config->Read("global_font", &globalFont);
@ -161,6 +105,9 @@ public:
*/
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());
Glob_config->Write("global_font", this->fontPicker->GetSelectedFont());
wxCommandEvent evt = wxCommandEvent();
@ -173,6 +120,9 @@ public:
private:
MainFrame *frame;
wxCheckBox *showLineNumbers = nullptr;
wxCheckBox *showIndentGuides = nullptr;
wxCheckBox *showCodeFolding = nullptr;
wxFontPickerCtrl *fontPicker = nullptr;
};
@ -188,15 +138,6 @@ public:
}
};
class FontPrefPane: public wxStockPreferencesPage {
public:
FontPrefPane() : wxStockPreferencesPage(Kind_Advanced) {}
virtual wxWindow *CreateWindow(wxWindow *parent)
{
return new FontPrefPanePage(parent);
}
};
// -----------------------------------------------------------------------------
// ! Implementation of PrefPane Class
// -----------------------------------------------------------------------------
@ -205,7 +146,6 @@ PrefPane::PrefPane()
{
this->pref_window = new wxPreferencesEditor();
this->pref_window->AddPage(new GeneralPrefPane());
this->pref_window->AddPage(new FontPrefPane());
}
PrefPane::~PrefPane()