Fix syntax error, add file changed/saved indicator

This commit is contained in:
Timothy Warren 2019-05-31 22:46:27 -04:00
parent 6028925475
commit 2767b03c01
4 changed files with 77 additions and 55 deletions

View File

@ -14,11 +14,7 @@ all:
dev: all dev: all
build: run: all
@mkdir -p build
./cmake.sh Tyro
run: build
ifneq ($(OS),Darwin) ifneq ($(OS),Darwin)
./$(PROGRAM) ./$(PROGRAM)
else else
@ -27,11 +23,11 @@ endif
ifeq ($(OS),Darwin) ifeq ($(OS),Darwin)
run-app: run-app: all
open -a $(PWD)/build/Tyro.app open -a $(PWD)/build/Tyro.app
endif endif
run-grind: run-grind: all
valgrind $(PROGRAM) valgrind $(PROGRAM)
# Make optimized and striped executable # Make optimized and striped executable
@ -80,8 +76,6 @@ run-tests: tests
tests: $(TEST_RUNNER) tests: $(TEST_RUNNER)
./build/test_runner ./build/test_runner
tests-verbose: $(TEST_RUNNER) tests-verbose: $(TEST_RUNNER)
./build/test_runner -s ./build/test_runner -s

View File

@ -194,7 +194,20 @@ bool EditPane::SaveFile(const wxString &filename)
if (this->FileWritable()) if (this->FileWritable())
{ {
this->SetSavePoint(); this->SetSavePoint();
return wxStyledTextCtrl::SaveFile(filename); bool saved = wxStyledTextCtrl::SaveFile(filename);
if (saved)
{
auto parent = (wxAuiNotebook*) this->GetParent();
auto currentPage = parent->GetCurrentPage();
auto idx = parent->GetPageIndex(currentPage);
wxString currentTitle = parent->GetPageText(idx);
currentTitle.Replace("*", "");
parent->SetPageText(idx, currentTitle);
}
return saved;
} }
return false; return false;
@ -270,6 +283,25 @@ void EditPane::BindEvents()
} }
}, wxID_ANY); }, wxID_ANY);
// On modification, update parent tab to show "dirtyness"
this->Bind(wxEVT_STC_MODIFIED, [=](wxStyledTextEvent& event) {
auto parent = (wxAuiNotebook*) this->GetParent();
auto currentPage = parent->GetCurrentPage();
auto idx = parent->GetPageIndex(currentPage);
wxString currentTitle = parent->GetPageText(idx);
if (this->IsModified() && ! currentTitle.Contains("*"))
{
parent->SetPageText(idx, currentTitle + "*");
}
if (currentTitle.Contains("*") && ! this->IsModified())
{
currentTitle.Replace("*", "");
parent->SetPageText(idx, currentTitle);
}
}, wxID_ANY);
// this->Bind(wxEVT_STC_CHARADDED, &EditPane::OnCharAdded, this, wxID_ANY); // this->Bind(wxEVT_STC_CHARADDED, &EditPane::OnCharAdded, this, wxID_ANY);
} }
@ -405,19 +437,19 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
} }
// Set bold, if it applies // Set bold, if it applies
if this->theme_config->GetThemeValue("bold", key).isBool()) if (this->theme_config->GetThemeValue("bold", key).isBool())
{ {
this->StyleSetBold(i, this->theme_config->GetThemeValue("bold", key).asBool()); this->StyleSetBold(i, this->theme_config->GetThemeValue("bold", key).asBool());
} }
// Italic // Italic
if this->theme_config->GetThemeValue("italic", key).isBool()) if (this->theme_config->GetThemeValue("italic", key).isBool())
{ {
this->StyleSetItalic(i, this->theme_config->GetThemeValue("italic", key).asBool()); this->StyleSetItalic(i, this->theme_config->GetThemeValue("italic", key).asBool());
} }
// Underline // Underline
if this->theme_config->GetThemeValue("underline", key).isBool()) if (this->theme_config->GetThemeValue("underline", key).isBool())
{ {
this->StyleSetUnderline(i, this->theme_config->GetThemeValue("underline", key).asBool()); this->StyleSetUnderline(i, this->theme_config->GetThemeValue("underline", key).asBool());
} }

View File

@ -1,20 +1,17 @@
#include "src/widgets/TyroMenu.h" #include "src/widgets/TyroMenu.h"
#include "src/settings/LangConfig.h"
static LangConfig *lang_config = nullptr;
/** /**
* Constructor * Constructor
*/ */
TyroMenu::TyroMenu() TyroMenu::TyroMenu()
{ {
fileMenu = new wxMenu(); this->fileMenu = new wxMenu();
editMenu = new wxMenu(); this->editMenu = new wxMenu();
viewMenu = new wxMenu(); this->viewMenu = new wxMenu();
langMenu = new wxMenu(); this->langMenu = new wxMenu();
helpMenu = new wxMenu(); this->helpMenu = new wxMenu();
lang_config = new LangConfig(); this->lang_config = new LangConfig();
this->SetupMainMenus(); this->SetupMainMenus();
this->SetupLangMenu(); this->SetupLangMenu();
@ -33,7 +30,7 @@ TyroMenu::TyroMenu()
TyroMenu::~TyroMenu() TyroMenu::~TyroMenu()
{ {
wxLogDebug("TyroMenu Destructor Called."); wxLogDebug("TyroMenu Destructor Called.");
delete lang_config; delete this->lang_config;
} }
/** /**
@ -44,41 +41,38 @@ TyroMenu::~TyroMenu()
void TyroMenu::SetupMainMenus() void TyroMenu::SetupMainMenus()
{ {
// Add items to top-level menus // Add items to top-level menus
fileMenu->Append(wxID_NEW, "&New\tCtrl+N", "Create a new file"); this->fileMenu->Append(wxID_NEW, "&New\tCtrl+N", "Create a new file");
fileMenu->AppendSeparator(); this->fileMenu->AppendSeparator();
fileMenu->Append(wxID_OPEN, "&Open\tCtrl+O", "Opens an existing file"); this->fileMenu->Append(wxID_OPEN, "&Open\tCtrl+O", "Opens an existing file");
fileMenu->Append(myID_OPEN_DIR, "&Open Dir\tShift+Ctrl+O", "Opens the selected folder in the sidebar"); this->fileMenu->Append(myID_OPEN_DIR, "&Open Dir\tShift+Ctrl+O", "Opens the selected folder in the sidebar");
this->fileMenu->AppendSeparator();
fileMenu->Append(wxID_SAVE, "&Save\tCtrl+S", "Save the content"); this->fileMenu->Append(wxID_SAVE, "&Save\tCtrl+S", "Save the content");
fileMenu->Append(wxID_SAVEAS, "Save &As...\tShift+Ctrl+S", "Save current file as..."); this->fileMenu->Append(wxID_SAVEAS, "Save &As...\tShift+Ctrl+S", "Save current file as...");
fileMenu->AppendSeparator(); this->fileMenu->AppendSeparator();
fileMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current document"); this->fileMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current document");
fileMenu->Append(myID_CLOSE_ALL, "C&lose All\tShift+Ctrl+W", "Close all open documents."); this->fileMenu->Append(myID_CLOSE_ALL, "C&lose All\tShift+Ctrl+W", "Close all open documents.");
fileMenu->Append(wxID_EXIT, "&Quit\tCtrl+Q", "Quit the application"); this->fileMenu->Append(wxID_EXIT, "&Quit\tCtrl+Q", "Quit the application");
editMenu->Append(wxID_UNDO, "&Undo\tCtrl+Z", "Undo last action"); this->editMenu->Append(wxID_UNDO, "&Undo\tCtrl+Z", "Undo last action");
editMenu->Append(wxID_REDO, "&Redo\tCtrl+Y", "Redo last action"); this->editMenu->Append(wxID_REDO, "&Redo\tCtrl+Y", "Redo last action");
editMenu->AppendSeparator(); this->editMenu->AppendSeparator();
editMenu->Append(wxID_CUT, "Cu&t\tCtrl+X", "Cut selected text"); this->editMenu->Append(wxID_CUT, "Cu&t\tCtrl+X", "Cut selected text");
editMenu->Append(wxID_COPY, "&Copy\tCtrl+C", "Copy selected text"); this->editMenu->Append(wxID_COPY, "&Copy\tCtrl+C", "Copy selected text");
editMenu->Append(wxID_PASTE, "&Paste\tCtrl+V", "Paste contents of clipboard"); this->editMenu->Append(wxID_PASTE, "&Paste\tCtrl+V", "Paste contents of clipboard");
//editMenu->Append(wxID_DELETE, "&Delete\tDel"); //editMenu->Append(wxID_DELETE, "&Delete\tDel");
editMenu->AppendSeparator(); this->editMenu->AppendSeparator();
editMenu->Append(wxID_FIND, "&Find\tCtrl+F"); this->editMenu->Append(wxID_FIND, "&Find\tCtrl+F");
editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R"); this->editMenu->Append(wxID_REPLACE, "&Replace\tCtrl+R");
this->editMenu->AppendSeparator();
editMenu->AppendSeparator(); this->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"); this->editMenu->AppendSeparator();
#ifndef TRAVIS this->editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P");
editMenu->AppendSeparator();
editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P");
#endif
viewMenu->AppendCheckItem(myID_VIEW_WHITESPACE, "Show Invisible Characters\tCtrl+Shift+I", "Toggle visibility of white space characters"); this->viewMenu->AppendCheckItem(myID_VIEW_WHITESPACE, "Show Invisible Characters\tCtrl+Shift+I", "Toggle visibility of white space characters");
viewMenu->AppendCheckItem(myID_VIEW_LINE_ENDINGS, "Show line endings", "Toggle visibility of line ending characters"); this->viewMenu->AppendCheckItem(myID_VIEW_LINE_ENDINGS, "Show line endings", "Toggle visibility of line ending characters");
viewMenu->AppendCheckItem(myID_LINE_WRAP, "Word Wrap", "Toggle wrapping of long lines"); this->viewMenu->AppendCheckItem(myID_LINE_WRAP, "Word Wrap", "Toggle wrapping of long lines");
helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application"); this->helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application");
} }
/** /**

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include "src/widgets/widget.h" #include "src/widgets/widget.h"
#include "src/settings/LangConfig.h"
class TyroMenu : public wxMenuBar { class TyroMenu : public wxMenuBar {
public: public:
@ -13,6 +14,7 @@ public:
void SetIdChecked(int id, bool checked); void SetIdChecked(int id, bool checked);
void SetCurrentLanguage(string lang); void SetCurrentLanguage(string lang);
private: private:
LangConfig *lang_config = nullptr;
wxMenu *fileMenu = nullptr; wxMenu *fileMenu = nullptr;
wxMenu *editMenu = nullptr; wxMenu *editMenu = nullptr;
wxMenu *viewMenu = nullptr; wxMenu *viewMenu = nullptr;
@ -21,4 +23,4 @@ private:
void SetupMainMenus(); void SetupMainMenus();
void SetupLangMenu(); void SetupLangMenu();
void EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable); void EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable);
}; };