[gedit-plugins] drawspaces: split out view activatable
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] drawspaces: split out view activatable
- Date: Mon, 31 Mar 2014 20:46:34 +0000 (UTC)
commit 245a12e7dfc526fbfdb18192bce8a04d0a87cf07
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Mar 31 22:32:55 2014 +0200
drawspaces: split out view activatable
plugins/drawspaces/Makefile.am | 2 +
.../drawspaces/gedit-drawspaces-app-activatable.c | 2 +
.../drawspaces/gedit-drawspaces-view-activatable.c | 227 ++++++++++++++++++++
.../drawspaces/gedit-drawspaces-view-activatable.h | 61 ++++++
.../gedit-drawspaces-window-activatable.c | 103 +---------
.../gedit-drawspaces-window-activatable.h | 4 -
6 files changed, 293 insertions(+), 106 deletions(-)
---
diff --git a/plugins/drawspaces/Makefile.am b/plugins/drawspaces/Makefile.am
index ad89325..f453e52 100644
--- a/plugins/drawspaces/Makefile.am
+++ b/plugins/drawspaces/Makefile.am
@@ -33,6 +33,8 @@ plugins_drawspaces_libdrawspaces_la_SOURCES = \
plugins/drawspaces/gedit-drawspaces-app-activatable.c \
plugins/drawspaces/gedit-drawspaces-window-activatable.h\
plugins/drawspaces/gedit-drawspaces-window-activatable.c\
+ plugins/drawspaces/gedit-drawspaces-view-activatable.h \
+ plugins/drawspaces/gedit-drawspaces-view-activatable.c \
$(BUILT_SOURCES)
plugin_in_files += plugins/drawspaces/drawspaces.plugin.desktop.in
diff --git a/plugins/drawspaces/gedit-drawspaces-app-activatable.c
b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
index 199cfb3..bfc8504 100644
--- a/plugins/drawspaces/gedit-drawspaces-app-activatable.c
+++ b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
@@ -22,6 +22,7 @@
#include "gedit-drawspaces-app-activatable.h"
#include "gedit-drawspaces-window-activatable.h"
+#include "gedit-drawspaces-view-activatable.h"
#include <gedit/gedit-app.h>
#include <gedit/gedit-app-activatable.h>
@@ -361,6 +362,7 @@ peas_register_types (PeasObjectModule *module)
{
gedit_drawspaces_app_activatable_register_type (G_TYPE_MODULE (module));
gedit_drawspaces_window_activatable_register (G_TYPE_MODULE (module));
+ gedit_drawspaces_view_activatable_register (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
GEDIT_TYPE_APP_ACTIVATABLE,
diff --git a/plugins/drawspaces/gedit-drawspaces-view-activatable.c
b/plugins/drawspaces/gedit-drawspaces-view-activatable.c
new file mode 100644
index 0000000..7c84a87
--- /dev/null
+++ b/plugins/drawspaces/gedit-drawspaces-view-activatable.c
@@ -0,0 +1,227 @@
+/*
+ * gedit-drawspaces-view-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gedit is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gedit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gedit-drawspaces-view-activatable.h"
+
+#include <gedit/gedit-view.h>
+#include <gedit/gedit-view-activatable.h>
+#include <libpeas/peas-object-module.h>
+
+
+typedef struct _GeditDrawspacesViewActivatablePrivate
+{
+ GeditView *view;
+ GSettings *settings;
+ GtkSourceDrawSpacesFlags flags;
+
+ guint enable : 1;
+} GeditDrawspacesViewActivatablePrivate;
+
+enum
+{
+ PROP_0,
+ PROP_VIEW
+};
+
+static void gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDrawspacesViewActivatable,
+ gedit_drawspaces_view_activatable,
+ G_TYPE_OBJECT,
+ 0,
+ G_ADD_PRIVATE_DYNAMIC (GeditDrawspacesViewActivatable)
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_VIEW_ACTIVATABLE,
+ gedit_view_activatable_iface_init))
+
+static void
+gedit_drawspaces_view_activatable_dispose (GObject *object)
+{
+ GeditDrawspacesViewActivatable *activatable = GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (object);
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ g_clear_object (&priv->view);
+
+ G_OBJECT_CLASS (gedit_drawspaces_view_activatable_parent_class)->dispose (object);
+}
+
+static void
+gedit_drawspaces_view_activatable_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeditDrawspacesViewActivatable *activatable = GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (object);
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ priv->view = GEDIT_VIEW (g_value_dup_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_drawspaces_view_activatable_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeditDrawspacesViewActivatable *activatable = GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (object);
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ g_value_set_object (value, priv->view);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_drawspaces_view_activatable_class_init (GeditDrawspacesViewActivatableClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = gedit_drawspaces_view_activatable_dispose;
+ object_class->set_property = gedit_drawspaces_view_activatable_set_property;
+ object_class->get_property = gedit_drawspaces_view_activatable_get_property;
+
+ g_object_class_override_property (object_class, PROP_VIEW, "view");
+}
+
+static void
+gedit_drawspaces_view_activatable_class_finalize (GeditDrawspacesViewActivatableClass *klass)
+{
+}
+
+static void
+gedit_drawspaces_view_activatable_init (GeditDrawspacesViewActivatable *self)
+{
+}
+
+static void
+get_config_options (GeditDrawspacesViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ priv->enable = g_settings_get_boolean (priv->settings,
+ SETTINGS_KEY_SHOW_WHITE_SPACE);
+
+ priv->flags = g_settings_get_flags (priv->settings,
+ SETTINGS_KEY_DRAW_SPACES);
+}
+
+static void
+draw_spaces (GeditDrawspacesViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (priv->view),
+ priv->enable ? priv->flags : 0);
+}
+
+static void
+on_draw_spaces_changed (GSettings *settings,
+ const gchar *key,
+ GeditDrawspacesViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ priv->flags = g_settings_get_flags (priv->settings,
+ SETTINGS_KEY_DRAW_SPACES);
+
+ draw_spaces (activatable);
+}
+
+static void
+on_show_white_space_changed (GSettings *settings,
+ const gchar *key,
+ GeditDrawspacesViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
+
+ priv->enable = g_settings_get_boolean (settings, key);
+
+ draw_spaces (activatable);
+}
+
+static void
+gedit_drawspaces_view_activatable_window_activate (GeditViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv;
+
+ priv = gedit_drawspaces_view_activatable_get_instance_private (GEDIT_DRAWSPACES_VIEW_ACTIVATABLE
(activatable));
+ priv->settings = g_settings_new (DRAWSPACES_SETTINGS_BASE);
+
+ get_config_options (GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (activatable));
+
+ if (priv->enable)
+ {
+ draw_spaces (GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (activatable));
+ }
+
+ g_signal_connect (priv->settings,
+ "changed::show-white-space",
+ G_CALLBACK (on_show_white_space_changed),
+ activatable);
+ g_signal_connect (priv->settings,
+ "changed::draw-spaces",
+ G_CALLBACK (on_draw_spaces_changed),
+ activatable);
+}
+
+static void
+gedit_drawspaces_view_activatable_window_deactivate (GeditViewActivatable *activatable)
+{
+ GeditDrawspacesViewActivatablePrivate *priv;
+
+ priv = gedit_drawspaces_view_activatable_get_instance_private (GEDIT_DRAWSPACES_VIEW_ACTIVATABLE
(activatable));
+
+ priv->enable = FALSE;
+ draw_spaces (GEDIT_DRAWSPACES_VIEW_ACTIVATABLE (activatable));
+
+ g_clear_object (&priv->settings);
+}
+
+static void
+gedit_view_activatable_iface_init (GeditViewActivatableInterface *iface)
+{
+ iface->activate = gedit_drawspaces_view_activatable_window_activate;
+ iface->deactivate = gedit_drawspaces_view_activatable_window_deactivate;
+}
+
+void
+gedit_drawspaces_view_activatable_register (GTypeModule *module)
+{
+ gedit_drawspaces_view_activatable_register_type (module);
+
+ peas_object_module_register_extension_type (PEAS_OBJECT_MODULE (module),
+ GEDIT_TYPE_VIEW_ACTIVATABLE,
+ GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE);
+}
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/drawspaces/gedit-drawspaces-view-activatable.h
b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
new file mode 100644
index 0000000..4968369
--- /dev/null
+++ b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
@@ -0,0 +1,61 @@
+/*
+ * gedit-drawspaces-view-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ *
+ * gedit is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gedit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__
+#define __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE (gedit_drawspaces_view_activatable_get_type
())
+#define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE, GeditDrawspacesViewActivatable))
+#define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE, GeditDrawspacesViewActivatable const))
+#define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE, GeditDrawspacesViewActivatableClass))
+#define GEDIT_IS_DRAWSPACES_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE))
+#define GEDIT_IS_DRAWSPACES_VIEW_ACTIVATABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE))
+#define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GEDIT_TYPE_DRAWSPACES_VIEW_ACTIVATABLE, GeditDrawspacesViewActivatableClass))
+
+#define DRAWSPACES_SETTINGS_BASE "org.gnome.gedit.plugins.drawspaces"
+#define SETTINGS_KEY_SHOW_WHITE_SPACE "show-white-space"
+#define SETTINGS_KEY_DRAW_SPACES "draw-spaces"
+
+typedef struct _GeditDrawspacesViewActivatable GeditDrawspacesViewActivatable;
+typedef struct _GeditDrawspacesViewActivatableClass GeditDrawspacesViewActivatableClass;
+
+struct _GeditDrawspacesViewActivatable
+{
+ GObject parent;
+};
+
+struct _GeditDrawspacesViewActivatableClass
+{
+ GObjectClass parent_class;
+};
+
+GType gedit_drawspaces_view_activatable_get_type (void) G_GNUC_CONST;
+
+void gedit_drawspaces_view_activatable_register (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/drawspaces/gedit-drawspaces-window-activatable.c
b/plugins/drawspaces/gedit-drawspaces-window-activatable.c
index d27c0ea..b34bb9d 100644
--- a/plugins/drawspaces/gedit-drawspaces-window-activatable.c
+++ b/plugins/drawspaces/gedit-drawspaces-window-activatable.c
@@ -21,6 +21,7 @@
#endif
#include "gedit-drawspaces-window-activatable.h"
+#include "gedit-drawspaces-view-activatable.h"
#include <glib/gi18n-lib.h>
#include <gedit/gedit-debug.h>
@@ -34,9 +35,6 @@ typedef struct _GeditDrawspacesWindowActivatablePrivate
{
GSettings *settings;
GeditWindow *window;
- GtkSourceDrawSpacesFlags flags;
-
- guint enable : 1;
} GeditDrawspacesWindowActivatablePrivate;
enum
@@ -45,7 +43,6 @@ enum
PROP_WINDOW
};
-static void draw_spaces (GeditDrawspacesWindowActivatable *window_activatable);
static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDrawspacesWindowActivatable,
@@ -57,31 +54,6 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDrawspacesWindowActivatable,
gedit_window_activatable_iface_init))
static void
-on_settings_changed (GSettings *settings,
- const gchar *key,
- GeditDrawspacesWindowActivatable *activatable)
-{
- GeditDrawspacesWindowActivatablePrivate *priv =
gedit_drawspaces_window_activatable_get_instance_private (activatable);
-
- priv->flags = g_settings_get_flags (priv->settings,
- SETTINGS_KEY_DRAW_SPACES);
-
- draw_spaces (activatable);
-}
-
-static void
-on_show_white_space_changed (GSettings *settings,
- const gchar *key,
- GeditDrawspacesWindowActivatable *activatable)
-{
- GeditDrawspacesWindowActivatablePrivate *priv =
gedit_drawspaces_window_activatable_get_instance_private (activatable);
-
- priv->enable = g_settings_get_boolean (settings, key);
-
- draw_spaces (activatable);
-}
-
-static void
gedit_drawspaces_window_activatable_init (GeditDrawspacesWindowActivatable *activatable)
{
}
@@ -140,55 +112,6 @@ gedit_drawspaces_window_activatable_get_property (GObject *object,
}
static void
-draw_spaces (GeditDrawspacesWindowActivatable *activatable)
-{
- GeditDrawspacesWindowActivatablePrivate *priv;
- GList *views, *l;
-
- priv = gedit_drawspaces_window_activatable_get_instance_private (activatable);
-
- views = gedit_window_get_views (priv->window);
- for (l = views; l != NULL; l = g_list_next (l))
- {
- gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (l->data),
- priv->enable ? priv->flags : 0);
- }
-
- g_list_free (views);
-}
-
-static void
-tab_added_cb (GeditWindow *window,
- GeditTab *tab,
- GeditDrawspacesWindowActivatable *activatable)
-{
- GeditDrawspacesWindowActivatablePrivate *priv;
- GeditView *view;
-
- priv = gedit_drawspaces_window_activatable_get_instance_private (activatable);
-
- if (priv->enable)
- {
- view = gedit_tab_get_view (tab);
-
- gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (view),
- priv->flags);
- }
-}
-
-static void
-get_config_options (GeditDrawspacesWindowActivatable *activatable)
-{
- GeditDrawspacesWindowActivatablePrivate *priv =
gedit_drawspaces_window_activatable_get_instance_private (activatable);
-
- priv->enable = g_settings_get_boolean (priv->settings,
- SETTINGS_KEY_SHOW_WHITE_SPACE);
-
- priv->flags = g_settings_get_flags (priv->settings,
- SETTINGS_KEY_DRAW_SPACES);
-}
-
-static void
gedit_drawspaces_window_activatable_window_activate (GeditWindowActivatable *activatable)
{
GeditDrawspacesWindowActivatablePrivate *priv;
@@ -199,30 +122,11 @@ gedit_drawspaces_window_activatable_window_activate (GeditWindowActivatable *act
priv = gedit_drawspaces_window_activatable_get_instance_private (GEDIT_DRAWSPACES_WINDOW_ACTIVATABLE
(activatable));
priv->settings = g_settings_new (DRAWSPACES_SETTINGS_BASE);
- get_config_options (GEDIT_DRAWSPACES_WINDOW_ACTIVATABLE (activatable));
-
action = g_settings_create_action (priv->settings,
SETTINGS_KEY_SHOW_WHITE_SPACE);
g_action_map_add_action (G_ACTION_MAP (priv->window),
action);
g_object_unref (action);
-
- if (priv->enable)
- {
- draw_spaces (GEDIT_DRAWSPACES_WINDOW_ACTIVATABLE (activatable));
- }
-
- g_signal_connect (priv->window, "tab-added",
- G_CALLBACK (tab_added_cb), activatable);
-
- g_signal_connect (priv->settings,
- "changed::show-white-space",
- G_CALLBACK (on_show_white_space_changed),
- activatable);
- g_signal_connect (priv->settings,
- "changed::draw-spaces",
- G_CALLBACK (on_settings_changed),
- activatable);
}
static void
@@ -237,11 +141,6 @@ gedit_drawspaces_window_activatable_window_deactivate (GeditWindowActivatable *a
g_action_map_remove_action (G_ACTION_MAP (priv->window),
SETTINGS_KEY_SHOW_WHITE_SPACE);
- priv->enable = FALSE;
- draw_spaces (GEDIT_DRAWSPACES_WINDOW_ACTIVATABLE (activatable));
-
- g_signal_handlers_disconnect_by_func (priv->window, tab_added_cb,
- activatable);
g_clear_object (&priv->settings);
}
diff --git a/plugins/drawspaces/gedit-drawspaces-window-activatable.h
b/plugins/drawspaces/gedit-drawspaces-window-activatable.h
index 2b63014..339952d 100644
--- a/plugins/drawspaces/gedit-drawspaces-window-activatable.h
+++ b/plugins/drawspaces/gedit-drawspaces-window-activatable.h
@@ -33,10 +33,6 @@ G_BEGIN_DECLS
#define GEDIT_IS_DRAWSPACES_WINDOW_ACTIVATABLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),
GEDIT_TYPE_DRAWSPACES_WINDOW_ACTIVATABLE))
#define GEDIT_DRAWSPACES_WINDOW_ACTIVATABLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),
GEDIT_TYPE_DRAWSPACES_WINDOW_ACTIVATABLE, GeditDrawspacesWindowActivatableClass))
-#define DRAWSPACES_SETTINGS_BASE "org.gnome.gedit.plugins.drawspaces"
-#define SETTINGS_KEY_SHOW_WHITE_SPACE "show-white-space"
-#define SETTINGS_KEY_DRAW_SPACES "draw-spaces"
-
typedef struct _GeditDrawspacesWindowActivatable GeditDrawspacesWindowActivatable;
typedef struct _GeditDrawspacesWindowActivatableClass GeditDrawspacesWindowActivatableClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]