Add basic preferences dialog, still needs to have functionality, see #6

This commit is contained in:
Tim Warren 2015-05-26 15:46:55 -04:00
parent 0f09ced684
commit f9509f8a13
9 changed files with 165 additions and 31 deletions

View File

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

View File

@ -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();

View File

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

View File

@ -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);
}

View File

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

96
src/widgets/PrefPane.cpp Normal file
View File

@ -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());
}

21
src/widgets/PrefPane.h Normal file
View File

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

View File

@ -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);
}

View File

@ -12,12 +12,14 @@
#include <wx/fdrepdlg.h>
#include <wx/aui/aui.h>
#include <wx/stc/stc.h>
#include <wx/preferences.h>
// Tyro includes
#include "TyroMenu.h"
#include "EditPane.h"
#include "TabContainer.h"
#include "MainFrame.h"
#include "PrefPane.h"
#endif /* TYRO_WIDGET_H */