2015-05-07 17:05:27 -04:00
|
|
|
/**
|
|
|
|
* Theme manager
|
|
|
|
*/
|
|
|
|
|
2015-05-07 14:06:12 -04:00
|
|
|
#include "ThemeConfig.h"
|
|
|
|
#include <config/themes_json.h>
|
|
|
|
|
2015-06-03 17:06:55 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2015-05-07 14:06:12 -04:00
|
|
|
ThemeConfig::ThemeConfig()
|
|
|
|
{
|
|
|
|
this->LoadJson(themes_json);
|
2015-05-07 17:05:27 -04:00
|
|
|
this->SetTheme("Solarized");
|
2015-05-07 14:06:12 -04:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:06:55 -04:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2015-06-18 13:34:54 -04:00
|
|
|
ThemeConfig::~ThemeConfig() {}
|
2015-05-07 14:06:12 -04:00
|
|
|
|
2015-06-03 17:06:55 -04:00
|
|
|
/**
|
|
|
|
* Set the current theme
|
|
|
|
*
|
|
|
|
* @param string theme_name
|
2015-06-19 16:37:24 -04:00
|
|
|
* @return bool
|
2015-06-03 17:06:55 -04:00
|
|
|
*/
|
2015-06-19 16:37:24 -04:00
|
|
|
bool ThemeConfig::SetTheme(string theme_name)
|
2015-05-07 14:06:12 -04:00
|
|
|
{
|
|
|
|
JsonValue theme_list = this->GetRoot();
|
2015-06-19 16:37:24 -04:00
|
|
|
JsonValue selected_theme = theme_list.get(theme_name, JsonValue());
|
|
|
|
|
|
|
|
if (selected_theme.isNull()) return FALSE;
|
|
|
|
|
|
|
|
if (selected_theme.isObject())
|
|
|
|
{
|
|
|
|
this->current_theme = selected_theme;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2015-05-07 14:06:12 -04:00
|
|
|
}
|
|
|
|
|
2015-06-03 17:06:55 -04:00
|
|
|
/**
|
|
|
|
* Get the name of the currently selected theme
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-05-07 14:06:12 -04:00
|
|
|
JsonValue ThemeConfig::GetTheme()
|
|
|
|
{
|
|
|
|
return this->current_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a setting from the current theme
|
|
|
|
*
|
|
|
|
* @param string type
|
|
|
|
* @param string key
|
|
|
|
* @return JsonValue
|
|
|
|
*/
|
|
|
|
JsonValue ThemeConfig::GetThemeValue(string type, string key)
|
|
|
|
{
|
|
|
|
JsonValue value = this->current_theme
|
|
|
|
.get(type, JsonValue())
|
|
|
|
.get(key, JsonValue());
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the configured color for the specified theme
|
|
|
|
* @param type
|
|
|
|
* @param key
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
wxColor ThemeConfig::GetThemeColor(string type, string key)
|
|
|
|
{
|
|
|
|
JsonValue color_value = this->GetThemeValue(type, key);
|
|
|
|
|
|
|
|
if (color_value.isArray())
|
|
|
|
{
|
|
|
|
return wxColor(
|
|
|
|
(unsigned char) color_value[0].asUInt(),
|
|
|
|
(unsigned char) color_value[1].asUInt(),
|
|
|
|
(unsigned char) color_value[2].asUInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-19 16:37:24 -04:00
|
|
|
return wxColor("BLACK");
|
2015-05-07 14:06:12 -04:00
|
|
|
}
|
|
|
|
}
|