Lots of refactoring, need to fix a segfault with Close All

This commit is contained in:
Tim Warren 2015-05-07 17:05:27 -04:00
parent 033e7bf229
commit 36e07a9784
14 changed files with 331 additions and 221 deletions

View File

@ -87,8 +87,14 @@ lib: $(OBJECTS) $(BASE_LIB)
run: run:
ifneq ($(OS),Darwin) ifneq ($(OS),Darwin)
./build/Tyro ./$(PROGRAM)
else else
./build/Tyro.app/Contents/MacOS/Tyro
endif
ifeq ($(OS),Darwin)
run-app:
open -a $(PWD)/build/Tyro.app open -a $(PWD)/build/Tyro.app
endif endif

View File

@ -20,11 +20,14 @@ private:
wxConfigBase *Config; wxConfigBase *Config;
//************************************************************** //**************************************************************
#include "widgets/widget.h"
#include "widgets/MainFrame.h"
IMPLEMENT_APP(TyroApp); IMPLEMENT_APP(TyroApp);
// Some global stuff
TyroMenu *mbar;
MainFrame *main_frame;
/** /**
* Start the event loop and create the main window * Start the event loop and create the main window
* *
@ -36,13 +39,14 @@ bool TyroApp::OnInit()
this->SetVendorName(APP_VENDOR); this->SetVendorName(APP_VENDOR);
Config = wxConfigBase::Get(); Config = wxConfigBase::Get();
MainFrame* frame = new MainFrame(0L, APP_NAME); mbar = new TyroMenu();
main_frame = new MainFrame(0L, APP_NAME);
SetTopWindow(frame); SetTopWindow(main_frame);
frame->Layout(); main_frame->Layout();
frame->CenterOnScreen(); main_frame->CenterOnScreen();
frame->Show(true); main_frame->Show(true);
return true; return true;
} }

View File

@ -57,7 +57,7 @@ string LangConfig::GetLangByFile(wxFileName &fileName)
} }
} }
this->SetLang(lang); this->SetLang("");
return this->lang; return this->lang;
} }

View File

@ -1,10 +1,14 @@
/**
* Theme manager
*/
#include "ThemeConfig.h" #include "ThemeConfig.h"
#include <config/themes_json.h> #include <config/themes_json.h>
ThemeConfig::ThemeConfig() ThemeConfig::ThemeConfig()
{ {
this->LoadJson(themes_json); this->LoadJson(themes_json);
this->current_theme = "Solarized"; this->SetTheme("Solarized");
} }
ThemeConfig::~ThemeConfig() {} ThemeConfig::~ThemeConfig() {}

View File

@ -1,8 +1,5 @@
/* /**
* File: ThemeConfig.h * Theme manager
* Author: twarren
*
* Created on May 7, 2015, 9:39 AM
*/ */
#ifndef TYRO_THEME_CONFIG_H #ifndef TYRO_THEME_CONFIG_H

View File

@ -1,4 +1,8 @@
#include "EditPane.h" /**
* The editor widget
*/
#include "widget.h"
EditPane::EditPane( EditPane::EditPane(
wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size
@ -120,8 +124,11 @@ void EditPane::Highlight(wxString filePath)
* @return void * @return void
*/ */
void EditPane::ApplyTheme(string lang, string theme) void EditPane::ApplyTheme(string lang, string theme)
{ {
theme_config->SetTheme(theme); if (theme != "")
{
theme_config->SetTheme(theme);
}
// Get the keywords and mapping for the selected language // Get the keywords and mapping for the selected language
JsonValue lexer_map = lang_config->GetLexerMap(lang); JsonValue lexer_map = lang_config->GetLexerMap(lang);

View File

@ -1,7 +1,6 @@
#ifndef TYROEDIT_PANE_H #ifndef TYROEDIT_PANE_H
#define TYROEDIT_PANE_H #define TYROEDIT_PANE_H
#include "../wx_common.h"
#include "../settings/LangConfig.h" #include "../settings/LangConfig.h"
#include "../settings/ThemeConfig.h" #include "../settings/ThemeConfig.h"
@ -22,7 +21,7 @@ public:
void Highlight(wxString filePath); void Highlight(wxString filePath);
bool SaveFile(); bool SaveFile();
bool SaveFile(const wxString &filename); bool SaveFile(const wxString &filename);
void ApplyTheme(string lang, string theme="Solarized"); void ApplyTheme(string lang, string theme="");
private: private:
StringConstMap lexerMap; StringConstMap lexerMap;
StringConstMap::iterator lexerMapIt; StringConstMap::iterator lexerMapIt;

View File

@ -1,7 +1,10 @@
/** /**
* Main Application Frame * Main Application Frame
*/ */
#include "MainFrame.h" #include "widget.h"
extern TyroMenu *mbar;
static TabContainer *notebook;
MainFrame::MainFrame(wxFrame *frame, const wxString &title) MainFrame::MainFrame(wxFrame *frame, const wxString &title)
: wxFrame(frame, -1, title) : wxFrame(frame, -1, title)
@ -14,7 +17,11 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
this->SetIcon(app_icon); this->SetIcon(app_icon);
// Create menus and bars // Create menus and bars
this->SetupMenu(); #ifdef __WXMAC__
wxMenuBar::MacSetCommonMenuBar(mbar);
#endif // __WXMAC__
SetMenuBar(mbar);
this->SetupStatusBar(); this->SetupStatusBar();
this->SetupToolbar(); this->SetupToolbar();
@ -35,7 +42,11 @@ MainFrame::MainFrame(wxFrame *frame, const wxString &title)
SetSizerAndFit(base_sizer); SetSizerAndFit(base_sizer);
} }
MainFrame::~MainFrame() {} MainFrame::~MainFrame()
{
wxLogDebug("Main Frame Destructor Called.");
//delete notebook;
}
void MainFrame::SetupStatusBar() void MainFrame::SetupStatusBar()
{ {
@ -96,68 +107,6 @@ void MainFrame::SetupToolbar()
toolBar->Realize(); toolBar->Realize();
} }
/**
* Create the main menu
*
* @return void
*/
void MainFrame::SetupMenu()
{
// create a menu bar
this->mbar = new wxMenuBar();
// Create Base menus
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, "&New\tCtrl+N", "Create a new file");
fileMenu->AppendSeparator();
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, "&Close\tCtrl+W", "Close the current document");
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");
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, "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->Append(wxID_REPLACE, "&Replace\tCtrl+R");
//editMenu->AppendSeparator();
//editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P");
//editMenu->AppendSeparator();
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");
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");
helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application");
// Add the menus to the menubar
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);
#endif // __WXMAC__
SetMenuBar(mbar);
}
/** /**
* Bind event handlers * Bind event handlers
* *
@ -171,7 +120,7 @@ void MainFrame::BindEvents()
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSave, this, wxID_SAVE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSave, this, wxID_SAVE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSaveAs, this, wxID_SAVEAS); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSaveAs, this, wxID_SAVEAS);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnCloseTab, this, wxID_CLOSE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnCloseTab, this, wxID_CLOSE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnCloseAll, this, myID_CLOSE_ALL); Bind(wxEVT_COMMAND_MENU_SELECTED, &TabContainer::OnCloseAll, notebook, myID_CLOSE_ALL);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT);
// Edit Menu Events // Edit Menu Events
@ -188,12 +137,7 @@ void MainFrame::BindEvents()
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleWhitespace, this, myID_VIEW_WHITESPACE);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleLineWrap, this, myID_LINE_WRAP); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleLineWrap, this, myID_LINE_WRAP);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleLineEndings, this, myID_VIEW_LINE_ENDINGS); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnToggleLineEndings, this, myID_VIEW_LINE_ENDINGS);
// Notebook Events
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &MainFrame::OnClose, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &MainFrame::OnClosed, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_TAB_RIGHT_DOWN, &MainFrame::OnTabContextMenu, this, wxID_ANY);
// Find/Replace Events // Find/Replace Events
Bind(wxEVT_FIND, &MainFrame::OnFindDialog, this, wxID_ANY); Bind(wxEVT_FIND, &MainFrame::OnFindDialog, this, wxID_ANY);
Bind(wxEVT_FIND_NEXT, &MainFrame::OnFindDialog, this, wxID_ANY); Bind(wxEVT_FIND_NEXT, &MainFrame::OnFindDialog, this, wxID_ANY);
@ -240,60 +184,7 @@ void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event))
notebook->AddTab(filelist[i]); notebook->AddTab(filelist[i]);
} }
this->EnableEditControls(true); //this->EnableEditControls(true);
}
/**
* Event handler for file saving checks on tab close
*
* @param wxAuiNotebookEvent& event
* @return void
*/
void MainFrame::OnClose(wxAuiNotebookEvent &event)
{
int current_tab = notebook->GetSelection();
EditPane *editor = notebook->GetCurrentEditor();
// Sanity check
if (current_tab == -1) return;
if (editor->IsModified())
{
int Msgbox_Choice = wxMessageBox(
"File has not been saved, save file before closing?",
"Modified File",
wxYES_NO | wxCANCEL | wxICON_QUESTION,
this
);
if (Msgbox_Choice == wxCANCEL)
{
return event.Veto();
}
else if (Msgbox_Choice == wxYES)
{
editor->SaveFile();
if (editor->IsModified())
{
wxMessageBox(TYRO_SAVE_ERROR, TYRO_SAVE_ERROR_CAPTION, wxOK | wxICON_EXCLAMATION);
return event.Veto();
}
}
};
}
/**
* Event handler triggered after a tab is closed
*
* @param WXUNUSED
* @return void
*/
void MainFrame::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{
if (notebook->GetPageCount() == 0)
{
this->EnableEditControls(false);
}
} }
/** /**
@ -615,59 +506,10 @@ void MainFrame::OnToggleLineEndings(wxCommandEvent &event)
*/ */
void MainFrame::EnableEditControls(bool enable) void MainFrame::EnableEditControls(bool enable)
{ {
this->fileMenu->Enable(wxID_SAVE, enable); mbar->EnableEditControls(enable);
this->fileMenu->Enable(wxID_SAVEAS, enable);
this->fileMenu->Enable(wxID_CLOSE, enable);
this->fileMenu->Enable(myID_CLOSE_ALL, enable);
// Enable/disable top level menus
this->EnableEntireMenu(myEDIT_MENU, this->editMenu, enable);
this->EnableEntireMenu(myVIEW_MENU, this->viewMenu, enable);
this->EnableEntireMenu(myLANG_MENU, this->langMenu, enable);
this->toolBar->EnableTool(wxID_SAVE, enable); this->toolBar->EnableTool(wxID_SAVE, enable);
this->toolBar->EnableTool(wxID_CLOSE, enable); this->toolBar->EnableTool(wxID_CLOSE, enable);
this->toolBar->EnableTool(wxID_COPY, enable); this->toolBar->EnableTool(wxID_COPY, enable);
this->toolBar->EnableTool(wxID_CUT, enable); this->toolBar->EnableTool(wxID_CUT, enable);
this->toolBar->EnableTool(wxID_PASTE, enable); this->toolBar->EnableTool(wxID_PASTE, enable);
} }
/**
* Enable/disable all the items in the menu, for environments
* that don't properly support disabling the menu by the parent label (like Ubuntu's Unity)
*
* @param size_t menuId
* @param wxMenu* menu
* @param bool enable
* @return void
*/
void MainFrame::EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable)
{
// Toggle the top of the menu
this->mbar->EnableTop(menuId, enable);
// Toggle the rest of the items in the menu
wxMenuItemList list = menu->GetMenuItems();
wxMenuItemList::iterator iter;
for(iter = list.begin(); iter != list.end(); ++iter)
{
wxMenuItem *current = *iter;
current->Enable(enable);
}
}
/**
* Displays a context menu on the current tab
*
* @return void
*/
void MainFrame::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
{
// Create Menu
wxMenu *contextMenu = new wxMenu();
contextMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current tab");
contextMenu->Append(myID_CLOSE_ALL, "C&lose All\tShift+Ctrl+W", "Close all open documents.");
this->PopupMenu(contextMenu);
}

View File

@ -5,46 +5,31 @@
#ifndef TYROMAIN_H #ifndef TYROMAIN_H
#define TYROMAIN_H #define TYROMAIN_H
#include "../wx_common.h"
#include <wx/cmdline.h> #include <wx/cmdline.h>
#include <wx/config.h> #include <wx/config.h>
#include <wx/aboutdlg.h> #include <wx/aboutdlg.h>
#include <wx/fdrepdlg.h> #include <wx/fdrepdlg.h>
#include "TabContainer.h" #include "TabContainer.h"
class MainFrame: public wxFrame class MainFrame: public wxFrame
{ {
friend class TabContainer;
public: public:
MainFrame(wxFrame *frame, const wxString &title); MainFrame(wxFrame *frame, const wxString &title);
~MainFrame(); ~MainFrame();
void EnableEditControls(bool enable=true);
private: private:
TabContainer *notebook;
wxToolBar *toolBar; wxToolBar *toolBar;
wxMenuBar *mbar;
wxMenu *fileMenu;
wxMenu *editMenu;
wxMenu *viewMenu;
wxMenu *langMenu;
wxMenu *helpMenu;
wxFindReplaceData *findReplaceData; wxFindReplaceData *findReplaceData;
wxFindReplaceDialog *findDlg; wxFindReplaceDialog *findDlg;
wxFindReplaceDialog *replaceDlg; wxFindReplaceDialog *replaceDlg;
void SetupMenu();
void SetupToolbar(); void SetupToolbar();
void SetupStatusBar(); void SetupStatusBar();
void BindEvents(); void BindEvents();
void EnableEditControls(bool enable=true);
void EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable=true);
// Main Menu Event handlers // Main Menu Event handlers
void OnNew(wxCommandEvent &event); void OnNew(wxCommandEvent &event);
void OnOpen(wxCommandEvent &event); void OnOpen(wxCommandEvent &event);
void OnClose(wxAuiNotebookEvent &event);
void OnCloseAll(wxCommandEvent &event); void OnCloseAll(wxCommandEvent &event);
void OnClosed(wxAuiNotebookEvent &event);
void OnFileClose(wxCommandEvent &event); void OnFileClose(wxCommandEvent &event);
void OnSave(wxCommandEvent &event); void OnSave(wxCommandEvent &event);
void OnSaveAs(wxCommandEvent &event); void OnSaveAs(wxCommandEvent &event);
@ -66,9 +51,6 @@ class MainFrame: public wxFrame
void OnCloseTab(wxCommandEvent &event); void OnCloseTab(wxCommandEvent &event);
void OnQuit(wxCommandEvent &event); void OnQuit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event); void OnAbout(wxCommandEvent &event);
// Tab Context Menu Event handlers
void OnTabContextMenu(wxAuiNotebookEvent &event);
}; };

View File

@ -2,8 +2,9 @@
* Wrapper around wxAuiNotebook * Wrapper around wxAuiNotebook
*/ */
#include "TabContainer.h" #include "widget.h"
extern MainFrame *main_frame;
static unsigned long untitled_document_count = 0; static unsigned long untitled_document_count = 0;
TabContainer::TabContainer( TabContainer::TabContainer(
@ -14,9 +15,16 @@ TabContainer::TabContainer(
long style long style
) : wxAuiNotebook(parent, id, pos, size, style) ) : wxAuiNotebook(parent, id, pos, size, style)
{ {
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &TabContainer::OnClose, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_TAB_RIGHT_DOWN, &TabContainer::OnTabContextMenu, this, wxID_ANY);
Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGED, &TabContainer::OnTabSwitch, this, wxID_ANY);
} }
TabContainer::~TabContainer() {} TabContainer::~TabContainer()
{
wxLogDebug("TabContainer destructor called");
}
/** /**
* Add a new blank document * Add a new blank document
@ -69,4 +77,107 @@ void TabContainer::AddTab(wxString filePath)
EditPane *TabContainer::GetCurrentEditor() EditPane *TabContainer::GetCurrentEditor()
{ {
return (EditPane *) this->GetCurrentPage(); return (EditPane *) this->GetCurrentPage();
}
/**
* Get the EditPane control in the specified tab
*
* @param size_t page_idx
* @return *EditPane
*/
EditPane *TabContainer::GetEditor(size_t page_idx)
{
return (EditPane *) this->GetPage(page_idx);
}
/**
* Event handler for file saving checks on tab close
*
* @param wxAuiNotebookEvent& event
* @return void
*/
void TabContainer::OnClose(wxAuiNotebookEvent &event)
{
int current_tab = this->GetSelection();
EditPane *editor = this->GetCurrentEditor();
// Sanity check
if (current_tab == -1) return;
if (editor->IsModified())
{
int Msgbox_Choice = wxMessageBox(
"File has not been saved, save file before closing?",
"Modified File",
wxYES_NO | wxCANCEL | wxICON_QUESTION,
this
);
if (Msgbox_Choice == wxCANCEL)
{
return event.Veto();
}
else if (Msgbox_Choice == wxYES)
{
editor->SaveFile();
if (editor->IsModified())
{
wxMessageBox(TYRO_SAVE_ERROR, TYRO_SAVE_ERROR_CAPTION, wxOK | wxICON_EXCLAMATION);
return event.Veto();
}
}
};
}
/**
* Event handler triggered after a tab is closed
*
* @param WXUNUSED
* @return void
*/
void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
{
if (this->GetPageCount() == 0)
{
main_frame->EnableEditControls(false);
}
}
/**
* Displays a context menu on the current tab
*
* @return void
*/
void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
{
// Create Menu
wxMenu *contextMenu = new wxMenu();
contextMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current tab");
contextMenu->Append(myID_CLOSE_ALL, "C&lose All\tShift+Ctrl+W", "Close all open documents.");
this->PopupMenu(contextMenu);
}
/**
* Close all the open tabs
*
* @return void
*/
void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event))
{
this->DeleteAllPages();
main_frame->EnableEditControls(false);
}
/**
* Update menu state when switching tabs
*
* @param wxAuiNotebookEvent& event
* @return void
*/
void TabContainer::OnTabSwitch(wxAuiNotebookEvent &WXUNUSED(event))
{
//EditPane *editor = this->GetEditor(event.GetSelection());
// @TODO: Update menu item checkboxes based on the state of the current editor
} }

View File

@ -5,12 +5,10 @@
#ifndef TABCONTAINER_H #ifndef TABCONTAINER_H
#define TABCONTAINER_H #define TABCONTAINER_H
#include "../wx_common.h" #include "EditPane.h"
#include "MainFrame.h"
#include <wx/aui/aui.h> #include <wx/aui/aui.h>
#include <wx/filename.h> #include <wx/filename.h>
#include "EditPane.h"
static long tab_style = wxBORDER_NONE | wxAUI_NB_TAB_SPLIT |wxAUI_NB_TAB_MOVE static long tab_style = wxBORDER_NONE | wxAUI_NB_TAB_SPLIT |wxAUI_NB_TAB_MOVE
| wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON
@ -30,7 +28,13 @@ public:
void AddTab(); void AddTab();
void AddTab(wxString filePath); void AddTab(wxString filePath);
EditPane *GetCurrentEditor(); EditPane *GetCurrentEditor();
EditPane *GetEditor(size_t page_idx);
void OnCloseAll(wxCommandEvent &event);
private: private:
void OnTabSwitch(wxAuiNotebookEvent &event);
void OnClose(wxAuiNotebookEvent &event);
void OnClosed(wxAuiNotebookEvent &event);
void OnTabContextMenu(wxAuiNotebookEvent &event);
}; };
#endif /* TABCONTAINER_H */ #endif /* TABCONTAINER_H */

108
src/widgets/TyroMenu.cpp Normal file
View File

@ -0,0 +1,108 @@
#include "widget.h"
TyroMenu::TyroMenu()
{
fileMenu = new wxMenu();
editMenu = new wxMenu();
viewMenu = new wxMenu();
langMenu = new wxMenu();
helpMenu = new wxMenu();
this->SetupMainMenus();
// Add the menus to the menubar
this->Insert(myFILE_MENU, fileMenu, "&File");
this->Insert(myEDIT_MENU, editMenu, "&Edit");
this->Insert(myVIEW_MENU, viewMenu, "&View");
this->Insert(myLANG_MENU, langMenu, "&Language");
this->Insert(myHELP_MENU, helpMenu, "&Help");
}
TyroMenu::~TyroMenu()
{
wxLogDebug("TyroMenu Destructor Called.");
//delete fileMenu;
//delete editMenu;
//delete viewMenu;
//delete langMenu;
//delete helpMenu;
}
void TyroMenu::SetupMainMenus()
{
// Add items to top-level menus
fileMenu->Append(wxID_NEW, "&New\tCtrl+N", "Create a new file");
fileMenu->AppendSeparator();
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, "&Close\tCtrl+W", "Close the current document");
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");
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, "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->Append(wxID_REPLACE, "&Replace\tCtrl+R");
//editMenu->AppendSeparator();
//editMenu->Append(wxID_PREFERENCES, "&Preferences\tCtrl+P");
//editMenu->AppendSeparator();
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");
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");
helpMenu->Append(wxID_ABOUT, "&About...\tF1", "Show info about this application");
}
void TyroMenu::SetupLangMenu()
{
}
void TyroMenu::EnableEditControls(bool enable)
{
this->fileMenu->Enable(wxID_SAVE, enable);
this->fileMenu->Enable(wxID_SAVEAS, enable);
this->fileMenu->Enable(wxID_CLOSE, enable);
this->fileMenu->Enable(myID_CLOSE_ALL, enable);
// Enable/disable top level menus
this->EnableEntireMenu(myEDIT_MENU, this->editMenu, enable);
this->EnableEntireMenu(myVIEW_MENU, this->viewMenu, enable);
this->EnableEntireMenu(myLANG_MENU, this->langMenu, enable);
}
/**
* Enable/disable all the items in the menu, for environments
* that don't properly support disabling the menu by the parent label (like Ubuntu's Unity)
*
* @param size_t menuId
* @param wxMenu* menu
* @param bool enable
* @return void
*/
void TyroMenu::EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable)
{
// Toggle the top of the menu
this->EnableTop(menuId, enable);
// Toggle the rest of the items in the menu
wxMenuItemList list = menu->GetMenuItems();
wxMenuItemList::iterator iter;
for(iter = list.begin(); iter != list.end(); ++iter)
{
wxMenuItem *current = *iter;
current->Enable(enable);
}
}

28
src/widgets/TyroMenu.h Normal file
View File

@ -0,0 +1,28 @@
/*
* File: TyroMenu.h
* Author: twarren
*
* Created on May 7, 2015, 3:10 PM
*/
#ifndef TYRO_MENU_H
#define TYRO_MENU_H
class TyroMenu : public wxMenuBar {
public:
TyroMenu();
~TyroMenu();
void EnableEditControls(bool enable);
private:
wxMenu *fileMenu;
wxMenu *editMenu;
wxMenu *viewMenu;
wxMenu *langMenu;
wxMenu *helpMenu;
void SetupMainMenus();
void SetupLangMenu();
void EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable);
};
#endif /* TYRO_MENU_H */

18
src/widgets/widget.h Normal file
View File

@ -0,0 +1,18 @@
/*
* File: widget.h
* Author: twarren
*
* Created on May 7, 2015, 2:35 PM
*/
#ifndef TYRO_WIDGET_H
#define TYRO_WIDGET_H
#include "../wx_common.h"
#include "TyroMenu.h"
#include "EditPane.h"
#include "TabContainer.h"
#include "MainFrame.h"
#endif /* TYRO_WIDGET_H */