[gedit/wip/redesign2: 12/12] quickopen: add/remove menuitem



commit 9d70253337f7880aa165210f4107c67be3346fb4
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Dec 25 22:08:27 2013 +0100

    quickopen: add/remove menuitem

 plugins/quickopen/quickopen/__init__.py |   59 ++++++++++++++++---------------
 1 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py
index 2ff4054..17da4f1 100644
--- a/plugins/quickopen/quickopen/__init__.py
+++ b/plugins/quickopen/quickopen/__init__.py
@@ -19,21 +19,10 @@
 
 from .popup import Popup
 import os
-from gi.repository import GObject, Gio, Gtk, Gedit
+from gi.repository import GObject, Gio, GLib, Gtk, Gedit
 from .virtualdirs import RecentDocumentsDirectory
 from .virtualdirs import CurrentDocumentsDirectory
 
-ui_str = """<ui>
-  <menubar name="MenuBar">
-    <menu name="FileMenu" action="File">
-      <placeholder name="FileOps_2">
-        <menuitem name="QuickOpen" action="QuickOpen"/>
-      </placeholder>
-    </menu>
-  </menubar>
-</ui>
-"""
-
 class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
     __gtype_name__ = "QuickOpenPlugin"
 
@@ -57,24 +46,36 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
         self._popup_size = size
 
     def _uninstall_menu(self):
-        manager = self.window.get_ui_manager()
-
-        manager.remove_ui(self._ui_id)
-        manager.remove_action_group(self._action_group)
-
-        manager.ensure_update()
+        gear_menu = self.window.get_gear_menu()
+        for i in range(gear_menu.get_n_items()):
+            id_attr = gear_menu.get_item_attribute_value(i, "id", GLib.VariantType.new("s"))
+            if id_attr and id_attr.get_string() == "ext2":
+                model = gear_menu.get_item_link(i, "section")
+                for j in range(model.get_n_items()):
+                    attr = model.get_item_attribute_value(j, "id", GLib.VariantType.new("s"))
+                    if attr and attr.get_string() == "quickopen":
+                        model.remove(j)
+                        break
+                break
+
+        self.window.remove_action("quickopen")
 
     def _install_menu(self):
-        manager = self.window.get_ui_manager()
-        self._action_group = Gtk.ActionGroup(name="GeditQuickOpenPluginActions")
-        self._action_group.add_actions([
-            ("QuickOpen", Gtk.STOCK_OPEN, _("Quick Open..."),
-             '<Primary><Alt>o', _("Quickly open documents"),
-             self.on_quick_open_activate)
-        ])
-
-        manager.insert_action_group(self._action_group)
-        self._ui_id = manager.add_ui_from_string(ui_str)
+        action = Gio.SimpleAction(name="quickopen")
+        action.connect('activate', self.on_quick_open_activate)
+        self.window.add_action(action)
+
+        gear_menu = self.window.get_gear_menu()
+        for i in  range(gear_menu.get_n_items()):
+            id_attr = gear_menu.get_item_attribute_value(i, "id", GLib.VariantType.new("s"))
+            if id_attr and id_attr.get_string() == "ext2":
+                model = gear_menu.get_item_link(i, "section")
+
+                item = Gio.MenuItem.new(_("Quick Open..."), "win.quickopen")
+                item.set_attribute_value("id", GLib.Variant.new_string("quickopen"))
+                item.set_attribute_value("accel", GLib.Variant.new_string("<Primary><Alt>O"))
+                model.append_item(item)
+                break
 
     def _create_popup(self):
         paths = []
@@ -174,7 +175,7 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
         return desktopdir
 
     # Callbacks
-    def on_quick_open_activate(self, action, user_data=None):
+    def on_quick_open_activate(self, action, parameter, user_data=None):
         if not self._popup:
             self._create_popup()
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]