Lexers can now be loaded

This commit is contained in:
Tim Warren 2015-04-10 15:11:15 -04:00
parent 0561e531ef
commit e0d8b1203d
11 changed files with 67 additions and 30 deletions

View File

@ -8,7 +8,7 @@ PROGRAM_SRC = $(wildcard src/*.cpp src/widgets/*.cpp)
PROGRAM = build/Tyro
PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC))
BASE_FLAGS = -DSCI_LEXER -std=gnu++11
BASE_FLAGS = -DSCI_LEXER -std=c++11
LDLIBS = $(TARGET) $(shell wx-config --libs base core aui stc adv) -lssh2
WX_CXXFLAGS = $(shell wx-config --cxxflags) $(BASE_FLAGS)

View File

@ -6,6 +6,7 @@
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

View File

@ -5,6 +5,10 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
// EditPane file extension to lexer mapping
typedef pair<string, int> StringConstMapData;
typedef map<string, int> StringConstMap;
const wxString TYRO_FILE_OPEN_WILDCARDS =
_T("Bash (*.sh, *.bsh) |*.sh;*.bsh|")
_T("Batch (*.bat, *.cmd, *.nt)|*.bat;*.cmd,*.nt|")

View File

@ -5,7 +5,36 @@ EditPane::EditPane(
const wxSize &size, long style
) : wxStyledTextCtrl (parent, id, pos, size, style)
{
StringConstMapData map_data[] = {
{"c", wxSTC_LEX_CPP},
{"h", wxSTC_LEX_CPP},
{"cpp", wxSTC_LEX_CPP},
{"cxx", wxSTC_LEX_CPP},
{"py", wxSTC_LEX_PYTHON},
{"php", wxSTC_LEX_PHPSCRIPT}
};
lexer_map = StringConstMap(
map_data,
map_data + sizeof map_data / sizeof map_data[0]
);
}
EditPane::~EditPane() {}
/**
* Encapsulate lexer selection when opening a file
*
* @param wxString filePath
* @return bool
*/
bool EditPane::LoadAndHighlight(wxString filePath)
{
wxFileName file(filePath);
wxString ext = file.GetExt();
//lexer_map_it = lexer_map.find((string) ext);
//this->SetLexer(lexer_map_it->second);
return this->LoadFile(filePath);
}

View File

@ -2,8 +2,10 @@
#define TYROEDIT_PANE_H
#include "../wx_common.h"
#include <wx/stc/stc.h>
#include "../../include/json/json.h"
#include "EditPaneDefinitions.h"
class EditPane: public wxStyledTextCtrl
{
@ -20,7 +22,10 @@ public:
wxVSCROLL
);
~EditPane();
bool LoadAndHighlight(wxString filePath);
private:
StringConstMap lexer_map;
StringConstMap::iterator lexer_map_it;
};
#endif // TYRODOC_FRAME_H

View File

@ -1,19 +0,0 @@
#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

@ -107,6 +107,7 @@ void MainFrame::SetupMenu()
editMenu->Append(wxID_CUT, _T("Cu&t\tCtrl+X"), _T("Cut selected text"));
editMenu->Append(wxID_COPY, _T("&Copy\tCtrl+C"), _T("Copy selected text"));
editMenu->Append(wxID_PASTE, _T("&Paste\tCtrl+V"), _T("Paste contents of clipboard"));
editMenu->Append(wxID_CLEAR, _T("&Delete\tDel"));
editMenu->AppendSeparator();
editMenu->Append(wxID_SELECTALL, _T("Select All\tCtrl+A"), _T("Select all the text in the current document"));
@ -228,5 +229,7 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
info.SetDescription("Tyro, a text editor for all development");
info.SetCopyright(_T(" (C) 2015, Timothy J Warren"));
wxAboutBox(info, this);
wxGenericAboutDialog dlg;
dlg.Create(info, this);
dlg.ShowModal();
}

View File

@ -9,6 +9,7 @@
#include "../TyroApp.h"
#include <wx/aboutdlg.h>
#include <wx/generic/aboutdlgg.h>
#include "TabContainer.h"

View File

@ -14,7 +14,6 @@ TabContainer::TabContainer(
long style
) : wxAuiNotebook(parent, id, pos, size, style)
{
this->AddTab();
}
TabContainer::~TabContainer() {}
@ -23,22 +22,31 @@ void TabContainer::AddTab()
{
untitled_document_count++;
wxString caption;
caption.Printf("Untitled %lu", untitled_document_count);
EditPane *editor = new EditPane(this, wxID_ANY);
this->AddPage(editor, caption);
}
void TabContainer::AddTab(wxString filePath)
{
wxString caption=filePath;
wxFileName fileName(filePath);
wxString caption= fileName.GetFullName();
EditPane *editor = new EditPane(this, wxID_ANY);
editor->LoadFile(filePath);
bool loaded_file = editor->LoadAndHighlight(filePath);
this->AddPage(editor, caption);
if (loaded_file)
{
this->AddPage(editor, caption);
}
else
{
// @TODO Add Error dialog here
}
}
EditPane *TabContainer::GetCurrentEditor()

View File

@ -8,8 +8,10 @@
#include "../wx_common.h"
#include <wx/aui/aui.h>
#include <wx/filename.h>
#include "EditPane.h"
static long tab_style = wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS
| wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_CLOSE_ON_ALL_TABS
| wxAUI_NB_MIDDLE_CLICK_CLOSE | wxAUI_NB_TOP;

View File

@ -14,6 +14,9 @@
#include <wx/wx.h>
#endif
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include "definitions.h"
#endif /* WX_COMMON_H */