[gedit] Added GeditAppActivatable interface
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Added GeditAppActivatable interface
- Date: Sun, 29 Aug 2010 12:30:05 +0000 (UTC)
commit 56a790a6851ebc98766cc4aca27cb32dde1b41bf
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sun Aug 22 19:35:20 2010 +0200
Added GeditAppActivatable interface
gedit/Makefile.am | 2 +
gedit/gedit-app-activatable.c | 108 +++++++++++++++++++++++++++++++++++++++++
gedit/gedit-app-activatable.h | 61 +++++++++++++++++++++++
gedit/gedit-app.c | 54 ++++++++++++++++++++-
4 files changed, 223 insertions(+), 2 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index cd4cd6e..3240cb1 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -129,6 +129,7 @@ NOINST_H_FILES = \
INST_H_FILES = \
gedit-app.h \
+ gedit-app-activatable.h \
gedit-commands.h \
gedit-debug.h \
gedit-document.h \
@@ -159,6 +160,7 @@ header_DATA = \
$(INST_H_FILES)
libgedit_private_la_SOURCES = \
+ gedit-app-activatable.c \
gedit-view-activatable.c \
gedit-window-activatable.c
diff --git a/gedit/gedit-app-activatable.c b/gedit/gedit-app-activatable.c
new file mode 100644
index 0000000..7add471
--- /dev/null
+++ b/gedit/gedit-app-activatable.c
@@ -0,0 +1,108 @@
+/*
+ * gedit-app-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 Steve Frécinaux
+ * Copyright (C) 2010 Jesse van den Kieboom
+ *
+ * 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-app-activatable.h"
+#include "gedit-app.h"
+
+/**
+ * SECTION:gedit-app-activatable
+ * @short_description: Interface for activatable extensions on apps
+ * @see_also: #PeasExtensionSet
+ *
+ * #GeditAppActivatable is an interface which should be implemented by
+ * extensions that should be activated on a gedit application.
+ **/
+
+G_DEFINE_INTERFACE(GeditAppActivatable, gedit_app_activatable, G_TYPE_OBJECT)
+
+void
+gedit_app_activatable_default_init (GeditAppActivatableInterface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized)
+ {
+ /**
+ * GeditAppActivatable:app:
+ *
+ * The app property contains the gedit app for this
+ * #GeditAppActivatable instance.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("app",
+ "App",
+ "The gedit app",
+ GEDIT_TYPE_APP,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ initialized = TRUE;
+ }
+}
+
+/**
+ * gedit_app_activatable_activate:
+ * @activatable: A #GeditAppActivatable.
+ *
+ * Activates the extension on the application.
+ */
+void
+gedit_app_activatable_activate (GeditAppActivatable *activatable)
+{
+ GeditAppActivatableInterface *iface;
+
+ g_return_if_fail (GEDIT_IS_APP_ACTIVATABLE (activatable));
+
+ iface = GEDIT_APP_ACTIVATABLE_GET_IFACE (activatable);
+
+ if (iface->activate != NULL)
+ {
+ iface->activate (activatable);
+ }
+}
+
+/**
+ * gedit_app_activatable_deactivate:
+ * @activatable: A #GeditAppActivatable.
+ *
+ * Deactivates the extension from the application.
+ *
+ */
+void
+gedit_app_activatable_deactivate (GeditAppActivatable *activatable)
+{
+ GeditAppActivatableInterface *iface;
+
+ g_return_if_fail (GEDIT_IS_APP_ACTIVATABLE (activatable));
+
+ iface = GEDIT_APP_ACTIVATABLE_GET_IFACE (activatable);
+
+ if (iface->deactivate != NULL)
+ {
+ iface->deactivate (activatable);
+ }
+}
diff --git a/gedit/gedit-app-activatable.h b/gedit/gedit-app-activatable.h
new file mode 100644
index 0000000..f9a9bf8
--- /dev/null
+++ b/gedit/gedit-app-activatable.h
@@ -0,0 +1,61 @@
+/*
+ * gedit-app-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Steve Frécinaux
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ *
+ * 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_APP_ACTIVATABLE_H__
+#define __GEDIT_APP_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_APP_ACTIVATABLE (gedit_app_activatable_get_type ())
+#define GEDIT_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_APP_ACTIVATABLE, GeditAppActivatable))
+#define GEDIT_APP_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GEDIT_TYPE_APP_ACTIVATABLE, GeditAppActivatableInterface))
+#define GEDIT_IS_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_APP_ACTIVATABLE))
+#define GEDIT_APP_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEDIT_TYPE_APP_ACTIVATABLE, GeditAppActivatableInterface))
+
+typedef struct _GeditAppActivatable GeditAppActivatable; /* dummy typedef */
+typedef struct _GeditAppActivatableInterface GeditAppActivatableInterface;
+
+struct _GeditAppActivatableInterface
+{
+ GTypeInterface g_iface;
+
+ /* Virtual public methods */
+ void (*activate) (GeditAppActivatable *activatable);
+ void (*deactivate) (GeditAppActivatable *activatable);
+};
+
+/*
+ * Public methods
+ */
+GType gedit_app_activatable_get_type (void) G_GNUC_CONST;
+
+void gedit_app_activatable_activate (GeditAppActivatable *activatable);
+void gedit_app_activatable_deactivate (GeditAppActivatable *activatable);
+
+G_END_DECLS
+
+#endif /* __GEDIT_APP_ACTIVATABLE_H__ */
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 5792bac..8847c30 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -36,6 +36,7 @@
#include <unistd.h>
#include <glib/gi18n.h>
+#include <libpeas/peas-extension-set.h>
#include "gedit-app.h"
#include "gedit-commands.h"
@@ -45,6 +46,8 @@
#include "gedit-enum-types.h"
#include "gedit-dirs.h"
#include "gedit-settings.h"
+#include "gedit-app-activatable.h"
+#include "gedit-plugins-engine.h"
#ifdef OS_OSX
#include "gedit-app-osx.h"
@@ -80,6 +83,8 @@ struct _GeditAppPrivate
GSettings *settings;
GSettings *window_settings;
+
+ PeasExtensionSet *extensions;
};
G_DEFINE_ABSTRACT_TYPE(GeditApp, gedit_app, G_TYPE_INITIALLY_UNOWNED)
@@ -102,7 +107,7 @@ gedit_app_finalize (GObject *object)
static void
gedit_app_dispose (GObject *object)
{
- GeditApp *app = GEDIT_APP (object);
+ GeditApp *app = GEDIT_APP (object);
if (app->priv->window_settings != NULL)
{
@@ -116,6 +121,16 @@ gedit_app_dispose (GObject *object)
app->priv->settings = NULL;
}
+ if (app->priv->extensions != NULL)
+ {
+ peas_extension_set_call (app->priv->extensions,
+ "deactivate",
+ app);
+
+ g_object_unref (app->priv->extensions);
+ app->priv->extensions = NULL;
+ }
+
G_OBJECT_CLASS (gedit_app_parent_class)->dispose (object);
}
@@ -474,18 +489,53 @@ save_print_settings (GeditApp *app)
}
static void
+extension_added (PeasExtensionSet *extensions,
+ PeasPluginInfo *info,
+ PeasExtension *exten,
+ GeditApp *app)
+{
+ peas_extension_call (exten, "activate");
+}
+
+static void
+extension_removed (PeasExtensionSet *extensions,
+ PeasPluginInfo *info,
+ PeasExtension *exten,
+ GeditApp *app)
+{
+ peas_extension_call (exten, "deactivate");
+}
+
+static void
gedit_app_init (GeditApp *app)
{
app->priv = GEDIT_APP_GET_PRIVATE (app);
load_accels ();
-
+
/* Load settings */
app->priv->settings = gedit_settings_new ();
app->priv->window_settings = g_settings_new ("org.gnome.gedit.state.window");
/* initial lockdown state */
app->priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (app->priv->settings));
+
+ app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (gedit_plugins_engine_get_default ()),
+ GEDIT_TYPE_APP_ACTIVATABLE,
+ "app", app,
+ NULL);
+
+ g_signal_connect (app->priv->extensions,
+ "extension-added",
+ G_CALLBACK (extension_added),
+ app);
+
+ g_signal_connect (app->priv->extensions,
+ "extension-removed",
+ G_CALLBACK (extension_removed),
+ app);
+
+ peas_extension_set_call (app->priv->extensions, "activate");
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]