From 0e64bdc1bad834a97bd70aa5853218f26c593fd1 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Mon, 1 Jun 2015 14:10:02 -0400 Subject: [PATCH] Fix windows build, use a closure for some event handlers --- .travis.yml | 1 + Makefile | 2 +- src/widgets/MainFrame.cpp | 150 ++++++++++++++------------------------ src/widgets/MainFrame.h | 10 +-- 4 files changed, 57 insertions(+), 106 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34837d8..97d8b0a 100755 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_install: # Upgrade gcc - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get -qq update + - sudo apt-get install -qq gcc-4.8 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 98 # Install dependencies diff --git a/Makefile b/Makefile index eb565fe..93c4ce8 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ endif ifeq ($(OS),Windows_NT) CXXFLAGS += -static - CXX += -std=gnu++11 -Wno-unknown-pragmas -Wno-missing-field-initializers -DWIN32 + CXX += -std=gnu++11 -Wno-unknown-pragmas -Wno-missing-field-initializers -I/include -DWIN32 LDLIBS += -L/lib -lwsock32 endif diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 5242937..79d43b9 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -15,10 +15,8 @@ static TabContainer *notebook; * Constructor */ MainFrame::MainFrame(wxFrame *frame, const wxString &title) - : wxFrame(frame, -1, title) + : wxFrame(frame, -1, title, wxDefaultPosition, wxSize(800,600)) { - this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); - // Create the tab container notebook = new TabContainer(this); @@ -148,15 +146,52 @@ void MainFrame::BindEvents() Bind(wxEVT_MENU, &MainFrame::OnQuit, this, wxID_EXIT); // Edit Menu Events - Bind(wxEVT_MENU, &MainFrame::OnEditCut, this, wxID_CUT); - Bind(wxEVT_MENU, &MainFrame::OnEditCopy, this, wxID_COPY); - Bind(wxEVT_MENU, &MainFrame::OnEditPaste, this, wxID_PASTE); - Bind(wxEVT_MENU, &MainFrame::OnEditSelectAll, this, wxID_SELECTALL); - Bind(wxEVT_MENU, &MainFrame::OnEditUndo, this, wxID_UNDO); - 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); + this->Bind(wxEVT_MENU, [=](wxCommandEvent& event) { + EditPane *editor = notebook->GetCurrentEditor(); + + switch(event.GetId()) + { + case wxID_CUT: + editor->Cut(); + break; + + case wxID_COPY: + editor->Copy(); + break; + + case wxID_PASTE: + if (editor->CanPaste()) editor->Paste(); + break; + + case wxID_SELECTALL: + editor->SelectAll(); + break; + + case wxID_UNDO: + if (editor->CanUndo()) editor->Undo(); + break; + + case wxID_REDO: + if (editor->CanRedo()) editor->Redo(); + break; + + case wxID_PREFERENCES: + Glob_pref_pane->Show(this); + break; + + case wxID_FIND: + this->OnEditFind(event); + break; + + case wxID_REPLACE: + this->OnEditReplace(event); + break; + + default: + event.Skip(true); + break; + } + }); // View Menu Events Bind(wxEVT_MENU, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE); @@ -339,76 +374,7 @@ void MainFrame::OnSaveAs(wxCommandEvent &WXUNUSED(event)) */ void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event)) { - Destroy(); -} - -/** - * Cut to the clipboard - * - * @return void - */ -void MainFrame::OnEditCut(wxCommandEvent &WXUNUSED(event)) -{ - notebook->GetCurrentEditor()->Cut(); -} - -/** - * Copy to the clipboard - * - * @return void - */ -void MainFrame::OnEditCopy(wxCommandEvent &WXUNUSED(event)) -{ - notebook->GetCurrentEditor()->Copy(); -} - -/** - * Paste from the clipboard - * - * @return void - */ -void MainFrame::OnEditPaste(wxCommandEvent &WXUNUSED(event)) -{ - if (notebook->GetCurrentEditor()->CanPaste()) - { - notebook->GetCurrentEditor()->Paste(); - } -} - -/** - * Select all the text in the current document - * - * @return void - */ -void MainFrame::OnEditSelectAll(wxCommandEvent &WXUNUSED(event)) -{ - notebook->GetCurrentEditor()->SelectAll(); -} - -/** - * Undo recent change(s) - * - * @return void - */ -void MainFrame::OnEditUndo(wxCommandEvent &WXUNUSED(event)) -{ - if (notebook->GetCurrentEditor()->CanUndo()) - { - notebook->GetCurrentEditor()->Undo(); - } -} - -/** - * Redo recent change(s) - * - * @return void - */ -void MainFrame::OnEditRedo(wxCommandEvent &WXUNUSED(event)) -{ - if (notebook->GetCurrentEditor()->CanRedo()) - { - notebook->GetCurrentEditor()->Redo(); - } + this->Destroy(); } /** @@ -462,9 +428,9 @@ void MainFrame::OnEditFind(wxCommandEvent &WXUNUSED(event)) } else { - this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); - findDlg = new wxFindReplaceDialog(this, this->findReplaceData, "Find"); - findDlg->Show(true); + this->findData = new wxFindReplaceData(wxFR_DOWN); + this->findDlg = new wxFindReplaceDialog(this, this->findData, "Find"); + this->findDlg->Show(true); } } @@ -482,10 +448,10 @@ void MainFrame::OnEditReplace(wxCommandEvent &WXUNUSED(event)) else { this->findReplaceData = new wxFindReplaceData(wxFR_DOWN); - replaceDlg = new wxFindReplaceDialog(this, this->findReplaceData, + this->replaceDlg = new wxFindReplaceDialog(this, this->findReplaceData, "Find and Replace", wxFR_REPLACEDIALOG); - replaceDlg->Show(true); + this->replaceDlg->Show(true); } } @@ -634,16 +600,6 @@ 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 * diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index 495013b..ad57c42 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -19,6 +19,7 @@ class MainFrame: public wxFrame wxAuiManager *manager; wxAuiToolBar *toolBar; wxFindReplaceData *findReplaceData; + wxFindReplaceData *findData; wxFindReplaceDialog *findDlg; wxFindReplaceDialog *replaceDlg; void SetupToolbar(); @@ -34,17 +35,10 @@ class MainFrame: public wxFrame void OnSave(wxCommandEvent &event); void OnSaveAs(wxCommandEvent &event); - void OnEditCut(wxCommandEvent &event); - void OnEditCopy(wxCommandEvent &event); - void OnEditPaste(wxCommandEvent &event); - void OnEditSelectAll(wxCommandEvent &event); - void OnEditUndo(wxCommandEvent &event); - void OnEditRedo(wxCommandEvent &event); - void OnEditPreferences(wxCommandEvent &event); - void OnEditFind(wxCommandEvent &event); void OnEditReplace(wxCommandEvent &event); void OnFindDialog(wxFindDialogEvent &event); + void OnToggleWhitespace(wxCommandEvent &event); void OnToggleLineWrap(wxCommandEvent &event); void OnToggleLineEndings(wxCommandEvent &event);