Make Config class more generic

This commit is contained in:
Tim Warren 2015-04-21 09:55:28 -04:00
parent 09a7095f74
commit c849b906cb
4 changed files with 27 additions and 27 deletions

View File

@ -4,12 +4,12 @@
#include "Config.h" #include "Config.h"
TyroConfig::TyroConfig() TyroConfig::TyroConfig() {}
TyroConfig::~TyroConfig() {}
void TyroConfig::LoadJson(const char json[])
{ {
// Defines languages_json string json_string(json);
// Generated on compile from languages.json
#include "../../config/languages_json.h"
string json_string(languages_json);
if ( ! reader.parse(json_string, default_root)) if ( ! reader.parse(json_string, default_root))
{ {
@ -17,22 +17,7 @@ TyroConfig::TyroConfig()
} }
} }
TyroConfig::~TyroConfig()
{
}
JsonValue TyroConfig::GetRoot() JsonValue TyroConfig::GetRoot()
{ {
return default_root; return default_root;
}
JsonValue TyroConfig::GetLang(string name)
{
return default_root.get(name, JsonValue());
}
JsonValue TyroConfig::GetLangKeywords(string name)
{
return this->GetLang(name).get("keywords", JsonValue());
} }

View File

@ -13,8 +13,7 @@ public:
TyroConfig(); TyroConfig();
~TyroConfig(); ~TyroConfig();
JsonValue GetRoot(); JsonValue GetRoot();
JsonValue GetLang(string name); void LoadJson(const char json[]);
JsonValue GetLangKeywords(string name);
private: private:
JsonValue default_root; JsonValue default_root;
JsonReader reader; JsonReader reader;

View File

@ -5,7 +5,13 @@ EditPane::EditPane(
const wxSize &size, long style const wxSize &size, long style
) : wxStyledTextCtrl (parent, id, pos, size, style) ) : wxStyledTextCtrl (parent, id, pos, size, style)
{ {
config = new TyroConfig(); #include "../../config/languages_json.h"
lang_config = new TyroConfig();
lang_config->LoadJson(languages_json);
#include "../../config/themes_json.h"
theme_config = new TyroConfig();
theme_config->LoadJson(themes_json);
lexerMap["batch"] = wxSTC_LEX_BATCH; lexerMap["batch"] = wxSTC_LEX_BATCH;
lexerMap["caml"] = wxSTC_LEX_CAML; lexerMap["caml"] = wxSTC_LEX_CAML;
@ -27,7 +33,8 @@ EditPane::EditPane(
EditPane::~EditPane() EditPane::~EditPane()
{ {
delete config; delete lang_config;
delete theme_config;
} }
/** /**
@ -78,7 +85,7 @@ void EditPane::Highlight(wxString filePath)
this->SetProperty("font.quality", "3"); // LCD Optimized this->SetProperty("font.quality", "3"); // LCD Optimized
// Get the list of keywords for the current language // Get the list of keywords for the current language
JsonValue keywords_array = config->GetLangKeywords(lang); JsonValue keywords_array = this->GetKeywordList(lang);
// Make sure every background is the same color! // Make sure every background is the same color!
for(int i = 0; i <= wxSTC_STYLE_MAX; i++) for(int i = 0; i <= wxSTC_STYLE_MAX; i++)
@ -196,7 +203,7 @@ bool EditPane::Load(wxString filePath)
*/ */
string EditPane::GetLangByFile() string EditPane::GetLangByFile()
{ {
JsonValue langList = config->GetRoot(); JsonValue langList = lang_config->GetRoot();
JsonValue::iterator it; JsonValue::iterator it;
wxString curr_file = this->fileName.GetFullName(); wxString curr_file = this->fileName.GetFullName();
@ -344,3 +351,10 @@ void EditPane::OnMarginClick(wxStyledTextEvent& event)
} }
} }
} }
JsonValue EditPane::GetKeywordList(string lang)
{
return lang_config->GetRoot()
.get(lang, JsonValue())
.get("keywords", JsonValue());
}

View File

@ -31,7 +31,8 @@ public:
private: private:
StringConstMap lexerMap; StringConstMap lexerMap;
StringConstMap::iterator lexerMapIt; StringConstMap::iterator lexerMapIt;
TyroConfig *config; TyroConfig *lang_config;
TyroConfig *theme_config;
enum enum
{ {
MARGIN_FOLD, MARGIN_FOLD,
@ -41,6 +42,7 @@ private:
bool FileWritable(); bool FileWritable();
void BindEvents(); void BindEvents();
void OnMarginClick(wxStyledTextEvent &event); void OnMarginClick(wxStyledTextEvent &event);
JsonValue GetKeywordList(string lang);
}; };
#endif // TYRODOC_FRAME_H #endif // TYRODOC_FRAME_H