Skip to content

Commit f665396

Browse files
committed
C++20 & clang-tidy cleanup
Also fix two missing part 1. jp layout check, never ported to fcitx5. 2. preedit.cpp missing a piece of code that is never ported to fcitx-anthy.
1 parent 642e14f commit f665396

31 files changed

+1539
-1263
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.6)
22

33
project(fcitx5-anthy VERSION 5.1.6)
44

5-
set(REQUIRED_FCITX_VERSION 5.1.12)
5+
set(REQUIRED_FCITX_VERSION 5.1.13)
66
find_package(ECM 1.0.0 REQUIRED)
77
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
88
include(FeatureSummary)

src/action.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@
99
#include "action.h"
1010
#include "utils.h"
1111
#include <fcitx-config/option.h>
12+
#include <fcitx-utils/key.h>
13+
#include <fcitx-utils/keysym.h>
14+
#include <fcitx/event.h>
15+
#include <functional>
16+
#include <string>
17+
#include <utility>
1218

13-
Action::Action()
14-
: name_(""), performFunction_(nullptr), keyBindings_(nullptr) {}
19+
Action::Action() : performFunction_(nullptr), keyBindings_(nullptr) {}
1520

16-
Action::Action(const std::string &name, const fcitx::KeyList &hotkey, PMF pmf)
17-
: name_(name), performFunction_(pmf), keyBindings_(&hotkey) {}
21+
Action::Action(std::string name, const fcitx::KeyList &hotkey,
22+
std::function<bool()> pmf)
23+
: name_(std::move(name)), performFunction_(std::move(pmf)),
24+
keyBindings_(&hotkey) {}
1825

19-
bool Action::perform(AnthyState *performer) {
26+
bool Action::perform() {
2027
if (performFunction_) {
21-
return (performer->*performFunction_)();
28+
return performFunction_();
2229
}
2330

2431
return false;
2532
}
2633

27-
bool Action::perform(AnthyState *performer, const fcitx::KeyEvent &key) {
28-
if (!performFunction_)
34+
bool Action::perform(const fcitx::KeyEvent &key) {
35+
if (!performFunction_) {
2936
return false;
37+
}
3038

3139
if (!matchKeyEvent(key)) {
3240
return false;
3341
}
34-
return (performer->*performFunction_)();
42+
return performFunction_();
3543
}
3644

3745
bool Action::matchKeyEvent(const fcitx::KeyEvent &key) {

src/action.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
#define _FCITX5_ANTHY_ACTION_H_
1010

1111
#include <fcitx-config/option.h>
12+
#include <fcitx-utils/key.h>
13+
#include <fcitx-utils/macros.h>
1214
#include <fcitx/event.h>
15+
#include <functional>
1316
#include <string>
1417

1518
#define ACTION_CONFIG_CIRCLE_INPUT_MODE_KEY "CircleInputModeKey"
@@ -92,18 +95,16 @@
9295

9396
class AnthyState;
9497

95-
typedef bool (AnthyState::*PMF)();
96-
9798
class Action {
9899

99100
public:
100101
Action();
101-
Action(const std::string &name, const fcitx::KeyList &hotkey, PMF pmf);
102+
Action(std::string name, const fcitx::KeyList &hotkey,
103+
std::function<bool()> pmf);
102104
FCITX_INLINE_DEFINE_DEFAULT_DTOR_AND_MOVE_WITHOUT_SPEC(Action);
103105

104-
public:
105-
bool perform(AnthyState *performer);
106-
bool perform(AnthyState *performer, const fcitx::KeyEvent &key);
106+
bool perform();
107+
bool perform(const fcitx::KeyEvent &key);
107108

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

@@ -113,7 +114,7 @@ class Action {
113114

114115
private:
115116
std::string name_;
116-
PMF performFunction_;
117+
std::function<bool()> performFunction_;
117118
const fcitx::KeyList *keyBindings_;
118119
};
119120

src/config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
#include <fcitx-config/enum.h>
1212
#include <fcitx-config/option.h>
1313
#include <fcitx-utils/i18n.h>
14+
#include <fcitx-utils/key.h>
15+
#include <fcitx-utils/keysym.h>
1416
#include <fcitx/candidatelist.h>
17+
#include <string>
1518

1619
namespace fcitx {
1720
FCITX_CONFIG_ENUM_NAME_WITH_I18N(CandidateLayoutHint, N_("Not Set"),
@@ -80,6 +83,11 @@ enum class TenKeyType {
8083
FCITX_CONFIG_ENUM_NAME_WITH_I18N(TenKeyType, N_("Wide"), N_("Half"),
8184
N_("Follow mode"));
8285

86+
enum class PeriodBehavior { None, Convert, Commit };
87+
88+
FCITX_CONFIG_ENUM_NAME_WITH_I18N(PeriodBehavior, N_("None"), N_("Convert"),
89+
N_("Commit"));
90+
8391
struct AnthyKeyProfile {
8492

8593
fcitx::KeyList hk_CONVERT;
@@ -202,6 +210,10 @@ FCITX_CONFIGURATION(
202210
fcitx::OptionWithAnnotation<TenKeyType, TenKeyTypeI18NAnnotation>
203211
tenKeyType{this, "TenKeyType", _("Ten key type"),
204212
TenKeyType::FOLLOWMODE};
213+
fcitx::OptionWithAnnotation<PeriodBehavior, PeriodBehaviorI18NAnnotation>
214+
periodBehavior{this, "PeriodBehavior",
215+
_("Behavior on a comma or a period"),
216+
PeriodBehavior::None};
205217
fcitx::Option<bool> learnOnManualCommit{this, "LearnOnManualCommit",
206218
_("Learn on manual commit"), true};
207219
fcitx::Option<bool> learnOnAutoCommit{this, "LearnOnAutoCommit",

0 commit comments

Comments
 (0)