Add Disable menu item on Input Menu. Use it to disable InputContext.
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 23 Feb 2009 07:05:50 +0000 (15:05 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 23 Feb 2009 07:05:50 +0000 (15:05 +0800)
bus/inputcontext.c
ibus/inputcontext.py
ibus/interface/iinputcontext.py
ui/gtk/panel.py

index 866c837..6ba7322 100644 (file)
@@ -799,6 +799,40 @@ _ic_set_capabilities (BusInputContext  *context,
 }
 
 static IBusMessage *
+_ic_enable (BusInputContext *context,
+            IBusMessage     *message,
+            BusConnection   *connection)
+{
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
+    g_assert (message != NULL);
+    g_assert (BUS_IS_CONNECTION (connection));
+
+    IBusMessage *reply;
+
+    bus_input_context_enable (context);
+
+    reply = ibus_message_new_method_return (message);
+    return reply;
+}
+
+static IBusMessage *
+_ic_disable (BusInputContext *context,
+            IBusMessage     *message,
+            BusConnection   *connection)
+{
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
+    g_assert (message != NULL);
+    g_assert (BUS_IS_CONNECTION (connection));
+
+    IBusMessage *reply;
+
+    bus_input_context_disable (context);
+
+    reply = ibus_message_new_method_return (message);
+    return reply;
+}
+
+static IBusMessage *
 _ic_is_enabled (BusInputContext *context,
                 IBusMessage     *message,
                 BusConnection   *connection)
@@ -945,6 +979,8 @@ bus_input_context_ibus_message (BusInputContext *context,
         { IBUS_INTERFACE_INPUT_CONTEXT, "FocusOut",          _ic_focus_out },
         { IBUS_INTERFACE_INPUT_CONTEXT, "Reset",             _ic_reset },
         { IBUS_INTERFACE_INPUT_CONTEXT, "SetCapabilities",   _ic_set_capabilities },
+        { IBUS_INTERFACE_INPUT_CONTEXT, "Enable",            _ic_enable },
+        { IBUS_INTERFACE_INPUT_CONTEXT, "Disable",           _ic_disable },
         { IBUS_INTERFACE_INPUT_CONTEXT, "IsEnabled",         _ic_is_enabled },
         { IBUS_INTERFACE_INPUT_CONTEXT, "SetEngine",         _ic_set_engine },
         { IBUS_INTERFACE_INPUT_CONTEXT, "GetEngine",         _ic_get_engine },
index 10233da..c9aa634 100644 (file)
@@ -197,6 +197,12 @@ class InputContext(object.Object):
     def reset(self):
         return self.__context.Reset()
 
+    def enable(self):
+        return self.__context.Enable()
+
+    def disable(self):
+        return self.__context.Disable()
+
     def is_enabled(self):
         return self.__context.IsEnabled()
 
index e5cf129..d88a9c1 100644 (file)
@@ -57,6 +57,12 @@ class IInputContext(dbus.service.Object):
     @method()
     def Reset(self): pass
 
+    @method()
+    def Enable(self): pass
+
+    @method()
+    def Disable(self): pass
+
     @method(out_signature="b")
     def IsEnabled(self): pass
 
index ee29ea0..fb9ae6e 100644 (file)
@@ -314,11 +314,11 @@ class Panel(ibus.PanelBase):
                 langs.remove(_("Other"))
                 langs.append(_("Other"))
 
+            size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
             for lang in langs:
                 if len(tmp[lang]) == 1:
                     engine = tmp[lang][0]
                     item = gtk.ImageMenuItem("%s - %s" % (lang, engine.longname))
-                    size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
                     if engine.icon:
                         item.set_image (_icon.IconWidget(engine.icon, size[0]))
                     else:
@@ -332,7 +332,6 @@ class Panel(ibus.PanelBase):
                     item.set_submenu(submenu)
                     for engine in tmp[lang]:
                         item = gtk.ImageMenuItem(engine.longname)
-                        size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
                         if engine.icon:
                             item.set_image (_icon.IconWidget(engine.icon, size[0]))
                         else:
@@ -340,6 +339,11 @@ class Panel(ibus.PanelBase):
                         item.connect("activate", self.__im_menu_item_activate_cb, engine)
                         submenu.add(item)
 
+        item = gtk.ImageMenuItem(_("Disable"))
+        item.set_image (_icon.IconWidget("gtk-close", size[0]))
+        item.connect("activate", self.__im_menu_item_activate_cb, None)
+        menu.add (item)
+
         menu.show_all()
         menu.set_take_focus(False)
         return menu
@@ -367,7 +371,10 @@ class Panel(ibus.PanelBase):
                 self.__status_icon)
 
     def __im_menu_item_activate_cb(self, item, engine):
-        self.__focus_ic.set_engine(engine)
+        if engine:
+            self.__focus_ic.set_engine(engine)
+        else:
+            self.__focus_ic.disable()
 
     def __sys_menu_item_activate_cb(self, item, command):
         if command == gtk.STOCK_PREFERENCES: