Preferences window for some basic settings, closes #6

This commit is contained in:
Tim Warren 2015-05-27 11:37:02 -04:00
parent f9509f8a13
commit ed9593312c
9 changed files with 175 additions and 73 deletions

View File

@ -27,12 +27,15 @@ else
WX_LDLIBS = $(shell wx-config --libs base core aui stc adv) WX_LDLIBS = $(shell wx-config --libs base core aui stc adv)
endif endif
ifeq ($(CXX),clang++)
CXX += -std=c++11
endif
# Platform compiler flags # Platform compiler flags
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)
CXX = $(shell wx-config --cxx) -no-cpp-precomp -Xpreprocessor -Wno-missing-field-initializers CXX = $(shell wx-config --cxx) -D__WXMAC__
LDLIBS += /usr/local/lib/libssh2.a LDLIBS += /usr/local/lib/libssh2.a
else else
CXX += -Wno-missing-field-initializers
LDLIBS += -lssh2 LDLIBS += -lssh2
endif endif
@ -42,11 +45,7 @@ ifeq ($(OS),Windows_NT)
LDLIBS += -L/lib -lwsock32 LDLIBS += -L/lib -lwsock32
endif endif
ifeq ($(CXX),clang++) CXX += -Wno-unknown-pragmas -Wno-unknown-warning-option -Wno-potentially-evaluated-expression -Wno-missing-field-initializers -Iinclude -I. -I/usr/local/include
CXX += -std=c++11
endif
CXX += -Iinclude -I. -I/usr/local/include
ifdef $(DEV) ifdef $(DEV)
all: CXXFLAGS = $(DEV_CXXFLAGS) all: CXXFLAGS = $(DEV_CXXFLAGS)

View File

@ -12,6 +12,10 @@ const wxString APP_VERSION = "0.5.0";
const wxString APP_VERSION_MORE = "Pre-release"; const wxString APP_VERSION_MORE = "Pre-release";
// Command-line arguments // Command-line arguments
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#endif
const wxCmdLineEntryDesc Glob_cmdLineDesc[] = { const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
{ {
wxCMD_LINE_PARAM, wxCMD_LINE_PARAM,
@ -23,6 +27,9 @@ const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
}, },
{wxCMD_LINE_NONE} {wxCMD_LINE_NONE}
}; };
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// Some boilerplate text // Some boilerplate text
const wxString TYRO_SAVE_ERROR = "Failed to save the file. Maybe you lack the permissions."; const wxString TYRO_SAVE_ERROR = "Failed to save the file. Maybe you lack the permissions.";
@ -34,6 +41,13 @@ const wxString TYRO_OPEN_ERROR_CAPTION = "Open Failed";
typedef map<string, int> StringConstMap; typedef map<string, int> StringConstMap;
typedef map<string, string> StringMap; typedef map<string, string> StringMap;
// Editor margins
enum myMargins
{
MARGIN_FOLD,
MARGIN_LINE_NUMBERS
};
// Top level menus // Top level menus
enum myMenuIds { enum myMenuIds {
myFILE_MENU, myFILE_MENU,

View File

@ -5,6 +5,7 @@
#include "widget.h" #include "widget.h"
extern StringConstMap Glob_lexer_map; extern StringConstMap Glob_lexer_map;
extern wxConfig *Glob_config;
/** /**
* Constructor * Constructor
@ -31,25 +32,7 @@ EditPane::EditPane(
this->SetProperty("styling.within.preprocessor", "1"); this->SetProperty("styling.within.preprocessor", "1");
this->SetProperty("lexer.cpp.track.preprocessor", "1"); this->SetProperty("lexer.cpp.track.preprocessor", "1");
this->SetProperty("font.quality", "3"); // LCD Optimized this->SetProperty("font.quality", "3"); // LCD Optimized
// Set up Code folding
this->SetProperty("fold", "1");
this->SetProperty("fold.comment", "1");
this->SetProperty("fold.compact", "1");
this->SetProperty("fold.html", "1");
this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL);
this->SetMarginWidth(MARGIN_FOLD, 16);
this->SetMarginSensitive(MARGIN_FOLD, true);
this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS);
this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
//this->SetLayoutCache (wxSTC_CACHE_DOCUMENT); //this->SetLayoutCache (wxSTC_CACHE_DOCUMENT);
// set spaces and indention // set spaces and indention
@ -148,6 +131,18 @@ void EditPane::ApplyTheme(string lang, string theme)
this->_ApplyTheme(lexer_map); this->_ApplyTheme(lexer_map);
} }
/**
* Re-style the control based on changed preferences
*
* @param string [theme]
* @return void
*/
void EditPane::ReApplyTheme(string theme)
{
wxLogDebug("Current lang: %s", lang_config->GetLangByName(this->GetCurrentLang()));
this->ApplyTheme(lang_config->GetLangByName(this->GetCurrentLang()), theme);
}
/** /**
* Check file path and open the selected file * Check file path and open the selected file
* *
@ -178,26 +173,7 @@ bool EditPane::Load(wxString filePath)
*/ */
bool EditPane::SaveFile() bool EditPane::SaveFile()
{ {
wxString fname; wxString fname = this->fileName.GetFullPath();
/*if ( ! this->fileName.IsOk())
{
wxFileDialog dlg (
this,
_T("Save file"),
wxEmptyString,
wxEmptyString,
TYRO_FILE_SAVE_WILDCARDS,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
if (dlg.ShowModal() != wxID_OK) return false;
fname = dlg.GetPath();
}
else*/
{
fname = this->fileName.GetFullPath();
}
const wxString cfname(fname); const wxString cfname(fname);
@ -371,14 +347,62 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
this->StyleSetForeground(i, default_foreground); this->StyleSetForeground(i, default_foreground);
this->StyleSetFont(i, *defaultFont); this->StyleSetFont(i, *defaultFont);
} }
// Set up Code folding
if (Glob_config->ReadBool("show_code_folding", false))
{
this->SetProperty("fold", "1");
this->SetProperty("fold.comment", "1");
this->SetProperty("fold.compact", "1");
this->SetProperty("fold.html", "1");
this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL);
this->SetMarginWidth(MARGIN_FOLD, 16);
this->SetMarginSensitive(MARGIN_FOLD, true);
this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS);
this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
}
else
{
this->SetProperty("fold", "0");
this->SetProperty("fold.comment", "0");
this->SetProperty("fold.compact", "0");
this->SetProperty("fold.html", "0");
this->SetMarginWidth(MARGIN_FOLD, 0);
}
// Setup indent guides
if (Glob_config->ReadBool("show_indent_guides", false))
{
this->StyleSetForeground(wxSTC_STYLE_DEFAULT, default_foreground);
this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, default_foreground);
this->SetIndentationGuides(1);
}
else
{
this->SetIndentationGuides(0);
}
this->StyleSetForeground (wxSTC_STYLE_DEFAULT, default_foreground); // Setup line numbers
this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColor(147, 161, 161)); if (Glob_config->ReadBool("show_line_numbers", true))
{
this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999")); this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999"));
this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground); this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground);
this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background); this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background);
this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER); this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
}
else
{
this->SetMarginWidth (MARGIN_LINE_NUMBERS, 0);
}
int max = lexer_map.size(); int max = lexer_map.size();

View File

@ -19,6 +19,7 @@ public:
void Highlight(wxString filePath); void Highlight(wxString filePath);
bool SaveFile(); bool SaveFile();
bool SaveFile(const wxString &filename); bool SaveFile(const wxString &filename);
void ReApplyTheme(string theme="");
void ApplyTheme(string lang, string theme=""); void ApplyTheme(string lang, string theme="");
string GetCurrentLang(); string GetCurrentLang();
void SetCurrentLang(string name); void SetCurrentLang(string name);
@ -26,11 +27,6 @@ private:
StringConstMap::iterator lexerMapIt; StringConstMap::iterator lexerMapIt;
LangConfig *lang_config; LangConfig *lang_config;
ThemeConfig *theme_config; ThemeConfig *theme_config;
enum myMargins
{
MARGIN_FOLD,
MARGIN_LINE_NUMBERS
};
bool FileReadable(); bool FileReadable();
bool FileWritable(); bool FileWritable();
void BindEvents(); void BindEvents();

View File

@ -23,7 +23,6 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
notebook = new TabContainer(this); notebook = new TabContainer(this);
// Set the frame icon // Set the frame icon
wxIcon app_icon(tyro_icon); wxIcon app_icon(tyro_icon);
this->SetIcon(app_icon); this->SetIcon(app_icon);
@ -635,7 +634,30 @@ void MainFrame::OnLangSelect(wxCommandEvent &event)
} }
} }
/**
* Show the preferences dialog
*
* @return void
*/
void MainFrame::OnEditPreferences(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnEditPreferences(wxCommandEvent &WXUNUSED(event))
{ {
Glob_pref_pane->Show(this); Glob_pref_pane->Show(this);
} }
/**
* Applies settings when prefs are changed
*
* @return void
*/
void MainFrame::OnPrefsChanged(wxCommandEvent &WXUNUSED(event))
{
wxLogDebug("In OnPrefsChanged method");
EditPane *editor;
for(size_t i = 0; i < notebook->GetPageCount(); i++)
{
editor = notebook->GetEditor(i);
editor->ReApplyTheme();
}
}

View File

@ -14,6 +14,7 @@ class MainFrame: public wxFrame
~MainFrame(); ~MainFrame();
void EnableEditControls(bool enable=true); void EnableEditControls(bool enable=true);
void OpenFiles(wxArrayString filelist); void OpenFiles(wxArrayString filelist);
void OnPrefsChanged(wxCommandEvent &event);
private: private:
wxAuiManager *manager; wxAuiManager *manager;
wxAuiToolBar *toolBar; wxAuiToolBar *toolBar;

View File

@ -1,10 +1,14 @@
#include "widget.h" #include "widget.h"
extern wxConfigBase *Glob_config;
class GeneralPrefPanePage : public wxPanel { class GeneralPrefPanePage : public wxPanel {
public: public:
GeneralPrefPanePage(wxWindow *parent) GeneralPrefPanePage(wxWindow *parent)
: wxPanel(parent) : wxPanel(parent)
{ {
this->frame = (MainFrame *) parent;
showLineNumbers = new wxCheckBox(this, myID_PREFS_LINE_NUMBERS, "Show line numbers"); showLineNumbers = new wxCheckBox(this, myID_PREFS_LINE_NUMBERS, "Show line numbers");
showIndentGuides = new wxCheckBox(this, myID_PREFS_IDENT_GUIDES, "Show indent guides"); showIndentGuides = new wxCheckBox(this, myID_PREFS_IDENT_GUIDES, "Show indent guides");
showCodeFolding = new wxCheckBox(this, myID_PREFS_CODE_FOLDING, "Show code folding"); showCodeFolding = new wxCheckBox(this, myID_PREFS_CODE_FOLDING, "Show code folding");
@ -21,10 +25,19 @@ public:
// On supported platforms // On supported platforms
if (wxPreferencesEditor::ShouldApplyChangesImmediately()) if (wxPreferencesEditor::ShouldApplyChangesImmediately())
{ {
// @TODO add event handlers showLineNumbers->Bind(wxEVT_CHECKBOX, &GeneralPrefPanePage::ToggleShowLineNumbers, this, myID_PREFS_LINE_NUMBERS);
showIndentGuides->Bind(wxEVT_CHECKBOX, &GeneralPrefPanePage::ToggleShowIndentGuides, this, myID_PREFS_IDENT_GUIDES);
showCodeFolding->Bind(wxEVT_CHECKBOX, &GeneralPrefPanePage::ToggleShowCodeFolding, this, myID_PREFS_CODE_FOLDING);
} }
} }
~GeneralPrefPanePage()
{
delete showLineNumbers;
delete showIndentGuides;
delete showCodeFolding;
}
/** /**
* Apply current settings to the pref window * Apply current settings to the pref window
* *
@ -32,7 +45,10 @@ public:
*/ */
virtual bool TransferDataToWindow() virtual bool TransferDataToWindow()
{ {
showLineNumbers->SetValue(true); 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));
return true; return true;
} }
@ -44,17 +60,45 @@ public:
*/ */
virtual bool TransferDataFromWindow() 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());
wxCommandEvent evt = wxCommandEvent();
this->frame->OnPrefsChanged(evt);
Glob_config->Flush();
return true; return true;
} }
~GeneralPrefPanePage()
{
}
private: private:
MainFrame *frame;
wxCheckBox *showLineNumbers; wxCheckBox *showLineNumbers;
wxCheckBox *showIndentGuides; wxCheckBox *showIndentGuides;
wxCheckBox *showCodeFolding; wxCheckBox *showCodeFolding;
void ToggleShowLineNumbers(wxCommandEvent &event)
{
Glob_config->Write("show_line_numbers", event.IsChecked());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
}
void ToggleShowIndentGuides(wxCommandEvent &event)
{
Glob_config->Write("show_indent_guides", event.IsChecked());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
}
void ToggleShowCodeFolding(wxCommandEvent &event)
{
Glob_config->Write("show_code_folding", event.IsChecked());
this->frame->OnPrefsChanged(event);
Glob_config->Flush();
}
}; };
class GeneralPrefPane: public wxStockPreferencesPage { class GeneralPrefPane: public wxStockPreferencesPage {
@ -73,7 +117,7 @@ public:
PrefPane::PrefPane() PrefPane::PrefPane()
{ {
this->pref_window = new wxPreferencesEditor(); this->pref_window = new wxPreferencesEditor();
this->setupGeneral(); this->pref_window->AddPage(new GeneralPrefPane());
} }
PrefPane::~PrefPane() PrefPane::~PrefPane()
@ -86,11 +130,6 @@ void PrefPane::Show(wxWindow *parent)
this->pref_window->Show(parent); this->pref_window->Show(parent);
} }
void PrefPane::setupGeneral()
{
//this->pref_window.reset(new wxPreferencesEditor);
this->pref_window->AddPage(new GeneralPrefPane());
}

View File

@ -13,8 +13,6 @@ public:
protected: protected:
wxPreferencesEditor *pref_window; wxPreferencesEditor *pref_window;
private:
void setupGeneral();
}; };
#endif /* TYRO_PREF_PANE_H */ #endif /* TYRO_PREF_PANE_H */

View File

@ -7,6 +7,11 @@
#include "common.h" #include "common.h"
#ifndef __WXMAC__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
#endif
#ifdef WX_PRECOMP #ifdef WX_PRECOMP
#include "wx_pch.h" #include "wx_pch.h"
#endif #endif
@ -22,6 +27,10 @@
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/artprov.h> #include <wx/artprov.h>
#ifndef __WXMAC__
#pragma clang diagnostic pop
#endif
// Tyro-specific variables // Tyro-specific variables
#include "definitions.h" #include "definitions.h"