[devhelp] gedit-plugin: port to GObject introspection and gedit 3



commit 69decf92f9abf434a19d48a4871a4bca671bb0c9
Author: Dan Williams <dcbw redhat com>
Date:   Tue Feb 15 15:44:34 2011 -0600

    gedit-plugin: port to GObject introspection and gedit 3
    
    Gedit plugins now:
    
    1) are identified by a file extension of .plugin, not .desktop
    2) are installed in /usr/lib[64]/gedit/plugins, not gedit-2/plugins
    3) should use GObject Introspection
    4) don't need a whole directory to themselves
    
    Requires pygobject from either the 2-28 branch, or git master.  Earlier
    pygobject releases are buggy with GObject introspection.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642002

 .gitignore                                 |    2 +-
 configure.ac                               |    1 -
 misc/gedit-plugin/Makefile.am              |   11 ++--
 misc/gedit-plugin/devhelp.desktop.in       |    4 +-
 misc/gedit-plugin/{devhelp => }/devhelp.py |   88 +++++++++++++++++-----------
 misc/gedit-plugin/devhelp/.cvsignore       |    3 -
 misc/gedit-plugin/devhelp/Makefile.am      |    5 --
 misc/gedit-plugin/devhelp/__init__.py      |   37 ------------
 po/POTFILES.in                             |    2 +-
 9 files changed, 62 insertions(+), 91 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 8116ebf..8da3540 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,7 +52,7 @@ libtool
 /po/quot.sed
 /po/remove-potcdate.sin
 /misc/gedit-plugin/devhelp.desktop
-/misc/gedit-plugin/devhelp.gedit-plugin
+/misc/gedit-plugin/devhelp.plugin
 /src/devhelp
 /src/dh-marshal.c
 /src/dh-marshal.h
diff --git a/configure.ac b/configure.ac
index 65cf94e..fb9397d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,7 +133,6 @@ data/ui/Makefile
 data/dtd/Makefile
 misc/Makefile
 misc/gedit-plugin/Makefile
-misc/gedit-plugin/devhelp/Makefile
 contrib/Makefile
 ])
 
diff --git a/misc/gedit-plugin/Makefile.am b/misc/gedit-plugin/Makefile.am
index 4fe2930..4afb528 100644
--- a/misc/gedit-plugin/Makefile.am
+++ b/misc/gedit-plugin/Makefile.am
@@ -1,14 +1,13 @@
-SUBDIRS = devhelp
-
 @INTLTOOL_DESKTOP_RULE@
 DESKTOP_IN_FILES = devhelp.desktop.in
 DESKTOP_FILES =$(DESKTOP_IN_FILES:.desktop.in=.desktop)
 
-plugindir = $(libdir)/gedit-2/plugins
-plugin_DATA = $(DESKTOP_FILES:.desktop=.gedit-plugin)
+plugindir = $(libdir)/gedit/plugins
+plugin_PYTHON = devhelp.py
+plugin_DATA = $(DESKTOP_FILES:.desktop=.plugin)
 
-.desktop.gedit-plugin:
-	cp $< $*.gedit-plugin
+.desktop.plugin:
+	cp $< $*.plugin
 
 CLEANFILES = $(DESKTOP_FILES) $(plugin_DATA)
 DISTCLEANFILES = $(DESKTOP_FILES) $(plugin_DATA)
diff --git a/misc/gedit-plugin/devhelp.desktop.in b/misc/gedit-plugin/devhelp.desktop.in
index c4457f5..5d136cd 100644
--- a/misc/gedit-plugin/devhelp.desktop.in
+++ b/misc/gedit-plugin/devhelp.desktop.in
@@ -1,7 +1,7 @@
-[Gedit Plugin]
+[Plugin]
 Loader=python
 Module=devhelp
-IAge=2
+IAge=3
 _Name=Devhelp support
 _Description=Makes F2 bring up Devhelp for the word at the cursor
 Authors=Richard Hult
diff --git a/misc/gedit-plugin/devhelp/devhelp.py b/misc/gedit-plugin/devhelp.py
similarity index 55%
rename from misc/gedit-plugin/devhelp/devhelp.py
rename to misc/gedit-plugin/devhelp.py
index 0a5bd3d..ae06a97 100644
--- a/misc/gedit-plugin/devhelp/devhelp.py
+++ b/misc/gedit-plugin/devhelp.py
@@ -2,8 +2,10 @@
 #
 #    Gedit devhelp plugin
 #    Copyright (C) 2006 Imendio AB
+#    Copyright (C) 2011 Red Hat, Inc.
 #
 #    Author: Richard Hult <richard imendio com>
+#    Author: Dan Williams <dcbw redhat com>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -19,50 +21,68 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-import gedit
-import gtk
+from gi.repository import GObject, Gtk, Gedit
 import os
 import gettext
 
-class DevhelpInstance:
-    def __init__(self, window):
-        self._window = window
+ui_str = """
+<ui>
+  <menubar name="MenuBar">
+    <menu name="ToolsMenu" action="Tools">
+      <placeholder name="ToolsOps_5">
+        <menuitem name="Devhelp" action="Devhelp"/>
+      </placeholder>
+    </menu>
+  </menubar>
+</ui>
+"""
 
-    def activate(self):
-        manager = self._window.get_ui_manager()
-	# Translate actions below, hardcoding domain here to avoid complications now
-	_ = lambda s: gettext.dgettext('devhelp', s);
+import pdb
+
+class DevhelpPlugin(GObject.Object, Gedit.WindowActivatable):
+    __gtype_name__ = "DevhelpPlugin"
+
+    window = GObject.property(type=GObject.GObject)
 
-        self._action_group = gtk.ActionGroup("GeditDevhelpPluginActions")
-        self._action_group.add_actions([('Devhelp', None,
-                                         _('Show API Documentation'),
-                                         'F2',
-                                         _('Show API Documentation for the word at the cursor'),
-                                         self.on_action_devhelp_activate)])
-        
-        self._merge_id = manager.new_merge_id()
-        manager.insert_action_group(self._action_group, -1)		
-        manager.add_ui(self._merge_id, '/MenuBar/ToolsMenu/ToolsOps_5',
-                       'Devhelp', 'Devhelp', gtk.UI_MANAGER_MENUITEM, False)
-        
-    def deactivate(self):
-        manager = self._window.get_ui_manager()
-        manager.remove_ui(self._merge_id)
+    def __init__(self):
+        GObject.Object.__init__(self)
+
+    def do_activate(self):
+        self._insert_menu()
+
+    def do_deactivate(self):
+        self._remove_menu()
+
+    def _remove_menu(self):
+        manager = self.window.get_ui_manager()
+        manager.remove_ui(self._ui_id)
         manager.remove_action_group(self._action_group)
         self._action_group = None
+        manager.ensure_update()
+
+    def _insert_menu(self):
+        manager = self.window.get_ui_manager()
+
+	# Translate actions below, hardcoding domain here to avoid complications now
+	_ = lambda s: gettext.dgettext('devhelp', s);
+
+        self._action_group = Gtk.ActionGroup(name="GeditDevhelpPluginActions")
+	self._action_group.add_actions([('Devhelp', None,
+	                                 _('Show API Documentation'),
+	                                 'F2',
+	                                 _('Show API Documentation for the word at the cursor'),
+	                                 lambda a, w: self.do_devhelp(w.get_active_document()))],
+	                                 self.window)
+        manager.insert_action_group(self._action_group, -1)
+        self._ui_id = manager.add_ui_from_string(ui_str)
 
     def _is_word_separator(self, c):
         return not (c.isalnum() or c == '_')
 
-    def on_action_devhelp_activate(self, *args):
-        view = self._window.get_active_view()
-        buffer = view.get_buffer()
-
+    def do_devhelp(self, document):
         # Get the word at the cursor
-        insert = buffer.get_iter_at_mark(buffer.get_insert())
-
-        start = insert.copy()
-        end = insert.copy()
+        start = document.get_iter_at_mark(document.get_insert())
+        end = start.copy()
 
         # If just after a word, move back into it
         c = start.get_char()
@@ -89,9 +109,7 @@ class DevhelpInstance:
                 break
 
         if end.compare(start) > 0:
-            text = buffer.get_text(start,end).strip()
+            text = document.get_text(start,end,False).strip()
             if text:
                 # FIXME: We need a dbus interface for devhelp soon...
                 os.spawnlp(os.P_NOWAIT, 'devhelp', 'devhelp', '-s', text)
-            
-
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bd823b5..db4f25a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,7 +4,7 @@ data/devhelp.desktop.in.in
 data/devhelp.schemas.in
 [type: gettext/glade]data/ui/devhelp.builder
 misc/gedit-plugin/devhelp.desktop.in
-misc/gedit-plugin/devhelp/devhelp.py
+misc/gedit-plugin/devhelp.py
 src/dh-assistant.c
 src/dh-assistant-view.c
 src/dh-base.c



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