diff options
author | Peng Wu <alexepico@gmail.com> | 2018-06-06 15:11:10 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2018-06-06 15:11:10 +0800 |
commit | 927d3e23a6b8ee30b26b9fe8203c5fc4e56baf52 (patch) | |
tree | f3527944f8830728fc3f7b73bbd5b2d5d6d008f4 /src | |
parent | fa7d7df55f7e2894742851068b39735992cca51d (diff) | |
download | ibus-libpinyin-927d3e23a6b8ee30b26b9fe8203c5fc4e56baf52.tar.gz ibus-libpinyin-927d3e23a6b8ee30b26b9fe8203c5fc4e56baf52.tar.xz ibus-libpinyin-927d3e23a6b8ee30b26b9fe8203c5fc4e56baf52.zip |
re-factor fillLookupTable method
Diffstat (limited to 'src')
-rw-r--r-- | src/PYPPhoneticEditor.cc | 67 | ||||
-rw-r--r-- | src/PYPTradCandidates.cc | 4 |
2 files changed, 9 insertions, 62 deletions
diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index 5e58854..324eabd 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -216,75 +216,20 @@ PhoneticEditor::updateCandidates (void) return TRUE; } -#if 0 -gboolean -PhoneticEditor::fillLookupTableByPage (void) -{ - guint len = 0; - pinyin_get_n_candidate (m_instance, &len); - - guint filled_nr = m_lookup_table.size (); - guint page_size = m_lookup_table.pageSize (); - - /* fill lookup table by libpinyin get candidates. */ - guint need_nr = MIN (page_size, len - filled_nr); - g_assert (need_nr >=0); - if (need_nr == 0) - return FALSE; - - String word; - for (guint i = filled_nr; i < filled_nr + need_nr; i++) { - if (i >= len) /* no more candidates */ - break; - - lookup_candidate_t * candidate = NULL; - pinyin_get_candidate (m_instance, i, &candidate); - - const gchar * phrase_string = NULL; - pinyin_get_candidate_string (m_instance, candidate, &phrase_string); - - /* show get candidates. */ - if (G_LIKELY (m_props.modeSimp ())) { - word = phrase_string; - } else { /* Traditional Chinese */ - word.truncate (0); - SimpTradConverter::simpToTrad (phrase_string, word); - } - - Text text (word); - m_lookup_table.appendCandidate (text); - } - - return TRUE; -} -#endif - gboolean PhoneticEditor::fillLookupTable (void) { - guint len = 0; - pinyin_get_n_candidate (m_instance, &len); - String word; - for (guint i = 0; i < len; i++) { - lookup_candidate_t * candidate = NULL; - pinyin_get_candidate (m_instance, i, &candidate); - - const gchar * phrase_string = NULL; - pinyin_get_candidate_string (m_instance, candidate, &phrase_string); - - /* show get candidates. */ - if (G_LIKELY (m_props.modeSimp ())) { - word = phrase_string; - } else { /* Traditional Chinese */ - word.truncate (0); - SimpTradConverter::simpToTrad (phrase_string, word); - } + for (guint i = 0; i < m_candidates.size (); i++) { + EnhancedCandidate & candidate = m_candidates[i]; + word = candidate.m_display_string; Text text (word); + /* show user candidate as blue. */ - if (pinyin_is_user_candidate (m_instance, candidate)) + if (CANDIDATE_USER == candidate.m_candidate_type) text.appendAttribute (IBUS_ATTR_TYPE_FOREGROUND, 0x000000ef, 0, -1); + m_lookup_table.appendCandidate (text); } diff --git a/src/PYPTradCandidates.cc b/src/PYPTradCandidates.cc index fd221ab..6442783 100644 --- a/src/PYPTradCandidates.cc +++ b/src/PYPTradCandidates.cc @@ -32,6 +32,7 @@ TraditionalCandidates::processCandidates (std::vector<EnhancedCandidate> & candi { m_candidates.clear (); + String trad; for (guint i = 0; i < candidates.size (); i++) { EnhancedCandidate & enhanced = candidates[i]; @@ -39,7 +40,8 @@ TraditionalCandidates::processCandidates (std::vector<EnhancedCandidate> & candi enhanced.m_candidate_type = CANDIDATE_TRADITIONAL_CHINESE; enhanced.m_candidate_id = i; - String trad; + + trad.truncate (0); SimpTradConverter::simpToTrad (enhanced.m_display_string.c_str (), trad); enhanced.m_display_string = trad; } |