Various code cleanup

This commit is contained in:
Timothy Warren 2019-05-17 16:19:42 -04:00
parent c13750b06e
commit f2dc0a9eae
5 changed files with 28 additions and 28 deletions

View File

@ -46,7 +46,7 @@ public:
this->SetVendorName(APP_VENDOR); this->SetVendorName(APP_VENDOR);
// Initialize globals // Initialize globals
this->InitLexerMap(); TyroApp::InitLexerMap();
Glob_config = wxConfigBase::Get(); Glob_config = wxConfigBase::Get();
Glob_menu_bar = new TyroMenu(); Glob_menu_bar = new TyroMenu();
Glob_main_frame = new MainFrame(nullptr, APP_NAME, CalculateWindowSize()); Glob_main_frame = new MainFrame(nullptr, APP_NAME, CalculateWindowSize());
@ -122,7 +122,7 @@ private:
/** /**
* Set up mapping for lexers * Set up mapping for lexers
*/ */
void InitLexerMap() void 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;
@ -167,4 +167,4 @@ private:
}; };
// Set up the main method and event loop // Set up the main method and event loop
IMPLEMENT_APP(TyroApp); wxIMPLEMENT_APP(TyroApp);

View File

@ -7,7 +7,7 @@
LangConfig::LangConfig() LangConfig::LangConfig()
{ {
this->LoadJson(languages_json); this->LoadJson(languages_json);
this->lang = ""; this->language = "";
// "cache" reverse map of languages to their keys // "cache" reverse map of languages to their keys
JsonValue langList = this->GetRoot(); JsonValue langList = this->GetRoot();
@ -62,7 +62,7 @@ string LangConfig::GetLangByFile(wxFileName &fileName)
) )
{ {
this->SetLang(lang); this->SetLang(lang);
return this->lang; return this->language;
} }
// Go to the next pattern for this language // Go to the next pattern for this language
@ -71,7 +71,7 @@ string LangConfig::GetLangByFile(wxFileName &fileName)
} }
this->SetLang(""); this->SetLang("");
return this->lang; return this->language;
} }
/** /**
@ -82,7 +82,7 @@ string LangConfig::GetLangByFile(wxFileName &fileName)
*/ */
JsonValue LangConfig::GetKeywordList(string lang) JsonValue LangConfig::GetKeywordList(string lang)
{ {
if (lang == "none") lang = this->lang; if (lang == "none") lang = this->language;
return this->GetRoot() return this->GetRoot()
.get(lang, JsonValue()) .get(lang, JsonValue())
@ -97,7 +97,7 @@ JsonValue LangConfig::GetKeywordList(string lang)
*/ */
JsonValue LangConfig::GetLexerMap(string lang) JsonValue LangConfig::GetLexerMap(string lang)
{ {
if (lang == "none") lang = this->lang; if (lang == "none") lang = this->language;
return this->GetRoot() return this->GetRoot()
.get(lang, JsonValue()) .get(lang, JsonValue())
@ -112,7 +112,7 @@ JsonValue LangConfig::GetLexerMap(string lang)
*/ */
void LangConfig::SetLang(string lang) void LangConfig::SetLang(string lang)
{ {
this->lang = lang; this->language = lang;
} }
/** /**
@ -120,7 +120,7 @@ void LangConfig::SetLang(string lang)
*/ */
string LangConfig::GetLang() string LangConfig::GetLang()
{ {
return this->lang; return this->language;
} }
/** /**
@ -131,7 +131,7 @@ string LangConfig::GetLang()
string LangConfig::GetCurrentLangName() string LangConfig::GetCurrentLangName()
{ {
return this->GetRoot() return this->GetRoot()
.get(this->lang, JsonValue()) .get(this->language, JsonValue())
.get("name", JsonValue()) .get("name", JsonValue())
.asString(); .asString();
} }

View File

@ -16,6 +16,6 @@ public:
string GetCurrentLangName(); string GetCurrentLangName();
string GetLangByName(string name); string GetLangByName(string name);
private: private:
string lang; string language;
StringMap reverseMap; StringMap reverseMap;
}; };

View File

@ -84,7 +84,7 @@ void EditPane::Highlight(wxString filePath)
* @param string theme * @param string theme
* @return void * @return void
*/ */
void EditPane::ApplyTheme(string lang, string theme) void EditPane::ApplyTheme(const string &lang, const string &theme)
{ {
this->StyleClearAll(); this->StyleClearAll();
@ -138,7 +138,7 @@ void EditPane::ApplyTheme(string lang, string theme)
* @param string [theme] * @param string [theme]
* @return void * @return void
*/ */
void EditPane::ReApplyTheme(string theme) void EditPane::ReApplyTheme(const string &theme)
{ {
this->ApplyTheme(lang_config->GetLangByName(this->GetCurrentLang()), theme); this->ApplyTheme(lang_config->GetLangByName(this->GetCurrentLang()), theme);
} }
@ -302,16 +302,16 @@ void EditPane::OnCharAdded(wxStyledTextEvent& event)
* Iterate through the theme settings and apply them * Iterate through the theme settings and apply them
* *
* @param JsonValue lexer_map - Maps token types to theme colors * @param JsonValue lexer_map - Maps token types to theme colors
* @param int addtoi - Offset for some languages
* @return void * @return void
*/ */
void EditPane::_ApplyTheme(JsonValue &lexer_map) void EditPane::_ApplyTheme(JsonValue &lexer_map)
{ {
// Font setup // Font setup
wxFont *defaultFont = wxFont::New( wxFont defaultFont(
TYRO_DEFAULT_FONT_SIZE, TYRO_DEFAULT_FONT_SIZE,
wxFONTFAMILY_MODERN, wxFONTFAMILY_TELETYPE,
wxFONTFLAG_ANTIALIASED wxFONTFLAG_DEFAULT,
wxFONTWEIGHT_NORMAL
); );
static const wxColor default_background = this->theme_config->GetThemeColor("background", "default"); static const wxColor default_background = this->theme_config->GetThemeColor("background", "default");
@ -334,7 +334,7 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
wxString fontFace; wxString fontFace;
if ( ! Glob_config->Read("global_font", &globalFont)) if ( ! Glob_config->Read("global_font", &globalFont))
{ {
this->StyleSetFont(i, *defaultFont); this->StyleSetFont(i, defaultFont);
} }
else else
{ {
@ -358,11 +358,11 @@ void EditPane::_ApplyTheme(JsonValue &lexer_map)
this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_CIRCLEPLUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_CIRCLEMINUSCONNECTED, "WHITE", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, "BLACK", "BLACK");
this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK"); this->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, "BLACK", "BLACK");
} }
else else
{ {
@ -452,7 +452,7 @@ string EditPane::GetCurrentLang()
* @param string name * @param string name
* @return void * @return void
*/ */
void EditPane::SetCurrentLang(string name) void EditPane::SetCurrentLang(const string &name)
{ {
// Update the current lang in the config // Update the current lang in the config
string langKey = this->lang_config->GetLangByName(name); string langKey = this->lang_config->GetLangByName(name);

View File

@ -7,7 +7,7 @@
class EditPane: public wxStyledTextCtrl class EditPane: public wxStyledTextCtrl
{ {
public: public:
EditPane( explicit EditPane(
wxWindow *parent, wxWindow *parent,
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
const wxPoint &post = wxDefaultPosition, const wxPoint &post = wxDefaultPosition,
@ -19,10 +19,10 @@ public:
void Highlight(wxString filePath); void Highlight(wxString filePath);
bool SaveFile(); bool SaveFile();
bool SaveFile(const wxString &filename); bool SaveFile(const wxString &filename);
void ReApplyTheme(string theme=""); void ReApplyTheme(const string &theme="");
void ApplyTheme(string lang, string theme=""); void ApplyTheme(const string &lang, const string &theme="");
string GetCurrentLang(); string GetCurrentLang();
void SetCurrentLang(string name); void SetCurrentLang(const string &name);
protected: protected:
StringConstMap::iterator lexerMapIt; StringConstMap::iterator lexerMapIt;
LangConfig *lang_config = nullptr; LangConfig *lang_config = nullptr;
@ -31,6 +31,6 @@ protected:
bool FileWritable(); bool FileWritable();
void BindEvents(); void BindEvents();
void OnCharAdded(wxStyledTextEvent &event); void OnCharAdded(wxStyledTextEvent &event);
void SetTheme(string theme_name); // void SetTheme(const string &theme_name);
void _ApplyTheme(JsonValue &lexer_map); void _ApplyTheme(JsonValue &lexer_map);
}; };