diff options
author | Peng Wu <alexepico@gmail.com> | 2018-05-29 16:38:29 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2018-05-29 19:04:47 +0800 |
commit | f04c1c1fc48323e887180ac83efd7b9d378a732e (patch) | |
tree | 40603b0c854e25de6a57dcb0513602e16dfc92e0 /src | |
parent | 48e0fe774d08fc0f0efeaa5184923958d134a86e (diff) | |
download | ibus-libpinyin-f04c1c1fc48323e887180ac83efd7b9d378a732e.tar.gz ibus-libpinyin-f04c1c1fc48323e887180ac83efd7b9d378a732e.tar.xz ibus-libpinyin-f04c1c1fc48323e887180ac83efd7b9d378a732e.zip |
write class TraditionalCandidates
Diffstat (limited to 'src')
-rw-r--r-- | src/PYPEnhancedCandidates.h | 4 | ||||
-rw-r--r-- | src/PYPPhoneticEditor.h | 2 | ||||
-rw-r--r-- | src/PYPTradCandidates.cc | 63 | ||||
-rw-r--r-- | src/PYPTradCandidates.h | 47 |
4 files changed, 113 insertions, 3 deletions
diff --git a/src/PYPEnhancedCandidates.h b/src/PYPEnhancedCandidates.h index 96b970d..02af094 100644 --- a/src/PYPEnhancedCandidates.h +++ b/src/PYPEnhancedCandidates.h @@ -58,8 +58,8 @@ public: SelectCandidateAction selectCandidate (EnhancedCandidate & candidate); protected: - gboolean selectCandidateInPhoneticEditor (CandidateType type, guint id) { - return m_editor->selectCandidateInternal (type, id); + SelectCandidateAction selectCandidateInPhoneticEditor (EnhancedCandidate & candidate) { + return m_editor->selectCandidateInternal (candidate); } /* will call selectCandidateInternal method of class PhoneticEditor. */ diff --git a/src/PYPPhoneticEditor.h b/src/PYPPhoneticEditor.h index 79ef340..88a36fc 100644 --- a/src/PYPPhoneticEditor.h +++ b/src/PYPPhoneticEditor.h @@ -57,7 +57,7 @@ public: virtual gboolean fillLookupTable (); protected: - gboolean selectCandidateInternal (CandidateType type, guint id); + SelectCandidateAction selectCandidateInternal (EnhancedCandidate & candidate); gboolean selectCandidate (guint i); gboolean selectCandidateInPage (guint i); diff --git a/src/PYPTradCandidates.cc b/src/PYPTradCandidates.cc new file mode 100644 index 0000000..d682f60 --- /dev/null +++ b/src/PYPTradCandidates.cc @@ -0,0 +1,63 @@ +/* vim:set et ts=4 sts=4: + * + * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus + * + * Copyright (c) 2018 Peng Wu <alexepico@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "PYPTradCandidates.h" +#include "PYSimpTradConverter.h" + +using namespace PY; + +gboolean +TraditionalCandidates::processCandidates (std::vector<EnhancedCandidate> & candidates) +{ + m_candidates.clear (); + + for (guint i = 0; i < candidates.size (); i++) { + EnhancedCandidate & candidate = candidates[i]; + + m_candidates.push_back (candidate); + + candidate.m_candidate_type = CANDIDATE_TRADITIONAL_CHINESE; + candidate.m_candidate_id = i; + String trad; + SimpTradConverter::simpToTrad (candidate.c_str (), trad); + candidate.m_display_string = trad; + } + + return TRUE; +} + +SelectCandidateAction +TraditionalCandidates::selectCandidate (EnhancedCandidate & candidate) +{ + assert (CANDIDATE_TRADITIONAL_CHINESE == candidate.m_candidate_type); + + SelectCandidateAction action = SELECT_CANDIDATE_ALREADY_HANDLED; + + action = selectCandidateInPhoneticEditor (candidate); + + if (SELECT_CANDIDATE_MODIFY_IN_PLACE_AND_COMMIT == action) { + String trad; + SimpTradConverter::simpToTrad (candidate.c_str (), trad); + candidate.m_display_string = trad; + } + + return action; +} diff --git a/src/PYPTradCandidates.h b/src/PYPTradCandidates.h new file mode 100644 index 0000000..92579cd --- /dev/null +++ b/src/PYPTradCandidates.h @@ -0,0 +1,47 @@ +/* vim:set et ts=4 sts=4: + * + * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus + * + * Copyright (c) 2018 Peng Wu <alexepico@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __PY_LIB_PINYIN_TRADITIONAL_CANDIDATES_H_ +#define __PY_LIB_PINYIN_TRADITIONAL_CANDIDATES_H_ + +#include <vector> +#include "PYPEnhancedCandidates.h" + +namespace PY { + +class TraditionalCandidates : public EnhancedCandidate { +public: + TraditionalCandidates (PhoneticEditor *editor) { + m_editor = editor; + } + +public: + gboolean processCandidates (std::vector<EnhancedCandidate> & candidates); + + SelectCandidateAction selectCandidate (EnhancedCandidate & candidate); + +protected: + std::vector<EnhancedCandidate> m_candidates; +}; + +}; + +#endif |