[gedit-cossa] Update style when the document is saved.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-cossa] Update style when the document is saved.
- Date: Thu, 2 Jun 2011 10:59:28 +0000 (UTC)
commit 64f1ce36477e2f511a0d8b999f9ea90c5abfc435
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu Jun 2 13:01:11 2011 +0200
Update style when the document is saved.
Implement the view activatable to make things easier
src/gedit-cossa-plugin.c | 114 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 92 insertions(+), 22 deletions(-)
---
diff --git a/src/gedit-cossa-plugin.c b/src/gedit-cossa-plugin.c
index 1cb7941..739c1dc 100644
--- a/src/gedit-cossa-plugin.c
+++ b/src/gedit-cossa-plugin.c
@@ -26,15 +26,20 @@
#include <gedit/gedit-debug.h>
#include <gedit/gedit-window.h>
#include <gedit/gedit-window-activatable.h>
+#include <gedit/gedit-view.h>
+#include <gedit/gedit-view-activatable.h>
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_5"
+#define COSSA_WINDOW_PREVIEW "GeditCossaPluginWindowPreview"
enum {
PROP_0,
- PROP_WINDOW
+ PROP_WINDOW,
+ PROP_VIEW
};
static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
+static void gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface);
static void preview_activated_cb (GtkAction *action,
gpointer user_data);
@@ -44,18 +49,19 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (CossaPlugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_WINDOW_ACTIVATABLE,
- gedit_window_activatable_iface_init))
+ gedit_window_activatable_iface_init)
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_VIEW_ACTIVATABLE,
+ gedit_view_activatable_iface_init))
typedef struct CossaPluginPrivate CossaPluginPrivate;
struct CossaPluginPrivate
{
GeditWindow *window;
+ GeditView *view;
GtkActionGroup *ui_action_group;
guint ui_id;
-
- GHashTable *previews;
};
static const GtkActionEntry action_entries[] = {
@@ -66,13 +72,10 @@ static const GtkActionEntry action_entries[] = {
static void
cossa_plugin_init (CossaPlugin *plugin)
{
- CossaPluginPrivate *priv;
-
gedit_debug_message (DEBUG_PLUGINS, "CossaPlugin initializing");
- priv = plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
- COSSA_TYPE_PLUGIN,
- CossaPluginPrivate);
- priv->previews = g_hash_table_new (NULL, NULL);
+ plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+ COSSA_TYPE_PLUGIN,
+ CossaPluginPrivate);
}
static void
@@ -88,6 +91,9 @@ cossa_plugin_set_property (GObject *object,
case PROP_WINDOW:
priv->window = g_value_dup_object (value);
break;
+ case PROP_VIEW:
+ priv->view = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -107,6 +113,9 @@ cossa_plugin_get_property (GObject *object,
case PROP_WINDOW:
g_value_set_object (value, priv->window);
break;
+ case PROP_VIEW:
+ g_value_set_object (value, priv->view);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -124,16 +133,16 @@ cossa_plugin_dispose (GObject *object)
priv->window = NULL;
}
- if (priv->ui_action_group != NULL)
+ if (priv->view != NULL)
{
- g_object_unref (priv->ui_action_group);
- priv->ui_action_group = NULL;
+ g_object_unref (priv->view);
+ priv->view = NULL;
}
- if (priv->previews != NULL)
+ if (priv->ui_action_group != NULL)
{
- g_hash_table_unref (priv->previews);
- priv->previews = NULL;
+ g_object_unref (priv->ui_action_group);
+ priv->ui_action_group = NULL;
}
G_OBJECT_CLASS (cossa_plugin_parent_class)->dispose (object);
@@ -149,6 +158,7 @@ cossa_plugin_class_init (CossaPluginClass *klass)
object_class->dispose = cossa_plugin_dispose;
g_object_class_override_property (object_class, PROP_WINDOW, "window");
+ g_object_class_override_property (object_class, PROP_VIEW, "view");
g_type_class_add_private (klass, sizeof (CossaPluginPrivate));
}
@@ -159,7 +169,7 @@ cossa_plugin_class_finalize (CossaPluginClass *klass)
}
static void
-cossa_plugin_activate (GeditWindowActivatable *activatable)
+cossa_window_activatable_activate (GeditWindowActivatable *activatable)
{
CossaPluginPrivate *priv;
GtkUIManager *manager;
@@ -191,7 +201,7 @@ cossa_plugin_activate (GeditWindowActivatable *activatable)
}
static void
-cossa_plugin_deactivate (GeditWindowActivatable *activatable)
+cossa_window_activatable_deactivate (GeditWindowActivatable *activatable)
{
CossaPluginPrivate *priv;
GtkUIManager *manager;
@@ -208,8 +218,8 @@ cossa_plugin_deactivate (GeditWindowActivatable *activatable)
static void
gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface)
{
- iface->activate = cossa_plugin_activate;
- iface->deactivate = cossa_plugin_deactivate;
+ iface->activate = cossa_window_activatable_activate;
+ iface->deactivate = cossa_window_activatable_deactivate;
}
static gchar *
@@ -243,6 +253,63 @@ update_style (CossaWindow *window,
}
static void
+on_document_saved (GeditDocument *doc,
+ const GError *error,
+ CossaPlugin *plugin)
+{
+ if (error == NULL)
+ {
+ GtkWidget *window;
+ CossaPluginPrivate *priv;
+
+ priv = plugin->priv;
+ window = g_object_get_data (G_OBJECT (priv->view), COSSA_WINDOW_PREVIEW);
+
+ if (window != NULL)
+ update_style (COSSA_WINDOW (window), priv->view);
+ }
+}
+
+static void
+cossa_view_activatable_activate (GeditViewActivatable *activatable)
+{
+ CossaPluginPrivate *priv;
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = COSSA_PLUGIN (activatable)->priv;
+
+ doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)));
+
+ g_signal_connect (doc, "saved",
+ G_CALLBACK (on_document_saved),
+ activatable);
+}
+
+static void
+cossa_view_activatable_deactivate (GeditViewActivatable *activatable)
+{
+ CossaPluginPrivate *priv;
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = COSSA_PLUGIN (activatable)->priv;
+
+ doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)));
+
+ g_signal_handlers_disconnect_by_func (doc, on_document_saved, activatable);
+}
+
+static void
+gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface)
+{
+ iface->activate = cossa_view_activatable_activate;
+ iface->deactivate = cossa_view_activatable_deactivate;
+}
+
+static void
preview_activated_cb (GtkAction *action,
gpointer user_data)
{
@@ -254,7 +321,7 @@ preview_activated_cb (GtkAction *action,
priv = COSSA_PLUGIN (user_data)->priv;
cur_view = gedit_window_get_active_view (priv->window);
- window = g_hash_table_lookup (priv->previews, cur_view);
+ window = g_object_get_data (G_OBJECT (cur_view), COSSA_WINDOW_PREVIEW);
if (!window)
{
@@ -284,7 +351,7 @@ preview_activated_cb (GtkAction *action,
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
- g_hash_table_insert (priv->previews, cur_view, window);
+ g_object_set_data (G_OBJECT (cur_view), COSSA_WINDOW_PREVIEW, window);
}
gtk_widget_show (window);
@@ -299,4 +366,7 @@ peas_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
GEDIT_TYPE_WINDOW_ACTIVATABLE,
COSSA_TYPE_PLUGIN);
+ peas_object_module_register_extension_type (module,
+ GEDIT_TYPE_VIEW_ACTIVATABLE,
+ COSSA_TYPE_PLUGIN);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]