From f0dbed16415c61e602352d2a273d980949179e15 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Thu, 9 Apr 2015 17:16:28 -0400 Subject: [PATCH] Start on lexers for syntax highlighting --- Makefile | 9 +++--- config/scintilla.json | 5 +++ src/common.h | 1 + src/definitions.h | 51 +++++++++++++++++++++++++++++++ src/widgets/EditPane.h | 3 +- src/widgets/EditPaneDefinitions.h | 19 ++++++++++++ src/widgets/MainFrame.cpp | 48 +++++++++++++++++++++++++---- src/widgets/MainFrame.h | 7 +++++ src/widgets/TabContainer.cpp | 4 ++- src/wx_common.h | 2 ++ 10 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 config/scintilla.json create mode 100644 src/definitions.h create mode 100644 src/widgets/EditPaneDefinitions.h diff --git a/Makefile b/Makefile index 1192ee1..e9b31b6 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,12 @@ PROGRAM_SRC = $(wildcard src/*.cpp src/widgets/*.cpp) PROGRAM = build/Tyro PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC)) -LDLIBS = -ldl $(TARGET) $(shell wx-config --libs base core aui stc) -lssh2 -WX_CXXFLAGS = $(shell wx-config --cxxflags) -DEV_CXXFLAGS = -g -Wall -Wextra -CXXFLAGS = -Os -I./src -I./include +BASE_FLAGS = -DSCI_LEXER -std=gnu++11 +LDLIBS = $(TARGET) $(shell wx-config --libs base core aui stc) -lssh2 +WX_CXXFLAGS = $(shell wx-config --cxxflags) $(BASE_FLAGS) +DEV_CXXFLAGS = -g -Wall -Wextra +CXXFLAGS = -Os TEST_SRC= $(wildcard tests/*.cpp) TESTS = $(patsubst %.cpp,%,$(TEST_SRC)) diff --git a/config/scintilla.json b/config/scintilla.json new file mode 100644 index 0000000..dee2d0c --- /dev/null +++ b/config/scintilla.json @@ -0,0 +1,5 @@ +{ + "default_style": { + + } +} diff --git a/src/common.h b/src/common.h index 8a9f2bf..6db2aee 100644 --- a/src/common.h +++ b/src/common.h @@ -8,6 +8,7 @@ #include #include #include +#include using namespace std; diff --git a/src/definitions.h b/src/definitions.h new file mode 100644 index 0000000..c0beff0 --- /dev/null +++ b/src/definitions.h @@ -0,0 +1,51 @@ +/** + * Miscellaneous Program-specific definitions + */ + +#ifndef DEFINITIONS_H +#define DEFINITIONS_H + +const wxString TYRO_FILE_OPEN_WILDCARDS = + _T("Bash (*.sh, *.bsh) |*.sh;*.bsh|") + _T("Batch (*.bat, *.cmd, *.nt)|*.bat;*.cmd,*.nt|") + _T("C/C++ (*.c,*.cpp,*.h)| *.c;*.cc;*.cpp;*.cxx;*.cs;*.h;*.hh;*.hpp;*.hxx;*.sma;*.cp |") + _T("CSS (*.css)|*.css|") + _T("Fortran (*.f9*, *.f, *.for)|*.f9*;*.f,*.for|") + _T("HTML/XHTML (*.html, *.htm)|*.htm*|") + _T("Java (*.java)|*.java|") + _T("JavaScript(*.js)|*.js|") + _T("Makefile |Makefile;makefile.*;MAKEFILE;configure.*;*.mak|") + _T("Pascal (*.pas, *.inc, *.pp)|*.pas;*.inc;*.pp|") + _T("Perl (*.pl, *.cgi)|*.pl;*.pm;*.cgi;*.pod|") + _T("PHP (*.php)|*.php|") + _T("Ruby (*.rb)|*.rb|") + _T("SQL (*.sql)|*.sql|") + _T("TCL (*.tcl)|*.tcl|") + _T("Text (*.txt)|*.txt") + _T("All files (*.*)|*.*|"); + +const wxString TYRO_FILE_SAVE_WILDCARDS = + _T("HTML/XHTML (*.html)|*.html|") + _T("CSS (*.css)|*.css|") + _T("JavaScript(*.js)|*.js|") + _T("SQL (*.sql)|*.sql|") + _T("Perl (*.pl, *.cgi)|*.pl;*.cgi|") + _T("PHP (*.php)|*.php|") + _T("Java (*.java)|*.java|") + _T("Fortran (*.f9*, *.f, *.for)|*.f9*;*.f,*.for|") + _T("Pascal (*.pas, *.inc, *.pp)|*.pas;*.inc;*.pp|") + _T("C/C++ (*.c,*.cpp,*.h)| *.c;*.cc;*.cpp;*.cxx;*.cs;*.h;*.hh;*.hpp;*.hxx;*.sma;*.cp |") + _T("Makefile |Makefile|") + _T("Ruby (*.rb)|*.rb|") + _T("Blitz Basic files (*.bb)|*.bb|") + _T("TCL (*.tcl)|*.tcl|") + _T("Bash (*.sh) |*.sh|") + _T("Batch (*.bat)|*.bat|") + _T("Text (*.txt)|*.txt|") + _T("Other (*.*)|*.*"); + + + + +#endif /* DEFINITIONS_H */ + diff --git a/src/widgets/EditPane.h b/src/widgets/EditPane.h index e208421..53f4e5d 100644 --- a/src/widgets/EditPane.h +++ b/src/widgets/EditPane.h @@ -2,7 +2,8 @@ #define TYROEDIT_PANE_H #include "../wx_common.h" -#include +#include "../../include/json/json.h" +#include "EditPaneDefinitions.h" class EditPane: public wxStyledTextCtrl { diff --git a/src/widgets/EditPaneDefinitions.h b/src/widgets/EditPaneDefinitions.h new file mode 100644 index 0000000..1fd2585 --- /dev/null +++ b/src/widgets/EditPaneDefinitions.h @@ -0,0 +1,19 @@ + + +#ifndef EDITPANEDEFINITIONS_H +#define EDITPANEDEFINITIONS_H + +#include + +// EditPane file extension to lexer mapping +map TYROLEXER_MAPPING = { + {"c", wxSTC_LEX_CPP}, + {"h", wxSTC_LEX_CPP}, + {"cpp", wxSTC_LEX_CPP}, + {"cxx", wxSTC_LEX_CPP}, + {"py", wxSTC_LEX_PYTHON}, + {"php", wxSTC_LEX_PHPSCRIPT} +}; + +#endif /* EDITPANEDEFINITIONS_H */ + diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 94a10e9..646bfea 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -126,6 +126,8 @@ void MainFrame::SetupMenu() void MainFrame::BindEvents() { Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnNew, this, wxID_NEW); + Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnOpen, this, wxID_OPEN); + Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnFileClose, this, wxID_CLOSE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditCut, this, wxID_CUT); @@ -136,16 +138,40 @@ void MainFrame::BindEvents() Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditRedo, this, wxID_REDO); } -void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event)) -{ - Destroy(); -} - void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event)) { notebook->AddTab(); } +void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event)) +{ + wxString filename; + + wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString, + TYRO_FILE_OPEN_WILDCARDS, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR); + + if (dlg.ShowModal() != wxID_OK) return; + + filename = dlg.GetPath(); + + notebook->AddTab(filename); +} + +void MainFrame::OnFileClose(wxCommandEvent &WXUNUSED(event)) +{ + +} + +void MainFrame::OnSave(wxCommandEvent &WXUNUSED(event)) +{ + +} + +void MainFrame::OnSaveAs(wxCommandEvent &WXUNUSED(event)) +{ + +} + void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event)) { Destroy(); @@ -192,5 +218,15 @@ void MainFrame::OnEditRedo(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) { - wxMessageBox(_T("Tyro, a text editor for all development\n Copyright 2015, Timothy J. Warren"), wxT("About Tyro"), wxOK| wxICON_INFORMATION, this); + wxAboutDialogInfo info; + + info.SetName("Tyro"); + info.SetVersion("0.0.1", "Prerelease"); + + info.AddDeveloper("Tim Warren, Programmer"); + + info.SetDescription("Tyro, a text editor for all development"); + info.SetCopyright(_T(" (C) 2015, Timothy J Warren")); + + wxAboutBox(info, this); } diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index 47f58b1..3f1d91f 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -7,6 +7,9 @@ #include "../wx_common.h" #include "../TyroApp.h" + +#include + #include "TabContainer.h" class MainFrame: public wxFrame @@ -27,6 +30,10 @@ class MainFrame: public wxFrame void SetupStatusBar(); void BindEvents(); void OnNew(wxCommandEvent &event); + void OnOpen(wxCommandEvent &event); + void OnFileClose(wxCommandEvent &event); + void OnSave(wxCommandEvent &event); + void OnSaveAs(wxCommandEvent &event); void OnEditCut(wxCommandEvent &event); void OnEditCopy(wxCommandEvent &event); void OnEditPaste(wxCommandEvent &event); diff --git a/src/widgets/TabContainer.cpp b/src/widgets/TabContainer.cpp index e71dc9d..94f9e18 100644 --- a/src/widgets/TabContainer.cpp +++ b/src/widgets/TabContainer.cpp @@ -33,9 +33,11 @@ void TabContainer::AddTab() void TabContainer::AddTab(wxString filePath) { - wxString caption=""; + wxString caption=filePath; EditPane *editor = new EditPane(this, wxID_ANY); + editor->LoadFile(filePath); + this->AddPage(editor, caption); } diff --git a/src/wx_common.h b/src/wx_common.h index 456b19f..fe8be63 100644 --- a/src/wx_common.h +++ b/src/wx_common.h @@ -14,5 +14,7 @@ #include #endif +#include "definitions.h" + #endif /* WX_COMMON_H */