Skip to content

Commit bb9a65f

Browse files
committed
Save initial input configuration
1 parent 78e5b52 commit bb9a65f

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.0)
2-
project(fcitx5-cskk VERSION 0.1.0)
2+
project(fcitx5-cskk VERSION 0.2.0-dev)
33
set(CMAKE_CXX_STANDARD 20)
44

55
find_package(ECM 1.0.0 REQUIRED)

src/cskk.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include "cskk.h"
1515
#include <cstdlib>
16+
#include <fcitx-config/iniparser.h>
1617
#include <fcitx-utils/log.h>
1718
#include <fcitx/addonmanager.h>
1819
#include <fcitx/inputpanel.h>
@@ -32,7 +33,7 @@ FCITX_DEFINE_LOG_CATEGORY(cskk_log, "cskk");
3233
/*******************************************************************************
3334
* CskkEngine
3435
******************************************************************************/
35-
36+
const string CskkEngine::config_file_path = "conf/fcitx5-cskk";
3637
CskkEngine::CskkEngine(Instance *instance)
3738
: instance_{instance}, factory_([this](InputContext &ic) {
3839
auto newCskkContext = new FcitxCskkContext(this, &ic);
@@ -49,7 +50,7 @@ void CskkEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) {
4950
auto ic = keyEvent.inputContext();
5051
auto context = ic->propertyFor(&factory_);
5152
context->keyEvent(keyEvent);
52-
CSKK_DEBUG() << "CSKK Engine keyEvent end";
53+
CSKK_DEBUG() << "Engine keyEvent end";
5354
}
5455
void CskkEngine::save() {}
5556
void CskkEngine::activate(const InputMethodEntry &, InputContextEvent &) {}
@@ -69,10 +70,13 @@ void CskkEngine::reset(const InputMethodEntry &entry,
6970
void CskkEngine::setConfig(const RawConfig &config) {
7071
CSKK_DEBUG() << "Cskk setconfig";
7172
config_.load(config, true);
72-
// TODO: Save. Any file name convention etc?
73+
safeSaveAsIni(config_, CskkEngine::config_file_path);
74+
reloadConfig();
7375
}
7476
void CskkEngine::reloadConfig() {
7577
CSKK_DEBUG() << "Cskkengine reload config";
78+
readAsIni(config_, CskkEngine::config_file_path);
79+
7680
loadDictionary();
7781
if (factory_.registered()) {
7882
instance_->inputContextManager().foreach ([this](InputContext *ic) {
@@ -175,6 +179,7 @@ void CskkEngine::freeDictionaries() {
175179
FcitxCskkContext::FcitxCskkContext(CskkEngine *engine, InputContext *ic)
176180
: context_(skk_context_new(nullptr, 0)), ic_(ic), engine_(engine) {
177181
CSKK_DEBUG() << "Cskk context new";
182+
skk_context_set_input_mode(context_, *engine_->config().inputMode);
178183
}
179184
FcitxCskkContext::~FcitxCskkContext() = default;
180185
void FcitxCskkContext::keyEvent(KeyEvent &keyEvent) {
@@ -235,6 +240,11 @@ void FcitxCskkContext::applyConfig() {
235240
skk_context_set_dictionaries(context_, engine_->dictionaries().data(),
236241
engine_->dictionaries().size());
237242
}
243+
void FcitxCskkContext::copyTo(InputContextProperty *context) {
244+
auto otherContext = dynamic_cast<FcitxCskkContext *>(context);
245+
skk_context_set_input_mode(otherContext->context(),
246+
skk_context_get_input_mode(context_));
247+
}
238248

239249
/*******************************************************************************
240250
* CskkFactory

src/cskk.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct InputModeAnnotation : public EnumAnnotation {
5050
FCITX_CONFIGURATION(
5151
CskkConfig,
5252
OptionWithAnnotation<InputMode, InputModeAnnotation> inputMode{
53-
this, "InitialInputMode", _("InitialInputMode. Fake yet."), Hiragana};
53+
this, "InitialInputMode", _("InitialInputMode"), Hiragana};
5454
Option<bool> showAnnotation{this, "ShowAnnotation",
5555
_("Show Annotation. Fake yet."), true};);
5656

@@ -71,14 +71,18 @@ class CskkEngine final : public InputMethodEngine {
7171
const Configuration *getConfig() const override { return &config_; }
7272
void setConfig(const RawConfig &config) override;
7373
void reloadConfig() override;
74+
7475
const auto &dictionaries() { return dictionaries_; }
76+
const auto &config() { return config_; }
7577

7678
private:
7779
Instance *instance_;
7880
FactoryFor<FcitxCskkContext> factory_;
7981
CskkConfig config_;
8082
std::vector<CskkDictionaryFfi *> dictionaries_;
8183

84+
static const std::string config_file_path;
85+
8286
void loadDictionary();
8387
static std::string getXDGDataHome();
8488
static std::vector<std::string> getXDGDataDirs();
@@ -90,13 +94,17 @@ class FcitxCskkContext final : public InputContextProperty {
9094
public:
9195
FcitxCskkContext(CskkEngine *engine, InputContext *ic);
9296
~FcitxCskkContext() override;
97+
// Copy used for sharing state among programs
98+
void copyTo(InputContextProperty *state) override;
99+
93100
void keyEvent(KeyEvent &keyEvent);
94101
void commitPreedit();
95102
void reset();
96103
void updateUI();
97-
98104
void applyConfig();
99105

106+
auto &context() { return context_; }
107+
100108
private:
101109
// TODO: unique_ptr using some wrapper class for Rust exposed pointer? Need
102110
// bit more research.

0 commit comments

Comments
 (0)