From 9db9bf2f0e7b02449c071a7f0e42f99523b49d0c Mon Sep 17 00:00:00 2001 From: mokapsing <39441028+mokapsing@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:49:18 +0800 Subject: [PATCH] add nextSchemaOption --- po/ca.po | 6 +++++- po/da.po | 6 +++++- po/de.po | 6 +++++- po/fcitx5-rime.pot | 6 +++++- po/he.po | 4 ++++ po/ja.po | 6 +++++- po/ko.po | 6 +++++- po/ru.po | 6 +++++- po/tr.po | 6 +++++- po/vi.po | 6 +++++- po/zh_CN.po | 6 +++++- po/zh_TW.po | 6 +++++- src/rimeengine.cpp | 15 ++++++++++++++- src/rimeengine.h | 2 +- src/rimestate.cpp | 32 +++++++++++++++++++++++++++++++- src/rimestate.h | 1 + 16 files changed, 106 insertions(+), 14 deletions(-) diff --git a/po/ca.po b/po/ca.po index 2c4a422..6e3bc40 100644 --- a/po/ca.po +++ b/po/ca.po @@ -60,10 +60,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "" diff --git a/po/da.po b/po/da.po index 848004c..aa4e630 100644 --- a/po/da.po +++ b/po/da.po @@ -59,10 +59,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "Latinsk tilstand" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "" diff --git a/po/de.po b/po/de.po index bda7fb0..601fa91 100644 --- a/po/de.po +++ b/po/de.po @@ -61,10 +61,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "Lateinischer Modus" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "" diff --git a/po/fcitx5-rime.pot b/po/fcitx5-rime.pot index 28b0ffb..5688b33 100644 --- a/po/fcitx5-rime.pot +++ b/po/fcitx5-rime.pot @@ -55,10 +55,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "" diff --git a/po/he.po b/po/he.po index 6dfb6b3..5d703a3 100644 --- a/po/he.po +++ b/po/he.po @@ -65,6 +65,10 @@ msgstr "" msgid "Latin Mode" msgstr "" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:78 msgid "Load available plugins automatically" msgstr "" diff --git a/po/ja.po b/po/ja.po index 1eda577..848bcab 100644 --- a/po/ja.po +++ b/po/ja.po @@ -62,10 +62,14 @@ msgstr "全角は有効です。" msgid "Half Shape is enabled." msgstr "半角は有効です。" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "ラテンモード" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "利用可能なプラグインを自動的にロードする" diff --git a/po/ko.po b/po/ko.po index 3d02639..f5aa2e1 100644 --- a/po/ko.po +++ b/po/ko.po @@ -60,10 +60,14 @@ msgstr "전각이 활성화되었습니다." msgid "Half Shape is enabled." msgstr "반각이 활성화되었습니다." -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "로마자 모드" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "사용 가능한 플러그인 자동으로 불러오기" diff --git a/po/ru.po b/po/ru.po index 66339be..dccabf4 100644 --- a/po/ru.po +++ b/po/ru.po @@ -63,10 +63,14 @@ msgstr "Полноширинная форма включена." msgid "Half Shape is enabled." msgstr "Полуширинная форма включена." -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "Режим Латиницы" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "Автоматически загружать доступные плагины" diff --git a/po/tr.po b/po/tr.po index d530303..bfbcf3f 100644 --- a/po/tr.po +++ b/po/tr.po @@ -60,10 +60,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "Latin Modu" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "Kullanılabilir eklentileri otomatikmen yükle" diff --git a/po/vi.po b/po/vi.po index 6e6b822..cb98d43 100644 --- a/po/vi.po +++ b/po/vi.po @@ -59,10 +59,14 @@ msgstr "" msgid "Half Shape is enabled." msgstr "" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "" diff --git a/po/zh_CN.po b/po/zh_CN.po index e43f1d3..b87e45e 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -61,10 +61,14 @@ msgstr "已启用全角字符。 " msgid "Half Shape is enabled." msgstr "已启用半角字符。" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "英文模式" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "下一个方案" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "自动加载可用插件" diff --git a/po/zh_TW.po b/po/zh_TW.po index d5fcd58..1896998 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -65,10 +65,14 @@ msgstr "已啟用全形字符。" msgid "Half Shape is enabled." msgstr "已啟用半形字符。" -#: src/rimestate.cpp:67 src/rimeengine.cpp:822 +#: src/rimestate.cpp:67 src/rimeengine.cpp:828 msgid "Latin Mode" msgstr "羅馬拼音模式" +#: src/rimeengine.cpp:858 +msgid "Next Schema" +msgstr "下一个方案" + #: src/rimeengine.h:77 msgid "Load available plugins automatically" msgstr "自動載入可用插件" diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp index b61bece..2da1090 100644 --- a/src/rimeengine.cpp +++ b/src/rimeengine.cpp @@ -849,9 +849,22 @@ void RimeEngine::updateSchemaMenu() { instance_->userInterfaceManager().registerAction(&schemaAction); schemaMenu_.insertAction(&separatorAction_, &schemaAction); updateActionsForSchema(schemaId); - schemas_.insert(schemaId); + schemas_.push_back(schemaId); } api_->free_schema_list(&list); + + schemActions_.emplace_back(); + auto &schemaAction = schemActions_.back(); + schemaAction.setShortText(_("Next Schema")); + schemaAction.connect( + [this](InputContext *ic) { + auto state = ic->propertyFor(&factory_); + blockNotificationFor(30000); + state->switchNextSchema(); + imAction_->update(ic); + }); + instance_->userInterfaceManager().registerAction("fcitx-rime-next-schema", &schemaAction); + schemaMenu_.insertAction(&separatorAction_, &schemaAction); } } diff --git a/src/rimeengine.h b/src/rimeengine.h index b2aa05c..2857bd1 100644 --- a/src/rimeengine.h +++ b/src/rimeengine.h @@ -184,7 +184,7 @@ class RimeEngine final : public InputMethodEngineV2 { FCITX_ADDON_DEPENDENCY_LOADER(notifications, instance_->addonManager()); - std::unordered_set schemas_; + std::vector schemas_; std::list schemActions_; std::unordered_map>> diff --git a/src/rimestate.cpp b/src/rimestate.cpp index 3e7e825..8fddcf0 100644 --- a/src/rimestate.cpp +++ b/src/rimestate.cpp @@ -120,6 +120,36 @@ void RimeState::selectSchema(const std::string &schema) { api->select_schema(session(), schema.data()); } +void RimeState::switchNextSchema() { + std::string currentSchemaId; + std::string targetSchemaId; + const auto& schemas = engine_->schemas(); + auto api = engine_->api(); + if (api->is_maintenance_mode()) { + return; + } + getStatus([¤tSchemaId](const RimeStatus &status) { + currentSchemaId = status.schema_id ? status.schema_id : ""; + }); + if (currentSchemaId.empty()) { + return; + } + targetSchemaId = *schemas.begin(); + if (!schemas.empty()) { + auto it = std::find(schemas.begin(), schemas.end(), currentSchemaId); + if (it != schemas.end() && std::next(it) != schemas.end()) { + targetSchemaId = *std::next(it); + } + } + if (targetSchemaId.empty()) { + return; + } + engine_->blockNotificationFor(30000); + api->set_option(session(), RIME_ASCII_MODE, false); + api->select_schema(session(), targetSchemaId.data()); + return; +} + void RimeState::keyEvent(KeyEvent &event) { auto api = engine_->api(); if (api->is_maintenance_mode()) { @@ -388,7 +418,7 @@ void RimeState::restore() { if (savedCurrentSchema_.empty()) { return; } - if (!engine_->schemas().count(savedCurrentSchema_)) { + if (!std::count(engine_->schemas().begin(), engine_->schemas().end(), savedCurrentSchema_)) { return; } diff --git a/src/rimestate.h b/src/rimestate.h index e87718f..e3b523e 100644 --- a/src/rimestate.h +++ b/src/rimestate.h @@ -39,6 +39,7 @@ class RimeState : public InputContextProperty { std::string subModeLabel(); void toggleLatinMode(); void setLatinMode(bool latin); + void switchNextSchema(); void selectSchema(const std::string &schemaId); RimeSessionId session(bool requestNewSession = true);