Skip to content

' #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 18, 2025
Merged

' #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.6)

project(fcitx5-anthy VERSION 5.1.6)

set(REQUIRED_FCITX_VERSION 5.1.12)
set(REQUIRED_FCITX_VERSION 5.1.13)
find_package(ECM 1.0.0 REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(FeatureSummary)
Expand Down
26 changes: 17 additions & 9 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,37 @@
#include "action.h"
#include "utils.h"
#include <fcitx-config/option.h>
#include <fcitx-utils/key.h>
#include <fcitx-utils/keysym.h>
#include <fcitx/event.h>
#include <functional>
#include <string>
#include <utility>

Action::Action()
: name_(""), performFunction_(nullptr), keyBindings_(nullptr) {}
Action::Action() : performFunction_(nullptr), keyBindings_(nullptr) {}

Action::Action(const std::string &name, const fcitx::KeyList &hotkey, PMF pmf)
: name_(name), performFunction_(pmf), keyBindings_(&hotkey) {}
Action::Action(std::string name, const fcitx::KeyList &hotkey,
std::function<bool()> pmf)
: name_(std::move(name)), performFunction_(std::move(pmf)),
keyBindings_(&hotkey) {}

bool Action::perform(AnthyState *performer) {
bool Action::perform() {
if (performFunction_) {
return (performer->*performFunction_)();
return performFunction_();
}

return false;
}

bool Action::perform(AnthyState *performer, const fcitx::KeyEvent &key) {
if (!performFunction_)
bool Action::perform(const fcitx::KeyEvent &key) {
if (!performFunction_) {
return false;
}

if (!matchKeyEvent(key)) {
return false;
}
return (performer->*performFunction_)();
return performFunction_();
}

bool Action::matchKeyEvent(const fcitx::KeyEvent &key) {
Expand Down
15 changes: 8 additions & 7 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#define _FCITX5_ANTHY_ACTION_H_

#include <fcitx-config/option.h>
#include <fcitx-utils/key.h>
#include <fcitx-utils/macros.h>
#include <fcitx/event.h>
#include <functional>
#include <string>

#define ACTION_CONFIG_CIRCLE_INPUT_MODE_KEY "CircleInputModeKey"
Expand Down Expand Up @@ -92,18 +95,16 @@

class AnthyState;

typedef bool (AnthyState::*PMF)();

class Action {

public:
Action();
Action(const std::string &name, const fcitx::KeyList &hotkey, PMF pmf);
Action(std::string name, const fcitx::KeyList &hotkey,
std::function<bool()> pmf);
FCITX_INLINE_DEFINE_DEFAULT_DTOR_AND_MOVE_WITHOUT_SPEC(Action);

public:
bool perform(AnthyState *performer);
bool perform(AnthyState *performer, const fcitx::KeyEvent &key);
bool perform();
bool perform(const fcitx::KeyEvent &key);

// bool operator<(const Action &b) { return name_ < b.name_; }

Expand All @@ -113,7 +114,7 @@ class Action {

private:
std::string name_;
PMF performFunction_;
std::function<bool()> performFunction_;
const fcitx::KeyList *keyBindings_;
};

Expand Down
12 changes: 12 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include <fcitx-config/enum.h>
#include <fcitx-config/option.h>
#include <fcitx-utils/i18n.h>
#include <fcitx-utils/key.h>
#include <fcitx-utils/keysym.h>
#include <fcitx/candidatelist.h>
#include <string>

namespace fcitx {
FCITX_CONFIG_ENUM_NAME_WITH_I18N(CandidateLayoutHint, N_("Not Set"),
Expand Down Expand Up @@ -80,6 +83,11 @@ enum class TenKeyType {
FCITX_CONFIG_ENUM_NAME_WITH_I18N(TenKeyType, N_("Wide"), N_("Half"),
N_("Follow mode"));

enum class PeriodBehavior { None, Convert, Commit };

FCITX_CONFIG_ENUM_NAME_WITH_I18N(PeriodBehavior, N_("None"), N_("Convert"),
N_("Commit"));

struct AnthyKeyProfile {

fcitx::KeyList hk_CONVERT;
Expand Down Expand Up @@ -202,6 +210,10 @@ FCITX_CONFIGURATION(
fcitx::OptionWithAnnotation<TenKeyType, TenKeyTypeI18NAnnotation>
tenKeyType{this, "TenKeyType", _("Ten key type"),
TenKeyType::FOLLOWMODE};
fcitx::OptionWithAnnotation<PeriodBehavior, PeriodBehaviorI18NAnnotation>
periodBehavior{this, "PeriodBehavior",
_("Behavior on a comma or a period"),
PeriodBehavior::None};
fcitx::Option<bool> learnOnManualCommit{this, "LearnOnManualCommit",
_("Learn on manual commit"), true};
fcitx::Option<bool> learnOnAutoCommit{this, "LearnOnAutoCommit",
Expand Down
Loading
Loading