Start on lexers for syntax highlighting

This commit is contained in:
Tim Warren 2015-04-09 17:16:28 -04:00
parent 472c9f5693
commit f0dbed1641
10 changed files with 137 additions and 12 deletions

View File

@ -8,11 +8,12 @@ PROGRAM_SRC = $(wildcard src/*.cpp src/widgets/*.cpp)
PROGRAM = build/Tyro PROGRAM = build/Tyro
PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC)) PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC))
LDLIBS = -ldl $(TARGET) $(shell wx-config --libs base core aui stc) -lssh2 BASE_FLAGS = -DSCI_LEXER -std=gnu++11
WX_CXXFLAGS = $(shell wx-config --cxxflags)
DEV_CXXFLAGS = -g -Wall -Wextra
CXXFLAGS = -Os -I./src -I./include
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) TEST_SRC= $(wildcard tests/*.cpp)
TESTS = $(patsubst %.cpp,%,$(TEST_SRC)) TESTS = $(patsubst %.cpp,%,$(TEST_SRC))

5
config/scintilla.json Normal file
View File

@ -0,0 +1,5 @@
{
"default_style": {
}
}

View File

@ -8,6 +8,7 @@
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
using namespace std; using namespace std;

51
src/definitions.h Normal file
View File

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

View File

@ -2,7 +2,8 @@
#define TYROEDIT_PANE_H #define TYROEDIT_PANE_H
#include "../wx_common.h" #include "../wx_common.h"
#include <wx/stc/stc.h> #include "../../include/json/json.h"
#include "EditPaneDefinitions.h"
class EditPane: public wxStyledTextCtrl class EditPane: public wxStyledTextCtrl
{ {

View File

@ -0,0 +1,19 @@
#ifndef EDITPANEDEFINITIONS_H
#define EDITPANEDEFINITIONS_H
#include <wx/stc/stc.h>
// EditPane file extension to lexer mapping
map<string,int> 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 */

View File

@ -126,6 +126,8 @@ void MainFrame::SetupMenu()
void MainFrame::BindEvents() void MainFrame::BindEvents()
{ {
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnNew, this, wxID_NEW); 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::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditCut, this, wxID_CUT); 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); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditRedo, this, wxID_REDO);
} }
void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event))
{
Destroy();
}
void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event))
{ {
notebook->AddTab(); 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)) void MainFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
{ {
Destroy(); Destroy();
@ -192,5 +218,15 @@ void MainFrame::OnEditRedo(wxCommandEvent &WXUNUSED(event))
void MainFrame::OnAbout(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);
} }

View File

@ -7,6 +7,9 @@
#include "../wx_common.h" #include "../wx_common.h"
#include "../TyroApp.h" #include "../TyroApp.h"
#include <wx/aboutdlg.h>
#include "TabContainer.h" #include "TabContainer.h"
class MainFrame: public wxFrame class MainFrame: public wxFrame
@ -27,6 +30,10 @@ class MainFrame: public wxFrame
void SetupStatusBar(); void SetupStatusBar();
void BindEvents(); void BindEvents();
void OnNew(wxCommandEvent &event); 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 OnEditCut(wxCommandEvent &event);
void OnEditCopy(wxCommandEvent &event); void OnEditCopy(wxCommandEvent &event);
void OnEditPaste(wxCommandEvent &event); void OnEditPaste(wxCommandEvent &event);

View File

@ -33,9 +33,11 @@ void TabContainer::AddTab()
void TabContainer::AddTab(wxString filePath) void TabContainer::AddTab(wxString filePath)
{ {
wxString caption=""; wxString caption=filePath;
EditPane *editor = new EditPane(this, wxID_ANY); EditPane *editor = new EditPane(this, wxID_ANY);
editor->LoadFile(filePath);
this->AddPage(editor, caption); this->AddPage(editor, caption);
} }

View File

@ -14,5 +14,7 @@
#include <wx/wx.h> #include <wx/wx.h>
#endif #endif
#include "definitions.h"
#endif /* WX_COMMON_H */ #endif /* WX_COMMON_H */