Setup for json-based config for syntax highlighting

This commit is contained in:
Tim Warren 2015-04-14 17:00:48 -04:00
parent b32831dbad
commit 5639d33bb0
8 changed files with 120 additions and 54 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,5 +14,7 @@
using namespace std;
#define JSON_INCLUDE(a, b) (string (b) = "(#include (a))")
#endif // TYRO_COMMON_H

38
src/settings/Config.cpp Normal file
View File

@ -0,0 +1,38 @@
/**
* Object to control settings reading/writing
*/
#include "Config.h"
TyroConfig::TyroConfig()
{
string raw_json;
JSON_INCLUDE("../../config/scintilla.json", raw_json);
cout << raw_json << endl;
reader.parse(raw_json, default_root);
}
TyroConfig::~TyroConfig()
{
}
JsonValue TyroConfig::GetRoot()
{
return default_root;
}
JsonValue TyroConfig::GetLang(string name)
{
JsonValue root = this->GetRoot();
JsonValue lang = root.get("languages", "");
if (lang != "")
{
return lang.get(name, "");
}
return JsonValue("");
}

24
src/settings/Config.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef TYRO_CONFIG_H
#define TYRO_CONFIG_H
#include "../common.h"
#include "../../include/json/json.h"
typedef Json::Value JsonValue;
typedef Json::Reader JsonReader;
typedef Json::Writer JsonWriter;
class TyroConfig {
public:
TyroConfig();
~TyroConfig();
JsonValue GetRoot();
JsonValue GetLang(string name);
private:
JsonValue default_root;
JsonReader reader;
};
#endif /* TYRO_CONFIG_H */

View File

@ -1,21 +0,0 @@
/**
* Object to control settings reading/writing
*/
#include "Settings.h"
TyroSettings::TyroSettings()
{
ifstream file("../../config/scintilla.json");
reader.parse(file, default_root);
}
TyroSettings::~TyroSettings()
{
}
Json::Value TyroSettings::GetRoot()
{
return default_root;
}

View File

@ -1,26 +0,0 @@
/*
* File: Settings.h
* Author: twarren
*
* Created on April 13, 2015, 4:18 PM
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include "../common.h"
#include "../../include/json/json.h"
class TyroSettings {
public:
TyroSettings();
~TyroSettings();
Json::Value GetRoot();
private:
Json::Value default_root;
Json::Reader reader;
};
#endif /* SETTINGS_H */

View File

@ -5,7 +5,7 @@ EditPane::EditPane(
const wxSize &size, long style
) : wxStyledTextCtrl (parent, id, pos, size, style)
{
config = new TyroSettings();
config = new TyroConfig();
}
EditPane::~EditPane()
@ -35,6 +35,8 @@ bool EditPane::LoadAndHighlight(wxString filePath)
this->StyleSetFaceName(i, "Anonymous Pro");
}
JsonValue keywords_array = config->GetLang("cpp");
this->StyleSetForeground (wxSTC_STYLE_DEFAULT, wxColor(101, 123, 131));
this->StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColor(147, 161, 161));
@ -69,8 +71,8 @@ bool EditPane::LoadAndHighlight(wxString filePath)
this->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true);
this->StyleSetBold(wxSTC_C_OPERATOR, true);
this->SetKeyWords(0, "alignof and and_eq bitand bitor break case catch compl const_cast continue default delete do dynamic_cast else false for goto if namespace new not not_eq nullptr operator or or_eq reinterpret_cast return sizeof static_assert static_cast switch this throw true try typedef typeid using while xor xor_eq NULL");
this->SetKeyWords(1, "alignas asm auto bool char char16_t char32_t class const constexpr decltype double enum explicit export extern final float friend inline int long mutable noexcept override private protected public register short signed static struct template thread_local typename union unsigned virtual void volatile wchar_t");
this->SetKeyWords(0, keywords_array[0].asString());
this->SetKeyWords(1, keywords_array[1].asString());
return this->LoadFile(filePath);

View File

@ -2,7 +2,7 @@
#define TYROEDIT_PANE_H
#include "../wx_common.h"
#include "../settings/Settings.h"
#include "../settings/Config.h"
#include <wx/stc/stc.h>
@ -24,7 +24,7 @@ public:
wxString fileName;
bool LoadAndHighlight(wxString filePath);
private:
TyroSettings *config;
TyroConfig *config;
enum
{
MARGIN_LINE_NUMBERS,