Separate logic for setting editor properties from color scheme logic

This commit is contained in:
Timothy Warren 2019-07-01 15:10:53 -04:00
parent 8ea7ad4abc
commit 37faa83103
2 changed files with 78 additions and 58 deletions

View File

@ -25,7 +25,6 @@ EditorPane::EditorPane(
this->BindEvents();
// Some basic properties to set
this->SetStyleBits(8);
this->SetScrollWidthTracking(true);// Set scroll width by longest line
this->SetProperty("technology", "2");
this->SetProperty("error.inline", "0");
@ -34,6 +33,7 @@ EditorPane::EditorPane(
this->SetProperty("font.quality", "3"); // LCD Optimized
// this->SetLayoutCache (wxSTC_CACHE_DOCUMENT);
this->SetUseAntiAliasing(true);
// set spaces and indention
this->SetTabWidth(4);
@ -126,6 +126,7 @@ void EditorPane::ApplyTheme(const string &lang, const string &theme)
}
// Do the appropriate mappings to load the selected theme
this->_ApplyConfig();
this->_ApplyTheme(lexer_map);
}
@ -316,37 +317,21 @@ void EditorPane::BindEvents()
}
/**
* Iterate through the theme settings and apply them
* Set editor settings from config
*
* @param Json::Value lexer_map - Maps token types to theme colors
* @return void
*/
void EditorPane::_ApplyTheme(Json::Value &lexer_map)
void EditorPane::_ApplyConfig()
{
// Make sure to have a default font, especially for Linux
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
static const wxColor default_background = Glob_theme_config->GetThemeColor("background", "default");
static const wxColor default_foreground = Glob_theme_config->GetThemeColor("foreground", "default");
wxColor line_number_background = ( ! Glob_theme_config->GetThemeValue("line_numbers", "background").isNull())
? (Glob_theme_config->GetThemeColor("line_numbers", "background"))
: default_background;
? (Glob_theme_config->GetThemeColor("line_numbers", "background"))
: default_background;
wxColor line_number_foreground = ( ! Glob_theme_config->GetThemeValue("line_numbers", "foreground").isNull())
? (Glob_theme_config->GetThemeColor("line_numbers", "foreground"))
: default_foreground;
// Attempt to set the font according to config
Glob_config->Read("global_font", &globalFont);
// Set default colors/ fonts
for(int i = 0; i <= wxSTC_STYLE_MAX; i++)
{
this->StyleSetBackground(i, default_background);
this->StyleSetForeground(i, default_foreground);
this->StyleSetFont(i, globalFont);
}
? (Glob_theme_config->GetThemeColor("line_numbers", "foreground"))
: default_foreground;
// Set up Code folding
if (Glob_config->ReadBool("show_code_folding", false))
@ -403,6 +388,40 @@ void EditorPane::_ApplyTheme(Json::Value &lexer_map)
{
this->SetMarginWidth (MARGIN_LINE_NUMBERS, 0);
}
}
/**
* Iterate through the theme colors and apply them
*
* @param Json::Value lexer_map - Maps token types to theme colors
* @return void
*/
void EditorPane::_ApplyTheme(Json::Value &lexer_map)
{
// Make sure to have a default font, especially for Linux
wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
static const wxColor default_background = Glob_theme_config->GetThemeColor("background", "default");
static const wxColor default_foreground = Glob_theme_config->GetThemeColor("foreground", "default");
wxColor line_number_background = ( ! Glob_theme_config->GetThemeValue("line_numbers", "background").isNull())
? (Glob_theme_config->GetThemeColor("line_numbers", "background"))
: default_background;
wxColor line_number_foreground = ( ! Glob_theme_config->GetThemeValue("line_numbers", "foreground").isNull())
? (Glob_theme_config->GetThemeColor("line_numbers", "foreground"))
: default_foreground;
// Attempt to set the font according to config
Glob_config->Read("global_font", &globalFont);
// Set default colors/ fonts
for(int i = 0; i <= wxSTC_STYLE_MAX; i++)
{
this->StyleSetBackground(i, default_background);
this->StyleSetForeground(i, default_foreground);
this->StyleSetFont(i, globalFont);
}
int max = lexer_map.size();
for (int i = 0; i < max; i++)

View File

@ -28,5 +28,6 @@ protected:
bool FileReadable();
bool FileWritable();
void BindEvents();
void _ApplyConfig();
void _ApplyTheme(Json::Value &lexer_map);
};