Skip to content

Commit

Permalink
Merge pull request rime#58 from rime/feature/alternative_select_labels
Browse files Browse the repository at this point in the history
Fix rime#57: add menu/alternative_select_labels
  • Loading branch information
osfans committed Oct 20, 2015
2 parents 4eade83 + b992f35 commit 4734375
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ typedef struct rime_context_t {
RimeMenu menu;
// v0.9.2
char* commit_text_preview;
char** select_labels;
} RimeContext;

/*!
Expand Down
17 changes: 17 additions & 0 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ RIME_API Bool RimeGetContext(RimeSessionId session_id, RimeContext* context) {
context->menu.select_keys = new char[select_keys.length() + 1];
std::strcpy(context->menu.select_keys, select_keys.c_str());
}
Config* config = schema->config();
an<ConfigList> select_labels = config->GetList("menu/alternative_select_labels");
if (select_labels && page_size <= select_labels->size()) {
context->select_labels = new char*[page_size];
for (size_t i = 0; i < page_size; ++i) {
an<ConfigValue> value = select_labels->GetValueAt(i);
string label = value->str();
context->select_labels[i] = new char[label.length() + 1];
std::strcpy(context->select_labels[i], label.c_str());
}
}
}
}
}
Expand All @@ -297,6 +308,12 @@ RIME_API Bool RimeFreeContext(RimeContext* context) {
}
delete[] context->menu.candidates;
delete[] context->menu.select_keys;
if (RIME_STRUCT_HAS_MEMBER(*context, context->select_labels) && context->select_labels) {
for (int i = 0; i < context->menu.page_size; ++i) {
delete[] context->select_labels[i];
}
delete[] context->select_labels;
}
if (RIME_STRUCT_HAS_MEMBER(*context, context->commit_text_preview)) {
delete[] context->commit_text_preview;
}
Expand Down

0 comments on commit 4734375

Please sign in to comment.