From 4e4a49182d488730c0467fca7a63f8e756c66804 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Tue, 13 Feb 2018 15:00:46 +0800 Subject: [PATCH] fix(rime_api): use user_config_open() to access user.yaml --- src/rime_api.cc | 27 ++++++++++++++++----------- src/rime_api.h | 5 +++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/rime_api.cc b/src/rime_api.cc index 02271b25e..39e8251d5 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -542,24 +542,28 @@ RIME_API Bool RimeSelectSchema(RimeSessionId session_id, const char* schema_id) // config -RIME_API Bool RimeSchemaOpen(const char *schema_id, RimeConfig* config) { - if (!schema_id || !config) return False; - Config::Component* cc = Config::Require("schema"); +static Bool open_config_in_component(const char* config_component, + const char* config_id, + RimeConfig* config) { + if (!config_id || !config) return False; + Config::Component* cc = Config::Require(config_component); if (!cc) return False; - Config* c = cc->Create(schema_id); + Config* c = cc->Create(config_id); if (!c) return False; config->ptr = (void*)c; return True; } +RIME_API Bool RimeSchemaOpen(const char *schema_id, RimeConfig* config) { + return open_config_in_component("schema", schema_id, config); +} + RIME_API Bool RimeConfigOpen(const char *config_id, RimeConfig* config) { - if (!config_id || !config) return False; - Config::Component* cc = Config::Require("config"); - if (!cc) return False; - Config* c = cc->Create(config_id); - if (!c) return False; - config->ptr = (void*)c; - return True; + return open_config_in_component("config", config_id, config); +} + +RIME_API Bool RimeUserConfigOpen(const char* config_id, RimeConfig* config) { + return open_config_in_component("user_config", config_id, config); } RIME_API Bool RimeConfigClose(RimeConfig *config) { @@ -1008,6 +1012,7 @@ RIME_API RimeApi* rime_get_api() { s_api.select_schema = &RimeSelectSchema; s_api.schema_open = &RimeSchemaOpen; s_api.config_open = &RimeConfigOpen; + s_api.user_config_open = &RimeUserConfigOpen; s_api.config_close = &RimeConfigClose; s_api.config_get_bool = &RimeConfigGetBool; s_api.config_get_int = &RimeConfigGetInt; diff --git a/src/rime_api.h b/src/rime_api.h index 07cdf82c2..2d39d21e7 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -283,6 +283,8 @@ RIME_API Bool RimeSelectSchema(RimeSessionId session_id, const char* schema_id); RIME_API Bool RimeSchemaOpen(const char* schema_id, RimeConfig* config); // .yaml RIME_API Bool RimeConfigOpen(const char* config_id, RimeConfig* config); +// access config files in user data directory, eg. user.yaml and installation.yaml +RIME_API Bool RimeUserConfigOpen(const char* config_id, RimeConfig* config); RIME_API Bool RimeConfigClose(RimeConfig* config); RIME_API Bool RimeConfigInit(RimeConfig* config); RIME_API Bool RimeConfigLoadString(RimeConfig* config, const char* yaml); @@ -513,6 +515,9 @@ typedef struct rime_api_t { Bool (*candidate_list_next)(RimeCandidateListIterator* iterator); void (*candidate_list_end)(RimeCandidateListIterator* iterator); + // access config files in user data directory, eg. user.yaml and installation.yaml + Bool (*user_config_open)(const char *config_id, RimeConfig* config); + } RimeApi; //! API entry