summaryrefslogtreecommitdiffstats
path: root/src/PYPBopomofoEngine.cc
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2018-06-15 16:02:18 +0800
committerPeng Wu <alexepico@gmail.com>2018-06-15 16:02:18 +0800
commitea4784475c1491c9eb6fd0eec454588f2333ce75 (patch)
tree58c639adca5481d770cbfe4d63a34d70b3e06828 /src/PYPBopomofoEngine.cc
parent6eed8c257e9c5870fcd32aa8eedf01ce7bec6613 (diff)
downloadibus-libpinyin-ea4784475c1491c9eb6fd0eec454588f2333ce75.tar.gz
ibus-libpinyin-ea4784475c1491c9eb6fd0eec454588f2333ce75.tar.xz
ibus-libpinyin-ea4784475c1491c9eb6fd0eec454588f2333ce75.zip
support suggestion mode in BopomofoEngine
Diffstat (limited to 'src/PYPBopomofoEngine.cc')
-rw-r--r--src/PYPBopomofoEngine.cc47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/PYPBopomofoEngine.cc b/src/PYPBopomofoEngine.cc
index 0fc97ae..02faf0a 100644
--- a/src/PYPBopomofoEngine.cc
+++ b/src/PYPBopomofoEngine.cc
@@ -22,6 +22,7 @@
*/
#include "PYPBopomofoEngine.h"
#include <string>
+#include <assert.h>
#include "PYPunctEditor.h"
#include "PYPBopomofoEditor.h"
#include "PYFallbackEditor.h"
@@ -81,7 +82,7 @@ BopomofoEngine::processAccelKeyEvent (guint keyval, guint keycode,
gboolean triggered = FALSE;
if (m_prev_pressed_key == keyval) {
- if (PinyinConfig::instance ().mainSwitch () == accel) {
+ if (BopomofoConfig::instance ().mainSwitch () == accel) {
triggered = TRUE;
}
}
@@ -104,21 +105,21 @@ BopomofoEngine::processAccelKeyEvent (guint keyval, guint keycode,
}
/* Toggle full/half Letter Mode */
- if (PinyinConfig::instance (). letterSwitch () == accel) {
+ if (BopomofoConfig::instance (). letterSwitch () == accel) {
m_props.toggleModeFull ();
m_prev_pressed_key = keyval;
return TRUE;
}
/* Toggle full/half Punct Mode */
- if (PinyinConfig::instance (). punctSwitch () == accel) {
+ if (BopomofoConfig::instance (). punctSwitch () == accel) {
m_props.toggleModeFullPunct ();
m_prev_pressed_key = keyval;
return TRUE;
}
/* Toggle simp/trad Chinese Mode */
- if (PinyinConfig::instance ().tradSwitch () == accel) {
+ if (BopomofoConfig::instance ().tradSwitch () == accel) {
m_props.toggleModeSimp ();
m_prev_pressed_key = keyval;
return TRUE;
@@ -143,6 +144,29 @@ BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
return FALSE;
if (m_props.modeChinese ()) {
+ /* return from MODE_SUGGESTION to normal input. */
+ if (m_input_mode == MODE_SUGGESTION) {
+ /* only accept input to select candidate. */
+ if (IBUS_Escape == keyval) {
+ m_editors[m_input_mode]->reset ();
+ m_input_mode = MODE_INIT;
+ /* m_editors[m_input_mode]->reset (); */
+ m_editors[m_input_mode]->update ();
+ return TRUE;
+ }
+
+ switch (keyval) {
+ case IBUS_0 ... IBUS_9:
+ case IBUS_space:
+ case IBUS_Return:
+ /* still in suggestion mode. */
+ break;
+
+ default:
+ m_input_mode = MODE_INIT;
+ }
+ }
+
if (G_UNLIKELY (m_input_mode == MODE_INIT &&
m_editors[MODE_INIT]->text ().empty () &&
cmshm_filter (modifiers) == 0 &&
@@ -262,8 +286,21 @@ void
BopomofoEngine::commitText (Text & text)
{
Engine::commitText (text);
- if (m_input_mode != MODE_INIT)
+
+ if (m_input_mode != MODE_INIT && m_input_mode != MODE_SUGGESTION)
m_input_mode = MODE_INIT;
+ else if (BopomofoConfig::instance ().showSuggestion ()) {
+ if (m_input_mode == MODE_INIT) {
+ m_input_mode = MODE_SUGGESTION;
+ m_editors[m_input_mode]->setText (text.text (), 0);
+ m_editors[m_input_mode]->update ();
+ } else if (m_input_mode == MODE_SUGGESTION) {
+ m_editors[m_input_mode]->setText (text.text (), 0);
+ m_editors[m_input_mode]->update ();
+ } else
+ assert (FALSE);
+ }
+
#if 1
/* handle "<num>+.<num>+" here */
if (text.text ())