Skip to content

Commit

Permalink
write user.yaml on RimeSelectSchema (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Oct 14, 2023
1 parent 298a9dd commit bcb3555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/rime/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ConcreteEngine : public Engine {
vector<of<Filter>> filters_;
vector<of<Formatter>> formatters_;
vector<of<Processor>> post_processors_;
// To make sure dumping user.yaml when processors_.clear(),
// switcher is owned by processors_[0]
weak<Switcher> switcher_;
};

// implementations
Expand Down Expand Up @@ -274,6 +277,14 @@ void ConcreteEngine::OnSelect(Context* ctx) {
void ConcreteEngine::ApplySchema(Schema* schema) {
if (!schema)
return;
if (auto switcher = switcher_.lock()) {
if (Config* user_config = switcher->user_config()) {
user_config->SetString("var/previously_selected_schema",
schema->schema_id());
user_config->SetInt("var/schema_access_time/" + schema->schema_id(),
time(NULL));
}
}
schema_.reset(schema);
context_->Clear();
context_->ClearTransientOptions();
Expand All @@ -289,6 +300,7 @@ void ConcreteEngine::InitializeComponents() {
filters_.clear();

if (auto switcher = New<Switcher>(this)) {
switcher_ = switcher;
processors_.push_back(switcher);
if (schema_->schema_id() == ".default") {
if (Schema* schema = switcher->CreateSchema()) {
Expand Down
4 changes: 0 additions & 4 deletions src/rime/gear/schema_list_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class SchemaSelection : public SimpleCandidate, public SwitcherCommand {

void SchemaSelection::Apply(Switcher* switcher) {
switcher->Deactivate();
if (Config* user_config = switcher->user_config()) {
user_config->SetString("var/previously_selected_schema", keyword_);
user_config->SetInt("var/schema_access_time/" + keyword_, time(NULL));
}
if (Engine* engine = switcher->attached_engine()) {
if (keyword_ != engine->schema()->schema_id()) {
engine->ApplySchema(new Schema(keyword_));
Expand Down

0 comments on commit bcb3555

Please sign in to comment.