Preferences window for some basic settings, closes #6
This commit is contained in:
parent
f9509f8a13
commit
ed9593312c
13
Makefile
13
Makefile
@ -27,12 +27,15 @@ else
|
||||
WX_LDLIBS = $(shell wx-config --libs base core aui stc adv)
|
||||
endif
|
||||
|
||||
ifeq ($(CXX),clang++)
|
||||
CXX += -std=c++11
|
||||
endif
|
||||
|
||||
# Platform compiler flags
|
||||
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
|
||||
else
|
||||
CXX += -Wno-missing-field-initializers
|
||||
LDLIBS += -lssh2
|
||||
endif
|
||||
|
||||
@ -42,11 +45,7 @@ ifeq ($(OS),Windows_NT)
|
||||
LDLIBS += -L/lib -lwsock32
|
||||
endif
|
||||
|
||||
ifeq ($(CXX),clang++)
|
||||
CXX += -std=c++11
|
||||
endif
|
||||
|
||||
CXX += -Iinclude -I. -I/usr/local/include
|
||||
CXX += -Wno-unknown-pragmas -Wno-unknown-warning-option -Wno-potentially-evaluated-expression -Wno-missing-field-initializers -Iinclude -I. -I/usr/local/include
|
||||
|
||||
ifdef $(DEV)
|
||||
all: CXXFLAGS = $(DEV_CXXFLAGS)
|
||||
|
@ -12,6 +12,10 @@ const wxString APP_VERSION = "0.5.0";
|
||||
const wxString APP_VERSION_MORE = "Pre-release";
|
||||
|
||||
// Command-line arguments
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
|
||||
{
|
||||
wxCMD_LINE_PARAM,
|
||||
@ -23,6 +27,9 @@ const wxCmdLineEntryDesc Glob_cmdLineDesc[] = {
|
||||
},
|
||||
{wxCMD_LINE_NONE}
|
||||
};
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
// Some boilerplate text
|
||||
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, string> StringMap;
|
||||
|
||||
// Editor margins
|
||||
enum myMargins
|
||||
{
|
||||
MARGIN_FOLD,
|
||||
MARGIN_LINE_NUMBERS
|
||||
};
|
||||
|
||||
// Top level menus
|
||||
enum myMenuIds {
|
||||
myFILE_MENU,
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "widget.h"
|
||||
|
||||
extern StringConstMap Glob_lexer_map;
|
||||
extern wxConfig *Glob_config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -31,25 +32,7 @@ EditPane::EditPane(
|
||||
this->SetProperty("styling.within.preprocessor", "1");
|
||||
this->SetProperty("lexer.cpp.track.preprocessor", "1");
|
||||
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);
|
||||
|
||||
// set spaces and indention
|
||||
@ -148,6 +131,18 @@ void EditPane::ApplyTheme(string lang, string theme)
|
||||
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
|
||||
*
|
||||
@ -178,26 +173,7 @@ bool EditPane::Load(wxString filePath)
|
||||
*/
|
||||
bool EditPane::SaveFile()
|
||||
{
|
||||
wxString fname;
|
||||
|
||||
/*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();
|
||||
}
|
||||
wxString fname = this->fileName.GetFullPath();
|
||||
|
||||
const wxString cfname(fname);
|
||||
|
||||
@ -371,14 +347,62 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
|
||||
this->StyleSetForeground(i, default_foreground);
|
||||
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);
|
||||
this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColor(147, 161, 161));
|
||||
|
||||
this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999"));
|
||||
this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground);
|
||||
this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background);
|
||||
this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
|
||||
// Setup line numbers
|
||||
if (Glob_config->ReadBool("show_line_numbers", true))
|
||||
{
|
||||
this->SetMarginWidth (MARGIN_LINE_NUMBERS, TextWidth(wxSTC_STYLE_LINENUMBER, "_999"));
|
||||
this->StyleSetForeground (wxSTC_STYLE_LINENUMBER, line_number_foreground);
|
||||
this->StyleSetBackground (wxSTC_STYLE_LINENUMBER, line_number_background);
|
||||
this->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->SetMarginWidth (MARGIN_LINE_NUMBERS, 0);
|
||||
}
|
||||
|
||||
int max = lexer_map.size();
|
||||
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
void Highlight(wxString filePath);
|
||||
bool SaveFile();
|
||||
bool SaveFile(const wxString &filename);
|
||||
void ReApplyTheme(string theme="");
|
||||
void ApplyTheme(string lang, string theme="");
|
||||
string GetCurrentLang();
|
||||
void SetCurrentLang(string name);
|
||||
@ -26,11 +27,6 @@ private:
|
||||
StringConstMap::iterator lexerMapIt;
|
||||
LangConfig *lang_config;
|
||||
ThemeConfig *theme_config;
|
||||
enum myMargins
|
||||
{
|
||||
MARGIN_FOLD,
|
||||
MARGIN_LINE_NUMBERS
|
||||
};
|
||||
bool FileReadable();
|
||||
bool FileWritable();
|
||||
void BindEvents();
|
||||
|
@ -23,7 +23,6 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
|
||||
notebook = new TabContainer(this);
|
||||
|
||||
// Set the frame icon
|
||||
|
||||
wxIcon app_icon(tyro_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))
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ class MainFrame: public wxFrame
|
||||
~MainFrame();
|
||||
void EnableEditControls(bool enable=true);
|
||||
void OpenFiles(wxArrayString filelist);
|
||||
void OnPrefsChanged(wxCommandEvent &event);
|
||||
private:
|
||||
wxAuiManager *manager;
|
||||
wxAuiToolBar *toolBar;
|
||||
|
@ -1,10 +1,14 @@
|
||||
#include "widget.h"
|
||||
|
||||
extern wxConfigBase *Glob_config;
|
||||
|
||||
class GeneralPrefPanePage : public wxPanel {
|
||||
public:
|
||||
GeneralPrefPanePage(wxWindow *parent)
|
||||
: wxPanel(parent)
|
||||
{
|
||||
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");
|
||||
@ -21,10 +25,19 @@ public:
|
||||
// On supported platforms
|
||||
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
|
||||
*
|
||||
@ -32,7 +45,10 @@ public:
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@ -44,17 +60,45 @@ 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());
|
||||
|
||||
wxCommandEvent evt = wxCommandEvent();
|
||||
this->frame->OnPrefsChanged(evt);
|
||||
|
||||
Glob_config->Flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
~GeneralPrefPanePage()
|
||||
{
|
||||
|
||||
}
|
||||
private:
|
||||
MainFrame *frame;
|
||||
wxCheckBox *showLineNumbers;
|
||||
wxCheckBox *showIndentGuides;
|
||||
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 {
|
||||
@ -73,7 +117,7 @@ public:
|
||||
PrefPane::PrefPane()
|
||||
{
|
||||
this->pref_window = new wxPreferencesEditor();
|
||||
this->setupGeneral();
|
||||
this->pref_window->AddPage(new GeneralPrefPane());
|
||||
}
|
||||
|
||||
PrefPane::~PrefPane()
|
||||
@ -86,11 +130,6 @@ void PrefPane::Show(wxWindow *parent)
|
||||
this->pref_window->Show(parent);
|
||||
}
|
||||
|
||||
void PrefPane::setupGeneral()
|
||||
{
|
||||
//this->pref_window.reset(new wxPreferencesEditor);
|
||||
this->pref_window->AddPage(new GeneralPrefPane());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -13,8 +13,6 @@ public:
|
||||
|
||||
protected:
|
||||
wxPreferencesEditor *pref_window;
|
||||
private:
|
||||
void setupGeneral();
|
||||
};
|
||||
|
||||
#endif /* TYRO_PREF_PANE_H */
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifndef __WXMAC__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
|
||||
#endif
|
||||
|
||||
#ifdef WX_PRECOMP
|
||||
#include "wx_pch.h"
|
||||
#endif
|
||||
@ -22,6 +27,10 @@
|
||||
#include <wx/filename.h>
|
||||
#include <wx/artprov.h>
|
||||
|
||||
#ifndef __WXMAC__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
// Tyro-specific variables
|
||||
#include "definitions.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user