Miscellaneous

This commit is contained in:
Tim Warren 2015-04-21 17:06:21 -04:00
parent e42e31e4b0
commit 29b385283d
6 changed files with 196 additions and 96 deletions

View File

@ -128,7 +128,7 @@
"close flush lines read seek setvbuf write clock date difftime execute exit getenv remove rename setlocale time tmpname coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield io.close io.flush io.input io.lines io.open io.output io.popen io.read io.tmpfile io.type io.write io.stderr io.stdin io.stdout os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname debug.debug debug.getfenv debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.getuservalue debug.setfenv debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.setuservalue debug.traceback debug.upvalueid debug.upvaluejoin package.cpath package.loaded package.loaders package.loadlib package.path package.preload package.seeall"
],
"lexer_map": [
"default", "comment", "comment_line", "comment_doc", "number", "word", "string", "character", "string", "preprocessor", "operator", "identifier", "string_eol", "keyword2", "keyword3", "keyword4", "keyword5", "keyword6", "keyword7", "keyword8", "label"
"default", "comment", "comment_line", "comment_doc", "number", "keyword1", "string", "character", "string", "preprocessor", "operator", "identifier", "string_eol", "keyword2", "keyword3", "keyword4", "keyword5", "keyword6", "keyword7", "keyword8", "label"
]
},
"makefile": {
@ -137,7 +137,7 @@
""
],
"lexer_map": [
"default", "comment", "preprocessor", "identifier", "operator"
"default", "comment", "preprocessor", "identifier", "operator", "label"
]
},
"markdown": {
@ -146,7 +146,7 @@
""
],
"lexer_map": [
"default"
"default", "comment", "preprocessor", "preprocessor", "identifier", "identifier", "operator", "operator", "operator", "operator", "operator", "operator", "comment_doc", "number", "number"
]
},
"php": {

View File

@ -1,11 +1,82 @@
{
"Solarized" : {
/*
base03 0, 43, 54
base02 7, 54, 66
base01 88, 110, 117
base00 101, 123, 131
base0 131, 148, 150
base1 147, 161, 161
base2 238, 232, 213
base3 253, 246, 227
yellow 181, 137, 0
orange 203, 75, 22
red 220, 50, 47
magenta 211, 54, 130
violet 108, 113, 196
blue 38, 139, 210
cyan 42, 161, 152
green 133, 153, 0
*/
"background": {
"default": [253, 246, 227]
},
"foreground": {
"default": [101, 123, 131],
"keyword1": [220, 50, 47],
"keyword2": [42, 161, 152],
"keyword3": [181, 137, 0],
"keyword4": [181, 137, 0],
"keyword5": [181, 137, 0],
"keyword6": [181, 137, 0],
"comment": [147, 161, 161],
"comment_line": [147, 161, 161],
"comment_doc": [131, 148, 150],
"comment_special": [101, 123, 131],
"character": [108, 113, 196],
"character_eol": [108, 113, 196],
"string": [108, 113, 196],
"string_eol": [108, 113, 196],
"delimeter": [38, 139, 210],
"punctuation": [101, 123, 131],
"operator": [101, 123, 131],
"brace": [101, 123, 131],
"command": [],
"identifier": [38, 139, 210],
"label": [220, 50, 47],
"number": [211, 54, 130],
"parameter": [0, 43, 54],
"regex": [7, 54, 66],
"uuid": [0, 43, 54],
"value": [7, 54, 66],
"preprocessor": [181, 137, 0],
"script": [88, 110, 117],
"error": [220, 50, 47]
},
"bold": {
"keyword2": true,
"operator": true,
"label": true,
"error": true
},
"italic": {
"error": true
},
"underline": {
},
"line_numbers": {
"foreground": [147, 161, 161],
"background": [238, 232, 213]
}
},
"Solarized Dark" : {
"background": {
"default": [0, 43, 54]
},
"foreground": {
"default": [131, 148, 150],
"keyword1": [220, 50, 47],
"keyword2": [203, 76, 22],
"keyword3": [181, 137, 0],
"keyword4": [181, 137, 0],
@ -23,7 +94,7 @@
"punctuation": [101, 123, 131],
"operator": [101, 123, 131],
"brace": [101, 123, 131],
"command": [],
"command": [101, 123, 131],
"identifier": [38, 139, 210],
"label": [38, 139, 210],
"number": [211, 54, 130],
@ -49,42 +120,5 @@
"foreground": [147, 161, 161],
"background": [238, 232, 213]
}
},
"Solarized Dark" : {
"background": {
"default": []
},
"foreground": {
"default": [],
"keyword1": [],
"keyword2": [],
"keyword3": [],
"keyword4": [],
"keyword5": [],
"keyword6": [],
"comment": [],
"line_comment": [],
"doc_comment": [],
"special_comment": [],
"character": [],
"character_eol": [],
"string": [],
"string_eol": [],
"delimeter": [],
"punctuation": [],
"operator": [],
"brace": [],
"command": [],
"identifier": [],
"label": [],
"number": [],
"parameter": [],
"regex": [],
"uuid": [],
"value": [],
"preprocessor": [],
"script": [],
"error": []
}
}
}

View File

@ -13,6 +13,7 @@ EditPane::EditPane(
theme_config = new TyroConfig();
theme_config->LoadJson(themes_json);
// Map language types to their lexers
lexerMap["batch"] = wxSTC_LEX_BATCH;
lexerMap["caml"] = wxSTC_LEX_CAML;
lexerMap["cmake"] = wxSTC_LEX_CMAKE;
@ -82,22 +83,22 @@ void EditPane::Highlight(wxString filePath)
this->ApplyTheme(lang);
// Set up Code folding
this->SetProperty(wxT("fold"), wxT("1"));
this->SetProperty(wxT("fold.comment"), wxT("1"));
this->SetProperty(wxT("fold.compact"), wxT("1"));
this->SetProperty(wxT("fold.html"), wxT("1"));
this->SetProperty("fold", "1");
this->SetProperty("fold.comment", "1");
this->SetProperty("fold.compact", "1");
this->SetProperty("fold.html", "1");
this->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
this->SetMarginType(MARGIN_FOLD, wxSTC_MARGIN_SYMBOL);
this->SetMarginWidth(MARGIN_FOLD, 16);
this->SetMarginSensitive(MARGIN_FOLD, true);
this->SetMarginMask(MARGIN_FOLD, wxSTC_MASK_FOLDERS);
this->MarkerDefine (wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, _T("WHITE"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, _T("WHITE"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, _T("BLACK"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, _T("WHITE"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, _T("WHITE"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, _T("BLACK"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, _T("BLACK"), _T("BLACK"));
this->MarkerDefine (wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK");
this->MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
this->SetLayoutCache (wxSTC_CACHE_NONE);
this->SetUseHorizontalScrollBar(1);
@ -112,6 +113,13 @@ void EditPane::Highlight(wxString filePath)
this->SetBackSpaceUnIndents(true);
}
/**
* Set the current theme for the current language
*
* @param string lang
* @param string theme
* @return void
*/
void EditPane::ApplyTheme(string lang, string theme)
{
this->SetTheme(theme);
@ -196,12 +204,14 @@ string EditPane::GetLangByFile()
wxString cur = file_pattern.BeforeFirst(';');
if (
(cur == curr_file) ||
(cur == (curr_file.BeforeLast('.') + _T(".*"))) ||
(cur == (_T("*.") + curr_file.AfterLast('.')))
(cur == (curr_file.BeforeLast('.') + ".*")) ||
(cur == ("*." + curr_file.AfterLast('.')))
)
{
return lang;
}
// Go to the next pattern for this language
file_pattern = file_pattern.AfterFirst(';');
}
}
@ -314,6 +324,12 @@ void EditPane::BindEvents()
Bind(wxEVT_STC_MARGINCLICK, &EditPane::OnMarginClick, this, wxID_ANY);
}
/**
* Code folding event handler
*
* @param wxStyledTextEvent& event
* @return void
*/
void EditPane::OnMarginClick(wxStyledTextEvent& event)
{
if (event.GetMargin() == MARGIN_FOLD) {
@ -325,6 +341,12 @@ void EditPane::OnMarginClick(wxStyledTextEvent& event)
}
}
/**
* Get the list of keywords for the selected language
*
* @param string lang
* @return JsonValue
*/
JsonValue EditPane::GetKeywordList(string lang)
{
return lang_config->GetRoot()
@ -332,6 +354,13 @@ JsonValue EditPane::GetKeywordList(string lang)
.get("keywords", JsonValue());
}
/**
* Retrieve a setting from the current theme
*
* @param string type
* @param string key
* @return JsonValue
*/
JsonValue EditPane::GetThemeValue(string type, string key)
{
JsonValue value = this->current_theme
@ -382,20 +411,21 @@ void EditPane::_ApplyTheme(JsonValue lexer_map)
);
#endif
wxColor default_background = this->GetThemeColor("background", "default");
wxColor default_foreground = this->GetThemeColor("foreground", "default");
static const wxColor default_background = this->GetThemeColor("background", "default");
static const wxColor default_foreground = this->GetThemeColor("foreground", "default");
wxColor line_number_background = ( ! this->GetThemeValue("line_numbers", "background").isNull())
? (this->GetThemeColor("line_numbers", "background"))
: wxColor("White");
: default_background;
wxColor line_number_foreground = ( ! this->GetThemeValue("line_numbers", "foreground").isNull())
? (this->GetThemeColor("line_numbers", "foreground"))
: wxColor("Black");
: default_foreground;
// Set default colors/ fonts
for(int i = 0; i <= wxSTC_STYLE_MAX; i++)
{
this->StyleSetBackground(i, default_background);
this->StyleSetForeground(i, default_foreground);
this->StyleSetFont(i, *defaultFont);
}
@ -428,12 +458,13 @@ void EditPane::_ApplyTheme(JsonValue lexer_map)
{
this->StyleSetBold(i, this->GetThemeValue("bold", key).asBool());
}
// Italic
if (this->GetThemeValue("italic", key).isBool())
{
this->StyleSetItalic(i, this->GetThemeValue("italic", key).asBool());
}
}
/*this->StyleSetBold(wxSTC_C_WORD, false);
this->StyleSetBold(wxSTC_C_WORD2, true);
this->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true);
this->StyleSetBold(wxSTC_C_OPERATOR, true);*/
}
void EditPane::SetTheme(string theme_name)

View File

@ -33,7 +33,6 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
SetSizerAndFit(base_sizer);
}
MainFrame::~MainFrame() {}
void MainFrame::SetupStatusBar()
@ -43,6 +42,11 @@ void MainFrame::SetupStatusBar()
SetStatusText(_(""), 1);
}
/**
* Create the main toolbar
*
* @return void
*/
void MainFrame::SetupToolbar()
{
// Icon files
@ -90,46 +94,54 @@ void MainFrame::SetupToolbar()
toolBar->Realize();
}
/**
* Create the main menu
*
* @return void
*/
void MainFrame::SetupMenu()
{
// create a menu bar
mbar = new wxMenuBar();
// Create Base menus
fileMenu = new wxMenu(_T(""));
editMenu = new wxMenu(_T(""));
viewMenu = new wxMenu(_T(""));
helpMenu = new wxMenu(_T(""));
fileMenu = new wxMenu("");
editMenu = new wxMenu("");
viewMenu = new wxMenu("");
langMenu = new wxMenu("");
helpMenu = new wxMenu("");
// Add items to top-level menus
fileMenu->Append(wxID_NEW, _T("&New\tCtrl+N"), _T("Create a new file"));
fileMenu->Append(wxID_NEW, "&New\tCtrl+N", "Create a new file");
fileMenu->AppendSeparator();
fileMenu->Append(wxID_OPEN, _T("&Open\tCtrl+O"), _T("Opens an existing file"));
fileMenu->Append(wxID_SAVE, _T("&Save\tCtrl+S"), _T("Save the content"));
fileMenu->Append(wxID_SAVEAS, _T("Save &As...\tShift+Ctrl+S"), _T("Save current file as..."));
fileMenu->Append(wxID_OPEN, "&Open\tCtrl+O", "Opens an existing file");
fileMenu->Append(wxID_SAVE, "&Save\tCtrl+S", "Save the content");
fileMenu->Append(wxID_SAVEAS, "Save &As...\tShift+Ctrl+S", "Save current file as...");
fileMenu->AppendSeparator();
fileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl+W"), _T("Close the current document"));
fileMenu->Append(wxID_EXIT, _T("&Quit\tCtrl+Q"), _T("Quit the application"));
fileMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current document");
fileMenu->Append(wxID_EXIT, "&Quit\tCtrl+Q", "Quit the application");
editMenu->Append(wxID_UNDO, _T("&Undo\tCtrl+Z"), _T("Undo last action"));
editMenu->Append(wxID_REDO, _T("&Redo\tCtrl+Y"), _T("Redo last action"));
editMenu->Append(wxID_UNDO, "&Undo\tCtrl+Z", "Undo last action");
editMenu->Append(wxID_REDO, "&Redo\tCtrl+Y", "Redo last action");
editMenu->AppendSeparator();
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->Append(wxID_CUT, "Cu&t\tCtrl+X", "Cut selected text");
editMenu->Append(wxID_COPY, "&Copy\tCtrl+C", "Copy selected text");
editMenu->Append(wxID_PASTE, "&Paste\tCtrl+V", "Paste contents of clipboard");
editMenu->Append(wxID_CLEAR, "&Delete\tDel");
editMenu->AppendSeparator();
editMenu->Append (wxID_FIND, _("&Find\tCtrl+F"));
editMenu->AppendSeparator();
editMenu->Append(wxID_SELECTALL, _T("Select All\tCtrl+A"), _T("Select all the text in the current document"));
//editMenu->Append(wxID_FIND, "&Find\tCtrl+F");
//editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R");
//editMenu->AppendSeparator();
editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document");
helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show info about this application"));
helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application");
// Add the menus to the menubar
mbar->Append(fileMenu, _T("&File"));
mbar->Append(editMenu, _T("&Edit"));
mbar->Append(viewMenu, _T("&View"));
mbar->Append(helpMenu, _T("&Help"));
mbar->Append(fileMenu, "&File");
mbar->Append(editMenu, "&Edit");
//mbar->Append(viewMenu, "&View");
mbar->Append(langMenu, "&Language")
mbar->Append(helpMenu, "&Help");
#ifdef __WXMAC__
wxMenuBar::MacSetCommonMenuBar(mbar);
@ -137,6 +149,11 @@ void MainFrame::SetupMenu()
SetMenuBar(mbar);
}
/**
* Bind event handlers
*
* @return void
*/
void MainFrame::BindEvents()
{
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnNew, this, wxID_NEW);
@ -328,11 +345,17 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
info.AddDeveloper("Tim Warren, Programmer");
info.SetDescription("Tyro, a text editor for all development");
info.SetCopyright(_T(" (C) 2015, Timothy J Warren"));
info.SetCopyright(" (C) 2015, Timothy J Warren");
wxAboutBox(info);
}
/**
* Toggle enable/disable of document-specific controls
*
* @param bool enable
* @return void
*/
void MainFrame::EnableEditControls(bool enable)
{
fileMenu->Enable(wxID_SAVE, enable);

View File

@ -27,18 +27,15 @@ class MainFrame: public wxFrame
wxMenu *fileMenu;
wxMenu *editMenu;
wxMenu *viewMenu;
wxMenu *langMenu;
wxMenu *helpMenu;
enum
{
idMenuQuit = 1000,
idMenuAbout
};
wxRect DetermineFrameSize();
void SetupMenu();
void SetupToolbar();
void SetupStatusBar();
void BindEvents();
void EnableEditControls(bool enable=true);
// Event handlers
void OnNew(wxCommandEvent &event);
void OnOpen(wxCommandEvent &event);
void OnClose(wxAuiNotebookEvent &event);

View File

@ -18,6 +18,11 @@ TabContainer::TabContainer(
TabContainer::~TabContainer() {}
/**
* Add a new blank document
*
* @return void
*/
void TabContainer::AddTab()
{
untitled_document_count++;
@ -31,6 +36,12 @@ void TabContainer::AddTab()
this->AddPage(editor, caption, true);
}
/**
* Open an existing document
*
* @param wxString filePath
* @return void
*/
void TabContainer::AddTab(wxString filePath)
{
wxFileName fileName(filePath);
@ -40,7 +51,6 @@ void TabContainer::AddTab(wxString filePath)
if (editor->Load(filePath))
{
wxLogDebug("File should be properly loaded.");
this->AddPage(editor, caption, true);
return;
@ -49,6 +59,11 @@ void TabContainer::AddTab(wxString filePath)
wxLogDebug("Failed to load file!?");
}
/**
* Get the EditPane control in the current tab
*
* @return *EditPane
*/
EditPane *TabContainer::GetCurrentEditor()
{
return (EditPane *) this->GetCurrentPage();