[gedit-plugins] Remove usage of [gs]et_data in other plugins.



commit f5cbbb58fcb267c7be0d8d36bf3d4c3e5d74043c
Author: Benjamin Berg <benjamin sipsolutions net>
Date:   Tue Aug 7 19:56:03 2012 +0200

    Remove usage of [gs]et_data in other plugins.

 plugins/commander/commander/info.py           |    8 +++-----
 plugins/multiedit/multiedit/Makefile.am       |    1 -
 plugins/multiedit/multiedit/__init__.py       |    9 +++++----
 plugins/multiedit/multiedit/constants.py      |   24 ------------------------
 plugins/multiedit/multiedit/documenthelper.py |    5 ++---
 plugins/sessionsaver/__init__.py              |    6 +-----
 plugins/textsize/textsize/Makefile.am         |    1 -
 plugins/textsize/textsize/__init__.py         |    5 +++--
 plugins/textsize/textsize/constants.py        |   24 ------------------------
 plugins/textsize/textsize/documenthelper.py   |    5 +++--
 10 files changed, 17 insertions(+), 71 deletions(-)
---
diff --git a/plugins/commander/commander/info.py b/plugins/commander/commander/info.py
index 3e19400..a5fff5f 100644
--- a/plugins/commander/commander/info.py
+++ b/plugins/commander/commander/info.py
@@ -224,7 +224,7 @@ class Info(TransparentWindow):
 		image = Gtk.Image.new_from_stock(stock, Gtk.IconSize.MENU)
 		image.show()
 
-		image.set_data('COMMANDER_ACTION_STOCK_ITEM', [stock, Gtk.IconSize.MENU])
+		image.commander_action_stock_item = (stock, Gtk.IconSize.MENU)
 
 		self.ensure_button_bar()
 
@@ -252,8 +252,7 @@ class Info(TransparentWindow):
 		img.set_state(Gtk.StateType.PRELIGHT)
 		widget.get_window().set_cursor(Gdk.Cursor.new(Gdk.HAND2))
 
-		stock = img.get_data('COMMANDER_ACTION_STOCK_ITEM')
-		pix = img.render_icon(stock[0], stock[1])
+		pix = img.render_icon(*img.commander_action_stock_item)
 		img.set_from_pixbuf(pix)
 
 	def on_action_leave_notify(self, widget, evnt):
@@ -261,8 +260,7 @@ class Info(TransparentWindow):
 		img.set_state(Gtk.StateType.NORMAL)
 		widget.get_window().set_cursor(None)
 
-		stock = img.get_data('COMMANDER_ACTION_STOCK_ITEM')
-		pix = img.render_icon(stock[0], stock[1])
+		pix = img.render_icon(*img.commander_action_stock_item)
 		img.set_from_pixbuf(pix)
 
 	def on_action_activate(self, widget, evnt, callback, data):
diff --git a/plugins/multiedit/multiedit/Makefile.am b/plugins/multiedit/multiedit/Makefile.am
index cd1454f..e0dc214 100644
--- a/plugins/multiedit/multiedit/Makefile.am
+++ b/plugins/multiedit/multiedit/Makefile.am
@@ -3,7 +3,6 @@
 plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/multiedit
 
 plugin_PYTHON = 		\
-	constants.py 		\
 	documenthelper.py 	\
 	__init__.py 		\
 	signals.py
diff --git a/plugins/multiedit/multiedit/__init__.py b/plugins/multiedit/multiedit/__init__.py
index 461e76e..ffc483d 100644
--- a/plugins/multiedit/multiedit/__init__.py
+++ b/plugins/multiedit/multiedit/__init__.py
@@ -20,7 +20,6 @@
 #  Boston, MA 02111-1307, USA.
 
 from gi.repository import GObject, Gtk, Gedit
-import constants
 from signals import Signals
 from documenthelper import DocumentHelper
 import gettext
@@ -95,7 +94,9 @@ class MultiEditPlugin(GObject.Object, Gedit.WindowActivatable, Signals):
         pass
 
     def get_helper(self, view):
-        return view.get_data(constants.DOCUMENT_HELPER_KEY)
+        if not hasattr(view, "multiedit_document_helper"):
+            return None
+        return view.multiedit_document_helper
 
     def add_document_helper(self, view):
         if self.get_helper(view) != None:
@@ -125,13 +126,13 @@ class MultiEditPlugin(GObject.Object, Gedit.WindowActivatable, Signals):
 
     def on_active_tab_changed(self, window, tab):
         view = tab.get_view()
-        helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
+        helper = self.get_helper(view)
 
         self.get_action().set_active(helper != None and helper.enabled())
 
     def on_multi_edit_mode(self, action):
         view = self.window.get_active_view()
-        helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
+        helper = self.get_helper(view)
 
         if helper != None:
             helper.toggle_multi_edit(self.get_action().get_active())
diff --git a/plugins/multiedit/multiedit/documenthelper.py b/plugins/multiedit/multiedit/documenthelper.py
index 9643f9a..cfc4aaf 100644
--- a/plugins/multiedit/multiedit/documenthelper.py
+++ b/plugins/multiedit/multiedit/documenthelper.py
@@ -24,7 +24,6 @@ import time
 import xml.sax.saxutils
 from gi.repository import GObject, Pango, PangoCairo, Gdk, Gtk, Gedit
 from signals import Signals
-import constants
 import gettext
 from gpdefs import *
 
@@ -38,7 +37,7 @@ class DocumentHelper(Signals):
     def __init__(self, view):
         Signals.__init__(self)
 
-        view.set_data(constants.DOCUMENT_HELPER_KEY, self)
+        view.multiedit_document_helper = self
 
         self._view = view
         self._buffer = None
@@ -135,7 +134,7 @@ class DocumentHelper(Signals):
         self._cancel_column_mode()
         self.reset_buffer(None)
 
-        self._view.set_data(constants.DOCUMENT_HELPER_KEY, None)
+        self._view.multiedit_document_helper = None
 
         self.disconnect_signals(self._view)
         self._view = None
diff --git a/plugins/sessionsaver/__init__.py b/plugins/sessionsaver/__init__.py
index b8f2aa1..961796c 100644
--- a/plugins/sessionsaver/__init__.py
+++ b/plugins/sessionsaver/__init__.py
@@ -56,7 +56,6 @@ class SessionSaverPlugin(GObject.Object, Gedit.WindowActivatable):
 
     window = GObject.property(type = Gedit.Window)
 
-    ACTION_HANDLER_DATA_KEY = "SessionSaverActionHandlerData"
     SESSION_MENU_PATH = '/MenuBar/FileMenu/FileOps_2/FileSessionMenu/SessionPluginPlaceHolder'
 
     def __init__(self):
@@ -85,7 +84,6 @@ class SessionSaverPlugin(GObject.Object, Gedit.WindowActivatable):
                                 "")
             handler = action.connect("activate", self.session_menu_action, session)
 
-            action.set_data(self.ACTION_HANDLER_DATA_KEY, handler)
             # Add an action to the session list items.
             self._action_group.add_action(action)
 
@@ -127,9 +125,7 @@ class SessionSaverPlugin(GObject.Object, Gedit.WindowActivatable):
         manager.remove_ui(self._menu_ui_id)
 
         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)
+            action.disconnect_by_func(self.session_menu_action)
             self._action_group.remove_action(action)
 
         manager.remove_action_group(self._action_group)
diff --git a/plugins/textsize/textsize/Makefile.am b/plugins/textsize/textsize/Makefile.am
index 28ec71e..a1d0b47 100644
--- a/plugins/textsize/textsize/Makefile.am
+++ b/plugins/textsize/textsize/Makefile.am
@@ -3,7 +3,6 @@
 plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/textsize
 
 plugin_PYTHON =	\
-	constants.py \
 	documenthelper.py \
 	__init__.py \
 	signals.py
diff --git a/plugins/textsize/textsize/__init__.py b/plugins/textsize/textsize/__init__.py
index 3516d90..22ff105 100644
--- a/plugins/textsize/textsize/__init__.py
+++ b/plugins/textsize/textsize/__init__.py
@@ -23,7 +23,6 @@
 #  Boston, MA 02111-1307, USA.
 
 from gi.repository import GObject, Gtk, Gdk, Gedit
-import constants
 from documenthelper import DocumentHelper
 import gettext
 from gpdefs import *
@@ -173,7 +172,9 @@ class TextSizePlugin(GObject.Object, Gedit.WindowActivatable):
         self._action_group.set_sensitive(self.window.get_active_document() != None)
 
     def get_helper(self, view):
-        return view.get_data(constants.DOCUMENT_HELPER_KEY)
+        if not hasattr(view, "textsize_document_helper"):
+            return None
+        return view.textsize_document_helper
 
     def add_document_helper(self, view):
         if self.get_helper(view) != None:
diff --git a/plugins/textsize/textsize/documenthelper.py b/plugins/textsize/textsize/documenthelper.py
index 7cb55af..ad85b05 100644
--- a/plugins/textsize/textsize/documenthelper.py
+++ b/plugins/textsize/textsize/documenthelper.py
@@ -20,7 +20,6 @@
 #  Boston, MA 02111-1307, USA.
 
 from signals import Signals
-import constants
 from gi.repository import Gtk, Gdk, Pango
 
 class DocumentHelper(Signals):
@@ -32,7 +31,7 @@ class DocumentHelper(Signals):
         self.connect_signal(self._view, 'scroll-event', self.on_scroll_event)
         self.connect_signal(self._view, 'button-press-event', self.on_button_press_event)
 
-        self._view.set_data(constants.DOCUMENT_HELPER_KEY, self)
+        self._view.textsize_document_helper = self
 
         self._default_font = None
         self._last_font = None
@@ -45,6 +44,8 @@ class DocumentHelper(Signals):
         self.remove_font_tags()
         self.disconnect_signals(self._view)
 
+        self._view.textsize_document_helper = None
+
     def remove_font_tags(self):
         buf = self._view.get_buffer()
         table = buf.get_tag_table()



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