Auto swith mode when user press www. http: xxx@
authorPeng Huang <shawn.p.huang@gmail.com>
Wed, 10 Mar 2010 07:54:24 +0000 (15:54 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Wed, 10 Mar 2010 07:54:24 +0000 (15:54 +0800)
src/Editor.cc
src/Editor.h
src/Makefile.am
src/PinyinEditor.cc
src/PinyinEngine.cc
src/PinyinEngine.h
src/Pointer.h

index ab7d1bd..176023b 100644 (file)
@@ -16,8 +16,7 @@ Editor::~Editor (void)
 gboolean
 Editor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
 {
-    modifiers &= (IBUS_SHIFT_MASK |
-                  IBUS_CONTROL_MASK |
+    modifiers &= (IBUS_CONTROL_MASK |
                   IBUS_MOD1_MASK |
                   IBUS_SUPER_MASK |
                   IBUS_HYPER_MASK |
@@ -68,6 +67,7 @@ Editor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
             update ();
         }
         return TRUE;
+    case IBUS_space:
     case IBUS_Return:
     case IBUS_KP_Enter:
         {
@@ -80,7 +80,6 @@ Editor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
         reset ();
         return TRUE;
     default:
-        g_debug ("Unknown keyval %d", keyval);
         return TRUE;
     }
 }
index f780dc8..4a6ebca 100644 (file)
@@ -23,6 +23,12 @@ public:
     virtual void reset (void);
     virtual void candidateClicked (guint index, guint button, guint state);
 
+    const String & text (void) const { return m_text; }
+    void setText (const String & text, guint cursor) {
+        m_text = text;
+        m_cursor = cursor;
+    }
+
     /* signals */
     sigc::signal <void, Text &> signalCommitText (void) { return m_signal_commit_text; }
     sigc::signal <void, Text &, guint, gboolean> signalUpdatePreeditText (void) { return m_signal_update_preedit_text; }
index 1b1b80b..8bb0ebd 100644 (file)
@@ -181,9 +181,12 @@ pinyin.xml: pinyin.xml.in
        ) > $@
 
 test: ibus-engine-pinyin
-       $(ENV) G_DEBUG=fatal_warnings \
        $(builddir)/ibus-engine-pinyin
 
+# test: ibus-engine-pinyin
+#      $(ENV) G_DEBUG=fatal_warnings \
+#      $(builddir)/ibus-engine-pinyin
+
 ZhConversion.php:
        wget 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/ZhConversion.php?view=co&content-type=text%2Fplain' \
                -O $@
index 23cb565..64d9b99 100644 (file)
@@ -70,7 +70,7 @@ PinyinEditor::processNumber (guint keyval, guint keycode, guint modifiers)
     }
     if (modifiers == 0)
         selectCandidateInPage (i);
-    else if ((modifiers & ~ IBUS_LOCK_MASK) == IBUS_CONTROL_MASK)
+    else if ((modifiers & ~IBUS_LOCK_MASK) == IBUS_CONTROL_MASK)
         resetCandidateInPage (i);
     return TRUE;
 }
index eda9348..052ab68 100644 (file)
@@ -32,6 +32,7 @@ PinyinEngine::PinyinEngine (IBusEngine *engine)
     else
         m_editors[MODE_INIT] = new FullPinyinEditor (m_props);
 
+    m_editors[MODE_RAW] = new RawEditor (m_props);
     m_editors[MODE_EXTENSION] = new ExtEditor (m_props);
 
     m_props.signalUpdateProperty ().connect (sigc::mem_fun (*this, &PinyinEngine::slotUpdateProperty));
@@ -51,10 +52,18 @@ PinyinEngine::~PinyinEngine (void)
     }
 }
 
+
+#define CASHM_MASK       \
+    (IBUS_CONTROL_MASK | \
+    IBUS_MOD1_MASK |     \
+    IBUS_SUPER_MASK |    \
+    IBUS_HYPER_MASK |    \
+    IBUS_META_MASK)
+
 gboolean
 PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
 {
-    gboolean retval;
+    gboolean retval = FALSE;
 
     /* check Shift + Release hotkey,
      * and then ignore other Release key event */
@@ -66,17 +75,48 @@ PinyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers)
                 m_props.toggleModeChinese ();
             }
         }
-        m_prev_pressed_key = 0;
         return TRUE;
     }
 
-    retval = m_props.modeChinese () && m_editors[m_input_mode]->processKeyEvent (keyval, keycode, modifiers);
+    if (m_props.modeChinese ()) {
+        if (m_input_mode == MODE_INIT &&
+            ((modifiers & CASHM_MASK) == 0)) {
+            const String & text = m_editors[MODE_INIT]->text ();
+            if (text.isEmpty ()) {
+            #if 0
+                if (keyval == IBUS_i) {
+                    m_input_mode = MODE_EXTENSION;
+                }
+            #endif
+            }
+            else {
+                if (m_prev_pressed_key != IBUS_period) {
+                    if ((keyval == IBUS_at || keyval == IBUS_colon)) {
+                        m_input_mode = MODE_RAW;
+                        m_editors[MODE_RAW]->setText (text, text.length ());
+                        m_editors[MODE_INIT]->reset ();
+                    }
+                }
+                else {
+                    if ((keyval >= IBUS_a && keyval <= IBUS_z) ||
+                        (keyval >= IBUS_A && keyval <= IBUS_Z)) {
+                        String tmp = text;
+                        tmp += ".";
+                        m_input_mode = MODE_RAW;
+                        m_editors[MODE_RAW]->setText (tmp, tmp.length ());
+                        m_editors[MODE_INIT]->reset ();
+                    }
+                }
+            }
+        }
+        retval = m_editors[m_input_mode]->processKeyEvent (keyval, keycode, modifiers);
+    }
 
     if (G_UNLIKELY (!retval))
         retval = m_fallback_editor.processKeyEvent (keyval, keycode, modifiers);
 
     /* store ignored key event by editors */
-    m_prev_pressed_key = retval ? 0 : keyval;
+    m_prev_pressed_key = keyval;
 
     return retval;
 }
@@ -155,6 +195,8 @@ void
 PinyinEngine::slotCommitText (Text & text)
 {
     ibus_engine_commit_text (m_engine, text);
+    if (m_input_mode != MODE_INIT)
+        m_input_mode = MODE_INIT;
 }
 
 void
index a39c5cd..8708275 100644 (file)
@@ -74,8 +74,8 @@ private:
 
     enum {
         MODE_INIT = 0,          // init mode
-    #if 0
         MODE_RAW,               // raw mode
+    #if 0
         MODE_ENGLISH,           // press v into English input mode
         MODE_STROKE,            // press u into stroke input mode
     #endif
index 1fd1c08..dd963f4 100644 (file)
@@ -23,7 +23,9 @@ public:
 
         m_p = p;
         if (p) {
-            // g_debug ("%s, floating = %d",G_OBJECT_TYPE_NAME (p), g_object_is_floating (p));
+       #if 0
+            g_debug ("%s, floating = %d",G_OBJECT_TYPE_NAME (p), g_object_is_floating (p));
+       #endif
             g_object_ref_sink (p);
         }
     }