Skip to content

Commit

Permalink
fix(rime_api): use user_config_open() to access user.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 13, 2018
1 parent 2e5c39c commit 4e4a491
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// <config_id>.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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4e4a491

Please sign in to comment.