From 37fbde33e320a9f45ce8afd74487c6942fd60439 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Tue, 7 Jul 2015 10:01:17 -0400 Subject: [PATCH] Refactor includes to be more sane --- src/TyroApp.cpp | 6 +- src/settings/Config.h | 2 +- src/settings/LangConfig.h | 4 +- src/settings/ThemeConfig.h | 4 +- src/widgets/EditPane.cpp | 2 +- src/widgets/EditPane.h | 6 +- src/widgets/FilePane.cpp | 127 ++++++++++++----------------------- src/widgets/FilePane.h | 25 ++++--- src/widgets/MainFrame.cpp | 2 +- src/widgets/MainFrame.h | 8 ++- src/widgets/OldFilePane.cc | 98 +++++++++++++++++++++++++++ src/widgets/OldFilePane.hh | 25 +++++++ src/widgets/PrefPane.cpp | 3 +- src/widgets/PrefPane.h | 2 + src/widgets/TabContainer.cpp | 11 +-- src/widgets/TabContainer.h | 5 +- src/widgets/TyroMenu.cpp | 4 +- src/widgets/TyroMenu.h | 2 +- src/widgets/widget.h | 14 +--- tests/ConfigTest.cpp | 4 +- tests/LangConfigTest.cpp | 4 +- tests/SFTPest.cpp | 4 +- tests/ThemeConfigTest.cpp | 4 +- tests/main.cpp | 2 +- 24 files changed, 226 insertions(+), 142 deletions(-) create mode 100644 src/widgets/OldFilePane.cc create mode 100644 src/widgets/OldFilePane.hh diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index bca7698..866940e 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -2,14 +2,16 @@ * Main application file */ -#include "wx_common.h" -#include "widgets/widget.h" +#include "src/wx_common.h" +#include "src/widgets/widget.h" #include #include #include #include +#include "src/widgets/MainFrame.h" + // Some global stuff wxConfigBase *Glob_config = nullptr; diff --git a/src/settings/Config.h b/src/settings/Config.h index 1cac70c..18d6c74 100644 --- a/src/settings/Config.h +++ b/src/settings/Config.h @@ -1,7 +1,7 @@ #ifndef TYRO_CONFIG_H #define TYRO_CONFIG_H -#include "../common.h" +#include "src/common.h" class TyroConfig { public: diff --git a/src/settings/LangConfig.h b/src/settings/LangConfig.h index c7c00b7..36428d9 100644 --- a/src/settings/LangConfig.h +++ b/src/settings/LangConfig.h @@ -1,8 +1,8 @@ #ifndef TYRO_LANG_CONFIG_H #define TYRO_LANG_CONFIG_H -#include "../wx_common.h" -#include "Config.h" +#include "src/wx_common.h" +#include "src/settings/Config.h" class LangConfig : TyroConfig { public: diff --git a/src/settings/ThemeConfig.h b/src/settings/ThemeConfig.h index a3ccca2..644cbc4 100644 --- a/src/settings/ThemeConfig.h +++ b/src/settings/ThemeConfig.h @@ -5,8 +5,8 @@ #ifndef TYRO_THEME_CONFIG_H #define TYRO_THEME_CONFIG_H -#include "../wx_common.h" -#include "Config.h" +#include "src/wx_common.h" +#include "src/settings/Config.h" class ThemeConfig : TyroConfig { public: diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index dc5580b..1c25427 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -2,7 +2,7 @@ * The editor widget */ -#include "widget.h" +#include "src/widgets/EditPane.h" extern StringConstMap Glob_lexer_map; extern wxConfig *Glob_config; diff --git a/src/widgets/EditPane.h b/src/widgets/EditPane.h index 3c223a6..9e71248 100644 --- a/src/widgets/EditPane.h +++ b/src/widgets/EditPane.h @@ -1,8 +1,10 @@ #ifndef TYROEDIT_PANE_H #define TYROEDIT_PANE_H -#include "../settings/LangConfig.h" -#include "../settings/ThemeConfig.h" +#include "src/widgets/widget.h" +#include "src/settings/LangConfig.h" +#include "src/settings/ThemeConfig.h" + class EditPane: public wxStyledTextCtrl { diff --git a/src/widgets/FilePane.cpp b/src/widgets/FilePane.cpp index fd154ad..714be97 100644 --- a/src/widgets/FilePane.cpp +++ b/src/widgets/FilePane.cpp @@ -1,98 +1,55 @@ -#include "widget.h" +#include "src/widgets/FilePane.h" -extern MainFrame *Glob_main_frame; - -enum CustomFilePaneEventIds { - myFP_ID_OPEN = (wxID_HIGHEST * 2), - myFP_ID_RENAME, - myFP_ID_DELETE -}; - -/** - * Constructor - * @param parent - * @param id - * @param dir - * @param pos - * @param size - * @param style - * @param filter - */ FilePane::FilePane( wxWindow* parent, - const wxWindowID id, - const wxString &dir, - const wxPoint &pos, - const wxSize &size, - long style, - const wxString &filter -) : wxGenericDirCtrl(parent, id, dir, pos, size, style, filter) + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString &name +) : wxTreeListCtrl(parent, id, pos, size, style, name) { - this->CreateContextMenu(); - this->BindEvents(); + this->dir = new wxDir(); + this->InitImageList(); + this->SetImageList(this->img_list); - this->CollapseTree(); + this->dir->Open("."); - this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir() + "../"); - this->SetPath(this->GetDefaultPath()); + this->AppendColumn("", + wxCOL_WIDTH_AUTOSIZE, + wxALIGN_LEFT, + wxCOL_RESIZABLE | wxCOL_SORTABLE); + + wxTreeListItem root = this->GetRootItem(); } -/** - * Destructor - */ FilePane::~FilePane() { - wxLogDebug("File Pane Destructor Called."); - delete this->contextMenu; -} - -/** - * Bind event handlers - * - * @return void - */ -void FilePane::BindEvents() -{ - // Open files on double-click or enter - this->Bind(wxEVT_DIRCTRL_FILEACTIVATED, [=](wxTreeEvent&) { - wxLogDebug("File activated event fired"); - this->OpenSelectedFiles(); - }, wxID_ANY); - // Context Menu - this->Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, [=](wxTreeEvent&) { - this->PopupMenu(this->contextMenu); - }, wxID_ANY); +} + +void FilePane::InitImageList() +{ + wxSize iconSize = wxArtProvider::GetSizeHint(wxART_LIST); - // Open file(s) - this->Bind(wxEVT_MENU, [=](wxCommandEvent&) { - this->OpenSelectedFiles(); - }, myFP_ID_OPEN); -} - -/** - * Create the filePane Context Menu - * - * @return void - */ -void FilePane::CreateContextMenu() -{ - this->contextMenu = new wxMenu(); - this->contextMenu->Append(myFP_ID_OPEN, "&Open Ctrl+Shift+O", "Open the selected file(s)"); - //this->contextMenu->Append(myFP_ID_RENAME, "&Rename Ctrl+Shift+R", "Rename the selected file"); - //this->contextMenu->Append(myFP_ID_DELETE, "Delete", "Delete the selected file"); -} - -/** - * Open the files that are currently selected in the file pane in the current - * editor window - * - * @return void - */ -void FilePane::OpenSelectedFiles() -{ - wxArrayString paths; - this->GetPaths(paths); - Glob_main_frame->OpenFiles(paths); - this->UnselectAll(); + if (iconSize == wxDefaultSize) + { + iconSize = wxSize(16, 16); + } + + this->img_list = new wxImageList(iconSize.x, iconSize.y); + + static const char* icons[] = + { + wxART_NORMAL_FILE, + wxART_FOLDER, + wxART_FOLDER_OPEN + }; + + for (unsigned n = 0; n < WXSIZEOF(icons); n++) + { + this->img_list->Add( + wxArtProvider::GetIcon(icons[n], wxART_LIST, iconSize) + ); + } } \ No newline at end of file diff --git a/src/widgets/FilePane.h b/src/widgets/FilePane.h index f697802..c452404 100644 --- a/src/widgets/FilePane.h +++ b/src/widgets/FilePane.h @@ -1,24 +1,23 @@ #ifndef TYRO_FILE_PANE_H #define TYRO_FILE_PANE_H -class FilePane : public wxGenericDirCtrl { +#include "src/widgets/widget.h" + +class FilePane : public wxTreeListCtrl { public: FilePane( - wxWindow *parent, - const wxWindowID id = wxID_ANY, - const wxString &dir = wxDirDialogDefaultFolderStr, - const wxPoint &pos = wxDefaultPosition, - const wxSize &size = wxDefaultSize, - long style = wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS | - wxDIRCTRL_SHOW_FILTERS | wxDIRCTRL_MULTIPLE, - const wxString &filter = wxEmptyString + wxWindow *parent, + wxWindowID id=wxID_ANY, + const wxPoint &pos=wxDefaultPosition, + const wxSize &size=wxDefaultSize, + long style=wxTL_DEFAULT_STYLE, + const wxString &name=wxTreeListCtrlNameStr ); ~FilePane(); private: - wxMenu *contextMenu = nullptr; - void BindEvents(); - void CreateContextMenu(); - void OpenSelectedFiles(); + wxImageList *img_list = nullptr; + wxDir *dir = nullptr; + void InitImageList(); }; #endif /* TYRO_FILE_PANE_H */ diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index b960bcb..8af2e27 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -1,7 +1,7 @@ /** * Main Application Frame */ -#include "widget.h" +#include "src/widgets/MainFrame.h" // Nasty globals extern TyroMenu *Glob_menu_bar; diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index fe24b55..5e820c9 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -5,7 +5,13 @@ #ifndef TYROMAIN_H #define TYROMAIN_H -#include "TabContainer.h" +#include "src/widgets/TyroMenu.h" +#include "src/widgets/EditPane.h" +#include "src/widgets/TabContainer.h" +#ifndef TRAVIS +#include "src/widgets/PrefPane.h" +#endif +#include "src/widgets/FilePane.h" class MainFrame: public wxFrame { diff --git a/src/widgets/OldFilePane.cc b/src/widgets/OldFilePane.cc new file mode 100644 index 0000000..fd154ad --- /dev/null +++ b/src/widgets/OldFilePane.cc @@ -0,0 +1,98 @@ +#include "widget.h" + +extern MainFrame *Glob_main_frame; + +enum CustomFilePaneEventIds { + myFP_ID_OPEN = (wxID_HIGHEST * 2), + myFP_ID_RENAME, + myFP_ID_DELETE +}; + +/** + * Constructor + * @param parent + * @param id + * @param dir + * @param pos + * @param size + * @param style + * @param filter + */ +FilePane::FilePane( + wxWindow* parent, + const wxWindowID id, + const wxString &dir, + const wxPoint &pos, + const wxSize &size, + long style, + const wxString &filter +) : wxGenericDirCtrl(parent, id, dir, pos, size, style, filter) +{ + this->CreateContextMenu(); + this->BindEvents(); + + this->CollapseTree(); + + this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir() + "../"); + this->SetPath(this->GetDefaultPath()); +} + +/** + * Destructor + */ +FilePane::~FilePane() +{ + wxLogDebug("File Pane Destructor Called."); + delete this->contextMenu; +} + +/** + * Bind event handlers + * + * @return void + */ +void FilePane::BindEvents() +{ + // Open files on double-click or enter + this->Bind(wxEVT_DIRCTRL_FILEACTIVATED, [=](wxTreeEvent&) { + wxLogDebug("File activated event fired"); + this->OpenSelectedFiles(); + }, wxID_ANY); + + // Context Menu + this->Bind(wxEVT_TREE_ITEM_RIGHT_CLICK, [=](wxTreeEvent&) { + this->PopupMenu(this->contextMenu); + }, wxID_ANY); + + // Open file(s) + this->Bind(wxEVT_MENU, [=](wxCommandEvent&) { + this->OpenSelectedFiles(); + }, myFP_ID_OPEN); +} + +/** + * Create the filePane Context Menu + * + * @return void + */ +void FilePane::CreateContextMenu() +{ + this->contextMenu = new wxMenu(); + this->contextMenu->Append(myFP_ID_OPEN, "&Open Ctrl+Shift+O", "Open the selected file(s)"); + //this->contextMenu->Append(myFP_ID_RENAME, "&Rename Ctrl+Shift+R", "Rename the selected file"); + //this->contextMenu->Append(myFP_ID_DELETE, "Delete", "Delete the selected file"); +} + +/** + * Open the files that are currently selected in the file pane in the current + * editor window + * + * @return void + */ +void FilePane::OpenSelectedFiles() +{ + wxArrayString paths; + this->GetPaths(paths); + Glob_main_frame->OpenFiles(paths); + this->UnselectAll(); +} \ No newline at end of file diff --git a/src/widgets/OldFilePane.hh b/src/widgets/OldFilePane.hh new file mode 100644 index 0000000..f697802 --- /dev/null +++ b/src/widgets/OldFilePane.hh @@ -0,0 +1,25 @@ +#ifndef TYRO_FILE_PANE_H +#define TYRO_FILE_PANE_H + +class FilePane : public wxGenericDirCtrl { +public: + FilePane( + wxWindow *parent, + const wxWindowID id = wxID_ANY, + const wxString &dir = wxDirDialogDefaultFolderStr, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS | + wxDIRCTRL_SHOW_FILTERS | wxDIRCTRL_MULTIPLE, + const wxString &filter = wxEmptyString + ); + ~FilePane(); +private: + wxMenu *contextMenu = nullptr; + void BindEvents(); + void CreateContextMenu(); + void OpenSelectedFiles(); +}; + +#endif /* TYRO_FILE_PANE_H */ + diff --git a/src/widgets/PrefPane.cpp b/src/widgets/PrefPane.cpp index f834f59..8681f74 100644 --- a/src/widgets/PrefPane.cpp +++ b/src/widgets/PrefPane.cpp @@ -1,4 +1,5 @@ -#include "widget.h" +#include "src/widgets/PrefPane.h" +#include "src/widgets/MainFrame.h" extern wxConfigBase *Glob_config; diff --git a/src/widgets/PrefPane.h b/src/widgets/PrefPane.h index 9efd6bd..cd4d244 100644 --- a/src/widgets/PrefPane.h +++ b/src/widgets/PrefPane.h @@ -5,6 +5,8 @@ #ifndef TYRO_PREF_PANE_H #define TYRO_PREF_PANE_H +#include "src/widgets/widget.h" + class PrefPane { public: PrefPane(); diff --git a/src/widgets/TabContainer.cpp b/src/widgets/TabContainer.cpp index 48ca4af..c33b798 100644 --- a/src/widgets/TabContainer.cpp +++ b/src/widgets/TabContainer.cpp @@ -2,11 +2,14 @@ * Wrapper around wxAuiNotebook */ -#include "widget.h" +#include "src/widgets/TabContainer.h" +#include "src/widgets/MainFrame.h" extern TyroMenu *Glob_menu_bar; extern wxStatusBar *Glob_status_bar; +static MainFrame *parentFrame = nullptr; + static vector editors; static unsigned long untitled_document_count = 0; @@ -27,7 +30,7 @@ TabContainer::TabContainer( long style ) : wxAuiNotebook(parent, id, pos, size, style) { - this->parent = (MainFrame *) parent; + parentFrame = (MainFrame *) parent; this->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSE, &TabContainer::OnClose, this, wxID_ANY); this->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, this, wxID_ANY); @@ -173,7 +176,7 @@ void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event)) { if (this->GetPageCount() == 0) { - this->parent->EnableEditControls(false); + parentFrame->EnableEditControls(false); Glob_status_bar->SetStatusText("", STATUS_CURSOR_LOCATION); Glob_status_bar->SetStatusText("", STATUS_CURRENT_LANGUAGE); } @@ -203,7 +206,7 @@ void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event)) void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event)) { this->DeleteAllPages(); - this->parent->EnableEditControls(false); + parentFrame->EnableEditControls(false); } /** diff --git a/src/widgets/TabContainer.h b/src/widgets/TabContainer.h index 10866dc..f0f0f20 100644 --- a/src/widgets/TabContainer.h +++ b/src/widgets/TabContainer.h @@ -5,8 +5,8 @@ #ifndef TABCONTAINER_H #define TABCONTAINER_H -#include "EditPane.h" -#include "MainFrame.h" +#include "src/widgets/TyroMenu.h" +#include "src/widgets/EditPane.h" static long tab_style = wxBORDER_NONE | wxAUI_NB_TAB_SPLIT |wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON @@ -30,7 +30,6 @@ public: void OnCloseAll(wxCommandEvent &event); void OnCloseAllButThis(wxCommandEvent &event); private: - MainFrame *parent = nullptr; EditPane *NewEditor(); void OnTabSwitch(wxAuiNotebookEvent &event); void OnClose(wxAuiNotebookEvent &event); diff --git a/src/widgets/TyroMenu.cpp b/src/widgets/TyroMenu.cpp index 8e66161..4d83062 100644 --- a/src/widgets/TyroMenu.cpp +++ b/src/widgets/TyroMenu.cpp @@ -1,5 +1,5 @@ -#include "widget.h" -#include "../settings/LangConfig.h" +#include "src/widgets/TyroMenu.h" +#include "src/settings/LangConfig.h" static LangConfig *lang_config = nullptr; diff --git a/src/widgets/TyroMenu.h b/src/widgets/TyroMenu.h index 3074635..5f18125 100644 --- a/src/widgets/TyroMenu.h +++ b/src/widgets/TyroMenu.h @@ -4,7 +4,7 @@ #ifndef TYRO_MENU_H #define TYRO_MENU_H -#include "widget.h" +#include "src/widgets/widget.h" class TyroMenu : public wxMenuBar { public: diff --git a/src/widgets/widget.h b/src/widgets/widget.h index beb028e..ba9b12d 100644 --- a/src/widgets/widget.h +++ b/src/widgets/widget.h @@ -5,31 +5,21 @@ #define TYRO_WIDGET_H // Common wxWidgets stuff -#include "../wx_common.h" +#include "src/wx_common.h" // Base widgets #include #include #include #include -#include #include #include #include +#include #ifndef TRAVIS #include #endif -// Tyro includes -#include "TyroMenu.h" -#include "EditPane.h" -#include "TabContainer.h" -#include "MainFrame.h" -#ifndef TRAVIS -#include "PrefPane.h" -#endif -#include "FilePane.h" - #endif /* TYRO_WIDGET_H */ diff --git a/tests/ConfigTest.cpp b/tests/ConfigTest.cpp index 3d57056..115cfba 100644 --- a/tests/ConfigTest.cpp +++ b/tests/ConfigTest.cpp @@ -1,5 +1,5 @@ -#include "catch.hpp" -#include "../src/settings/Config.h" +#include "tests/catch.hpp" +#include "src/settings/Config.h" TEST_CASE ("Base config class load json") { diff --git a/tests/LangConfigTest.cpp b/tests/LangConfigTest.cpp index 600af28..eb68aa6 100644 --- a/tests/LangConfigTest.cpp +++ b/tests/LangConfigTest.cpp @@ -1,6 +1,6 @@ -#include "catch.hpp" -#include "../src/settings/LangConfig.h" +#include "tests/catch.hpp" +#include "src/settings/LangConfig.h" TEST_CASE("Language Config Library") { diff --git a/tests/SFTPest.cpp b/tests/SFTPest.cpp index 8c7b8eb..ae81e2e 100644 --- a/tests/SFTPest.cpp +++ b/tests/SFTPest.cpp @@ -1,5 +1,5 @@ -#include "catch.hpp" -#include "../src/base/SFTP.h" +#include "tests/catch.hpp" +#include "src/base/SFTP.h" TEST_CASE("SFTP Library") { diff --git a/tests/ThemeConfigTest.cpp b/tests/ThemeConfigTest.cpp index 634ce06..2ce4791 100644 --- a/tests/ThemeConfigTest.cpp +++ b/tests/ThemeConfigTest.cpp @@ -1,5 +1,5 @@ -#include "catch.hpp" -#include "../src/settings/ThemeConfig.h" +#include "tests/catch.hpp" +#include "src/settings/ThemeConfig.h" TEST_CASE("Theme Config Library") { diff --git a/tests/main.cpp b/tests/main.cpp index 063e878..59b4cf0 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,2 +1,2 @@ #define CATCH_CONFIG_MAIN -#include "catch.hpp" \ No newline at end of file +#include "tests/catch.hpp" \ No newline at end of file