From ee64ae24c46c64d32c50a686283be4578a1aac21 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 31 May 2019 14:17:30 -0400 Subject: [PATCH] Attempt to have a default font specified from the system --- src/TyroApp.cpp | 18 +++++++++--------- src/settings/ThemeConfig.cpp | 4 ++-- src/settings/ThemeConfig.h | 2 +- src/widgets/EditPane.cpp | 25 +++++++------------------ src/widgets/FilePane.cpp | 26 ++++++++++++++------------ src/widgets/FilePane.h | 2 +- src/widgets/PrefPane.cpp | 19 +++++++++++-------- 7 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 2e25ef3..711ea1d 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -22,10 +22,6 @@ StringConstMap Glob_lexer_map; PrefPane *Glob_pref_pane = nullptr; #endif -// Static app loading variables -static wxArrayString files; -static int param_count; - /** * Class with main method */ @@ -58,7 +54,7 @@ public: Glob_main_frame->Show(true); // Open passed files - if (param_count > 0) + if (this->param_count > 0) { Glob_main_frame->OpenFiles(files); } @@ -105,18 +101,22 @@ public: { // Get un-named parameters int i; - param_count = parser.GetParamCount(); + this->param_count = parser.GetParamCount(); - wxLogDebug("%i Parameters", param_count); + wxLogDebug("%i Parameters", this->param_count); - for (i = 0; i < param_count; i++) + for (i = 0; i < this->param_count; i++) { - files.Add(parser.GetParam(i)); + this->files.Add(parser.GetParam(i)); } return true; } private: + // app loading variables + wxArrayString files; + int param_count = 0; + /** * Set up mapping for lexers */ diff --git a/src/settings/ThemeConfig.cpp b/src/settings/ThemeConfig.cpp index 9283f9b..73cd71b 100644 --- a/src/settings/ThemeConfig.cpp +++ b/src/settings/ThemeConfig.cpp @@ -25,7 +25,7 @@ ThemeConfig::~ThemeConfig() {} * @param string theme_name * @return bool */ -bool ThemeConfig::SetTheme(string theme_name) +bool ThemeConfig::SetTheme(const string &theme_name) { JsonValue theme_list = this->GetRoot(); JsonValue selected_theme = theme_list.get(theme_name, JsonValue()); @@ -89,4 +89,4 @@ wxColor ThemeConfig::GetThemeColor(string type, string key) { return wxColor("BLACK"); } -} \ No newline at end of file +} diff --git a/src/settings/ThemeConfig.h b/src/settings/ThemeConfig.h index 2e8d759..5e09f6d 100644 --- a/src/settings/ThemeConfig.h +++ b/src/settings/ThemeConfig.h @@ -10,7 +10,7 @@ class ThemeConfig : TyroConfig { public: ThemeConfig(); ~ThemeConfig(); - bool SetTheme(string theme_name); + bool SetTheme(const string &theme_name); JsonValue GetTheme(); JsonValue GetThemeValue(string type, string key); wxColor GetThemeColor(string type, string key); diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index 27c9cc5..d9bcbda 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -306,13 +306,8 @@ void EditPane::OnCharAdded(wxStyledTextEvent& event) */ void EditPane::_ApplyTheme(JsonValue &lexer_map) { - // Font setup - wxFont defaultFont( - TYRO_DEFAULT_FONT_SIZE, - wxFONTFAMILY_TELETYPE, - wxFONTFLAG_DEFAULT, - wxFONTWEIGHT_NORMAL - ); + // Make sure to have a default font, especially for Linux + wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT); static const wxColor default_background = this->theme_config->GetThemeColor("background", "default"); static const wxColor default_foreground = this->theme_config->GetThemeColor("foreground", "default"); @@ -324,22 +319,16 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map) ? (this->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); - - wxFont globalFont; - wxString fontFace; - if ( ! Glob_config->Read("global_font", &globalFont)) - { - this->StyleSetFont(i, defaultFont); - } - else - { - this->StyleSetFont(i, globalFont); - } + + this->StyleSetFont(i, globalFont); } // Set up Code folding diff --git a/src/widgets/FilePane.cpp b/src/widgets/FilePane.cpp index 32bba94..5ec81c7 100644 --- a/src/widgets/FilePane.cpp +++ b/src/widgets/FilePane.cpp @@ -103,10 +103,10 @@ void FilePane::CreateTree(const wxString &path) this->AddDirToTree(root, dirs[0], wxString(""), true); } - delete files; - // Add files that are in the root path - this->AddDirFiles(root, this->base_path); + this->AddDirFiles(root, this->base_path, files); + + delete files; } /** @@ -199,20 +199,24 @@ void FilePane::AddDirToTree(wxTreeListItem &root, const wxString &path, const wx this->AddDirToTree(dir_node, dirs[0], newParent, true); } - delete files; - // Add the files, if they exist // Defer until after recursion so that files follow folders - this->AddDirFiles(dir_node, fullPath); + this->AddDirFiles(dir_node, fullPath, files); + + delete files; } -void FilePane::AddDirFiles(wxTreeListItem &root, const wxString &path) +/** + * Add the file leaves for the current file path in the tree + * + * @param wxTreeListITem &root - The branch of the tree representing the current path + * @param wxString &path - The filesystem path + * @param wxArrayString *files - The list of files + */ +void FilePane::AddDirFiles(wxTreeListItem &root, const wxString &path, wxArrayString *files) { wxLogInfo("Adding files for dir: %s", path); - auto *files = new wxArrayString(); - wxDir::GetAllFiles(path, files, wxEmptyString, wxDIR_FILES); - wxFileName rootPath(path); rootPath.MakeAbsolute(); @@ -235,8 +239,6 @@ void FilePane::AddDirFiles(wxTreeListItem &root, const wxString &path) this->AppendItem(root, fileLabel, Icon_File, Icon_File, fileData); this->file_set.insert(std::string(fileName.GetFullPath())); } - - delete files; } /** diff --git a/src/widgets/FilePane.h b/src/widgets/FilePane.h index a7bd333..d8219a9 100644 --- a/src/widgets/FilePane.h +++ b/src/widgets/FilePane.h @@ -25,6 +25,6 @@ private: void OpenFileInEditor(wxTreeListEvent& event); void InitImageList(); void AddDirToTree(wxTreeListItem &root, const wxString &path, const wxString &parent, bool recurse = false); - void AddDirFiles(wxTreeListItem &root, const wxString &path); + void AddDirFiles(wxTreeListItem &root, const wxString &path, wxArrayString *files); }; diff --git a/src/widgets/PrefPane.cpp b/src/widgets/PrefPane.cpp index 4ec8619..08e390b 100644 --- a/src/widgets/PrefPane.cpp +++ b/src/widgets/PrefPane.cpp @@ -101,13 +101,16 @@ public: 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, - this->GetFont(), - wxDefaultPosition, - wxDefaultSize, - wxFNTP_FONTDESC_AS_LABEL + this, + myID_PREFS_FONT, + globalFont, + wxDefaultPosition, + wxDefaultSize, + wxFNTP_FONTDESC_AS_LABEL ); this->fontPicker->SetLabelText("Editor Font"); wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL); @@ -142,7 +145,7 @@ public: */ virtual bool TransferDataToWindow() { - wxFont globalFont; + wxFont globalFont = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT); Glob_config->Read("global_font", &globalFont); this->fontPicker->SetSelectedFont(globalFont); @@ -202,7 +205,7 @@ PrefPane::PrefPane() { this->pref_window = new wxPreferencesEditor(); this->pref_window->AddPage(new GeneralPrefPane()); - // this->pref_window->AddPage(new FontPrefPane()); + this->pref_window->AddPage(new FontPrefPane()); } PrefPane::~PrefPane()