Skip to content

Commit

Permalink
add nextSchemaOption
Browse files Browse the repository at this point in the history
  • Loading branch information
mokapsing committed Apr 3, 2024
1 parent 68fc613 commit ad15daf
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 14 deletions.
6 changes: 5 additions & 1 deletion po/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion po/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion po/fcitx5-rime.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
4 changes: 4 additions & 0 deletions po/he.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion po/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "利用可能なプラグインを自動的にロードする"
Expand Down
6 changes: 5 additions & 1 deletion po/ko.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "사용 가능한 플러그인 자동으로 불러오기"
Expand Down
6 changes: 5 additions & 1 deletion po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Автоматически загружать доступные плагины"
Expand Down
6 changes: 5 additions & 1 deletion po/tr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion po/vi.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion po/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "自动加载可用插件"
Expand Down
6 changes: 5 additions & 1 deletion po/zh_TW.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "自動載入可用插件"
Expand Down
15 changes: 14 additions & 1 deletion src/rimeengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleAction::Activated>(
[this](InputContext *ic) {
auto state = ic->propertyFor(&factory_);
blockNotificationFor(30000);
state->switchNextSchema();
imAction_->update(ic);
});
instance_->userInterfaceManager().registerAction(&schemaAction);
schemaMenu_.insertAction(&separatorAction_, &schemaAction);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rimeengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class RimeEngine final : public InputMethodEngineV2 {

FCITX_ADDON_DEPENDENCY_LOADER(notifications, instance_->addonManager());

std::unordered_set<std::string> schemas_;
std::vector<std::string> schemas_;
std::list<SimpleAction> schemActions_;
std::unordered_map<std::string,
std::list<std::unique_ptr<RimeOptionAction>>>
Expand Down
32 changes: 31 additions & 1 deletion src/rimestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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([&currentSchemaId](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()) {
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/rimestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ad15daf

Please sign in to comment.