Refactor includes to be more sane

This commit is contained in:
Tim Warren 2015-07-07 10:01:17 -04:00
parent 2d4bc24dd6
commit 37fbde33e3
24 changed files with 226 additions and 142 deletions

View File

@ -2,14 +2,16 @@
* Main application file * Main application file
*/ */
#include "wx_common.h" #include "src/wx_common.h"
#include "widgets/widget.h" #include "src/widgets/widget.h"
#include <wx/app.h> #include <wx/app.h>
#include <wx/sysopt.h> #include <wx/sysopt.h>
#include <wx/vidmode.h> #include <wx/vidmode.h>
#include <wx/display.h> #include <wx/display.h>
#include "src/widgets/MainFrame.h"
// Some global stuff // Some global stuff
wxConfigBase *Glob_config = nullptr; wxConfigBase *Glob_config = nullptr;

View File

@ -1,7 +1,7 @@
#ifndef TYRO_CONFIG_H #ifndef TYRO_CONFIG_H
#define TYRO_CONFIG_H #define TYRO_CONFIG_H
#include "../common.h" #include "src/common.h"
class TyroConfig { class TyroConfig {
public: public:

View File

@ -1,8 +1,8 @@
#ifndef TYRO_LANG_CONFIG_H #ifndef TYRO_LANG_CONFIG_H
#define TYRO_LANG_CONFIG_H #define TYRO_LANG_CONFIG_H
#include "../wx_common.h" #include "src/wx_common.h"
#include "Config.h" #include "src/settings/Config.h"
class LangConfig : TyroConfig { class LangConfig : TyroConfig {
public: public:

View File

@ -5,8 +5,8 @@
#ifndef TYRO_THEME_CONFIG_H #ifndef TYRO_THEME_CONFIG_H
#define TYRO_THEME_CONFIG_H #define TYRO_THEME_CONFIG_H
#include "../wx_common.h" #include "src/wx_common.h"
#include "Config.h" #include "src/settings/Config.h"
class ThemeConfig : TyroConfig { class ThemeConfig : TyroConfig {
public: public:

View File

@ -2,7 +2,7 @@
* The editor widget * The editor widget
*/ */
#include "widget.h" #include "src/widgets/EditPane.h"
extern StringConstMap Glob_lexer_map; extern StringConstMap Glob_lexer_map;
extern wxConfig *Glob_config; extern wxConfig *Glob_config;

View File

@ -1,8 +1,10 @@
#ifndef TYROEDIT_PANE_H #ifndef TYROEDIT_PANE_H
#define TYROEDIT_PANE_H #define TYROEDIT_PANE_H
#include "../settings/LangConfig.h" #include "src/widgets/widget.h"
#include "../settings/ThemeConfig.h" #include "src/settings/LangConfig.h"
#include "src/settings/ThemeConfig.h"
class EditPane: public wxStyledTextCtrl class EditPane: public wxStyledTextCtrl
{ {

View File

@ -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( FilePane::FilePane(
wxWindow* parent, wxWindow* parent,
const wxWindowID id, wxWindowID id,
const wxString &dir,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
long style, long style,
const wxString &filter const wxString &name
) : wxGenericDirCtrl(parent, id, dir, pos, size, style, filter) ) : wxTreeListCtrl(parent, id, pos, size, style, name)
{ {
this->CreateContextMenu(); this->dir = new wxDir();
this->BindEvents(); this->InitImageList();
this->SetImageList(this->img_list);
this->CollapseTree(); this->dir->Open(".");
this->SetDefaultPath(wxStandardPaths::Get().GetDocumentsDir() + "../"); this->AppendColumn("",
this->SetPath(this->GetDefaultPath()); wxCOL_WIDTH_AUTOSIZE,
wxALIGN_LEFT,
wxCOL_RESIZABLE | wxCOL_SORTABLE);
wxTreeListItem root = this->GetRootItem();
} }
/**
* Destructor
*/
FilePane::~FilePane() FilePane::~FilePane()
{ {
wxLogDebug("File Pane Destructor Called.");
delete this->contextMenu;
} }
/** void FilePane::InitImageList()
* Bind event handlers
*
* @return void
*/
void FilePane::BindEvents()
{ {
// Open files on double-click or enter wxSize iconSize = wxArtProvider::GetSizeHint(wxART_LIST);
this->Bind(wxEVT_DIRCTRL_FILEACTIVATED, [=](wxTreeEvent&) {
wxLogDebug("File activated event fired");
this->OpenSelectedFiles();
}, wxID_ANY);
// Context Menu if (iconSize == wxDefaultSize)
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(); iconSize = wxSize(16, 16);
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");
} }
/** this->img_list = new wxImageList(iconSize.x, iconSize.y);
* Open the files that are currently selected in the file pane in the current
* editor window static const char* icons[] =
*
* @return void
*/
void FilePane::OpenSelectedFiles()
{ {
wxArrayString paths; wxART_NORMAL_FILE,
this->GetPaths(paths); wxART_FOLDER,
Glob_main_frame->OpenFiles(paths); wxART_FOLDER_OPEN
this->UnselectAll(); };
for (unsigned n = 0; n < WXSIZEOF(icons); n++)
{
this->img_list->Add(
wxArtProvider::GetIcon(icons[n], wxART_LIST, iconSize)
);
}
} }

View File

@ -1,24 +1,23 @@
#ifndef TYRO_FILE_PANE_H #ifndef TYRO_FILE_PANE_H
#define TYRO_FILE_PANE_H #define TYRO_FILE_PANE_H
class FilePane : public wxGenericDirCtrl { #include "src/widgets/widget.h"
class FilePane : public wxTreeListCtrl {
public: public:
FilePane( FilePane(
wxWindow *parent, wxWindow *parent,
const wxWindowID id = wxID_ANY, wxWindowID id=wxID_ANY,
const wxString &dir = wxDirDialogDefaultFolderStr,
const wxPoint &pos=wxDefaultPosition, const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize, const wxSize &size=wxDefaultSize,
long style = wxDIRCTRL_3D_INTERNAL | wxDIRCTRL_EDIT_LABELS | long style=wxTL_DEFAULT_STYLE,
wxDIRCTRL_SHOW_FILTERS | wxDIRCTRL_MULTIPLE, const wxString &name=wxTreeListCtrlNameStr
const wxString &filter = wxEmptyString
); );
~FilePane(); ~FilePane();
private: private:
wxMenu *contextMenu = nullptr; wxImageList *img_list = nullptr;
void BindEvents(); wxDir *dir = nullptr;
void CreateContextMenu(); void InitImageList();
void OpenSelectedFiles();
}; };
#endif /* TYRO_FILE_PANE_H */ #endif /* TYRO_FILE_PANE_H */

View File

@ -1,7 +1,7 @@
/** /**
* Main Application Frame * Main Application Frame
*/ */
#include "widget.h" #include "src/widgets/MainFrame.h"
// Nasty globals // Nasty globals
extern TyroMenu *Glob_menu_bar; extern TyroMenu *Glob_menu_bar;

View File

@ -5,7 +5,13 @@
#ifndef TYROMAIN_H #ifndef TYROMAIN_H
#define 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 class MainFrame: public wxFrame
{ {

View File

@ -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();
}

View File

@ -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 */

View File

@ -1,4 +1,5 @@
#include "widget.h" #include "src/widgets/PrefPane.h"
#include "src/widgets/MainFrame.h"
extern wxConfigBase *Glob_config; extern wxConfigBase *Glob_config;

View File

@ -5,6 +5,8 @@
#ifndef TYRO_PREF_PANE_H #ifndef TYRO_PREF_PANE_H
#define TYRO_PREF_PANE_H #define TYRO_PREF_PANE_H
#include "src/widgets/widget.h"
class PrefPane { class PrefPane {
public: public:
PrefPane(); PrefPane();

View File

@ -2,11 +2,14 @@
* Wrapper around wxAuiNotebook * Wrapper around wxAuiNotebook
*/ */
#include "widget.h" #include "src/widgets/TabContainer.h"
#include "src/widgets/MainFrame.h"
extern TyroMenu *Glob_menu_bar; extern TyroMenu *Glob_menu_bar;
extern wxStatusBar *Glob_status_bar; extern wxStatusBar *Glob_status_bar;
static MainFrame *parentFrame = nullptr;
static vector<EditPane *> editors; static vector<EditPane *> editors;
static unsigned long untitled_document_count = 0; static unsigned long untitled_document_count = 0;
@ -27,7 +30,7 @@ TabContainer::TabContainer(
long style long style
) : wxAuiNotebook(parent, id, pos, size, 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_CLOSE, &TabContainer::OnClose, this, wxID_ANY);
this->Bind(wxEVT_AUINOTEBOOK_PAGE_CLOSED, &TabContainer::OnClosed, 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) if (this->GetPageCount() == 0)
{ {
this->parent->EnableEditControls(false); parentFrame->EnableEditControls(false);
Glob_status_bar->SetStatusText("", STATUS_CURSOR_LOCATION); Glob_status_bar->SetStatusText("", STATUS_CURSOR_LOCATION);
Glob_status_bar->SetStatusText("", STATUS_CURRENT_LANGUAGE); Glob_status_bar->SetStatusText("", STATUS_CURRENT_LANGUAGE);
} }
@ -203,7 +206,7 @@ void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event)) void TabContainer::OnCloseAll(wxCommandEvent &WXUNUSED(event))
{ {
this->DeleteAllPages(); this->DeleteAllPages();
this->parent->EnableEditControls(false); parentFrame->EnableEditControls(false);
} }
/** /**

View File

@ -5,8 +5,8 @@
#ifndef TABCONTAINER_H #ifndef TABCONTAINER_H
#define TABCONTAINER_H #define TABCONTAINER_H
#include "EditPane.h" #include "src/widgets/TyroMenu.h"
#include "MainFrame.h" #include "src/widgets/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 +30,6 @@ public:
void OnCloseAll(wxCommandEvent &event); void OnCloseAll(wxCommandEvent &event);
void OnCloseAllButThis(wxCommandEvent &event); void OnCloseAllButThis(wxCommandEvent &event);
private: private:
MainFrame *parent = nullptr;
EditPane *NewEditor(); EditPane *NewEditor();
void OnTabSwitch(wxAuiNotebookEvent &event); void OnTabSwitch(wxAuiNotebookEvent &event);
void OnClose(wxAuiNotebookEvent &event); void OnClose(wxAuiNotebookEvent &event);

View File

@ -1,5 +1,5 @@
#include "widget.h" #include "src/widgets/TyroMenu.h"
#include "../settings/LangConfig.h" #include "src/settings/LangConfig.h"
static LangConfig *lang_config = nullptr; static LangConfig *lang_config = nullptr;

View File

@ -4,7 +4,7 @@
#ifndef TYRO_MENU_H #ifndef TYRO_MENU_H
#define TYRO_MENU_H #define TYRO_MENU_H
#include "widget.h" #include "src/widgets/widget.h"
class TyroMenu : public wxMenuBar { class TyroMenu : public wxMenuBar {
public: public:

View File

@ -5,31 +5,21 @@
#define TYRO_WIDGET_H #define TYRO_WIDGET_H
// Common wxWidgets stuff // Common wxWidgets stuff
#include "../wx_common.h" #include "src/wx_common.h"
// Base widgets // Base widgets
#include <wx/aboutdlg.h> #include <wx/aboutdlg.h>
#include <wx/fdrepdlg.h> #include <wx/fdrepdlg.h>
#include <wx/aui/aui.h> #include <wx/aui/aui.h>
#include <wx/stc/stc.h> #include <wx/stc/stc.h>
#include <wx/treectrl.h>
#include <wx/dir.h> #include <wx/dir.h>
#include <wx/dirctrl.h> #include <wx/dirctrl.h>
#include <wx/fontpicker.h> #include <wx/fontpicker.h>
#include <wx/treelist.h>
#ifndef TRAVIS #ifndef TRAVIS
#include <wx/preferences.h> #include <wx/preferences.h>
#endif #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 */ #endif /* TYRO_WIDGET_H */

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "tests/catch.hpp"
#include "../src/settings/Config.h" #include "src/settings/Config.h"
TEST_CASE ("Base config class load json") TEST_CASE ("Base config class load json")
{ {

View File

@ -1,6 +1,6 @@
#include "catch.hpp" #include "tests/catch.hpp"
#include "../src/settings/LangConfig.h" #include "src/settings/LangConfig.h"
TEST_CASE("Language Config Library") TEST_CASE("Language Config Library")
{ {

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "tests/catch.hpp"
#include "../src/base/SFTP.h" #include "src/base/SFTP.h"
TEST_CASE("SFTP Library") TEST_CASE("SFTP Library")
{ {

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "tests/catch.hpp"
#include "../src/settings/ThemeConfig.h" #include "src/settings/ThemeConfig.h"
TEST_CASE("Theme Config Library") TEST_CASE("Theme Config Library")
{ {

View File

@ -1,2 +1,2 @@
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include "catch.hpp" #include "tests/catch.hpp"