From b51dda858f5b29c10839116fb3deb1a017eea27d Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Wed, 18 Oct 2017 19:27:55 +0800 Subject: [PATCH] feat(config): add config compiler plugin that includes default:/menu into schema --- src/rime/config/default_config_plugin.cc | 31 ++++++++++++++++++++++++ src/rime/config/plugins.h | 6 +++++ src/rime/core_module.cc | 1 + src/rime/schema.cc | 10 +------- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 src/rime/config/default_config_plugin.cc diff --git a/src/rime/config/default_config_plugin.cc b/src/rime/config/default_config_plugin.cc new file mode 100644 index 0000000000..91a9c18bf4 --- /dev/null +++ b/src/rime/config/default_config_plugin.cc @@ -0,0 +1,31 @@ +// +// Copyright RIME Developers +// Distributed under the BSD License +// +#include +#include +#include +#include + +namespace rime { + +bool DefaultConfigPlugin::ReviewCompileOutput( + ConfigCompiler* compiler, an resource) { + return true; +} + +bool DefaultConfigPlugin::ReviewLinkOutput( + ConfigCompiler* compiler, an resource) { + if (!boost::ends_with(resource->resource_id, ".schema")) + return true; + auto target = Cow(resource, "menu"); + Reference reference{"default", "menu", true}; + if (!IncludeReference{reference} + .TargetedAt(target).Resolve(compiler)) { + LOG(ERROR) << "failed to include section " << reference; + return false; + } + return true; +} + +} // namespace rime diff --git a/src/rime/config/plugins.h b/src/rime/config/plugins.h index a52a83ab79..5ffcb50667 100644 --- a/src/rime/config/plugins.h +++ b/src/rime/config/plugins.h @@ -27,6 +27,12 @@ class AutoPatchConfigPlugin : public ConfigCompilerPlugin { Review ReviewLinkOutput; }; +class DefaultConfigPlugin : public ConfigCompilerPlugin { + public: + Review ReviewCompileOutput; + Review ReviewLinkOutput; +}; + class LegacyPresetConfigPlugin : public ConfigCompilerPlugin { public: Review ReviewCompileOutput; diff --git a/src/rime/core_module.cc b/src/rime/core_module.cc index 2a30f95c18..33e7c43018 100644 --- a/src/rime/core_module.cc +++ b/src/rime/core_module.cc @@ -22,6 +22,7 @@ static void rime_core_initialize() { auto config = new ConfigComponent; config->InstallPlugin(new AutoPatchConfigPlugin); + config->InstallPlugin(new DefaultConfigPlugin); config->InstallPlugin(new LegacyPresetConfigPlugin); config->InstallPlugin(new LegacyDictionaryConfigPlugin); r.Register("config", config); diff --git a/src/rime/schema.cc b/src/rime/schema.cc index 348467cf96..fb3ae45931 100644 --- a/src/rime/schema.cc +++ b/src/rime/schema.cc @@ -31,15 +31,7 @@ void Schema::FetchUsefulConfigItems() { if (!config_->GetString("schema/name", &schema_name_)) { schema_name_ = schema_id_; } - if (!config_->GetInt("menu/page_size", &page_size_) && - schema_id_ != ".default") { - // not defined in schema, use default setting - the default_config( - Config::Require("config")->Create("default")); - if (default_config) { - default_config->GetInt("menu/page_size", &page_size_); - } - } + config_->GetInt("menu/page_size", &page_size_); config_->GetString("menu/alternative_select_keys", &select_keys_); }