Skip to content

Commit

Permalink
feat(config): add config compiler plugin that includes default:/menu …
Browse files Browse the repository at this point in the history
…into schema
  • Loading branch information
lotem committed Oct 19, 2017
1 parent 7077389 commit b51dda8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
31 changes: 31 additions & 0 deletions src/rime/config/default_config_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright RIME Developers
// Distributed under the BSD License
//
#include <boost/algorithm/string.hpp>
#include <rime/config/config_compiler_impl.h>
#include <rime/config/config_cow_ref.h>
#include <rime/config/plugins.h>

namespace rime {

bool DefaultConfigPlugin::ReviewCompileOutput(
ConfigCompiler* compiler, an<ConfigResource> resource) {
return true;
}

bool DefaultConfigPlugin::ReviewLinkOutput(
ConfigCompiler* compiler, an<ConfigResource> 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
6 changes: 6 additions & 0 deletions src/rime/config/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/rime/core_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions src/rime/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> 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_);
}

Expand Down

0 comments on commit b51dda8

Please sign in to comment.