[gedit] Rework external-tools to not use set/get_data
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Rework external-tools to not use set/get_data
- Date: Sun, 16 Sep 2012 20:00:27 +0000 (UTC)
commit cf7549c8e5944a3fbf9d18170b6e45a552071b4c
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Sep 16 21:31:38 2012 +0200
Rework external-tools to not use set/get_data
Use simple python attributes instead
plugins/externaltools/tools/manager.py | 15 +++++---
plugins/externaltools/tools/windowactivatable.py | 41 ++++++++++-----------
2 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/plugins/externaltools/tools/manager.py b/plugins/externaltools/tools/manager.py
index e843a47..2a39a79 100644
--- a/plugins/externaltools/tools/manager.py
+++ b/plugins/externaltools/tools/manager.py
@@ -274,11 +274,16 @@ class LanguagesPopup(Gtk.Window):
def do_proximity_out_event(self, event):
return self.propagate_mouse_event(event)
-class Manager:
+class Manager(GObject.Object):
TOOL_COLUMN = 0 # For Tree
NAME_COLUMN = 1 # For Combo
+ __gsignals__ = {
+ 'tools-updated': (GObject.SignalFlags.RUN_LAST, None, ())
+ }
+
def __init__(self, datadir):
+ GObject.Object.__init__(self)
self.datadir = datadir
self.dialog = None
self._languages = {}
@@ -859,7 +864,8 @@ class Manager:
Gedit.App.get_default().show_help(self.dialog, 'gedit', 'gedit-plugins-external-tools')
return
- self.on_tool_manager_dialog_focus_out(dialog, None)
+ self.save_current_tool()
+ self.emit('tools-updated')
self.dialog.destroy()
self.dialog = None
@@ -867,10 +873,7 @@ class Manager:
def on_tool_manager_dialog_focus_out(self, dialog, event):
self.save_current_tool()
-
- for window in Gedit.App.get_default().get_windows():
- windowactivatable = window.get_data("ExternalToolsPluginWindowData")
- windowactivatable.menu.update()
+ self.emit('tools-updated')
def get_cell_data_cb(self, column, cell, model, piter, user_data=None):
tool = model.get_value(piter, self.TOOL_COLUMN)
diff --git a/plugins/externaltools/tools/windowactivatable.py b/plugins/externaltools/tools/windowactivatable.py
index 27aa179..da03b78 100644
--- a/plugins/externaltools/tools/windowactivatable.py
+++ b/plugins/externaltools/tools/windowactivatable.py
@@ -26,9 +26,6 @@ from capture import Capture
from functions import *
class ToolMenu(object):
- ACTION_HANDLER_DATA_KEY = "ExternalToolActionHandlerData"
- ACTION_ITEM_DATA_KEY = "ExternalToolActionItemData"
-
def __init__(self, library, window, panel, menupath):
super(ToolMenu, self).__init__()
self._library = library
@@ -52,13 +49,11 @@ class ToolMenu(object):
self._merge_id = 0
for action in self._action_group.list_actions():
- handler = action.get_data(self.ACTION_HANDLER_DATA_KEY)
-
- if handler is not None:
- action.disconnect(handler)
+ if action._tool_handler is not None:
+ action.disconnect(action._tool_handler)
- action.set_data(self.ACTION_ITEM_DATA_KEY, None)
- action.set_data(self.ACTION_HANDLER_DATA_KEY, None)
+ action._tool_item = None
+ action._tool_handler = None
self._action_group.remove_action(action)
@@ -88,9 +83,10 @@ class ToolMenu(object):
action = Gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None)
handler = action.connect("activate", capture_menu_action, self._window, self._panel, item)
- action.set_data(self.ACTION_ITEM_DATA_KEY, item)
- action.set_data(self.ACTION_HANDLER_DATA_KEY, handler)
-
+ # 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, )
@@ -109,7 +105,7 @@ class ToolMenu(object):
def on_accelmap_changed(self, accelmap, path, key, mod, tool):
tool.shortcut = Gtk.accelerator_name(key, mod)
tool.save()
- self._window.get_data("ExternalToolsPluginWindowData").update_manager(tool)
+ self._window._external_tools_window_activatable.update_manager(tool)
def update(self):
self.remove()
@@ -148,10 +144,9 @@ class ToolMenu(object):
language = document.get_language()
for action in self._action_group.list_actions():
- item = action.get_data(self.ACTION_ITEM_DATA_KEY)
-
- if item is not None:
- action.set_visible(states[item.applicability] and self.filter_language(language, item))
+ if action._tool_item is not None:
+ action.set_visible(states[action._tool_item.applicability] and
+ self.filter_language(language, action._tool_item))
# FIXME: restore the launch of the manager on configure using PeasGtk.Configurable
class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
@@ -166,9 +161,8 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
self.menu = None
def do_activate(self):
- # We need to get access to the activatable object to update the
- # menuitems from the manager.
- self.window.set_data("ExternalToolsPluginWindowData", self)
+ # Ugly hack... we need to get access to the activatable to update the menuitems
+ self.window._external_tools_window_activatable = self
self._library = ToolLibrary()
ui_manager = self.window.get_ui_manager()
@@ -224,7 +218,7 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
self.window.get_ui_manager().ensure_update()
def do_deactivate(self):
- self.window.set_data("ExternalToolsPluginWindowData", None)
+ self.window._external_tools_window_activatable = None
ui_manager = self.window.get_ui_manager()
self.menu.deactivate()
ui_manager.remove_ui(self._merge_id)
@@ -242,6 +236,7 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
self._manager.dialog.set_default_size(*self._manager_default_size)
self._manager.dialog.connect('destroy', self.on_manager_destroy)
+ self._manager.connect('tools-updated', self.on_manager_tools_updated)
window = Gedit.App.get_default().get_active_window()
self._manager.run(window)
@@ -257,4 +252,8 @@ class WindowActivatable(GObject.Object, Gedit.WindowActivatable):
self._manager_default_size = [alloc.width, alloc.height]
self._manager = None
+ def on_manager_tools_updated(self, manager):
+ for window in Gedit.App.get_default().get_windows():
+ window._external_tools_window_activatable.menu.update()
+
# ex:ts=4:et:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]