[gedit/wip/redesign2] wip
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/redesign2] wip
- Date: Thu, 2 Jan 2014 22:12:49 +0000 (UTC)
commit 46f0b6720a7143d56583918faebc13c008e9135b
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Jan 2 20:35:23 2014 +0100
wip
plugins/externaltools/tools/functions.py | 2 +-
plugins/externaltools/tools/library.py | 4 +-
plugins/externaltools/tools/windowactivatable.py | 92 +++++++---------------
3 files changed, 32 insertions(+), 66 deletions(-)
---
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index 5fa6a1f..4b758dc 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -286,7 +286,7 @@ class MultipleDocumentsSaver:
if self._counter == 0 and not self._error:
run_external_tool(self._window, self._panel, self._node)
-def capture_menu_action(action, window, panel, node):
+def capture_menu_action(action, parameter, window, panel, node):
if node.save_files == 'document' and window.get_active_document():
MultipleDocumentsSaver(window, panel, False, node)
return
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index 07064da..b1f2113 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -485,9 +485,9 @@ if __name__ == '__main__':
def print_dir(d, indent):
print(indent * " " + d.dirname + '/')
for i in d.subdirs:
- print_dir(i, indent+1)
+ print_dir(i, indent + 1)
for i in d.tools:
- print_tool(i, indent+1)
+ print_tool(i, indent + 1)
print_dir(library.tree, 0)
diff --git a/plugins/externaltools/tools/windowactivatable.py
b/plugins/externaltools/tools/windowactivatable.py
index da8089f..e4dece8 100644
--- a/plugins/externaltools/tools/windowactivatable.py
+++ b/plugins/externaltools/tools/windowactivatable.py
@@ -31,6 +31,8 @@ class ToolMenu(object):
self._library = library
self._window = window
self._panel = panel
+ self._menu = menu
+ self._action_tools = {}
self._signals = []
@@ -40,76 +42,42 @@ class ToolMenu(object):
self.remove()
def remove(self):
- if self._merge_id != 0:
- self._window.get_ui_manager().remove_ui(self._merge_id)
- self._window.get_ui_manager().remove_action_group(self._action_group)
- self._merge_id = 0
+ self._menu.remove_all()
- for action in self._action_group.list_actions():
- if action._tool_handler is not None:
- action.disconnect(action._tool_handler)
+ for name, tool in self._action_tools.items():
+ self._window.remove_action(name)
- action._tool_item = None
- action._tool_handler = None
+ if tool.shortcut:
+ app = Gio.Application.get_default()
+ app.remove_accelerator(tool.shortcut)
- self._action_group.remove_action(action)
+ self._signals = []
- accelmap = Gtk.AccelMap.get()
+ 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)
- for s in self._signals:
- accelmap.disconnect(s)
+ self._insert_directory(d, submenu)
- self._signals = []
+ for tool in sorted(directory.tools, key=lambda x: x.name.lower()):
+ action_name = 'external-tool_%X_%X' % (id(tool), id(tool.name))
+ self._action_tools[action_name] = tool
+
+ action = Gio.SimpleAction(name=action_name)
+ 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)
- def _insert_directory(self, directory, path):
- ui_manager = self._window.get_ui_manager()
-
- for item in sorted(directory.subdirs, key=lambda x: x.name.lower()):
- action_name = 'ExternalToolDirectory_%X_%X' % (id(item), id(item.name))
- action = Gtk.Action(action_name, item.name.replace('_', '__'), None, None)
- self._action_group.add_action(action)
-
- ui_manager.add_ui(self._merge_id, path,
- action_name, action_name,
- Gtk.UIManagerItemType.MENU, False)
-
- self._insert_directory(item, path + '/' + action_name)
-
- for item in sorted(directory.tools, key=lambda x: x.name.lower()):
- action_name = 'ExternalToolTool_%X_%X' % (id(item), id(item.name))
- action = Gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None)
- handler = action.connect("activate", capture_menu_action, self._window, self._panel, item)
-
- # Attach the item and the handler to the action object
- action._tool_item = item
- action._tool_handler = handler
-
- # Make sure to replace accel
- accelpath = '<Actions>/ExternalToolsPluginToolActions/%s' % (action_name, )
-
- if item.shortcut:
- key, mod = Gtk.accelerator_parse(item.shortcut)
- Gtk.AccelMap.change_entry(accelpath, key, mod, True)
-
- self._signals.append(Gtk.AccelMap.get().connect('changed::%s' % (accelpath,),
self.on_accelmap_changed, item))
-
- self._action_group.add_action_with_accel(action, item.shortcut)
-
- ui_manager.add_ui(self._merge_id, path,
- action_name, action_name,
- Gtk.UIManagerItemType.MENUITEM, False)
-
- def on_accelmap_changed(self, accelmap, path, key, mod, tool):
- tool.shortcut = Gtk.accelerator_name(key, mod)
- tool.save()
- self._window._external_tools_window_activatable.update_manager(tool)
+ if tool.shortcut:
+ app = Gio.Application.get_default()
+ app.add_accelerator(tool.shortcut, "win.%s" % action_name, None)
def update(self):
self.remove()
- self._merge_id = self._window.get_ui_manager().new_merge_id()
- self._insert_directory(self._library.tree, self._menupath)
- self._window.get_ui_manager().insert_action_group(self._action_group, -1)
- self.filter(self._window.get_active_document())
+ self._insert_directory(self._library.tree, self._menu)
def filter_language(self, language, item):
if not item.languages:
@@ -178,8 +146,7 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
# 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,
- # "/MenuBar/ToolsMenu/ToolsOps_4/ExternalToolsMenu/ExternalToolPlaceholder")
+ self.menu = ToolMenu(self._library, self.window, self._output_buffer, external_tools_submenu)
bottom = self.window.get_bottom_panel()
image = Gtk.Image.new_from_icon_name("system-run-symbolic", Gtk.IconSize.MENU)
@@ -191,7 +158,6 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
def do_update_state(self):
if self.menu is not None:
self.menu.filter(self.window.get_active_document())
- self.window.get_ui_manager().ensure_update()
def do_deactivate(self):
self.window._external_tools_window_activatable = None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]