diff --git a/src/rime/context.cc b/src/rime/context.cc index 9049ca6ba..4d69bd122 100644 --- a/src/rime/context.cc +++ b/src/rime/context.cc @@ -263,6 +263,7 @@ bool Context::get_option(const string& name) const { void Context::set_property(const string& name, const string& value) { properties_[name] = value; + property_update_notifier_(this, name); } string Context::get_property(const string& name) const { diff --git a/src/rime/context.h b/src/rime/context.h index 1c1ea3ee0..d8bc285c8 100644 --- a/src/rime/context.h +++ b/src/rime/context.h @@ -21,6 +21,8 @@ class Context { using Notifier = signal; using OptionUpdateNotifier = signal; + using PropertyUpdateNotifier = + signal; using KeyEventNotifier = signal; @@ -81,6 +83,9 @@ class Context { OptionUpdateNotifier& option_update_notifier() { return option_update_notifier_; } + PropertyUpdateNotifier& property_update_notifier() { + return property_update_notifier_; + } KeyEventNotifier& unhandled_key_notifier() { return unhandled_key_notifier_; } @@ -100,6 +105,7 @@ class Context { Notifier update_notifier_; Notifier delete_notifier_; OptionUpdateNotifier option_update_notifier_; + PropertyUpdateNotifier property_update_notifier_; KeyEventNotifier unhandled_key_notifier_; }; diff --git a/src/rime/engine.cc b/src/rime/engine.cc index 47fd17305..420abd012 100644 --- a/src/rime/engine.cc +++ b/src/rime/engine.cc @@ -43,6 +43,7 @@ class ConcreteEngine : public Engine { void OnSelect(Context* ctx); void OnContextUpdate(Context* ctx); void OnOptionUpdate(Context* ctx, const string& option); + void OnPropertyUpdate(Context* ctx, const string& property); vector> processors_; vector> segmentors_; @@ -79,6 +80,10 @@ ConcreteEngine::ConcreteEngine() { [this](Context* ctx, const string& option) { OnOptionUpdate(ctx, option); }); + context_->property_update_notifier().connect( + [this](Context* ctx, const string& property) { + OnPropertyUpdate(ctx, property); + }); InitializeComponents(); InitializeOptions(); } @@ -129,6 +134,15 @@ void ConcreteEngine::OnOptionUpdate(Context* ctx, const string& option) { message_sink_("option", msg); } +void ConcreteEngine::OnPropertyUpdate(Context* ctx, const string& property) { + if (!ctx) return; + LOG(INFO) << "updated property: " << property; + // notification + string value = ctx->get_property(property); + string msg(property + "=" + value); + message_sink_("property", msg); +} + void ConcreteEngine::Compose(Context* ctx) { if (!ctx) return; Composition& comp = ctx->composition();