summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-08-18 14:21:07 +0800
committerPeng Wu <alexepico@gmail.com>2017-08-18 14:21:07 +0800
commit6effa275c837ea1347c1df93855bf7f296579fdb (patch)
tree279cc1f1305631f11010eed2677f956935650055
parent724747e301a1f99939a5f0c9db18ac851242e44a (diff)
downloadibus-libpinyin-6effa275c837ea1347c1df93855bf7f296579fdb.tar.gz
ibus-libpinyin-6effa275c837ea1347c1df93855bf7f296579fdb.tar.xz
ibus-libpinyin-6effa275c837ea1347c1df93855bf7f296579fdb.zip
use sort option for pinyin_guess_candidates function
-rw-r--r--src/PYConfig.cc1
-rw-r--r--src/PYConfig.h2
-rw-r--r--src/PYPConfig.cc30
-rw-r--r--src/PYPFullPinyinEditor.cc11
-rw-r--r--src/PYPFullPinyinEditor.h1
-rw-r--r--src/PYPPhoneticEditor.cc3
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 ("<Shift>"));
@@ -235,6 +255,16 @@ LibPinyinConfig::valueChanged (const std::string &section,
}
} 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 ();