Skip to content

Commit bcb3555

Browse files
authored
write user.yaml on RimeSelectSchema (#736)
1 parent 298a9dd commit bcb3555

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/rime/engine.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class ConcreteEngine : public Engine {
5252
vector<of<Filter>> filters_;
5353
vector<of<Formatter>> formatters_;
5454
vector<of<Processor>> post_processors_;
55+
// To make sure dumping user.yaml when processors_.clear(),
56+
// switcher is owned by processors_[0]
57+
weak<Switcher> switcher_;
5558
};
5659

5760
// implementations
@@ -274,6 +277,14 @@ void ConcreteEngine::OnSelect(Context* ctx) {
274277
void ConcreteEngine::ApplySchema(Schema* schema) {
275278
if (!schema)
276279
return;
280+
if (auto switcher = switcher_.lock()) {
281+
if (Config* user_config = switcher->user_config()) {
282+
user_config->SetString("var/previously_selected_schema",
283+
schema->schema_id());
284+
user_config->SetInt("var/schema_access_time/" + schema->schema_id(),
285+
time(NULL));
286+
}
287+
}
277288
schema_.reset(schema);
278289
context_->Clear();
279290
context_->ClearTransientOptions();
@@ -289,6 +300,7 @@ void ConcreteEngine::InitializeComponents() {
289300
filters_.clear();
290301

291302
if (auto switcher = New<Switcher>(this)) {
303+
switcher_ = switcher;
292304
processors_.push_back(switcher);
293305
if (schema_->schema_id() == ".default") {
294306
if (Schema* schema = switcher->CreateSchema()) {

src/rime/gear/schema_list_translator.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ class SchemaSelection : public SimpleCandidate, public SwitcherCommand {
2626

2727
void SchemaSelection::Apply(Switcher* switcher) {
2828
switcher->Deactivate();
29-
if (Config* user_config = switcher->user_config()) {
30-
user_config->SetString("var/previously_selected_schema", keyword_);
31-
user_config->SetInt("var/schema_access_time/" + keyword_, time(NULL));
32-
}
3329
if (Engine* engine = switcher->attached_engine()) {
3430
if (keyword_ != engine->schema()->schema_id()) {
3531
engine->ApplySchema(new Schema(keyword_));

0 commit comments

Comments
 (0)