From 63b2ba5c4586d24a7b65f44c62dfc8b00932cf91 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Thu, 6 Jun 2024 07:19:11 -0400 Subject: [PATCH] add hotkey method to Action (#1070) --- CMakeLists.txt | 2 +- src/lib/fcitx/action.cpp | 11 +++++++++++ src/lib/fcitx/action.h | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a66f36296..ac1e1dcb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.6.0) -project(fcitx VERSION 5.1.10) +project(fcitx VERSION 5.1.11) set(FCITX_VERSION ${PROJECT_VERSION}) find_package(ECM REQUIRED 1.0.0) diff --git a/src/lib/fcitx/action.cpp b/src/lib/fcitx/action.cpp index 84fa323e0..67b21ffe2 100644 --- a/src/lib/fcitx/action.cpp +++ b/src/lib/fcitx/action.cpp @@ -18,6 +18,7 @@ class ActionPrivate : QPtrHolder { int id_ = 0; bool checkable_ = false; bool separator_ = false; + KeyList hotkey_; FCITX_DEFINE_SIGNAL_PRIVATE(Action, Update); }; @@ -92,6 +93,16 @@ const std::string &Action::name() const { void Action::update(InputContext *ic) { emit(ic); } +const KeyList &Action::hotkey() const { + FCITX_D(); + return d->hotkey_; +} + +void Action::setHotkey(const KeyList &hotkey) { + FCITX_D(); + d->hotkey_ = hotkey; +} + class SimpleActionPrivate : public QPtrHolder { public: SimpleActionPrivate(SimpleAction *q) : QPtrHolder(q) {} diff --git a/src/lib/fcitx/action.h b/src/lib/fcitx/action.h index c6d0d02c3..b840c89c4 100644 --- a/src/lib/fcitx/action.h +++ b/src/lib/fcitx/action.h @@ -9,6 +9,7 @@ #include #include +#include #include #include "fcitxcore_export.h" @@ -139,6 +140,24 @@ class FCITXCORE_EXPORT Action : public Element { FCITX_DECLARE_SIGNAL(Action, Update, void(InputContext *)); + /** + * Hotkey bound to the action. + * This is only for display purpose when UI implementation supports it, + * and it has nothing to do with the key handling logic. + * + * @return key list. + * @since 5.1.11 + */ + const KeyList &hotkey() const; + + /** + * Set associated hotkey for display. + * + * @param hotkey keys that trigger the action. + * @since 5.1.11 + */ + void setHotkey(const KeyList &hotkey); + private: void setName(const std::string &name); void setId(int id);