Add "Automatic reordering" option
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Mon, 9 Jan 2012 14:22:29 +0000 (23:22 +0900)
committerChoe Hwanjin <choe.hwanjin@gmail.com>
Mon, 9 Jan 2012 14:22:29 +0000 (23:22 +0900)
setup/main.py
setup/setup.ui
src/engine.c

index d4a76d3..9dd0238 100644 (file)
@@ -71,6 +71,10 @@ class Setup ():
        word_commit = self.__read("WordCommit", False)
         self.__word_commit.set_active(word_commit)
 
+       self.__auto_reorder = self.__builder.get_object("AutoReorder")
+       auto_reorder = self.__read("AutoReorder", True)
+        self.__auto_reorder.set_active(auto_reorder)
+
        # hanja tab
        button = self.__builder.get_object("HanjaKeyListAddButton")
        button.connect("clicked", self.on_hanja_key_add, None)
index 4e14375..6f928b0 100644 (file)
                             <property name="position">1</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkHBox" id="hbox7">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkCheckButton" id="AutoReorder">
+                                <property name="label" translatable="yes">Automatic _reordering</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="active">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="padding">12</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">2</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
index 6b0be64..602f073 100644 (file)
@@ -138,6 +138,11 @@ static void ibus_hangul_engine_update_lookup_table
                                             (IBusHangulEngine       *hangul);
 static gboolean ibus_hangul_engine_has_preedit
                                             (IBusHangulEngine       *hangul);
+static bool ibus_hangul_engine_on_transition
+                                            (HangulInputContext     *hic,
+                                             ucschar                 c,
+                                             const ucschar          *preedit,
+                                             void                   *data);
 
 static void ibus_config_value_changed       (IBusConfig             *config,
                                              const gchar            *section,
@@ -178,6 +183,7 @@ static HanjaKeyList hanja_keys;
 static int lookup_table_orientation = 0;
 static IBusKeymap *keymap = NULL;
 static gboolean word_commit = FALSE;
+static gboolean auto_reorder = TRUE;
 
 static glong
 ucschar_strlen (const ucschar* str)
@@ -257,6 +263,12 @@ ibus_hangul_init (IBusBus *bus)
         g_variant_unref(value);
     }
 
+    value = ibus_config_get_value (config, "engine/Hangul", "AutoReorder");
+    if (value != NULL) {
+        auto_reorder = g_variant_get_boolean (value);
+        g_variant_unref (value);
+    }
+
     keymap = ibus_keymap_get("us");
 }
 
@@ -323,6 +335,9 @@ ibus_hangul_engine_init (IBusHangulEngine *hangul)
     IBusText* tooltip;
 
     hangul->context = hangul_ic_new (hangul_keyboard->str);
+    hangul_ic_connect_callback (hangul->context, "transition",
+                                ibus_hangul_engine_on_transition, hangul);
+
     hangul->preedit = ustring_new();
     hangul->hanja_list = NULL;
     hangul->hangul_mode = TRUE;
@@ -1224,6 +1239,27 @@ ibus_hangul_engine_has_preedit (IBusHangulEngine *hangul)
     return FALSE;
 }
 
+static bool
+ibus_hangul_engine_on_transition (HangulInputContext     *hic,
+                                  ucschar                 c,
+                                  const ucschar          *preedit,
+                                  void                   *data)
+{
+    if (!auto_reorder) {
+        if (hangul_is_choseong (c)) {
+            if (hangul_ic_has_jungseong (hic) || hangul_ic_has_jongseong (hic))
+                return false;
+        }
+
+        if (hangul_is_jungseong (c)) {
+            if (hangul_ic_has_jongseong (hic))
+                return false;
+        }
+    }
+
+    return true;
+}
+
 static void
 ibus_config_value_changed (IBusConfig   *config,
                            const gchar  *section,
@@ -1243,6 +1279,8 @@ ibus_config_value_changed (IBusConfig   *config,
            hanja_key_list_set_from_string(&hanja_keys, str);
         } else if (strcmp(name, "WordCommit") == 0) {
             word_commit = g_variant_get_boolean (value);
+        } else if (strcmp (name, "AutoReorder") == 0) {
+            auto_reorder = g_variant_get_boolean (value);
         }
     } else if (strcmp(section, "panel") == 0) {
         if (strcmp(name, "lookup_table_orientation") == 0) {