2015-04-29 17:03:15 -04:00
|
|
|
/**
|
|
|
|
* Lexer configuration object
|
|
|
|
*
|
|
|
|
* @extends TyroConfig
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LangConfig.h"
|
|
|
|
#include <config/languages_json.h>
|
|
|
|
|
|
|
|
LangConfig::LangConfig()
|
|
|
|
{
|
|
|
|
this->LoadJson(languages_json);
|
|
|
|
this->lang = "";
|
2015-05-12 16:30:22 -04:00
|
|
|
|
|
|
|
// "cache" reverse map of languages to their keys
|
|
|
|
JsonValue langList = this->GetRoot();
|
|
|
|
JsonValue::iterator it;
|
|
|
|
|
|
|
|
for (it = langList.begin(); it != langList.end(); ++it)
|
|
|
|
{
|
|
|
|
JsonValue langObj = *it;
|
|
|
|
reverseMap[langObj.get("name", JsonValue()).asString()] = it.key().asString();
|
|
|
|
}
|
2015-04-29 17:03:15 -04:00
|
|
|
}
|
|
|
|
|
2015-05-08 16:01:36 -04:00
|
|
|
LangConfig::~LangConfig()
|
|
|
|
{
|
|
|
|
wxLogDebug("Called LangConfig Destructor");
|
|
|
|
}
|
2015-04-29 17:03:15 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine the format of the current file by
|
|
|
|
* matching its extension against the patterns
|
|
|
|
* in the configuration files
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
string LangConfig::GetLangByFile(wxFileName &fileName)
|
|
|
|
{
|
|
|
|
JsonValue langList = this->GetRoot();
|
|
|
|
JsonValue::iterator it;
|
|
|
|
|
|
|
|
wxString curr_file = fileName.GetFullName();
|
|
|
|
|
|
|
|
// Loop through each language to find a matching file pattern
|
|
|
|
for (it = langList.begin(); it != langList.end(); ++it)
|
|
|
|
{
|
|
|
|
string lang = it.key().asString();
|
|
|
|
|
|
|
|
// Parse the file pattern
|
|
|
|
wxString file_pattern((*it)["file_pattern"].asString());
|
|
|
|
|
|
|
|
file_pattern.Lower();
|
|
|
|
|
|
|
|
while ( ! file_pattern.empty())
|
|
|
|
{
|
|
|
|
wxString cur = file_pattern.BeforeFirst(';');
|
|
|
|
if (
|
|
|
|
(cur == curr_file) ||
|
|
|
|
(cur == (curr_file.BeforeLast('.') + ".*")) ||
|
|
|
|
(cur == ("*." + curr_file.AfterLast('.')))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
this->SetLang(lang);
|
|
|
|
return this->lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go to the next pattern for this language
|
|
|
|
file_pattern = file_pattern.AfterFirst(';');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 17:05:27 -04:00
|
|
|
this->SetLang("");
|
2015-04-29 17:03:15 -04:00
|
|
|
return this->lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of keywords for the selected language
|
|
|
|
*
|
|
|
|
* @param string lang
|
|
|
|
* @return JsonValue
|
|
|
|
*/
|
|
|
|
JsonValue LangConfig::GetKeywordList(string lang)
|
|
|
|
{
|
|
|
|
if (lang == "none") lang = this->lang;
|
|
|
|
|
|
|
|
return this->GetRoot()
|
|
|
|
.get(lang, JsonValue())
|
|
|
|
.get("keywords", JsonValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the lexer theme map for the current language
|
|
|
|
*
|
|
|
|
* @param string lang
|
|
|
|
* @return JsonValue
|
|
|
|
*/
|
|
|
|
JsonValue LangConfig::GetLexerMap(string lang)
|
|
|
|
{
|
|
|
|
if (lang == "none") lang = this->lang;
|
|
|
|
|
|
|
|
return this->GetRoot()
|
|
|
|
.get(lang, JsonValue())
|
|
|
|
.get("lexer_map", JsonValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LangConfig::SetLang(string lang)
|
|
|
|
{
|
|
|
|
this->lang = lang;
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:30:22 -04:00
|
|
|
/**
|
|
|
|
* Get the current language key
|
|
|
|
*/
|
2015-04-29 17:03:15 -04:00
|
|
|
string LangConfig::GetLang()
|
|
|
|
{
|
|
|
|
return this->lang;
|
2015-05-08 16:01:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-12 16:30:22 -04:00
|
|
|
/**
|
|
|
|
* Get the name attribute of the currently selected language
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
string LangConfig::GetCurrentLangName()
|
|
|
|
{
|
|
|
|
return this->GetRoot()
|
|
|
|
.get(this->lang, JsonValue())
|
|
|
|
.get("name", JsonValue())
|
|
|
|
.asString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the list of languages available
|
|
|
|
*
|
|
|
|
* @return StringMap
|
|
|
|
*/
|
2015-05-08 16:01:36 -04:00
|
|
|
StringMap LangConfig::GetLangList()
|
|
|
|
{
|
2015-05-12 16:30:22 -04:00
|
|
|
StringMap revList = this->reverseMap;
|
|
|
|
StringMap::iterator it;
|
2015-05-08 16:01:36 -04:00
|
|
|
|
|
|
|
StringMap outputList;
|
|
|
|
|
2015-05-12 16:30:22 -04:00
|
|
|
for (it = revList.begin(); it != revList.end(); ++it)
|
2015-05-08 16:01:36 -04:00
|
|
|
{
|
2015-05-12 16:30:22 -04:00
|
|
|
outputList[it->second] = it->first;
|
2015-05-08 16:01:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return outputList;
|
2015-04-29 17:03:15 -04:00
|
|
|
}
|