Font configuration for editor...for most environments

This commit is contained in:
Tim Warren 2015-06-12 16:50:27 -04:00
parent 619db418ff
commit 1ddcde45d5
7 changed files with 203 additions and 61 deletions

View File

@ -6,6 +6,7 @@
#include "widgets/widget.h"
#include <wx/app.h>
#include <wx/sysopt.h>
// Some global stuff
@ -35,6 +36,7 @@ public:
{
if ( ! wxApp::OnInit()) return false;
this->SetSystemOptions();
this->SetAppName(APP_NAME);
this->SetVendorName(APP_VENDOR);
@ -141,6 +143,20 @@ private:
Glob_lexer_map["xml"] = wxSTC_LEX_XML;
Glob_lexer_map["yaml"] = wxSTC_LEX_YAML;
}
/**
* Toolkit-specific settings
*/
void SetSystemOptions()
{
#ifdef __WXMAC__
wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1);
#endif
#ifdef __WXMSW__
wxSystemOptions::SetOption("msw.display.directdraw", 1);
#endif
}
};
// Set up the main method and event loop

View File

@ -8,7 +8,7 @@
// Application config
const wxString APP_NAME = "Tyro";
const wxString APP_VENDOR = "Aviat Ion";
const wxString APP_VERSION = "0.9.0";
const wxString APP_VERSION = "0.9.1";
const wxString APP_VERSION_MORE = "Pre-release";
// Command-line arguments
@ -37,6 +37,14 @@ const wxString TYRO_SAVE_ERROR_CAPTION = "Saving Failed";
const wxString TYRO_OPEN_ERROR = "Failed to open the file. Check that it exists, and that you have read permissions.";
const wxString TYRO_OPEN_ERROR_CAPTION = "Open Failed";
// Font defaults
const int TYRO_DEFAULT_FONT_FAMILY = (int) wxFONTFAMILY_MODERN;
#ifdef __WXMAC__
const int TYRO_DEFAULT_FONT_SIZE = 14;
#else
const int TYRO_DEFAULT_FONT_SIZE = 10;
#endif
// Typedef some common templates
typedef map<string, int> StringConstMap;
typedef map<string, string> StringMap;
@ -76,7 +84,8 @@ enum myMenuItemIds {
// Preferences, to apply to all files
myID_PREFS_LINE_NUMBERS,
myID_PREFS_CODE_FOLDING,
myID_PREFS_IDENT_GUIDES
myID_PREFS_IDENT_GUIDES,
myID_PREFS_FONT
};
const wxString TYRO_FILE_OPEN_WILDCARDS =

View File

@ -309,19 +309,11 @@ void EditPane::OnCharAdded(wxStyledTextEvent& event)
void EditPane::_ApplyTheme(JsonValue &lexer_map)
{
// Font setup
#ifdef __WXMAC__
wxFont *defaultFont = wxFont::New(
14,
TYRO_DEFAULT_FONT_SIZE,
wxFONTFAMILY_MODERN,
wxFONTFLAG_ANTIALIASED
);
#else
wxFont *defaultFont = wxFont::New(
10,
wxFONTFAMILY_MODERN,
wxFONTFLAG_ANTIALIASED
);
#endif
static const wxColor default_background = theme_config->GetThemeColor("background", "default");
static const wxColor default_foreground = theme_config->GetThemeColor("foreground", "default");
@ -338,7 +330,27 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
{
this->StyleSetBackground(i, default_background);
this->StyleSetForeground(i, default_foreground);
this->StyleSetFont(i, *defaultFont);
if ( ! HAS_FONT_BUG())
{
wxString fontFace;
int fontFamily = TYRO_DEFAULT_FONT_FAMILY;
int pointSize = TYRO_DEFAULT_FONT_SIZE;
Glob_config->Read("global_font_face_name", fontFace);
Glob_config->Read("global_font_family", fontFamily);
Glob_config->Read("global_font_point_size", pointSize);
wxFontInfo fInfo(pointSize);
fInfo.Family((wxFontFamily) fontFamily).FaceName(fontFace);
wxFont *font = new wxFont(fInfo);
this->StyleSetFont(i, *font);
}
else
{
this->StyleSetFont(i, *defaultFont);
}
}
// Set up Code folding

View File

@ -31,8 +31,8 @@ FilePane::FilePane(
this->CreateContextMenu();
this->BindEvents();
this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir());
this->SetPath(this->GetDefaultPath());
//this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir());
//this->SetPath(this->GetDefaultPath());
}
/**
@ -91,4 +91,5 @@ void FilePane::OpenSelectedFiles()
wxArrayString paths;
this->GetPaths(paths);
Glob_main_frame->OpenFiles(paths);
this->UnselectAll();
}

View File

@ -22,7 +22,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
// Create the tab container
notebook = new TabContainer(this);
filePane = new FilePane(this);
filePane = new FilePane(this, wxID_ANY, wxStandardPaths::Get().GetDocumentsDir());
// Set the frame icon
wxIcon app_icon(tyro_icon);
@ -83,8 +83,6 @@ void MainFrame::DoLayout()
wxAuiPaneInfo filePaneInfo;
filePaneInfo.Left()
.MinSize(225, 550)
.TopDockable(false)
.BottomDockable(false)
.RightDockable(true)
.LeftDockable(true)
.Resizable(true);
@ -171,14 +169,14 @@ void MainFrame::SetupToolbar()
void MainFrame::BindEvents()
{
// File Menu Events
Bind(wxEVT_MENU, &MainFrame::OnNew, this, wxID_NEW);
Bind(wxEVT_MENU, &MainFrame::OnOpen, this, wxID_OPEN);
Bind(wxEVT_MENU, &MainFrame::OnSave, this, wxID_SAVE);
Bind(wxEVT_MENU, &MainFrame::OnSaveAs, this, wxID_SAVEAS);
Bind(wxEVT_MENU, &MainFrame::OnCloseTab, this, wxID_CLOSE);
Bind(wxEVT_MENU, &TabContainer::OnCloseAllButThis, notebook, myID_CLOSE_ALL_BUT_THIS);
Bind(wxEVT_MENU, &TabContainer::OnCloseAll, notebook, myID_CLOSE_ALL);
Bind(wxEVT_MENU, &MainFrame::OnQuit, this, wxID_EXIT);
this->Bind(wxEVT_MENU, &MainFrame::OnNew, this, wxID_NEW);
this->Bind(wxEVT_MENU, &MainFrame::OnOpen, this, wxID_OPEN);
this->Bind(wxEVT_MENU, &MainFrame::OnSave, this, wxID_SAVE);
this->Bind(wxEVT_MENU, &MainFrame::OnSaveAs, this, wxID_SAVEAS);
this->Bind(wxEVT_MENU, &MainFrame::OnCloseTab, this, wxID_CLOSE);
this->Bind(wxEVT_MENU, &TabContainer::OnCloseAllButThis, notebook, myID_CLOSE_ALL_BUT_THIS);
this->Bind(wxEVT_MENU, &TabContainer::OnCloseAll, notebook, myID_CLOSE_ALL);
this->Bind(wxEVT_MENU, &MainFrame::OnQuit, this, wxID_EXIT);
// Edit Menu Events
this->Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
@ -229,25 +227,25 @@ void MainFrame::BindEvents()
});
// View Menu Events
Bind(wxEVT_MENU, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE);
Bind(wxEVT_MENU, &MainFrame::OnToggleLineWrap, this, myID_LINE_WRAP);
Bind(wxEVT_MENU, &MainFrame::OnToggleLineEndings, this, myID_VIEW_LINE_ENDINGS);
this->Bind(wxEVT_MENU, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE);
this->Bind(wxEVT_MENU, &MainFrame::OnToggleLineWrap, this, myID_LINE_WRAP);
this->Bind(wxEVT_MENU, &MainFrame::OnToggleLineEndings, this, myID_VIEW_LINE_ENDINGS);
// Find/Replace Events
Bind(wxEVT_FIND, &MainFrame::OnFindDialog, this, wxID_ANY);
Bind(wxEVT_FIND_NEXT, &MainFrame::OnFindDialog, this, wxID_ANY);
Bind(wxEVT_FIND_REPLACE, &MainFrame::OnFindDialog, this, wxID_ANY);
Bind(wxEVT_FIND_REPLACE_ALL, &MainFrame::OnFindDialog, this, wxID_ANY);
this->Bind(wxEVT_FIND, &MainFrame::OnFindDialog, this, wxID_ANY);
this->Bind(wxEVT_FIND_NEXT, &MainFrame::OnFindDialog, this, wxID_ANY);
this->Bind(wxEVT_FIND_REPLACE, &MainFrame::OnFindDialog, this, wxID_ANY);
this->Bind(wxEVT_FIND_REPLACE_ALL, &MainFrame::OnFindDialog, this, wxID_ANY);
this->Bind(wxEVT_FIND_CLOSE, [=](wxFindDialogEvent &event) {
wxLogDebug("wxEVT_FIND_CLOSE");
event.GetDialog()->Hide();
});
// Language Selection
Bind(wxEVT_MENU, &MainFrame::OnLangSelect, this, wxID_ANY);
this->Bind(wxEVT_MENU, &MainFrame::OnLangSelect, this, wxID_ANY);
// Help Menu Events
Bind(wxEVT_MENU, &MainFrame::OnAbout, this, wxID_ABOUT);
this->Bind(wxEVT_MENU, &MainFrame::OnAbout, this, wxID_ABOUT);
}
/**
@ -423,15 +421,55 @@ void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
{
wxAboutDialogInfo info;
wxPlatformInfo plat_info;
info.SetName(APP_NAME);
info.SetVersion(APP_VERSION, APP_VERSION_MORE);
info.AddDeveloper("Tim Warren");
info.AddArtist("Brian Smith: Main icon");
info.AddArtist("http://dryicons.com: Other icons");
info.SetDescription("Tyro, a text editor for all development");
#ifndef __WXGTK__
info.AddArtist("http://dryicons.com: Other icons");
#endif
wxString desc = "Tyro, a text editor for all development\n\n"
"System info: \n";
desc += wxString::Format("Architecture: %s\n",
wxPlatformInfo::GetArchName(plat_info.GetArchitecture()));
desc += wxString::Format("Operating System:\n\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",
plat_info.GetPortIdName(),
wxMAJOR_VERSION,
wxMINOR_VERSION,
wxRELEASE_NUMBER
);
#ifdef __WXGTK__
wxLinuxDistributionInfo dist_info = wxGetLinuxDistributionInfo();
wxString desk = plat_info.GetDesktopEnvironment();
if (desk != "")
{
desc += wxString::Format("Desktop Environment:%s\n", desk);
}
desc += "Distro: ";
desc += dist_info.Description;
if (dist_info.CodeName != "")
{
desc += " (" + dist_info.CodeName + ")\n";
}
#endif
info.SetDescription(desc);
info.SetCopyright(" (C) 2015");
wxAboutBox(info);

View File

@ -9,22 +9,32 @@ public:
{
this->frame = (MainFrame *) parent;
showLineNumbers = new wxCheckBox(this, myID_PREFS_LINE_NUMBERS, "Show line numbers");
showIndentGuides = new wxCheckBox(this, myID_PREFS_IDENT_GUIDES, "Show indent guides");
showCodeFolding = new wxCheckBox(this, myID_PREFS_CODE_FOLDING, "Show code folding");
this->showLineNumbers = new wxCheckBox(this, myID_PREFS_LINE_NUMBERS, "Show line numbers");
this->showIndentGuides = new wxCheckBox(this, myID_PREFS_IDENT_GUIDES, "Show indent guides");
this->showCodeFolding = new wxCheckBox(this, myID_PREFS_CODE_FOLDING, "Show code folding");
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
// Font size will have to wait until wxWidgets 3.0.3, where font widgets
// will actually work
/*wxFontPickerCtrl *fontPicker = new wxFontPickerCtrl(this, wxID_ANY);
wxSizer *fontSizer = new wxBoxSizer(wxHORIZONTAL);
fontSizer->Add(fontPicker, wxSizerFlags().Border());
sizer->Add(fontSizer, wxSizerFlags().Border());*/
// 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());
}
sizer->Add(showLineNumbers, wxSizerFlags().Border());
sizer->Add(showIndentGuides, wxSizerFlags().Border());
sizer->Add(showCodeFolding, wxSizerFlags().Border());
sizer->Add(this->showLineNumbers, wxSizerFlags().Border());
sizer->Add(this->showIndentGuides, wxSizerFlags().Border());
sizer->Add(this->showCodeFolding, wxSizerFlags().Border());
this->SetSizerAndFit(sizer);
@ -32,20 +42,32 @@ public:
// On supported platforms
if (wxPreferencesEditor::ShouldApplyChangesImmediately())
{
showLineNumbers->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
if ( ! HAS_FONT_BUG())
{
this->fontPicker->Bind(wxEVT_FONTPICKER_CHANGED, [=] (wxFontPickerEvent &event) {
wxFont font = event.GetFont();
Glob_config->Write("global_font_family", (int)font.GetFamily());
Glob_config->Write("global_font_face_name", font.GetFaceName());
Glob_config->Write("global_font_point_size", font.GetPointSize());
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());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
}, myID_PREFS_LINE_NUMBERS);
showIndentGuides->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
this->showIndentGuides->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
Glob_config->Write("show_indent_guides", event.IsChecked());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
}, myID_PREFS_IDENT_GUIDES);
showCodeFolding->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
this->showCodeFolding->Bind(wxEVT_CHECKBOX, [=] (wxCommandEvent &event) {
Glob_config->Write("show_code_folding", event.IsChecked());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
@ -55,9 +77,6 @@ public:
~GeneralPrefPanePage()
{
delete showLineNumbers;
delete showIndentGuides;
delete showCodeFolding;
}
/**
@ -67,9 +86,25 @@ public:
*/
virtual bool TransferDataToWindow()
{
showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true));
showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false));
showCodeFolding->SetValue(Glob_config->ReadBool("show_code_folding", false));
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())
{
wxString fontFace;
int fontFamily = TYRO_DEFAULT_FONT_FAMILY;
int pointSize = TYRO_DEFAULT_FONT_SIZE;
Glob_config->Read("global_font_face_name", fontFace);
Glob_config->Read("global_font_family", fontFamily);
Glob_config->Read("global_font_point_size", pointSize);
wxFontInfo fInfo(pointSize);
fInfo.Family((wxFontFamily) fontFamily).FaceName(fontFace);
this->fontPicker->SetSelectedFont(wxFont(fInfo));
}
return true;
}
@ -82,9 +117,17 @@ public:
*/
virtual bool TransferDataFromWindow()
{
Glob_config->Write("show_line_numbers", showLineNumbers->IsChecked());
Glob_config->Write("show_indent_guides", showIndentGuides->IsChecked());
Glob_config->Write("show_code_folding", showCodeFolding->IsChecked());
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())
{
wxFont font = this->fontPicker->GetSelectedFont();
Glob_config->Write("global_font_family", (int)font.GetFamily());
Glob_config->Write("global_font_face_name", font.GetFaceName());
Glob_config->Write("global_font_point_size", font.GetPointSize());
}
wxCommandEvent evt = wxCommandEvent();
this->frame->OnPrefsChanged(evt);
@ -96,6 +139,7 @@ public:
private:
MainFrame *frame;
wxFontPickerCtrl *fontPicker = nullptr;
wxCheckBox *showLineNumbers = nullptr;
wxCheckBox *showIndentGuides = nullptr;
wxCheckBox *showCodeFolding = nullptr;

View File

@ -7,6 +7,7 @@
#include "common.h"
// Disable annoying warning
#ifndef __WXMAC__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
@ -21,9 +22,14 @@
// Common helpers/functionality
#include <wx/debug.h>
#include <wx/utils.h>
#include <wx/version.h>
#include <wx/cmdline.h>
#include <wx/config.h>
#include <wx/font.h>
#include <wx/stdpaths.h>
#include <wx/platinfo.h>
#include <wx/vidmode.h>
#include <wx/filename.h>
#include <wx/artprov.h>
@ -31,6 +37,22 @@
#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()
{
#ifndef __WXMAC__
return false;
#endif
#if wxCHECK_VERSION(3,0,3)
return false;
#endif
wxPlatformInfo info;
return (info.GetOSMajorVersion() == 10 && info.GetOSMinorVersion() > 9);
}
// Tyro-specific variables
#include "definitions.h"