[gedit/wip/redesign2] external tools wip: use hidden-when to filter out items



commit ac0ef7d88008f403e29b8d0c72ac6d1416c392e5
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Jan 6 16:31:25 2014 +0100

    external tools wip: use hidden-when to filter out items

 plugins/externaltools/tools/windowactivatable.py |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/plugins/externaltools/tools/windowactivatable.py 
b/plugins/externaltools/tools/windowactivatable.py
index e17326b..51d9492 100644
--- a/plugins/externaltools/tools/windowactivatable.py
+++ b/plugins/externaltools/tools/windowactivatable.py
@@ -18,7 +18,7 @@
 
 __all__ = ('ExternalToolsPlugin', 'Manager', 'OutputPanel', 'Capture', 'UniqueById')
 
-from gi.repository import Gio, GObject, Gtk, Gedit, PeasGtk
+from gi.repository import GLib, Gio, GObject, Gtk, Gedit, PeasGtk
 from .manager import Manager
 from .library import ToolLibrary
 from .outputpanel import OutputPanel
@@ -53,10 +53,11 @@ class ToolMenu(object):
     def _insert_directory(self, directory, menu):
         for d in sorted(directory.subdirs, key=lambda x: x.name.lower()):
             submenu = Gio.Menu()
-            item = Gio.MenuItem.new_submenu(d.name.replace('_', '__'), submenu)
-            menu.append_item(item)
+            menu.append_submenu(d.name.replace('_', '__'), submenu)
+            section = Gio.Menu()
+            submenu.append_section(None, section)
 
-            self._insert_directory(d, submenu)
+            self._insert_directory(d, section)
 
         for tool in sorted(directory.tools, key=lambda x: x.name.lower()):
             action_name = 'external-tool_%X_%X' % (id(tool), id(tool.name))
@@ -66,7 +67,9 @@ class ToolMenu(object):
             action.connect('activate', capture_menu_action, self._window, self._panel, tool)
             self._window.add_action(action)
 
-            menu.append(tool.name.replace('_', '__'), "win.%s" % action_name)
+            item = Gio.MenuItem.new(tool.name.replace('_', '__'), "win.%s" % action_name)
+            item.set_attribute_value("hidden-when", GLib.Variant.new_string("action-disabled"))
+            menu.append_item(item)
 
             if tool.shortcut:
                 app = Gio.Application.get_default()
@@ -141,11 +144,13 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
         external_tools_submenu = Gio.Menu()
         item = Gio.MenuItem.new_submenu(_("External _Tools"), external_tools_submenu)
         self.gear_menu.append_menu_item(item)
+        external_tools_submenu_section = Gio.Menu()
+        external_tools_submenu.append_section(None, external_tools_submenu_section)
 
         # Create output console
         self._output_buffer = OutputPanel(self.plugin_info.get_data_dir(), self.window)
 
-        self.menu = ToolMenu(self._library, self.window, self._output_buffer, external_tools_submenu)
+        self.menu = ToolMenu(self._library, self.window, self._output_buffer, external_tools_submenu_section)
 
         bottom = self.window.get_bottom_panel()
         image = Gtk.Image.new_from_icon_name("system-run-symbolic", Gtk.IconSize.MENU)


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