Yet another progress commit

This commit is contained in:
Timothy Warren 2019-05-16 15:21:32 -04:00
parent 72be1d808f
commit c13750b06e
7 changed files with 82 additions and 98 deletions

20
.editorconfig Normal file
View File

@ -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

View File

@ -8,11 +8,9 @@
#include <wx/app.h> #include <wx/app.h>
#include <wx/sysopt.h> #include <wx/sysopt.h>
#include <wx/vidmode.h> #include <wx/vidmode.h>
#include <wx/display.h>
#include "src/widgets/MainFrame.h" #include "src/widgets/MainFrame.h"
// Some global stuff // Some global stuff
wxConfigBase *Glob_config = nullptr; wxConfigBase *Glob_config = nullptr;
TyroMenu *Glob_menu_bar = nullptr; TyroMenu *Glob_menu_bar = nullptr;
@ -51,7 +49,7 @@ public:
this->InitLexerMap(); this->InitLexerMap();
Glob_config = wxConfigBase::Get(); Glob_config = wxConfigBase::Get();
Glob_menu_bar = new TyroMenu(); 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 #ifndef TRAVIS
Glob_pref_pane = new PrefPane(); Glob_pref_pane = new PrefPane();
#endif #endif
@ -152,24 +150,9 @@ private:
Glob_lexer_map["yaml"] = wxSTC_LEX_YAML; 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 * Toolkit-specific settings
*/ */
void static SetSystemOptions() void static SetSystemOptions()
{ {
#ifdef __WXMAC__ #ifdef __WXMAC__

View File

@ -16,9 +16,9 @@ const wxString APP_VERSION_MORE = "Pre-release";
#endif #endif
const wxCmdLineEntryDesc Glob_cmdLineDesc[] = { const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
{ {
wxCMD_LINE_PARAM, wxCMD_LINE_PARAM,
NULL, nullptr,
NULL, nullptr,
"input file(s)", "input file(s)",
wxCMD_LINE_VAL_STRING, wxCMD_LINE_VAL_STRING,
wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE

View File

@ -175,9 +175,7 @@ bool EditPane::SaveFile()
{ {
wxString fname = this->fileName.GetFullPath(); wxString fname = this->fileName.GetFullPath();
const wxString cfname(fname); return this->SaveFile(fname);
return this->SaveFile(cfname);
} }
/** /**
@ -332,25 +330,18 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
this->StyleSetBackground(i, default_background); this->StyleSetBackground(i, default_background);
this->StyleSetForeground(i, default_foreground); this->StyleSetForeground(i, default_foreground);
if ( ! HAS_FONT_BUG()) wxFont globalFont;
{ wxString fontFace;
wxFont globalFont; if ( ! Glob_config->Read("global_font", &globalFont))
wxString fontFace;
if ( ! Glob_config->Read("global_font", &globalFont))
{
this->StyleSetFont(i, *defaultFont);
}
else
{
this->StyleSetFont(i, globalFont);
}
}
else
{ {
this->StyleSetFont(i, *defaultFont); this->StyleSetFont(i, *defaultFont);
} }
else
{
this->StyleSetFont(i, globalFont);
}
} }
// Set up Code folding // Set up Code folding
if (Glob_config->ReadBool("show_code_folding", false)) if (Glob_config->ReadBool("show_code_folding", false))
{ {

View File

@ -440,15 +440,15 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
wxString desc = "Tyro, a text editor for all development\n\n" wxString desc = "Tyro, a text editor for all development\n\n"
"System info: \n"; "System info: \n";
desc += wxString::Format("Architecture: %s\n", desc += wxString::Format("\tArchitecture: %s\n",
wxPlatformInfo::GetArchName(plat_info.GetArchitecture())); 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()), wxPlatformInfo::GetOperatingSystemIdName(plat_info.GetOperatingSystemId()),
plat_info.GetOSMajorVersion(), plat_info.GetOSMajorVersion(),
plat_info.GetOSMinorVersion()); 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(), plat_info.GetPortIdName(),
wxMAJOR_VERSION, wxMAJOR_VERSION,
wxMINOR_VERSION, wxMINOR_VERSION,
@ -460,10 +460,10 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
wxString desk = plat_info.GetDesktopEnvironment(); wxString desk = plat_info.GetDesktopEnvironment();
if (desk != "") 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; desc += dist_info.Description;
if (dist_info.CodeName != "") if (dist_info.CodeName != "")
@ -719,4 +719,4 @@ void MainFrame::OnPrefsChanged(wxCommandEvent &WXUNUSED(event))
editor->ReApplyTheme(); editor->ReApplyTheme();
} }
notebook->Thaw(); notebook->Thaw();
} }

View File

@ -16,22 +16,21 @@ public:
wxSizer *sizer = new wxBoxSizer(wxVERTICAL); wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
// Check that version of OS X is less than 10.10 for wxWidgets < 3.0.3 this->fontPicker = new wxFontPickerCtrl(
// Otherwise the font control will segfault this,
if( ! HAS_FONT_BUG()) myID_PREFS_FONT,
{ this->GetFont(),
this->fontPicker = new wxFontPickerCtrl( wxDefaultPosition,
this, wxDefaultSize,
myID_PREFS_FONT, wxFNTP_FONTDESC_AS_LABEL
wxNullFont, );
wxDefaultPosition, this->fontPicker->SetLabelText("Editor Font");
wxDefaultSize, wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL);
wxFNTP_USE_TEXTCTRL ^ wxFNTP_USEFONT_FOR_LABEL fontSizer->AddSpacer(50);
); fontSizer->Add(this->fontPicker, wxSizerFlags().Border());
wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL); fontSizer->AddSpacer(50);
fontSizer->Add(this->fontPicker, wxSizerFlags().Border()); sizer->Add(fontSizer, wxSizerFlags().Border());
sizer->Add(fontSizer, wxSizerFlags().Border());
}
sizer->Add(this->showLineNumbers, wxSizerFlags().Border()); sizer->Add(this->showLineNumbers, wxSizerFlags().Border());
sizer->Add(this->showIndentGuides, wxSizerFlags().Border()); sizer->Add(this->showIndentGuides, wxSizerFlags().Border());
@ -43,14 +42,11 @@ public:
// On supported platforms // On supported platforms
if (wxPreferencesEditor::ShouldApplyChangesImmediately()) if (wxPreferencesEditor::ShouldApplyChangesImmediately())
{ {
if ( ! HAS_FONT_BUG()) this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) {
{ Glob_config->Write("global_font", event.GetFont());
this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) { this->frame->OnPrefsChanged(event);
Glob_config->Write("global_font", event.GetFont()); Glob_config->Flush();
this->frame->OnPrefsChanged(event); }, myID_PREFS_FONT);
Glob_config->Flush();
}, myID_PREFS_FONT);
}
this->showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) { this->showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
Glob_config->Write("show_line_numbers", event.IsChecked()); Glob_config->Write("show_line_numbers", event.IsChecked());
@ -79,21 +75,18 @@ public:
/** /**
* Apply current settings to the pref window * Apply current settings to the pref window
* *
* @return bool * @return bool
*/ */
virtual bool TransferDataToWindow() virtual bool TransferDataToWindow()
{ {
this->showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true)); this->showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true));
this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false)); this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false));
this->showCodeFolding->SetValue(Glob_config->ReadBool("show_code_folding", 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; return true;
} }
@ -102,18 +95,15 @@ public:
* Called on platforms with modal preferences dialog to save * Called on platforms with modal preferences dialog to save
* and apply the changes * and apply the changes
* *
* @return bool * @return bool
*/ */
virtual bool TransferDataFromWindow() virtual bool TransferDataFromWindow()
{ {
Glob_config->Write("show_line_numbers", this->showLineNumbers->IsChecked()); Glob_config->Write("show_line_numbers", this->showLineNumbers->IsChecked());
Glob_config->Write("show_indent_guides", this->showIndentGuides->IsChecked()); Glob_config->Write("show_indent_guides", this->showIndentGuides->IsChecked());
Glob_config->Write("show_code_folding", this->showCodeFolding->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(); wxCommandEvent evt = wxCommandEvent();
this->frame->OnPrefsChanged(evt); this->frame->OnPrefsChanged(evt);

View File

@ -24,6 +24,7 @@
#include <wx/version.h> #include <wx/version.h>
#include <wx/cmdline.h> #include <wx/cmdline.h>
#include <wx/config.h> #include <wx/config.h>
#include <wx/display.h>
#include <wx/font.h> #include <wx/font.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/platinfo.h> #include <wx/platinfo.h>
@ -34,21 +35,20 @@
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
// Define a check for font-control bug /**
// in wxWidgets < 3.0.3 and OS X >= 10.10 * Calculate original window size based on size of the current monitor
static inline bool HAS_FONT_BUG() */
wxSize static CalculateWindowSize()
{ {
#ifndef __WXMAC__ wxDisplay display;
return false; wxVideoMode mode = display.GetCurrentMode();
#endif
wxLogDebug("Current display: %ix%i", mode.w, mode.h);
#if wxCHECK_VERSION(3,0,3)
return false; wxSize base((int)((float)mode.w * 0.9), (int)((float)mode.h * 0.9));
#endif
return base;
wxPlatformInfo info;
return (info.GetOSMajorVersion() == 10 && info.GetOSMinorVersion() > 9);
} }
// Tyro-specific variables // Tyro-specific variables
#include "definitions.h" #include "definitions.h"