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