diff --git a/src/ime-core/imi_context.cpp b/src/ime-core/imi_context.cpp index d45e97e0..f28d85bc 100644 --- a/src/ime-core/imi_context.cpp +++ b/src/ime-core/imi_context.cpp @@ -759,12 +759,14 @@ CIMIContext::getCandidates(unsigned frIdx, CCandidates& result) cp.m_candi.m_end = frIdx; if (fr.m_bwType != CLatticeFrame::NO_BESTWORD) { for (size_t i = 0; i < m_nBest; i++) { - if (fr.m_bestWords[i].m_start != m_candiStarts) - continue; if (fr.m_bestWords.find(i) == fr.m_bestWords.end()) continue; - CCandidate candi = fr.m_bestWords[i]; + if (candi.m_start != m_candiStarts) + continue; + if (candi.m_pLexiconState == NULL) + continue; + TLexiconState & lxst = *(candi.m_pLexiconState); int len = lxst.m_syls.size() - lxst.m_num_of_inner_fuzzies; if (len == 0) len = 1; diff --git a/src/ime-core/imi_context.h b/src/ime-core/imi_context.h index 7dba54e8..80c79904 100644 --- a/src/ime-core/imi_context.h +++ b/src/ime-core/imi_context.h @@ -256,6 +256,7 @@ class CIMIContext bool searchFrom(unsigned from = 1); + size_t getMaxBest() const { return m_maxBest; } void setMaxBest(size_t maxBest) { m_maxBest = maxBest; for (int i = 0; i < MAX_LATTICE_LENGTH; i++) { @@ -263,6 +264,7 @@ class CIMIContext } } + size_t getMaxTailCandidateNum() const { return m_maxTailCandidateNum; } void setMaxTailCandidateNum(size_t maxTailCandidateNum) { m_maxTailCandidateNum = maxTailCandidateNum; } diff --git a/src/ime-core/imi_view_classic.cpp b/src/ime-core/imi_view_classic.cpp index b838bcd0..d0f3cd4b 100644 --- a/src/ime-core/imi_view_classic.cpp +++ b/src/ime-core/imi_view_classic.cpp @@ -131,6 +131,7 @@ CIMIClassicView::updateWindows(unsigned mask) for (size_t j = 0; j < tail.size(); j++) { tail_text += tail[j].m_cwstr; } + m_tails.push_back(std::make_pair(tail_text, tail)); } } diff --git a/wrapper/ibus/setup/main.py b/wrapper/ibus/setup/main.py index 30fe365a..8c1e8056 100644 --- a/wrapper/ibus/setup/main.py +++ b/wrapper/ibus/setup/main.py @@ -452,6 +452,11 @@ def __init__(self): option_klass=PunctMapping) class MainWindow(): + SPECIAL_OBJECTS = [ + 'pymodel', 'memory_adjustment', 'candidate_adjustment', + 'max_best_adjustment', 'max_tail_candidate_adjustment', + ] + def __init__ (self): self.__bus = ibus.Bus() self.__config = self.__bus.get_config() @@ -466,7 +471,8 @@ def __init_ui(self, name): self.__init_gettext() xml_file = path.join(path.dirname(__file__), XML_FILE) self.__xml = gtk.Builder() - self.__xml.add_objects_from_file(xml_file, [name, 'pymodel', 'memory_adjustment', 'candidate_adjustment']) + self.__xml.add_objects_from_file(xml_file, self.SPECIAL_OBJECTS) + self.__xml.add_objects_from_file(xml_file, [name]) self.__xml.connect_signals(self) self.__init_options() self.window = self.__xml.get_object(name) @@ -486,6 +492,8 @@ def __init_options(self): self.__options = [ TrivalOption("General/MemoryPower", 3, self.__xml), TrivalOption("General/PageSize", 10, self.__xml), + TrivalOption("General/MaxBest", 1, self.__xml), + TrivalOption("General/MaxTailCandidate", 0, self.__xml), RadioOption("General/InitialStatus/Mode", 'Chinese', ['Chinese', 'English'], self.__xml), RadioOption("General/InitialStatus/Punct", 'Full', ['Full', 'Half'], self.__xml), diff --git a/wrapper/ibus/setup/setup.xml b/wrapper/ibus/setup/setup.xml index 49f581c8..246f271a 100644 --- a/wrapper/ibus/setup/setup.xml +++ b/wrapper/ibus/setup/setup.xml @@ -1615,6 +1615,7 @@ SunPinyin Setup False center + True @@ -2540,7 +2541,7 @@ True False 10 - 2 + 4 2 True @@ -2599,6 +2600,64 @@ + + + True + False + 0 + Number of Best Sentence + + + 2 + 3 + + + + + True + False + 0 + Number of Best Tail Candidate + + + 3 + 4 + + + + + True + True + max_best_adjustment + 0 + 0 + right + + + 1 + 2 + 2 + 3 + + + + + + True + True + max_tail_candidate_adjustment + 0 + 0 + right + + + 1 + 2 + 3 + 4 + + + @@ -2778,6 +2837,17 @@ + + 10 + 1 + 1 + 10 + + + 10 + 1 + 10 + 11 3 diff --git a/wrapper/ibus/src/sunpinyin_config_keys.h b/wrapper/ibus/src/sunpinyin_config_keys.h index 8015def7..d04a4c0c 100644 --- a/wrapper/ibus/src/sunpinyin_config_keys.h +++ b/wrapper/ibus/src/sunpinyin_config_keys.h @@ -39,6 +39,8 @@ #define CONFIG_GENERAL_PAGE_SIZE "General/PageSize" #define CONFIG_GENERAL_MEMORY_POWER "General/MemoryPower" #define CONFIG_GENERAL_CHARSET_LEVEL "General/Charset" +#define CONFIG_GENERAL_MAX_BEST "General/MaxBest" +#define CONFIG_GENERAL_MAX_TAIL_CANDIDATE "General/MaxTailCandidate" #define CONFIG_GENERAL_INITIAL_MODE "General/InitialStatus/Mode" #define CONFIG_GENERAL_INITIAL_PUNCT "General/InitialStatus/Punct" #define CONFIG_GENERAL_INITIAL_LETTER "General/InitialStatus/Letter" diff --git a/wrapper/ibus/src/sunpinyin_engine.cpp b/wrapper/ibus/src/sunpinyin_engine.cpp index cc3ed3e7..a928932f 100644 --- a/wrapper/ibus/src/sunpinyin_engine.cpp +++ b/wrapper/ibus/src/sunpinyin_engine.cpp @@ -244,6 +244,10 @@ SunPinyinEngine::onConfigChanged(const COptionEvent& event) update_cand_window_size(); } else if (event.name == CONFIG_GENERAL_CHARSET_LEVEL) { update_charset_level(); + } else if (event.name == CONFIG_GENERAL_MAX_BEST) { + update_max_best(); + } else if (event.name == CONFIG_GENERAL_MAX_TAIL_CANDIDATE) { + update_max_tail_candidate(); } else if (event.name == CONFIG_KEYBOARD_MODE_SWITCH) { update_mode_key(); } else if (event.name == CONFIG_KEYBOARD_PUNCT_SWITCH) { @@ -270,6 +274,8 @@ SunPinyinEngine::update_config() { update_history_power(); update_cand_window_size(); + update_max_best(); + update_max_tail_candidate(); update_charset_level(); update_page_key_minus(); update_page_key_comma(); @@ -350,7 +356,7 @@ SunPinyinEngine::update_preedit_string(const IPreeditString& preedit) ibus_engine_update_preedit_text(m_engine, ibus_text_new_from_ucs4(embed_cstr), - preedit.caret() - embed_pos, TRUE); + preedit.caret(), TRUE); } else { ibus_engine_hide_auxiliary_text(m_engine); @@ -487,6 +493,27 @@ SunPinyinEngine::update_smart_punc() m_pv->setSmartPunct(m_config.get(CONFIG_KEYBOARD_SMARK_PUNCT, true)); } +void +SunPinyinEngine::update_max_best() +{ + if (m_pv->getIC() == NULL) { + return; + } + int oldval = (int) m_pv->getIC()->getMaxBest(); + m_pv->getIC()->setMaxBest(m_config.get(CONFIG_GENERAL_MAX_BEST, oldval)); +} + +void +SunPinyinEngine::update_max_tail_candidate() +{ + if (m_pv->getIC() == NULL) { + return; + } + int oldval = (int) m_pv->getIC()->getMaxTailCandidateNum(); + m_pv->getIC()->setMaxTailCandidateNum( + m_config.get(CONFIG_GENERAL_MAX_TAIL_CANDIDATE, oldval)); +} + string_pairs parse_pairs(const std::vector& strings) { string_pairs pairs; diff --git a/wrapper/ibus/src/sunpinyin_engine.h b/wrapper/ibus/src/sunpinyin_engine.h index a0860a70..9bfb4cb8 100644 --- a/wrapper/ibus/src/sunpinyin_engine.h +++ b/wrapper/ibus/src/sunpinyin_engine.h @@ -101,6 +101,8 @@ class SunPinyinEngine : public IConfigurable void update_candi_delete_key(); void update_cancel_with_backspace(); void update_smart_punc(); + void update_max_best(); + void update_max_tail_candidate(); void update_charset_level(); void update_user_data_dir();