From f9509f8a13f96a1c2438e3a3cc479bb17fa22785 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Tue, 26 May 2015 15:46:55 -0400 Subject: [PATCH] Add basic preferences dialog, still needs to have functionality, see #6 --- Makefile | 5 +- src/TyroApp.cpp | 2 + src/definitions.h | 8 +++- src/widgets/MainFrame.cpp | 47 ++++++++++--------- src/widgets/MainFrame.h | 1 + src/widgets/PrefPane.cpp | 96 +++++++++++++++++++++++++++++++++++++++ src/widgets/PrefPane.h | 21 +++++++++ src/widgets/TyroMenu.cpp | 14 ++++-- src/widgets/widget.h | 2 + 9 files changed, 165 insertions(+), 31 deletions(-) create mode 100644 src/widgets/PrefPane.cpp create mode 100644 src/widgets/PrefPane.h diff --git a/Makefile b/Makefile index 26fcb67..31adf05 100644 --- a/Makefile +++ b/Makefile @@ -22,16 +22,17 @@ OS ?= $(shell uname -s) # Get static version of libs to link to on platforms that support it ifneq ($(OS),Linux) - WX_LDLIBS = $(shell wx-config --static --libs base core aui stc adv) + WX_LDLIBS = $(shell wx-config --static --libs base core aui stc adv) else WX_LDLIBS = $(shell wx-config --libs base core aui stc adv) endif # Platform compiler flags ifeq ($(OS),Darwin) - CXX = $(shell wx-config --cxx) + CXX = $(shell wx-config --cxx) -no-cpp-precomp -Xpreprocessor -Wno-missing-field-initializers LDLIBS += /usr/local/lib/libssh2.a else + CXX += -Wno-missing-field-initializers LDLIBS += -lssh2 endif diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 6fedf28..e9e531d 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -13,6 +13,7 @@ wxConfigBase *Glob_config; TyroMenu *Glob_menu_bar; MainFrame *Glob_main_frame; StringConstMap Glob_lexer_map; +PrefPane *Glob_pref_pane; // Static app loading variables static wxArrayString files; @@ -41,6 +42,7 @@ public: Glob_config = wxConfigBase::Get(); Glob_menu_bar = new TyroMenu(); Glob_main_frame = new MainFrame(0L, APP_NAME); + Glob_pref_pane = new PrefPane(); // Setup Main Window Glob_main_frame->Layout(); diff --git a/src/definitions.h b/src/definitions.h index f51bf63..a983f9e 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -45,11 +45,17 @@ enum myMenuIds { // General Menu ids enum myMenuItemIds { + // Menu options for immediate file myID_VIEW_WHITESPACE = wxID_HIGHEST + 1, myID_VIEW_LINE_ENDINGS, myID_CLOSE_ALL, myID_CLOSE_ALL_BUT_THIS, - myID_LINE_WRAP + myID_LINE_WRAP, + + // Preferences, to apply to all files + myID_PREFS_LINE_NUMBERS, + myID_PREFS_CODE_FOLDING, + myID_PREFS_IDENT_GUIDES }; const wxString TYRO_FILE_OPEN_WILDCARDS = diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 1429905..0d71b95 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -5,6 +5,7 @@ // Nasty globals extern TyroMenu *Glob_menu_bar; +extern PrefPane *Glob_pref_pane; static TabContainer *notebook; // Frame icon @@ -16,7 +17,7 @@ static TabContainer *notebook; MainFrame::MainFrame(wxFrame *frame, const wxString &title) : wxFrame(frame, -1, title) { - findReplaceData = new wxFindReplaceData(wxFR_DOWN); + this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); // Create the tab container notebook = new TabContainer(this); @@ -41,7 +42,7 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title) MainFrame::~MainFrame() { wxLogDebug("Main Frame Destructor Called."); - //delete notebook; + delete notebook; delete toolBar; manager->UnInit(); } @@ -156,6 +157,7 @@ void MainFrame::BindEvents() Bind(wxEVT_MENU, &MainFrame::OnEditRedo, this, wxID_REDO); Bind(wxEVT_MENU, &MainFrame::OnEditFind, this, wxID_FIND); Bind(wxEVT_MENU, &MainFrame::OnEditReplace, this, wxID_REPLACE); + Bind(wxEVT_MENU, &MainFrame::OnEditPreferences, this, wxID_PREFERENCES); // View Menu Events Bind(wxEVT_MENU, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE); @@ -461,7 +463,8 @@ void MainFrame::OnEditFind(wxCommandEvent &WXUNUSED(event)) } else { - findDlg = new wxFindReplaceDialog(this, findReplaceData, "Find"); + this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); + findDlg = new wxFindReplaceDialog(this, this->findReplaceData, "Find"); findDlg->Show(true); } } @@ -479,7 +482,8 @@ void MainFrame::OnEditReplace(wxCommandEvent &WXUNUSED(event)) } else { - replaceDlg = new wxFindReplaceDialog(this, findReplaceData, + this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); + replaceDlg = new wxFindReplaceDialog(this, this->findReplaceData, "Find and Replace", wxFR_REPLACEDIALOG); replaceDlg->Show(true); @@ -515,27 +519,12 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) { wxLogDebug("wxEVT_FIND"); + editor->SetAnchor(0); editor->SearchAnchor(); - - if ((fr_flags & wxFR_DOWN) != 0) - { - new_pos = editor->SearchNext(stc_flags, event.GetFindString()); - } - else - { - new_pos = editor->SearchPrev(stc_flags, event.GetFindString()); - } - - if (new_pos >= 0) - { - new_line = editor->LineFromPosition(new_pos); - editor->ScrollToLine(new_line); - } } - else if (type == wxEVT_FIND_NEXT) - { - wxLogDebug("wxEVT_FIND_NEXT"); - + + if (type == wxEVT_FIND_NEXT || type == wxEVT_FIND) + { if ((fr_flags & wxFR_DOWN) != 0) { new_pos = editor->SearchNext(stc_flags, event.GetFindString()); @@ -545,15 +534,20 @@ void MainFrame::OnFindDialog(wxFindDialogEvent &event) new_pos = editor->SearchPrev(stc_flags, event.GetFindString()); } - if (new_pos >= 0) + if (new_pos > 0) { new_line = editor->LineFromPosition(new_pos); editor->ScrollToLine(new_line); + //editor->SetAnchor(new_pos); + editor->SearchAnchor(); } + + return; } else if (type == wxEVT_FIND_REPLACE) { wxLogDebug("wxEVT_FIND_REPLACE"); + editor->ReplaceSelection(event.GetReplaceString()); } else if (type == wxEVT_FIND_REPLACE_ALL) { @@ -640,3 +634,8 @@ void MainFrame::OnLangSelect(wxCommandEvent &event) event.Skip(true); } } + +void MainFrame::OnEditPreferences(wxCommandEvent &WXUNUSED(event)) +{ + Glob_pref_pane->Show(this); +} diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index 1dc00e0..0d160a9 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -39,6 +39,7 @@ class MainFrame: public wxFrame void OnEditSelectAll(wxCommandEvent &event); void OnEditUndo(wxCommandEvent &event); void OnEditRedo(wxCommandEvent &event); + void OnEditPreferences(wxCommandEvent &event); void OnEditFind(wxCommandEvent &event); void OnEditReplace(wxCommandEvent &event); diff --git a/src/widgets/PrefPane.cpp b/src/widgets/PrefPane.cpp new file mode 100644 index 0000000..59a5530 --- /dev/null +++ b/src/widgets/PrefPane.cpp @@ -0,0 +1,96 @@ +#include "widget.h" + +class GeneralPrefPanePage : public wxPanel { +public: + GeneralPrefPanePage(wxWindow *parent) + : wxPanel(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"); + + wxSizer *sizer = new wxBoxSizer(wxVERTICAL); + + sizer->Add(showLineNumbers, wxSizerFlags().Border()); + sizer->Add(showIndentGuides, wxSizerFlags().Border()); + sizer->Add(showCodeFolding, wxSizerFlags().Border()); + + this->SetSizerAndFit(sizer); + + // Change settings on selection, rather than on apply button + // On supported platforms + if (wxPreferencesEditor::ShouldApplyChangesImmediately()) + { + // @TODO add event handlers + } + } + + /** + * Apply current settings to the pref window + * + * @return bool + */ + virtual bool TransferDataToWindow() + { + showLineNumbers->SetValue(true); + return true; + } + + /** + * Called on platforms with modal preferences dialog to save + * and apply the changes + * + * @return bool + */ + virtual bool TransferDataFromWindow() + { + return true; + } + + ~GeneralPrefPanePage() + { + + } +private: + wxCheckBox *showLineNumbers; + wxCheckBox *showIndentGuides; + wxCheckBox *showCodeFolding; +}; + +class GeneralPrefPane: public wxStockPreferencesPage { +public: + GeneralPrefPane() : wxStockPreferencesPage(Kind_General) {} + virtual wxWindow *CreateWindow(wxWindow *parent) + { + return new GeneralPrefPanePage(parent); + } +}; + +// ----------------------------------------------------------------------------- +// ! Implementation of PrefPane Class +// ----------------------------------------------------------------------------- + +PrefPane::PrefPane() +{ + this->pref_window = new wxPreferencesEditor(); + this->setupGeneral(); +} + +PrefPane::~PrefPane() +{ + delete this->pref_window; +} + +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()); +} + + + diff --git a/src/widgets/PrefPane.h b/src/widgets/PrefPane.h new file mode 100644 index 0000000..2ef460c --- /dev/null +++ b/src/widgets/PrefPane.h @@ -0,0 +1,21 @@ +/** + * Preference Panes + */ + +#ifndef TYRO_PREF_PANE_H +#define TYRO_PREF_PANE_H + +class PrefPane { +public: + PrefPane(); + ~PrefPane(); + void Show(wxWindow *parent); + +protected: + wxPreferencesEditor *pref_window; +private: + void setupGeneral(); +}; + +#endif /* TYRO_PREF_PANE_H */ + diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index 5e7b75f..615f161 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -61,11 +61,11 @@ void TyroMenu::SetupMainMenus() editMenu->Append(wxID_COPY, "&Copy\tCtrl+C", "Copy selected text"); editMenu->Append(wxID_PASTE, "&Paste\tCtrl+V", "Paste contents of clipboard"); //editMenu->Append(wxID_DELETE, "&Delete\tDel"); - editMenu->AppendSeparator(); + //editMenu->AppendSeparator(); //editMenu->Append(wxID_FIND, "&Find\tCtrl+F"); //editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R"); - //editMenu->AppendSeparator(); - //editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P"); + editMenu->AppendSeparator(); + editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P"); //editMenu->AppendSeparator(); editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document"); @@ -107,8 +107,14 @@ void TyroMenu::EnableEditControls(bool enable) this->fileMenu->Enable(wxID_CLOSE, enable); this->fileMenu->Enable(myID_CLOSE_ALL, enable); + this->editMenu->Enable(wxID_UNDO, enable); + this->editMenu->Enable(wxID_REDO, enable); + this->editMenu->Enable(wxID_CUT, enable); + this->editMenu->Enable(wxID_COPY, enable); + this->editMenu->Enable(wxID_PASTE, enable); + this->editMenu->Enable(wxID_SELECTALL, enable); + // Enable/disable top level menus - this->EnableEntireMenu(myEDIT_MENU, this->editMenu, enable); this->EnableEntireMenu(myVIEW_MENU, this->viewMenu, enable); this->EnableEntireMenu(myLANG_MENU, this->langMenu, enable); } diff --git a/src/widgets/widget.h b/src/widgets/widget.h index 44b135c..35334e6 100644 --- a/src/widgets/widget.h +++ b/src/widgets/widget.h @@ -12,12 +12,14 @@ #include #include #include +#include // Tyro includes #include "TyroMenu.h" #include "EditPane.h" #include "TabContainer.h" #include "MainFrame.h" +#include "PrefPane.h" #endif /* TYRO_WIDGET_H */