Skip to content

Commit

Permalink
feat: add property notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
osfans authored and lotem committed Sep 19, 2017
1 parent b6c02c1 commit fa7b5a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Context {
using Notifier = signal<void (Context* ctx)>;
using OptionUpdateNotifier =
signal<void (Context* ctx, const string& option)>;
using PropertyUpdateNotifier =
signal<void (Context* ctx, const string& property)>;
using KeyEventNotifier =
signal<void (Context* ctx, const KeyEvent& key_event)>;

Expand Down Expand Up @@ -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_;
}
Expand All @@ -100,6 +105,7 @@ class Context {
Notifier update_notifier_;
Notifier delete_notifier_;
OptionUpdateNotifier option_update_notifier_;
PropertyUpdateNotifier property_update_notifier_;
KeyEventNotifier unhandled_key_notifier_;
};

Expand Down
14 changes: 14 additions & 0 deletions src/rime/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<of<Processor>> processors_;
vector<of<Segmentor>> segmentors_;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fa7b5a5

Please sign in to comment.