From 6effa275c837ea1347c1df93855bf7f296579fdb Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 18 Aug 2017 14:21:07 +0800 Subject: use sort option for pinyin_guess_candidates function --- src/PYConfig.cc | 1 + src/PYConfig.h | 2 ++ src/PYPConfig.cc | 30 ++++++++++++++++++++++++++++++ src/PYPFullPinyinEditor.cc | 11 ----------- src/PYPFullPinyinEditor.h | 1 - src/PYPPhoneticEditor.cc | 3 ++- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/PYConfig.cc b/src/PYConfig.cc index 9bbc0c8..3741a89 100644 --- a/src/PYConfig.cc +++ b/src/PYConfig.cc @@ -47,6 +47,7 @@ Config::initDefaultValues (void) m_orientation = IBUS_ORIENTATION_HORIZONTAL; m_page_size = 5; m_remember_every_input = FALSE; + m_sort_option = SORT_BY_PHRASE_LENGTH_AND_FREQUENCY; m_shift_select_candidate = FALSE; m_minus_equal_page = TRUE; diff --git a/src/PYConfig.h b/src/PYConfig.h index 31efd38..d841949 100644 --- a/src/PYConfig.h +++ b/src/PYConfig.h @@ -46,6 +46,7 @@ public: guint orientation (void) const { return m_orientation; } guint pageSize (void) const { return m_page_size; } gboolean rememberEveryInput (void) const { return m_remember_every_input; } + sort_option_t sortOption (void) const { return m_sort_option; } gboolean shiftSelectCandidate (void) const { return m_shift_select_candidate; } gboolean minusEqualPage (void) const { return m_minus_equal_page; } gboolean commaPeriodPage (void) const { return m_comma_period_page; } @@ -96,6 +97,7 @@ protected: gint m_orientation; guint m_page_size; gboolean m_remember_every_input; + sort_option_t m_sort_option; gboolean m_shift_select_candidate; gboolean m_minus_equal_page; diff --git a/src/PYPConfig.cc b/src/PYPConfig.cc index 36d1e95..d7ab813 100644 --- a/src/PYPConfig.cc +++ b/src/PYPConfig.cc @@ -33,6 +33,7 @@ const gchar * const CONFIG_FUZZY_PINYIN = "fuzzy_pinyin"; const gchar * const CONFIG_ORIENTATION = "lookup_table_orientation"; const gchar * const CONFIG_PAGE_SIZE = "lookup_table_page_size"; const gchar * const CONFIG_REMEMBER_EVERY_INPUT = "remember_every_input"; +const gchar * const CONFIG_SORT_OPTION = "sort_option"; const gchar * const CONFIG_SHIFT_SELECT_CANDIDATE = "shift_select_candidate"; const gchar * const CONFIG_MINUS_EQUAL_PAGE = "minus_equal_page"; const gchar * const CONFIG_COMMA_PERIOD_PAGE = "comma_period_page"; @@ -93,6 +94,7 @@ LibPinyinConfig::initDefaultValues (void) m_orientation = IBUS_ORIENTATION_HORIZONTAL; m_page_size = 5; m_remember_every_input = FALSE; + m_sort_option = SORT_BY_PHRASE_LENGTH_AND_FREQUENCY; m_shift_select_candidate = FALSE; m_minus_equal_page = TRUE; @@ -139,6 +141,14 @@ static const struct { { "dynamic_adjust", DYNAMIC_ADJUST }, }; +static const struct{ + gint sort_option_index; + sort_option_t sort_option; +} sort_options [] = { + {0, SORT_BY_PHRASE_LENGTH_AND_FREQUENCY}, + {1, SORT_BY_PHRASE_LENGTH_AND_PINYIN_LENGTH_AND_FREQUENCY} +}; + void LibPinyinConfig::readDefaultValues (void) { @@ -184,6 +194,16 @@ LibPinyinConfig::readDefaultValues (void) } m_remember_every_input = read (CONFIG_REMEMBER_EVERY_INPUT, false); + const gint index = read (CONFIG_SORT_OPTION, 0); + m_sort_option = SORT_BY_PHRASE_LENGTH_AND_FREQUANCY; + + for (guint i = 0; i < G_N_ELEMENTS (sort_options); i++) { + if (index == sort_options[i].sort_option_index) { + /* set sort option. */ + m_sort_option = sort_options[i].sort_option; + } + } + m_dictionaries = read (CONFIG_DICTIONARIES, std::string ("")); m_main_switch = read (CONFIG_MAIN_SWITCH, std::string ("")); @@ -235,6 +255,16 @@ LibPinyinConfig::valueChanged (const std::string §ion, } } else if (CONFIG_REMEMBER_EVERY_INPUT == name) { m_remember_every_input = normalizeGVariant (value, false); + } else if (CONFIG_SORT_OPTION == name) { + const gint index = normalizeGVariant (value, 0); + m_sort_option = SORT_BY_PHRASE_LENGTH_AND_FREQUENCY; + + for (guint i = 0; i < G_N_ELEMENTS (sort_options); i++) { + if (index == sort_options[i].sort_option_index) { + /* set sort option. */ + m_sort_option = sort_options[i].sort_option; + } + } } else if (CONFIG_DICTIONARIES == name) { m_dictionaries = normalizeGVariant (value, std::string ("")); } else if (CONFIG_MAIN_SWITCH == name) { diff --git a/src/PYPFullPinyinEditor.cc b/src/PYPFullPinyinEditor.cc index b0ad3d7..27d5f26 100644 --- a/src/PYPFullPinyinEditor.cc +++ b/src/PYPFullPinyinEditor.cc @@ -106,17 +106,6 @@ FullPinyinEditor::updateAuxiliaryText (void) Editor::updateAuxiliaryText (text, TRUE); } -void -FullPinyinEditor::update (void) -{ - guint lookup_cursor = getLookupCursor (); - pinyin_guess_candidates (m_instance, lookup_cursor); - - updateLookupTable (); - updatePreeditText (); - updateAuxiliaryText (); -} - guint FullPinyinEditor::getLookupCursor (void) { diff --git a/src/PYPFullPinyinEditor.h b/src/PYPFullPinyinEditor.h index 84a160f..5f8e9e9 100644 --- a/src/PYPFullPinyinEditor.h +++ b/src/PYPFullPinyinEditor.h @@ -38,7 +38,6 @@ public: virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void reset (void); virtual void updateAuxiliaryText (void); - virtual void update (void); protected: diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index 8141685..481a06f 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -336,7 +336,8 @@ void PhoneticEditor::update (void) { guint lookup_cursor = getLookupCursor (); - pinyin_guess_candidates (m_instance, lookup_cursor); + pinyin_guess_candidates (m_instance, lookup_cursor, + m_config.sortOption ()); updateLookupTable (); updatePreeditText (); -- cgit