Open multiple files, and toggle viewing of whitespace characters

This commit is contained in:
Tim Warren 2015-04-23 16:40:59 -04:00
parent a3e7c1b1f0
commit dcdff24a87
8 changed files with 114 additions and 59 deletions

View File

@ -1,6 +1,6 @@
CXX += -I include
CXX += -I include -I.
SOURCES = $(wildcard include/**/*.cpp include/*.cpp src/settings/*.cpp)
SOURCES = $(wildcard include/**/*.cpp include/*.cpp src/network/*.cpp src/settings/*.cpp)
OBJECTS = $(patsubst %.cpp,%.o, $(SOURCES))
TYRO_LIB = build/Tyro.a
@ -14,8 +14,8 @@ WX_LDLIBS = $(shell wx-config --libs base core aui stc adv)
WX_CXXFLAGS = $(shell wx-config --cxxflags)
WX_RES = $(shell wx-config --rescomp)
DEV_CXXFLAGS = -g -Wall -Wextra -DDEBUG
CXXFLAGS = -Os -DNDEBUG
DEV_CXXFLAGS = -g -Wall -Wextra -DDEBUG -DSTATIC_BUILD
CXXFLAGS = -Os -DNDEBUG -DSTATIC_BUILD
TEST_SRC = $(wildcard tests/*.cpp)
TESTS = $(patsubst %.cpp,%,$(TEST_SRC))
@ -51,11 +51,6 @@ json_wrapper_build:
build:
@mkdir -p build
sftp_o:
$(CXX) -static $(CXXFLAGS) $(LDLIBS) -c -o src/network/SFTP.o src/network/SFTP.cpp
$(TYRO_LIB): build sftp_o
$(TYRO_LIB): OBJECTS += src/network/SFTP.o
$(TYRO_LIB): $(OBJECTS)
ar rcs $@ $(OBJECTS)
ranlib $@

File diff suppressed because one or more lines are too long

View File

@ -55,8 +55,6 @@
"error": [220, 50, 47]
},
"bold": {
"keyword1": true,
"keyword2": true,
"operator": true,
"label": true,
"error": true,

View File

@ -1,11 +1,6 @@
/***************************************************************
* Name: TyroApp.cpp
* Purpose: Code for Application Class
* Author: Timothy J Warren (tim@timshomepage.net)
* Created: 2015-03-30
* Copyright: Timothy J Warren (https://timshomepage.net)
* License:
**************************************************************/
/**
* Main application file
*/
#include "wx_common.h"
@ -27,6 +22,11 @@ private:
IMPLEMENT_APP(TyroApp);
/**
* Start the event loop and create the main window
*
* @return bool
*/
bool TyroApp::OnInit()
{
this->SetAppName(APP_NAME);
@ -43,6 +43,11 @@ bool TyroApp::OnInit()
return true;
}
/**
* Exit handler
*
* @return int
*/
int TyroApp::OnExit()
{
return close(true);

View File

@ -5,15 +5,6 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
// Top level menus
enum {
myFILE_MENU,
myEDIT_MENU,
myVIEW_MENU,
myLANG_MENU,
myHELP_MENU
};
// Application config
const wxString APP_NAME = "Tyro";
const wxString APP_VENDOR = "Aviat Ion";
@ -27,6 +18,7 @@ const wxString TYRO_OPEN_ERROR_CAPTION = "Open Failed";
// EditPane file extension to lexer mapping
typedef map<string, int> StringConstMap;
typedef map<string, string> StringMap;
const wxString TYRO_FILE_OPEN_WILDCARDS =
"All files (*.*)|*|"

View File

@ -5,11 +5,11 @@ EditPane::EditPane(
const wxSize &size, long style
) : wxStyledTextCtrl (parent, id, pos, size, style)
{
#include "../../config/languages_json.h"
#include <config/languages_json.h>
lang_config = new TyroConfig();
lang_config->LoadJson(languages_json);
#include "../../config/themes_json.h"
#include <config/themes_json.h>
theme_config = new TyroConfig();
theme_config->LoadJson(themes_json);
@ -105,8 +105,6 @@ void EditPane::Highlight(wxString filePath)
this->MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
this->SetLayoutCache (wxSTC_CACHE_CARET);
//this->SetViewWhiteSpace(wxSTC_WS_VISIBLEALWAYS);
// set spaces and indention
this->SetTabWidth(4);

View File

@ -3,6 +3,20 @@
*/
#include "MainFrame.h"
// Top level menus
enum {
myFILE_MENU,
myEDIT_MENU,
myVIEW_MENU,
myLANG_MENU,
myHELP_MENU
};
// Menu ids
enum {
myID_VIEW_WHITESPACE = wxID_HIGHEST
};
MainFrame::MainFrame(wxFrame *frame, const wxString &title)
: wxFrame(frame, -1, title)
{
@ -102,7 +116,7 @@ void MainFrame::SetupToolbar()
void MainFrame::SetupMenu()
{
// create a menu bar
mbar = new wxMenuBar();
this->mbar = new wxMenuBar();
// Create Base menus
fileMenu = new wxMenu("");
@ -132,16 +146,18 @@ void MainFrame::SetupMenu()
//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");
editMenu->Append(wxID_SELECTALL, "Select All\tCtrl+A", "Select all the text in the current document");
viewMenu->AppendCheckItem(myID_VIEW_WHITESPACE, "Show Invisible Characters\tCtrl+Shift+I", "Toggle visibility of white space characters");
helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application");
// Add the menus to the menubar
mbar->Append(fileMenu, "&File");
mbar->Append(editMenu, "&Edit");
//mbar->Append(viewMenu, "&View");
//mbar->Append(langMenu, "&Language");
mbar->Append(helpMenu, "&Help");
this->mbar->Append(fileMenu, "&File");
this->mbar->Append(editMenu, "&Edit");
this->mbar->Append(viewMenu, "&View");
this->mbar->Append(langMenu, "&Language");
this->mbar->Append(helpMenu, "&Help");
#ifdef __WXMAC__
wxMenuBar::MacSetCommonMenuBar(mbar);
@ -171,6 +187,7 @@ void MainFrame::BindEvents()
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditSelectAll, this, wxID_SELECTALL);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditUndo, this, wxID_UNDO);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnEditRedo, this, wxID_REDO);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE);
}
void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event))
@ -181,18 +198,24 @@ void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event))
void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
{
wxString filename;
wxArrayString filelist;
int listcount;
wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString,
TYRO_FILE_OPEN_WILDCARDS, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
wxFileDialog dlg (this, "Open file(s)", wxEmptyString, wxEmptyString,
TYRO_FILE_OPEN_WILDCARDS, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | wxFD_MULTIPLE);
if (dlg.ShowModal() != wxID_OK) return;
filename = dlg.GetPath();
dlg.GetPaths(filelist);
listcount = filelist.GetCount();
this->EnableEditControls();
// Open a new tab for each file
for (int i = 0; i < listcount; i++)
{
notebook->AddTab(filelist[i]);
}
notebook->AddTab(filename);
this->EnableEditControls(true);
}
void MainFrame::OnClose(wxAuiNotebookEvent &event)
@ -228,6 +251,12 @@ void MainFrame::OnClose(wxAuiNotebookEvent &event)
};
}
/**
* Event handler triggered after a tab is closed
*
* @param WXUNUSED
* @return void
*/
void MainFrame::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{
if (notebook->GetPageCount() == 0)
@ -350,6 +379,21 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
wxAboutBox(info);
}
/**
* Toggle display of invisibles
*
* @param wxCommandEvent& event
* @return void
*/
void MainFrame::OnToggleWhitespace(wxCommandEvent& event)
{
int flag = (event.IsChecked())
? wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE;
notebook->GetCurrentEditor()->SetViewWhiteSpace(flag);
}
/**
* Toggle enable/disable of document-specific controls
*
@ -358,20 +402,18 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event))
*/
void MainFrame::EnableEditControls(bool enable)
{
fileMenu->Enable(wxID_SAVE, enable);
fileMenu->Enable(wxID_SAVEAS, enable);
fileMenu->Enable(wxID_CLOSE, enable);
this->fileMenu->Enable(wxID_SAVE, enable);
this->fileMenu->Enable(wxID_SAVEAS, enable);
this->fileMenu->Enable(wxID_CLOSE, enable);
editMenu->Enable(wxID_CUT, enable);
editMenu->Enable(wxID_COPY, enable);
editMenu->Enable(wxID_PASTE, enable);
editMenu->Enable(wxID_CLEAR, enable);
//editMenu->Enable(wxID_FIND, enable);
editMenu->Enable(wxID_SELECTALL, enable);
// Enable/disable top level menus
this->mbar->EnableTop(myEDIT_MENU, enable);
this->mbar->EnableTop(myVIEW_MENU, enable);
this->mbar->EnableTop(myLANG_MENU, enable);
toolBar->EnableTool(wxID_SAVE, enable);
toolBar->EnableTool(wxID_CLOSE, enable);
toolBar->EnableTool(wxID_COPY, enable);
toolBar->EnableTool(wxID_CUT, enable);
toolBar->EnableTool(wxID_PASTE, enable);
this->toolBar->EnableTool(wxID_SAVE, enable);
this->toolBar->EnableTool(wxID_CLOSE, enable);
this->toolBar->EnableTool(wxID_COPY, enable);
this->toolBar->EnableTool(wxID_CUT, enable);
this->toolBar->EnableTool(wxID_PASTE, enable);
}

View File

@ -49,6 +49,7 @@ class MainFrame: public wxFrame
void OnEditUndo(wxCommandEvent &event);
void OnEditRedo(wxCommandEvent &event);
void OnCloseTab(wxCommandEvent &event);
void OnToggleWhitespace(wxCommandEvent &event);
void OnQuit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event);
};