diff --git a/src/rime/core_module.cc b/src/rime/core_module.cc index ea897bf20e..f9545734b9 100644 --- a/src/rime/core_module.cc +++ b/src/rime/core_module.cc @@ -11,6 +11,7 @@ // built-in components #include +#include using namespace rime; @@ -18,7 +19,9 @@ static void rime_core_initialize() { LOG(INFO) << "registering core components."; Registry& r = Registry::instance(); - r.Register("config", new ConfigComponent); + auto config = new ConfigComponent; + r.Register("config", config); + r.Register("schema", new SchemaComponent(config)); } static void rime_core_finalize() { diff --git a/src/rime/schema.cc b/src/rime/schema.cc index 33df9e8c54..348467cf96 100644 --- a/src/rime/schema.cc +++ b/src/rime/schema.cc @@ -17,9 +17,9 @@ Schema::Schema() Schema::Schema(const string& schema_id) : schema_id_(schema_id) { - config_.reset(Config::Require("config")->Create( - boost::starts_with(schema_id_, L".") ? - schema_id.substr(1) : schema_id + ".schema")); + config_.reset(boost::starts_with(schema_id_, L".") ? + Config::Require("config")->Create(schema_id.substr(1)) : + Config::Require("schema")->Create(schema_id)); FetchUsefulConfigItems(); } @@ -43,4 +43,8 @@ void Schema::FetchUsefulConfigItems() { config_->GetString("menu/alternative_select_keys", &select_keys_); } +Config* SchemaComponent::Create(const string& schema_id) { + return config_component_->Create(schema_id + ".schema"); +} + } // namespace rime diff --git a/src/rime/schema.h b/src/rime/schema.h index 033f8cad90..ed2e0b92ab 100644 --- a/src/rime/schema.h +++ b/src/rime/schema.h @@ -40,6 +40,19 @@ class Schema { string select_keys_; }; +class SchemaComponent : public Config::Component { + public: + SchemaComponent(ConfigComponent* config_component) + : config_component_(config_component) { + } + // NOTE: creates `Config` for the schema + Config* Create(const string& schema_id) override; + private: + // we do not own the ConfigComponent, do not try to deallocate it + // also be careful that there is no guarantee it will outlive us + ConfigComponent* config_component_; +}; + } // namespace rime #endif // RIME_SCHEMA_H_ diff --git a/src/rime_api.cc b/src/rime_api.cc index 0998421287..8322040f60 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -543,7 +543,7 @@ RIME_API Bool RimeSelectSchema(RimeSessionId session_id, const char* schema_id) RIME_API Bool RimeSchemaOpen(const char *schema_id, RimeConfig* config) { if (!schema_id || !config) return False; - Config::Component* cc = Config::Require("schema_config"); + Config::Component* cc = Config::Require("schema"); if (!cc) return False; Config* c = cc->Create(schema_id); if (!c) return False;