From 80245660d636c9567b808bfbfecc3864ae7307d8 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 24 Jun 2019 09:18:08 -0400 Subject: [PATCH] Fix font pref setting, share config objects --- Windows-Build.md | 4 +--- config/json2c.c | 2 +- src/TyroApp.cpp | 11 +++++------ src/widgets/MainFrame.cpp | 2 +- src/widgets/MainFrame.h | 2 +- src/widgets/PrefFrame.cpp | 15 +++++++++++---- src/widgets/TyroMenu.cpp | 7 +++---- src/widgets/TyroMenu.h | 1 - 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Windows-Build.md b/Windows-Build.md index e27568f..fd7195e 100644 --- a/Windows-Build.md +++ b/Windows-Build.md @@ -1,7 +1,5 @@ # Building on Windows -In order to keep a consistent build system, Tyro is built with MinGW and Msys. This allows for a *nix-style build environment on Windows. - ## Build Environment Setup: 1. Install [Visual Studio 2015](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx) (Community or Express should work) @@ -14,4 +12,4 @@ In order to keep a consistent build system, Tyro is built with MinGW and Msys. T ## Build Tyro - +TODO diff --git a/config/json2c.c b/config/json2c.c index 3ec69f7..c9b84b5 100644 --- a/config/json2c.c +++ b/config/json2c.c @@ -60,7 +60,7 @@ int main(int argc, char** argv) { fprintf(fo, "\n};\n\n"); fprintf(fo, "#endif\n"); - printf("converted %s\n", argv[1]); + printf("converted %s to .h file\n", argv[1]); return 0; } diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 523e012..36605a2 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -11,13 +11,14 @@ #include "src/widgets/MainFrame.h" -// Some global stuff +// All the ugly globals wxConfigBase *Glob_config = nullptr; +LangConfig *Glob_lang_config = nullptr; +ThemeConfig *Glob_theme_config = nullptr; +MainFrame *Glob_main_frame = nullptr; TyroMenu *Glob_menu_bar = nullptr; wxStatusBar *Glob_status_bar = nullptr; -MainFrame *Glob_main_frame = nullptr; -ThemeConfig *Glob_theme_config = nullptr; -LangConfig *Glob_lang_config = nullptr; + StringConstMap Glob_lexer_map; /** @@ -33,8 +34,6 @@ public: */ bool OnInit() final { - // if ( ! wxApp::OnInit()) return false; - TyroApp::SetSystemOptions(); this->SetAppName(APP_NAME); this->SetVendorName(APP_VENDOR); diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 2196ed1..10e4499 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -723,7 +723,7 @@ void MainFrame::OnLangSelect(wxCommandEvent &event) * * @return void */ -void MainFrame::OnPrefsChanged(wxCommandEvent &WXUNUSED(event)) +void MainFrame::OnPrefsChanged() { this->notebook->Freeze(); for(size_t i = 0; i < this->notebook->GetPageCount(); i++) diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index ba93d57..cee2d40 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -16,7 +16,7 @@ class MainFrame: public wxFrame ~MainFrame() override; void EnableEditControls(bool enable=true); void OpenFiles(wxArrayString filelist); - void OnPrefsChanged(wxCommandEvent &event); + void OnPrefsChanged(); private: PrefFrame *prefFrame = nullptr; FileTreePane *fileTreePane = nullptr; diff --git a/src/widgets/PrefFrame.cpp b/src/widgets/PrefFrame.cpp index c00805d..ace4950 100644 --- a/src/widgets/PrefFrame.cpp +++ b/src/widgets/PrefFrame.cpp @@ -63,21 +63,28 @@ public: { this->showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) { Glob_config->Write("show_line_numbers", event.IsChecked()); - Glob_main_frame->OnPrefsChanged(event); + Glob_main_frame->OnPrefsChanged(); Glob_config->Flush(); }, myID_PREFS_LINE_NUMBERS); this->showIndentGuides->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) { Glob_config->Write("show_indent_guides", event.IsChecked()); - Glob_main_frame->OnPrefsChanged(event); + Glob_main_frame->OnPrefsChanged(); Glob_config->Flush(); }, myID_PREFS_IDENT_GUIDES); this->showCodeFolding->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) { Glob_config->Write("show_code_folding", event.IsChecked()); - Glob_main_frame->OnPrefsChanged(event); + Glob_main_frame->OnPrefsChanged(); Glob_config->Flush(); }, myID_PREFS_CODE_FOLDING); + + this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) { + auto font = event.GetFont(); + Glob_config->Write("global_font", font); + Glob_main_frame->OnPrefsChanged(); + Glob_config->Flush(); + }, myID_PREFS_FONT); } } @@ -123,7 +130,7 @@ public: Glob_config->Write("global_font", this->fontPicker->GetSelectedFont()); auto evt = wxCommandEvent(); - Glob_main_frame->OnPrefsChanged(evt); + Glob_main_frame->OnPrefsChanged(); Glob_config->Flush(); diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index ecdbc43..76a6571 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -1,5 +1,7 @@ #include "src/widgets/TyroMenu.h" +extern LangConfig *Glob_lang_config; + /** * Constructor */ @@ -11,8 +13,6 @@ TyroMenu::TyroMenu() this->langMenu = new wxMenu(); this->helpMenu = new wxMenu(); - this->lang_config = new LangConfig(); - this->SetupMainMenus(); this->SetupLangMenu(); @@ -30,7 +30,6 @@ TyroMenu::TyroMenu() TyroMenu::~TyroMenu() { wxLogDebug("TyroMenu Destructor Called."); - delete this->lang_config; } /** @@ -82,7 +81,7 @@ void TyroMenu::SetupMainMenus() */ void TyroMenu::SetupLangMenu() { - StringMap languages = lang_config->GetLangList(); + StringMap languages = Glob_lang_config->GetLangList(); for (const auto lang: languages) { diff --git a/src/widgets/TyroMenu.h b/src/widgets/TyroMenu.h index 5bab445..ac693ae 100644 --- a/src/widgets/TyroMenu.h +++ b/src/widgets/TyroMenu.h @@ -14,7 +14,6 @@ public: void SetIdChecked(int id, bool checked); void SetCurrentLanguage(string lang); private: - LangConfig *lang_config = nullptr; wxMenu *fileMenu = nullptr; wxMenu *editMenu = nullptr; wxMenu *viewMenu = nullptr;