Skip to content

Commit fa7b5a5

Browse files
osfanslotem
authored andcommitted
feat: add property notifier
1 parent b6c02c1 commit fa7b5a5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/rime/context.cc

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ bool Context::get_option(const string& name) const {
263263
void Context::set_property(const string& name,
264264
const string& value) {
265265
properties_[name] = value;
266+
property_update_notifier_(this, name);
266267
}
267268

268269
string Context::get_property(const string& name) const {

src/rime/context.h

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Context {
2121
using Notifier = signal<void (Context* ctx)>;
2222
using OptionUpdateNotifier =
2323
signal<void (Context* ctx, const string& option)>;
24+
using PropertyUpdateNotifier =
25+
signal<void (Context* ctx, const string& property)>;
2426
using KeyEventNotifier =
2527
signal<void (Context* ctx, const KeyEvent& key_event)>;
2628

@@ -81,6 +83,9 @@ class Context {
8183
OptionUpdateNotifier& option_update_notifier() {
8284
return option_update_notifier_;
8385
}
86+
PropertyUpdateNotifier& property_update_notifier() {
87+
return property_update_notifier_;
88+
}
8489
KeyEventNotifier& unhandled_key_notifier() {
8590
return unhandled_key_notifier_;
8691
}
@@ -100,6 +105,7 @@ class Context {
100105
Notifier update_notifier_;
101106
Notifier delete_notifier_;
102107
OptionUpdateNotifier option_update_notifier_;
108+
PropertyUpdateNotifier property_update_notifier_;
103109
KeyEventNotifier unhandled_key_notifier_;
104110
};
105111

src/rime/engine.cc

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ConcreteEngine : public Engine {
4343
void OnSelect(Context* ctx);
4444
void OnContextUpdate(Context* ctx);
4545
void OnOptionUpdate(Context* ctx, const string& option);
46+
void OnPropertyUpdate(Context* ctx, const string& property);
4647

4748
vector<of<Processor>> processors_;
4849
vector<of<Segmentor>> segmentors_;
@@ -79,6 +80,10 @@ ConcreteEngine::ConcreteEngine() {
7980
[this](Context* ctx, const string& option) {
8081
OnOptionUpdate(ctx, option);
8182
});
83+
context_->property_update_notifier().connect(
84+
[this](Context* ctx, const string& property) {
85+
OnPropertyUpdate(ctx, property);
86+
});
8287
InitializeComponents();
8388
InitializeOptions();
8489
}
@@ -129,6 +134,15 @@ void ConcreteEngine::OnOptionUpdate(Context* ctx, const string& option) {
129134
message_sink_("option", msg);
130135
}
131136

137+
void ConcreteEngine::OnPropertyUpdate(Context* ctx, const string& property) {
138+
if (!ctx) return;
139+
LOG(INFO) << "updated property: " << property;
140+
// notification
141+
string value = ctx->get_property(property);
142+
string msg(property + "=" + value);
143+
message_sink_("property", msg);
144+
}
145+
132146
void ConcreteEngine::Compose(Context* ctx) {
133147
if (!ctx) return;
134148
Composition& comp = ctx->composition();

0 commit comments

Comments
 (0)