[gedit] Introduce GeditWindowActivatable



commit 4fe7161560941ae1aa42165ff4d71121ad6f67b9
Author: Steve Frécinaux <code istique net>
Date:   Tue Jun 22 22:34:53 2010 +0200

    Introduce GeditWindowActivatable
    
    This interface is for extensions that should be activated against a
    window.
    
    It is placed within a new libgedit-private.so library because otherwise
    libtool removes unused symbols...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=606363

 gedit/Makefile.am                |    9 +++-
 gedit/gedit-plugins-engine.c     |   42 ++++++++++++++
 gedit/gedit-window-activatable.c |  114 ++++++++++++++++++++++++++++++++++++++
 gedit/gedit-window-activatable.h |   70 +++++++++++++++++++++++
 gedit/gedit-window.c             |    4 +-
 gedit/gedit.c                    |   25 --------
 6 files changed, 236 insertions(+), 28 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index dc79446..cb8ec57 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -5,6 +5,8 @@ bin_PROGRAMS = gedit
 
 noinst_LTLIBRARIES = libgedit.la
 
+lib_LTLIBRARIES = libgedit-private.la
+
 INCLUDES =								\
 	-I$(top_srcdir)							\
 	-I$(srcdir)							\
@@ -22,6 +24,7 @@ gedit_SOURCES = \
 
 gedit_LDADD =			\
 	libgedit.la		\
+	libgedit-private.la	\
 	$(GEDIT_LIBS)		\
 	$(IGE_MAC_LIBS)		\
 	$(EGG_SMCLIENT_LIBS)	\
@@ -141,7 +144,8 @@ INST_H_FILES =				\
 	gedit-tab.h 			\
 	gedit-utils.h 			\
 	gedit-view.h 			\
-	gedit-window.h
+	gedit-window.h			\
+	gedit-window-activatable.h
 
 if !ENABLE_GVFS_METADATA
 INST_H_FILES += gedit-metadata-manager.h
@@ -152,6 +156,9 @@ headerdir = $(prefix)/include/gedit/gedit
 header_DATA = 				\
 	$(INST_H_FILES)
 
+libgedit_private_la_SOURCES =		\
+	gedit-window-activatable.c
+
 libgedit_c_files =			\
 	gedit-app.c			\
 	gedit-close-button.c		\
diff --git a/gedit/gedit-plugins-engine.c b/gedit/gedit-plugins-engine.c
index 13e2d77..657ef78 100644
--- a/gedit/gedit-plugins-engine.c
+++ b/gedit/gedit-plugins-engine.c
@@ -129,6 +129,47 @@ gedit_plugins_engine_class_init (GeditPluginsEngineClass *klass)
 	g_type_class_add_private (klass, sizeof (GeditPluginsEnginePrivate));
 }
 
+static void
+require_private_typelib (void)
+{
+	gchar *lib_dir;
+	gchar *filename;
+	GMappedFile *mfile;
+	GTypelib *typelib;
+	const gchar *ns;
+
+	lib_dir = gedit_dirs_get_gedit_lib_dir ();
+	filename = g_build_filename (lib_dir,
+				     "girepository-1.0",
+				     "Gedit-3.0.typelib",
+				     NULL);
+
+	mfile = g_mapped_file_new (filename, FALSE, NULL);
+
+	g_free (filename);
+	g_free (lib_dir);
+
+	if (mfile == NULL)
+	{
+		g_warning ("Private typelib 'Gedit-3.0' not found");
+		return;
+	}
+
+	typelib = g_typelib_new_from_mapped_file (mfile);
+	ns = g_irepository_load_typelib (g_irepository_get_default (),
+					 typelib,
+					 0,
+					 NULL);
+	if (!ns)
+	{
+		g_warning ("Typelib 'Gedit-3.0' could not be loaded");
+		g_typelib_free (typelib);
+		return;
+	}
+
+	gedit_debug_message (DEBUG_PLUGINS, "Namespace '%s' loaded.", ns);
+}
+
 GeditPluginsEngine *
 gedit_plugins_engine_get_default (void)
 {
@@ -145,6 +186,7 @@ gedit_plugins_engine_get_default (void)
 			       "Peas", "1.0", 0, NULL);
 	g_irepository_require (g_irepository_get_default (),
 			       "PeasUI", "1.0", 0, NULL);
+	require_private_typelib ();
 
 	modules_dir = gedit_dirs_get_binding_modules_dir ();
 	search_paths = g_new (gchar *, 5);
diff --git a/gedit/gedit-window-activatable.c b/gedit/gedit-window-activatable.c
new file mode 100644
index 0000000..f641c76
--- /dev/null
+++ b/gedit/gedit-window-activatable.c
@@ -0,0 +1,114 @@
+/*
+ * gedit-window-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 Steve Frécinaux
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gedit-window-activatable.h"
+
+/**
+ * SECTION:gedit-window-activatable
+ * @short_description: Interface for extensions activatable on windows
+ * @see_also: #PeasExtensionSet
+ *
+ * #GeditWindowActivatable is an interface which should be implemented by
+ * extensions that should be activated on a gedit main window.
+ **/
+G_DEFINE_INTERFACE(GeditWindowActivatable, gedit_window_activatable, G_TYPE_OBJECT)
+
+void
+gedit_window_activatable_default_init (GeditWindowActivatableInterface *iface)
+{
+}
+
+/**
+ * gedit_window_activatable_activate:
+ * @activatable: A #GeditWindowActivatable.
+ * @window: The #GeditWindow on which the plugin should be activated.
+ *
+ * Activates the extension on the given window.
+ */
+void
+gedit_window_activatable_activate (GeditWindowActivatable *activatable,
+				   GeditWindow            *window)
+{
+	GeditWindowActivatableInterface *iface;
+
+	g_return_if_fail (GEDIT_IS_WINDOW_ACTIVATABLE (activatable));
+	g_return_if_fail (GEDIT_IS_WINDOW (window));
+
+	iface = GEDIT_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (iface->activate != NULL)
+	{
+		iface->activate (activatable, window);
+	}
+}
+
+/**
+ * gedit_window_activatable_deactivate:
+ * @activatable: A #GeditWindowActivatable.
+ * @window: A #GeditWindow.
+ *
+ * Deactivates the plugin on the given window.
+ */
+void
+gedit_window_activatable_deactivate (GeditWindowActivatable *activatable,
+				     GeditWindow            *window)
+{
+	GeditWindowActivatableInterface *iface;
+
+	g_return_if_fail (GEDIT_IS_WINDOW_ACTIVATABLE (activatable));
+	g_return_if_fail (GEDIT_IS_WINDOW (window));
+
+	iface = GEDIT_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (iface->deactivate != NULL)
+	{
+		iface->deactivate (activatable, window);
+	}
+}
+
+/**
+ * gedit_window_activatable_update_state:
+ * @activatable: A #GeditWindowActivatable.
+ * @window: A #GeditWindow.
+ *
+ * Triggers an update of the plugin insternal state to take into account
+ * state changes in the window state, due to a plugin or an user action.
+ */
+void
+gedit_window_activatable_update_state (GeditWindowActivatable *activatable,
+				       GeditWindow            *window)
+{
+	GeditWindowActivatableInterface *iface;
+
+	g_return_if_fail (GEDIT_IS_WINDOW_ACTIVATABLE (activatable));
+	g_return_if_fail (GEDIT_IS_WINDOW (window));
+
+	iface = GEDIT_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
+
+	if (iface->update_state != NULL)
+	{
+		iface->update_state (activatable, window);
+	}
+}
diff --git a/gedit/gedit-window-activatable.h b/gedit/gedit-window-activatable.h
new file mode 100644
index 0000000..173260e
--- /dev/null
+++ b/gedit/gedit-window-activatable.h
@@ -0,0 +1,70 @@
+/*
+ * gedit-window-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Steve Frécinaux
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Library General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GEDIT_WINDOW_ACTIVATABLE_H__
+#define __GEDIT_WINDOW_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+#include "gedit-window.h"
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_WINDOW_ACTIVATABLE		(gedit_window_activatable_get_type ())
+#define GEDIT_WINDOW_ACTIVATABLE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_WINDOW_ACTIVATABLE, GeditWindowActivatable))
+#define GEDIT_WINDOW_ACTIVATABLE_IFACE(obj)	(G_TYPE_CHECK_CLASS_CAST ((obj), GEDIT_TYPE_WINDOW_ACTIVATABLE, GeditWindowActivatableInterface))
+#define GEDIT_IS_WINDOW_ACTIVATABLE(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_WINDOW_ACTIVATABLE))
+#define GEDIT_WINDOW_ACTIVATABLE_GET_IFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEDIT_TYPE_WINDOW_ACTIVATABLE, GeditWindowActivatableInterface))
+
+typedef struct _GeditWindowActivatable           GeditWindowActivatable; /* dummy typedef */
+typedef struct _GeditWindowActivatableInterface  GeditWindowActivatableInterface;
+
+struct _GeditWindowActivatableInterface
+{
+	GTypeInterface g_iface;
+
+	/* Virtual public methods */
+	void	(*activate)		(GeditWindowActivatable *activatable,
+					 GeditWindow            *window);
+	void	(*deactivate)		(GeditWindowActivatable	*activatable,
+					 GeditWindow            *window);
+	void	(*update_state)		(GeditWindowActivatable *activatable,
+                                         GeditWindow		*window);
+};
+
+/*
+ * Public methods
+ */
+GType	 gedit_window_activatable_get_type	(void)  G_GNUC_CONST;
+
+void	 gedit_window_activatable_activate	(GeditWindowActivatable *activatable,
+						 GeditWindow            *window);
+void	 gedit_window_activatable_deactivate	(GeditWindowActivatable *activatable,
+						 GeditWindow            *window);
+void	 gedit_window_activatable_update_state	(GeditWindowActivatable *activatable,
+						 GeditWindow            *window);
+
+G_END_DECLS
+
+#endif /* __GEDIT_WINDOW_ACTIVATABLE_H__ */
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 1ffc82d..fab13c8 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -38,7 +38,6 @@
 
 #include <glib/gi18n.h>
 #include <gio/gio.h>
-#include <libpeas/peas-activatable.h>
 #include <libpeas/peas-extension-set.h>
 
 #include "gedit-ui.h"
@@ -55,6 +54,7 @@
 #include "gedit-panel.h"
 #include "gedit-documents-panel.h"
 #include "gedit-plugins-engine.h"
+#include "gedit-window-activatable.h"
 #include "gedit-enum-types.h"
 #include "gedit-dirs.h"
 #include "gedit-status-combo-box.h"
@@ -4314,7 +4314,7 @@ gedit_window_init (GeditWindow *window)
 	gedit_debug_message (DEBUG_WINDOW, "Update plugins ui");
 	
 	window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (gedit_plugins_engine_get_default ()),
-							   PEAS_TYPE_ACTIVATABLE);
+							   GEDIT_TYPE_WINDOW_ACTIVATABLE);
 	g_signal_connect (window->priv->extensions,
 			  "extension-added",
 			  G_CALLBACK (extension_added),
diff --git a/gedit/gedit.c b/gedit/gedit.c
index c28df1b..a72acb8 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -56,10 +56,6 @@
 #include "gedit-metadata-manager.h"
 #endif
 
-#ifdef ENABLE_INTROSPECTION
-#include <girepository.h>
-#endif
-
 #ifdef G_OS_UNIX
 #include <gio/gunixinputstream.h>
 #include <unistd.h>
@@ -213,23 +209,6 @@ gedit_main (gboolean service)
 #endif
 }
 
-#ifdef ENABLE_INTROSPECTION
-static void
-setup_girepository (void)
-{
-	gchar *lib_dir;
-	gchar *typelib_dir;
-
-	lib_dir = gedit_dirs_get_gedit_lib_dir ();
-	typelib_dir = g_build_filename (lib_dir, "girepository-1.0", NULL);
-
-	g_irepository_prepend_search_path (typelib_dir);
-
-	g_free (typelib_dir);
-	g_free (lib_dir);
-}
-#endif
-
 int
 main (int argc, char *argv[])
 {
@@ -260,10 +239,6 @@ main (int argc, char *argv[])
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 
-#ifdef ENABLE_INTROSPECTION
-	setup_girepository ();
-#endif
-
 	/* Parse command line arguments */
 	command_line = gedit_command_line_get_default ();
 



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