From c13750b06e6f72aa5ed970351ea30a653a656123 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 16 May 2019 15:21:32 -0400 Subject: [PATCH] Yet another progress commit --- .editorconfig | 20 ++++++++++++ src/TyroApp.cpp | 21 ++----------- src/definitions.h | 6 ++-- src/widgets/EditPane.cpp | 27 ++++++---------- src/widgets/MainFrame.cpp | 12 +++---- src/widgets/PrefPane.cpp | 66 +++++++++++++++++---------------------- src/wx_common.h | 28 ++++++++--------- 7 files changed, 82 insertions(+), 98 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b909682 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = false +charset = utf-8 +indent_style = tab +trim_trailing_whitespace = true + +[*.{cpp,c,h,hpp,cxx}] +insert_final_newline = true + +# Yaml files +[*.{yml,yaml}] +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 266d43e..c0b7a4b 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -8,11 +8,9 @@ #include #include #include -#include #include "src/widgets/MainFrame.h" - // Some global stuff wxConfigBase *Glob_config = nullptr; TyroMenu *Glob_menu_bar = nullptr; @@ -51,7 +49,7 @@ public: this->InitLexerMap(); Glob_config = wxConfigBase::Get(); Glob_menu_bar = new TyroMenu(); - Glob_main_frame = new MainFrame(nullptr, APP_NAME, this->CalculateWindowSize()); + Glob_main_frame = new MainFrame(nullptr, APP_NAME, CalculateWindowSize()); #ifndef TRAVIS Glob_pref_pane = new PrefPane(); #endif @@ -152,24 +150,9 @@ private: Glob_lexer_map["yaml"] = wxSTC_LEX_YAML; } - /** - * Calculate original window size based on size of the current monitor - */ - wxSize CalculateWindowSize() - { - wxDisplay display; - wxVideoMode mode = display.GetCurrentMode(); - - wxLogDebug("Current display: %ix%i", mode.w, mode.h); - - wxSize base((int)((float)mode.w * 0.9), (int)((float)mode.h * 0.9)); - - return base; - } - /** * Toolkit-specific settings - */ + */ void static SetSystemOptions() { #ifdef __WXMAC__ diff --git a/src/definitions.h b/src/definitions.h index 8f367c2..0385ef8 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -16,9 +16,9 @@ const wxString APP_VERSION_MORE = "Pre-release"; #endif const wxCmdLineEntryDesc Glob_cmdLineDesc[] = { { - wxCMD_LINE_PARAM, - NULL, - NULL, + wxCMD_LINE_PARAM, + nullptr, + nullptr, "input file(s)", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index 2a7175d..119053e 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -175,9 +175,7 @@ bool EditPane::SaveFile() { wxString fname = this->fileName.GetFullPath(); - const wxString cfname(fname); - - return this->SaveFile(cfname); + return this->SaveFile(fname); } /** @@ -332,25 +330,18 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map) this->StyleSetBackground(i, default_background); this->StyleSetForeground(i, default_foreground); - if ( ! HAS_FONT_BUG()) - { - wxFont globalFont; - wxString fontFace; - if ( ! Glob_config->Read("global_font", &globalFont)) - { - this->StyleSetFont(i, *defaultFont); - } - else - { - this->StyleSetFont(i, globalFont); - } - } - else + wxFont globalFont; + wxString fontFace; + if ( ! Glob_config->Read("global_font", &globalFont)) { this->StyleSetFont(i, *defaultFont); } + else + { + this->StyleSetFont(i, globalFont); + } } - + // Set up Code folding if (Glob_config->ReadBool("show_code_folding", false)) { diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 48a84c3..aff29fb 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -440,15 +440,15 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) wxString desc = "Tyro, a text editor for all development\n\n" "System info: \n"; - desc += wxString::Format("Architecture: %s\n", + desc += wxString::Format("\tArchitecture: %s\n", wxPlatformInfo::GetArchName(plat_info.GetArchitecture())); - desc += wxString::Format("Operating System:\n\t%s %i.%i\n", + desc += wxString::Format("\tOperating System:\n\t\t%s %i.%i\n", wxPlatformInfo::GetOperatingSystemIdName(plat_info.GetOperatingSystemId()), plat_info.GetOSMajorVersion(), plat_info.GetOSMinorVersion()); - desc += wxString::Format("wxWidgets version: %s %i.%i.%i\n", + desc += wxString::Format("\nwxWidgets version: %s %i.%i.%i\n", plat_info.GetPortIdName(), wxMAJOR_VERSION, wxMINOR_VERSION, @@ -460,10 +460,10 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) wxString desk = plat_info.GetDesktopEnvironment(); if (desk != "") { - desc += wxString::Format("Desktop Environment:%s\n", desk); + desc += wxString::Format("\tDesktop Environment:%s\n", desk); } - desc += "Distro: "; + desc += "\tDistro: "; desc += dist_info.Description; if (dist_info.CodeName != "") @@ -719,4 +719,4 @@ void MainFrame::OnPrefsChanged(wxCommandEvent &WXUNUSED(event)) editor->ReApplyTheme(); } notebook->Thaw(); -} \ No newline at end of file +} diff --git a/src/widgets/PrefPane.cpp b/src/widgets/PrefPane.cpp index 6956114..602d4a0 100644 --- a/src/widgets/PrefPane.cpp +++ b/src/widgets/PrefPane.cpp @@ -16,22 +16,21 @@ public: wxSizer *sizer = new wxBoxSizer(wxVERTICAL); - // Check that version of OS X is less than 10.10 for wxWidgets < 3.0.3 - // Otherwise the font control will segfault - if( ! HAS_FONT_BUG()) - { - this->fontPicker = new wxFontPickerCtrl( - this, - myID_PREFS_FONT, - wxNullFont, - wxDefaultPosition, - wxDefaultSize, - wxFNTP_USE_TEXTCTRL ^ wxFNTP_USEFONT_FOR_LABEL - ); - wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL); - fontSizer->Add(this->fontPicker, wxSizerFlags().Border()); - sizer->Add(fontSizer, wxSizerFlags().Border()); - } + this->fontPicker = new wxFontPickerCtrl( + this, + myID_PREFS_FONT, + this->GetFont(), + 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()); + sizer->Add(this->showLineNumbers, wxSizerFlags().Border()); sizer->Add(this->showIndentGuides, wxSizerFlags().Border()); @@ -43,14 +42,11 @@ public: // On supported platforms if (wxPreferencesEditor::ShouldApplyChangesImmediately()) { - if ( ! HAS_FONT_BUG()) - { - 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); - } + 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); this->showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) { Glob_config->Write("show_line_numbers", event.IsChecked()); @@ -79,21 +75,18 @@ public: /** * Apply current settings to the pref window * - * @return bool - */ + * @return bool + */ virtual bool TransferDataToWindow() { 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)); - if ( ! HAS_FONT_BUG()) - { - wxFont globalFont; - Glob_config->Read("global_font", &globalFont); + wxFont globalFont; + Glob_config->Read("global_font", &globalFont); - this->fontPicker->SetSelectedFont(globalFont); - } + this->fontPicker->SetSelectedFont(globalFont); return true; } @@ -102,18 +95,15 @@ public: * Called on platforms with modal preferences dialog to save * and apply the changes * - * @return bool - */ + * @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()); - if ( ! HAS_FONT_BUG()) - { - Glob_config->Write("global_font", this->fontPicker->GetSelectedFont()); - } + Glob_config->Write("global_font", this->fontPicker->GetSelectedFont()); wxCommandEvent evt = wxCommandEvent(); this->frame->OnPrefsChanged(evt); diff --git a/src/wx_common.h b/src/wx_common.h index 111ac8e..618fe3b 100644 --- a/src/wx_common.h +++ b/src/wx_common.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -34,21 +35,20 @@ #pragma clang diagnostic pop #endif -// Define a check for font-control bug -// in wxWidgets < 3.0.3 and OS X >= 10.10 -static inline bool HAS_FONT_BUG() +/** + * Calculate original window size based on size of the current monitor + */ +wxSize static CalculateWindowSize() { -#ifndef __WXMAC__ - return false; -#endif - -#if wxCHECK_VERSION(3,0,3) - return false; -#endif - - wxPlatformInfo info; - return (info.GetOSMajorVersion() == 10 && info.GetOSMinorVersion() > 9); + wxDisplay display; + wxVideoMode mode = display.GetCurrentMode(); + + wxLogDebug("Current display: %ix%i", mode.w, mode.h); + + wxSize base((int)((float)mode.w * 0.9), (int)((float)mode.h * 0.9)); + + return base; } // Tyro-specific variables -#include "definitions.h" \ No newline at end of file +#include "definitions.h"