Misc code cleanup

This commit is contained in:
Timothy Warren 2019-06-18 11:22:49 -04:00
parent 7635609d13
commit f63cc9df32
14 changed files with 54 additions and 34 deletions

View File

@ -17,7 +17,7 @@ Required packages:
* build-essential * build-essential
* cmake * cmake
* libssh2-1-dev * libssh2-1-dev
* libwxgtk3.0-dev * libwxgtk3.0-dev or libwxgtk3.0-gtk3-dev
After these packages are installed, the project should build with a simple `make` command. After these packages are installed, the project should build with a simple `make` command.
@ -35,7 +35,7 @@ Build the app:
### Windows ### Windows
See the guide for building on Windows: [Windows-Build](./Windows-Build.md) * Todo
## Make commands ## Make commands
Please note that make commands are chainable. For a typical programming loop, `make clean dev run` is very useful. Please note that make commands are chainable. For a typical programming loop, `make clean dev run` is very useful.

View File

@ -68,7 +68,10 @@ public:
*/ */
int OnExit() override int OnExit() override
{ {
wxLogDebug("Closing App...");
// Deallocate config object // Deallocate config object
wxLogDebug("Deleting wxConfigBase");
delete wxConfigBase::Set((wxConfigBase *) nullptr); delete wxConfigBase::Set((wxConfigBase *) nullptr);
return close(true); return close(true);
@ -117,7 +120,7 @@ private:
/** /**
* Set up mapping for lexers * Set up mapping for lexers
*/ */
void static InitLexerMap() void const static InitLexerMap()
{ {
Glob_lexer_map[""] = wxSTC_LEX_NULL; Glob_lexer_map[""] = wxSTC_LEX_NULL;
Glob_lexer_map["batch"] = wxSTC_LEX_BATCH; Glob_lexer_map["batch"] = wxSTC_LEX_BATCH;

View File

@ -4,8 +4,8 @@
#include "Config.h" #include "Config.h"
TyroConfig::TyroConfig() {} TyroConfig::TyroConfig() = default;
TyroConfig::~TyroConfig() {} TyroConfig::~TyroConfig() = default;
void TyroConfig::LoadJson(const char json[]) void TyroConfig::LoadJson(const char json[])
{ {

View File

@ -26,7 +26,10 @@ LangConfig::LangConfig()
/** /**
* Destructor * Destructor
*/ */
LangConfig::~LangConfig() {} LangConfig::~LangConfig()
{
wxLogDebug("LangConfig Destructor Called.");
}
/** /**
* Determine the format of the current file by * Determine the format of the current file by
@ -110,7 +113,7 @@ JsonValue LangConfig::GetLexerMap(string lang)
* @param string lang * @param string lang
* @return void * @return void
*/ */
void LangConfig::SetLang(string lang) void LangConfig::SetLang(const string &lang)
{ {
this->language = lang; this->language = lang;
} }
@ -142,7 +145,7 @@ string LangConfig::GetCurrentLangName()
* @param string name * @param string name
* @return string * @return string
*/ */
string LangConfig::GetLangByName(string name) string LangConfig::GetLangByName(const string &name)
{ {
int count = this->reverseMap.count(name); int count = this->reverseMap.count(name);
return (count > 0) ? this->reverseMap[name] : ""; return (count > 0) ? this->reverseMap[name] : "";

View File

@ -7,14 +7,14 @@ class LangConfig : TyroConfig {
public: public:
LangConfig(); LangConfig();
~LangConfig(); ~LangConfig();
void SetLang(string lang); void SetLang(const string &lang);
string GetLang(); string GetLang();
string GetLangByFile(wxFileName &fileName); string GetLangByFile(wxFileName &fileName);
JsonValue GetKeywordList(string lang="none"); JsonValue GetKeywordList(string lang="none");
JsonValue GetLexerMap(string lang="none"); JsonValue GetLexerMap(string lang="none");
StringMap GetLangList(); StringMap GetLangList();
string GetCurrentLangName(); string GetCurrentLangName();
string GetLangByName(string name); string GetLangByName(const string &name);
private: private:
string language; string language;
StringMap reverseMap; StringMap reverseMap;

View File

@ -17,7 +17,10 @@ ThemeConfig::ThemeConfig()
/** /**
* Destructor * Destructor
*/ */
ThemeConfig::~ThemeConfig() {} ThemeConfig::~ThemeConfig()
{
wxLogDebug("ThemeConfig Destructor Called.");
}
/** /**
* Set the current theme * Set the current theme
@ -58,7 +61,7 @@ JsonValue ThemeConfig::GetTheme()
* @param string key * @param string key
* @return JsonValue * @return JsonValue
*/ */
JsonValue ThemeConfig::GetThemeValue(string type, string key) JsonValue ThemeConfig::GetThemeValue(const string &type, const string &key)
{ {
JsonValue value = this->current_theme JsonValue value = this->current_theme
.get(type, JsonValue()) .get(type, JsonValue())
@ -73,7 +76,7 @@ JsonValue ThemeConfig::GetThemeValue(string type, string key)
* @param key * @param key
* @return * @return
*/ */
wxColor ThemeConfig::GetThemeColor(string type, string key) wxColor ThemeConfig::GetThemeColor(const string &type, const string &key)
{ {
JsonValue color_value = this->GetThemeValue(type, key); JsonValue color_value = this->GetThemeValue(type, key);

View File

@ -12,8 +12,8 @@ public:
~ThemeConfig(); ~ThemeConfig();
bool SetTheme(const string &theme_name); bool SetTheme(const string &theme_name);
JsonValue GetTheme(); JsonValue GetTheme();
JsonValue GetThemeValue(string type, string key); JsonValue GetThemeValue(const string &type, const string &key);
wxColor GetThemeColor(string type, string key); wxColor GetThemeColor(const string &type, const string &key);
private: private:
JsonValue current_theme; JsonValue current_theme;
}; };

View File

@ -48,7 +48,7 @@ EditPane::EditPane(
*/ */
EditPane::~EditPane() EditPane::~EditPane()
{ {
wxLogDebug("Called EditPane Destructor"); wxLogDebug("EditPane Destructor Called.");
delete this->lang_config; delete this->lang_config;
delete this->theme_config; delete this->theme_config;
} }

View File

@ -41,6 +41,7 @@ FilePane::FilePane(
FilePane::~FilePane() FilePane::~FilePane()
{ {
wxLogDebug("FilePane Destructor Called.");
delete this->img_list; delete this->img_list;
} }

View File

@ -57,7 +57,8 @@ MainFrame::~MainFrame()
Glob_status_bar->Destroy(); Glob_status_bar->Destroy();
manager->UnInit();
this->manager->UnInit();
} }
/** /**
@ -682,7 +683,8 @@ void MainFrame::OnToggleLineEndings(wxCommandEvent &event)
void MainFrame::EnableEditControls(bool enable) void MainFrame::EnableEditControls(bool enable)
{ {
// Update menu items // Update menu items
Glob_menu_bar->EnableEditControls(enable); auto menu_bar = (TyroMenu *) this->GetMenuBar();
menu_bar->EnableEditControls(enable);
// Toggle toolbar items // Toggle toolbar items
this->toolBar->EnableTool(wxID_SAVE, enable); this->toolBar->EnableTool(wxID_SAVE, enable);

View File

@ -5,8 +5,14 @@ extern wxConfigBase *Glob_config;
class GeneralPrefPanePage : public wxPanel { class GeneralPrefPanePage : public wxPanel {
public: public:
GeneralPrefPanePage(wxWindow *parent) explicit GeneralPrefPanePage(
: wxPanel(parent) wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL | wxNO_BORDER,
const wxString& name = wxPanelNameStr
) : wxPanel(parent, winid, pos, size, style, name)
{ {
auto BASE_MARGIN = 30; auto BASE_MARGIN = 30;
@ -70,8 +76,9 @@ public:
} }
} }
~GeneralPrefPanePage() ~GeneralPrefPanePage() override
{ {
wxLogDebug("GeneralPrefPanePage Destructor Called.");
wxDELETE(this->showLineNumbers); wxDELETE(this->showLineNumbers);
wxDELETE(this->showIndentGuides); wxDELETE(this->showIndentGuides);
wxDELETE(this->showCodeFolding); wxDELETE(this->showCodeFolding);
@ -83,7 +90,7 @@ public:
* *
* @return bool * @return bool
*/ */
virtual bool TransferDataToWindow() bool TransferDataToWindow() override
{ {
this->showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true)); this->showLineNumbers->SetValue(Glob_config->ReadBool("show_line_numbers", true));
this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false)); this->showIndentGuides->SetValue(Glob_config->ReadBool("show_indent_guides", false));
@ -103,7 +110,7 @@ public:
* *
* @return bool * @return bool
*/ */
virtual bool TransferDataFromWindow() bool TransferDataFromWindow() override
{ {
Glob_config->Write("show_line_numbers", this->showLineNumbers->IsChecked()); Glob_config->Write("show_line_numbers", this->showLineNumbers->IsChecked());
Glob_config->Write("show_indent_guides", this->showIndentGuides->IsChecked()); Glob_config->Write("show_indent_guides", this->showIndentGuides->IsChecked());
@ -132,7 +139,7 @@ private:
class GeneralPrefPane: public wxStockPreferencesPage { class GeneralPrefPane: public wxStockPreferencesPage {
public: public:
GeneralPrefPane() : wxStockPreferencesPage(Kind_General) {} GeneralPrefPane() : wxStockPreferencesPage(Kind_General) {}
virtual wxWindow *CreateWindow(wxWindow *parent) wxWindow *CreateWindow(wxWindow *parent) override
{ {
return new GeneralPrefPanePage(parent); return new GeneralPrefPanePage(parent);
} }
@ -150,7 +157,8 @@ PrefPane::PrefPane()
PrefPane::~PrefPane() PrefPane::~PrefPane()
{ {
//delete this->pref_window; wxLogDebug("PrefPane Destructor Called.");
delete this->pref_window;
} }
void PrefPane::Show(wxWindow *parent) void PrefPane::Show(wxWindow *parent)

View File

@ -36,7 +36,7 @@ TabContainer::TabContainer(
*/ */
TabContainer::~TabContainer() TabContainer::~TabContainer()
{ {
wxLogDebug("TabContainer destructor called"); wxLogDebug("TabContainer Destructor Called.");
} }
/** /**
@ -71,7 +71,7 @@ void TabContainer::AddTab()
* @param wxString filePath * @param wxString filePath
* @return void * @return void
*/ */
void TabContainer::AddTab(wxString filePath) void TabContainer::AddTab(const wxString &filePath)
{ {
wxFileName fileName(filePath); wxFileName fileName(filePath);
@ -104,7 +104,7 @@ void TabContainer::AddTab(wxString filePath)
* *
* @return *EditPane * @return *EditPane
*/ */
EditPane *TabContainer::GetCurrentEditor() EditPane* TabContainer::GetCurrentEditor()
{ {
return (EditPane *) this->GetCurrentPage(); return (EditPane *) this->GetCurrentPage();
} }
@ -115,7 +115,7 @@ EditPane *TabContainer::GetCurrentEditor()
* @param size_t page_idx * @param size_t page_idx
* @return *EditPane * @return *EditPane
*/ */
EditPane *TabContainer::GetEditor(size_t page_idx) EditPane* TabContainer::GetEditor(size_t page_idx)
{ {
return (EditPane *) this->GetPage(page_idx); return (EditPane *) this->GetPage(page_idx);
} }
@ -184,7 +184,7 @@ void TabContainer::OnClosed(wxAuiNotebookEvent &WXUNUSED(event))
void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event)) void TabContainer::OnTabContextMenu(wxAuiNotebookEvent &WXUNUSED(event))
{ {
// Create Menu // Create Menu
wxMenu *contextMenu = new wxMenu(); auto *contextMenu = new wxMenu();
contextMenu->Append(wxID_CLOSE, "&Close\tCtrl+W", "Close the current tab"); 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."); contextMenu->Append(myID_CLOSE_ALL, "C&lose All\tShift+Ctrl+W", "Close all open documents.");
contextMenu->Append(myID_CLOSE_ALL_BUT_THIS, "Close All but this\tCtrl+Shift+Alt+W", "Close all open documents, except the one selected"); contextMenu->Append(myID_CLOSE_ALL_BUT_THIS, "Close All but this\tCtrl+Shift+Alt+W", "Close all open documents, except the one selected");

View File

@ -13,16 +13,16 @@ static long tab_style = wxBORDER_NONE | wxAUI_NB_TAB_SPLIT |wxAUI_NB_TAB_MOVE
class TabContainer: public wxAuiNotebook class TabContainer: public wxAuiNotebook
{ {
public: public:
TabContainer( explicit TabContainer(
wxWindow *parent, wxWindow *parent,
wxWindowID id=wxID_ANY, wxWindowID id=wxID_ANY,
const wxPoint &pos=wxDefaultPosition, const wxPoint &pos=wxDefaultPosition,
const wxSize &size=wxDefaultSize, const wxSize &size=wxDefaultSize,
long style=tab_style long style=tab_style
); );
~TabContainer(); ~TabContainer() override;
void AddTab(); void AddTab();
void AddTab(wxString filePath); void AddTab(const wxString &filePath);
EditPane *GetCurrentEditor(); EditPane *GetCurrentEditor();
EditPane *GetEditor(size_t page_idx); EditPane *GetEditor(size_t page_idx);
void OnCloseAll(wxCommandEvent &event); void OnCloseAll(wxCommandEvent &event);

View File

@ -166,7 +166,7 @@ void TyroMenu::EnableEntireMenu(size_t menuId, wxMenu *menu, bool enable)
*/ */
void TyroMenu::SetCurrentLanguage(string lang) void TyroMenu::SetCurrentLanguage(string lang)
{ {
if (lang == "") if (lang.empty())
{ {
lang = "Plain Text"; lang = "Plain Text";
} }