[gedit-plugins] drawspaces: new implementation based on TeplSpaceDrawerPrefs
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] drawspaces: new implementation based on TeplSpaceDrawerPrefs
- Date: Thu, 24 Sep 2020 13:38:53 +0000 (UTC)
commit 2060f8a6a416653791d26352cf012b4c9e9ee9bb
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Sep 24 01:25:51 2020 +0200
drawspaces: new implementation based on TeplSpaceDrawerPrefs
Tepl >= 5.1.0 is required.
https://gitlab.gnome.org/GNOME/gedit-plugins/issues/15
meson.build | 1 +
plugins/drawspaces/drawspaces.plugin.desktop.in.in | 4 +-
.../drawspaces/gedit-drawspaces-app-activatable.c | 293 ++-------------------
.../drawspaces/gedit-drawspaces-app-activatable.h | 32 +--
.../drawspaces/gedit-drawspaces-configurable.ui | 175 ------------
.../drawspaces/gedit-drawspaces-view-activatable.c | 130 ++-------
.../drawspaces/gedit-drawspaces-view-activatable.h | 17 +-
plugins/drawspaces/gedit-drawspaces.gresource.xml | 6 -
plugins/drawspaces/meson.build | 10 +-
.../org.gnome.gedit.plugins.drawspaces.gschema.xml | 26 +-
po/POTFILES.in | 1 -
11 files changed, 70 insertions(+), 625 deletions(-)
---
diff --git a/meson.build b/meson.build
index 2ecca7b..6b40dc1 100644
--- a/meson.build
+++ b/meson.build
@@ -26,6 +26,7 @@ localedir = join_paths(datadir, 'locale')
# Dependencies in common for all plugins
libpeas_dep = dependency('libpeas-1.0', version: '>= 1.14.1')
+tepl_dep = dependency('tepl-5', version: '>= 5.1.0')
gedit_dep = dependency('gedit', version: '>= 3.38')
appstream_util = find_program('appstream-util', required: false)
diff --git a/plugins/drawspaces/drawspaces.plugin.desktop.in.in
b/plugins/drawspaces/drawspaces.plugin.desktop.in.in
index 8374851..0c5b584 100644
--- a/plugins/drawspaces/drawspaces.plugin.desktop.in.in
+++ b/plugins/drawspaces/drawspaces.plugin.desktop.in.in
@@ -3,7 +3,7 @@ Module=drawspaces
IAge=3
Name=Draw Spaces
Description=Draw spaces and tabs
-Authors=Paolo Borelli <pborelli katamail com>;Steve Frécinaux <code istique net>;Ignacio Casal Quinteiro
<nacho resa gmail com>
-Copyright=Copyright © 2006 Paolo Borelli;Copyright © 2007 Steve Frécinaux;Copyright © 2008 Ignacio Casal
Quinteiro
+Authors=Paolo Borelli <pborelli katamail com>;Steve Frécinaux <code istique net>;Ignacio Casal Quinteiro
<nacho resa gmail com>;Sébastien Wilmet <swilmet gnome org>
+Copyright=Copyright © 2006 Paolo Borelli;Copyright © 2007 Steve Frécinaux;Copyright © 2008 Ignacio Casal
Quinteiro;Copyright © 2020 Sébastien Wilmet
Website=http://www.gedit.org
Version=@VERSION@
diff --git a/plugins/drawspaces/gedit-drawspaces-app-activatable.c
b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
index cb3d302..52f31ea 100644
--- a/plugins/drawspaces/gedit-drawspaces-app-activatable.c
+++ b/plugins/drawspaces/gedit-drawspaces-app-activatable.c
@@ -1,62 +1,35 @@
/*
* Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2020 Sébastien Wilmet <swilmet gnome org>
*
- * This program is free software; you can redistribute it and/or modify
+ * 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, or (at your option)
- * any later version.
+ * 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,
+ * 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
#include "gedit-drawspaces-app-activatable.h"
#include "gedit-drawspaces-view-activatable.h"
-
-#include <gedit/gedit-app.h>
-#include <gedit/gedit-app-activatable.h>
-#include <gedit/gedit-debug.h>
-#include <gio/gio.h>
-#include <glib/gi18n-lib.h>
+#include <tepl/tepl.h>
#include <libpeas-gtk/peas-gtk-configurable.h>
-typedef struct _GeditDrawspacesAppActivatablePrivate
-{
- GeditApp *app;
-} GeditDrawspacesAppActivatablePrivate;
-
-typedef struct _DrawspacesConfigureWidget DrawspacesConfigureWidget;
+/* TODO: rename the class to GeditDrawspacesPrefs or something like that, since
+ * it no longer implements the GeditAppActivatable interface.
+ */
-struct _DrawspacesConfigureWidget
+typedef struct _GeditDrawspacesAppActivatablePrivate
{
GSettings *settings;
- guint flags;
-
- GtkWidget *content;
-
- GtkWidget *draw_tabs;
- GtkWidget *draw_spaces;
- GtkWidget *draw_newline;
- GtkWidget *draw_nbsp;
- GtkWidget *draw_leading;
- GtkWidget *draw_text;
- GtkWidget *draw_trailing;
-};
-
-enum
-{
- PROP_0,
- PROP_APP
-};
+} GeditDrawspacesAppActivatablePrivate;
-static void gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface);
static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDrawspacesAppActivatable,
@@ -64,8 +37,6 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDrawspacesAppActivatable,
G_TYPE_OBJECT,
0,
G_ADD_PRIVATE_DYNAMIC (GeditDrawspacesAppActivatable)
- G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_APP_ACTIVATABLE,
- gedit_app_activatable_iface_init)
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE,
peas_gtk_configurable_iface_init))
@@ -75,63 +46,17 @@ gedit_drawspaces_app_activatable_dispose (GObject *object)
GeditDrawspacesAppActivatable *activatable = GEDIT_DRAWSPACES_APP_ACTIVATABLE (object);
GeditDrawspacesAppActivatablePrivate *priv = gedit_drawspaces_app_activatable_get_instance_private
(activatable);
- g_clear_object (&priv->app);
+ g_clear_object (&priv->settings);
G_OBJECT_CLASS (gedit_drawspaces_app_activatable_parent_class)->dispose (object);
}
-static void
-gedit_drawspaces_app_activatable_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GeditDrawspacesAppActivatable *activatable = GEDIT_DRAWSPACES_APP_ACTIVATABLE (object);
- GeditDrawspacesAppActivatablePrivate *priv = gedit_drawspaces_app_activatable_get_instance_private
(activatable);
-
- switch (prop_id)
- {
- case PROP_APP:
- priv->app = GEDIT_APP (g_value_dup_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gedit_drawspaces_app_activatable_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GeditDrawspacesAppActivatable *activatable = GEDIT_DRAWSPACES_APP_ACTIVATABLE (object);
- GeditDrawspacesAppActivatablePrivate *priv = gedit_drawspaces_app_activatable_get_instance_private
(activatable);
-
- switch (prop_id)
- {
- case PROP_APP:
- g_value_set_object (value, priv->app);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
static void
gedit_drawspaces_app_activatable_class_init (GeditDrawspacesAppActivatableClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gedit_drawspaces_app_activatable_dispose;
- object_class->set_property = gedit_drawspaces_app_activatable_set_property;
- object_class->get_property = gedit_drawspaces_app_activatable_get_property;
-
- g_object_class_override_property (object_class, PROP_APP, "app");
}
static void
@@ -140,190 +65,29 @@ gedit_drawspaces_app_activatable_class_finalize (GeditDrawspacesAppActivatableCl
}
static void
-gedit_drawspaces_app_activatable_init (GeditDrawspacesAppActivatable *self)
-{
-}
-
-static void
-gedit_drawspaces_app_activatable_activate (GeditAppActivatable *activatable)
-{
-}
-
-static void
-gedit_drawspaces_app_activatable_deactivate (GeditAppActivatable *activatable)
-{
-}
-
-static void
-gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface)
-{
- iface->activate = gedit_drawspaces_app_activatable_activate;
- iface->deactivate = gedit_drawspaces_app_activatable_deactivate;
-}
-
-static void
-widget_destroyed (GtkWidget *obj, gpointer widget_pointer)
-{
- DrawspacesConfigureWidget *widget = (DrawspacesConfigureWidget *)widget_pointer;
-
- gedit_debug (DEBUG_PLUGINS);
-
- g_object_unref (widget->settings);
- g_slice_free (DrawspacesConfigureWidget, widget_pointer);
-
- gedit_debug_message (DEBUG_PLUGINS, "END");
-}
-
-static void
-set_flag (DrawspacesConfigureWidget *widget, guint flag, gboolean active)
-{
- widget->flags = active ? widget->flags | flag : widget->flags & ~flag;
- g_settings_set_flags (widget->settings,
- SETTINGS_KEY_DRAW_SPACES,
- widget->flags);
-}
-
-static void
-on_draw_tabs_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_TAB, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_spaces_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_SPACE, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_newline_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_NEWLINE, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_nbsp_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
+gedit_drawspaces_app_activatable_init (GeditDrawspacesAppActivatable *activatable)
{
- set_flag (widget, GEDIT_DRAW_SPACES_NBSP, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_leading_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_LEADING, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_text_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_TEXT, gtk_toggle_button_get_active (button));
-}
-
-static void
-on_draw_trailing_toggled (GtkToggleButton *button,
- DrawspacesConfigureWidget *widget)
-{
- set_flag (widget, GEDIT_DRAW_SPACES_TRAILING, gtk_toggle_button_get_active (button));
-}
-
-static DrawspacesConfigureWidget *
-get_configuration_widget (GeditDrawspacesAppActivatable *activatable)
-{
- DrawspacesConfigureWidget *widget = NULL;
- GtkBuilder *builder;
-
- gchar *root_objects[] = {
- "content",
- NULL
- };
-
- widget = g_slice_new (DrawspacesConfigureWidget);
- widget->settings = g_settings_new (DRAWSPACES_SETTINGS_BASE);
- widget->flags = g_settings_get_flags (widget->settings,
- SETTINGS_KEY_DRAW_SPACES);
-
- builder = gtk_builder_new ();
- gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
- gtk_builder_add_objects_from_resource (builder,
"/org/gnome/gedit/plugins/drawspaces/ui/gedit-drawspaces-configurable.ui",
- root_objects, NULL);
- widget->content = GTK_WIDGET (gtk_builder_get_object (builder, "content"));
- g_object_ref (widget->content);
- widget->draw_tabs = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_tabs"));
- widget->draw_spaces = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_spaces"));
- widget->draw_newline = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_new_lines"));
- widget->draw_nbsp = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_nbsp"));
- widget->draw_leading = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_leading"));
- widget->draw_text = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_text"));
- widget->draw_trailing = GTK_WIDGET (gtk_builder_get_object (builder, "check_button_draw_trailing"));
- g_object_unref (builder);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_tabs),
- widget->flags & GEDIT_DRAW_SPACES_TAB);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_spaces),
- widget->flags & GEDIT_DRAW_SPACES_SPACE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_newline),
- widget->flags & GEDIT_DRAW_SPACES_NEWLINE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_nbsp),
- widget->flags & GEDIT_DRAW_SPACES_NBSP);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_leading),
- widget->flags & GEDIT_DRAW_SPACES_LEADING);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_text),
- widget->flags & GEDIT_DRAW_SPACES_TEXT);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->draw_trailing),
- widget->flags & GEDIT_DRAW_SPACES_TRAILING);
-
- g_signal_connect (widget->draw_tabs,
- "toggled",
- G_CALLBACK (on_draw_tabs_toggled),
- widget);
- g_signal_connect (widget->draw_spaces,
- "toggled",
- G_CALLBACK (on_draw_spaces_toggled),
- widget);
- g_signal_connect (widget->draw_newline,
- "toggled",
- G_CALLBACK (on_draw_newline_toggled),
- widget);
- g_signal_connect (widget->draw_nbsp,
- "toggled",
- G_CALLBACK (on_draw_nbsp_toggled),
- widget);
- g_signal_connect (widget->draw_leading,
- "toggled",
- G_CALLBACK (on_draw_leading_toggled),
- widget);
- g_signal_connect (widget->draw_text,
- "toggled",
- G_CALLBACK (on_draw_text_toggled),
- widget);
- g_signal_connect (widget->draw_trailing,
- "toggled",
- G_CALLBACK (on_draw_trailing_toggled),
- widget);
-
- g_signal_connect (widget->content,
- "destroy",
- G_CALLBACK (widget_destroyed),
- widget);
+ GeditDrawspacesAppActivatablePrivate *priv = gedit_drawspaces_app_activatable_get_instance_private
(activatable);
- return widget;
+ priv->settings = g_settings_new ("org.gnome.gedit.plugins.drawspaces");
}
static GtkWidget *
gedit_drawspaces_app_activatable_create_configure_widget (PeasGtkConfigurable *configurable)
{
- DrawspacesConfigureWidget *widget;
+ GeditDrawspacesAppActivatable *activatable = GEDIT_DRAWSPACES_APP_ACTIVATABLE (configurable);
+ GeditDrawspacesAppActivatablePrivate *priv = gedit_drawspaces_app_activatable_get_instance_private
(activatable);
+ TeplSpaceDrawerPrefs *prefs;
+ GtkSourceSpaceDrawer *space_drawer;
- widget = get_configuration_widget (GEDIT_DRAWSPACES_APP_ACTIVATABLE (configurable));
+ prefs = tepl_space_drawer_prefs_new ();
+ space_drawer = tepl_space_drawer_prefs_get_space_drawer (prefs);
+ gtk_source_space_drawer_bind_matrix_setting (space_drawer,
+ priv->settings, "matrix",
+ G_SETTINGS_BIND_DEFAULT |
+ G_SETTINGS_BIND_NO_SENSITIVITY);
- return widget->content;
+ return GTK_WIDGET (prefs);
}
static void
@@ -338,9 +102,6 @@ peas_register_types (PeasObjectModule *module)
gedit_drawspaces_app_activatable_register_type (G_TYPE_MODULE (module));
gedit_drawspaces_view_activatable_register (G_TYPE_MODULE (module));
- peas_object_module_register_extension_type (module,
- GEDIT_TYPE_APP_ACTIVATABLE,
- GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE);
peas_object_module_register_extension_type (module,
PEAS_GTK_TYPE_CONFIGURABLE,
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE);
diff --git a/plugins/drawspaces/gedit-drawspaces-app-activatable.h
b/plugins/drawspaces/gedit-drawspaces-app-activatable.h
index ac93ddc..f6a80bf 100644
--- a/plugins/drawspaces/gedit-drawspaces-app-activatable.h
+++ b/plugins/drawspaces/gedit-drawspaces-app-activatable.h
@@ -1,23 +1,23 @@
/*
* Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2020 Sébastien Wilmet <swilmet gnome org>
*
- * This program is free software; you can redistribute it and/or modify
+ * 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, or (at your option)
- * any later version.
+ * 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,
+ * 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __GEDIT_DRAWSPACES_APP_ACTIVATABLE_H__
-#define __GEDIT_DRAWSPACES_APP_ACTIVATABLE_H__
+#ifndef GEDIT_DRAWSPACES_APP_ACTIVATABLE_H
+#define GEDIT_DRAWSPACES_APP_ACTIVATABLE_H
#include <glib-object.h>
#include <libpeas/peas-object-module.h>
@@ -26,7 +26,6 @@ G_BEGIN_DECLS
#define GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE (gedit_drawspaces_app_activatable_get_type ())
#define GEDIT_DRAWSPACES_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE, GeditDrawspacesAppActivatable))
-#define GEDIT_DRAWSPACES_APP_ACTIVATABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE, GeditDrawspacesAppActivatable const))
#define GEDIT_DRAWSPACES_APP_ACTIVATABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE, GeditDrawspacesAppActivatableClass))
#define GEDIT_IS_DRAWSPACES_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE))
#define GEDIT_IS_DRAWSPACES_APP_ACTIVATABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GEDIT_TYPE_DRAWSPACES_APP_ACTIVATABLE))
@@ -45,21 +44,10 @@ struct _GeditDrawspacesAppActivatableClass
GObjectClass parent_class;
};
-enum _GeditDrawSpacesFlags {
- GEDIT_DRAW_SPACES_SPACE = 1 << 0,
- GEDIT_DRAW_SPACES_TAB = 1 << 1,
- GEDIT_DRAW_SPACES_NEWLINE = 1 << 2,
- GEDIT_DRAW_SPACES_NBSP = 1 << 3,
- GEDIT_DRAW_SPACES_LEADING = 1 << 4,
- GEDIT_DRAW_SPACES_TEXT = 1 << 5,
- GEDIT_DRAW_SPACES_TRAILING = 1 << 6,
- GEDIT_DRAW_SPACES_ALL = 0x7f
-};
-
-GType gedit_drawspaces_app_activatable_get_type (void) G_GNUC_CONST;
+GType gedit_drawspaces_app_activatable_get_type (void);
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS
-#endif /* __GEDIT_DRAWSPACES_APP_ACTIVATABLE_H__ */
+#endif /* GEDIT_DRAWSPACES_APP_ACTIVATABLE_H */
diff --git a/plugins/drawspaces/gedit-drawspaces-view-activatable.c
b/plugins/drawspaces/gedit-drawspaces-view-activatable.c
index c50978d..c6a92b5 100644
--- a/plugins/drawspaces/gedit-drawspaces-view-activatable.c
+++ b/plugins/drawspaces/gedit-drawspaces-view-activatable.c
@@ -1,8 +1,6 @@
/*
- * gedit-drawspaces-view-activatable.h
- * This file is part of gedit
- *
* Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2020 Sébastien Wilmet <swilmet 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
@@ -18,9 +16,7 @@
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gedit-drawspaces-app-activatable.h"
#include "gedit-drawspaces-view-activatable.h"
-
#include <gedit/gedit-view.h>
#include <gedit/gedit-view-activatable.h>
#include <libpeas/peas-object-module.h>
@@ -29,9 +25,6 @@ typedef struct _GeditDrawspacesViewActivatablePrivate
{
GeditView *view;
GSettings *settings;
- guint flags;
-
- guint enable : 1;
} GeditDrawspacesViewActivatablePrivate;
enum
@@ -57,6 +50,7 @@ gedit_drawspaces_view_activatable_dispose (GObject *object)
GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
g_clear_object (&priv->view);
+ g_clear_object (&priv->settings);
G_OBJECT_CLASS (gedit_drawspaces_view_activatable_parent_class)->dispose (object);
}
@@ -121,133 +115,47 @@ gedit_drawspaces_view_activatable_class_finalize (GeditDrawspacesViewActivatable
}
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 inline void
-parse_flags (guint flags,
- GtkSourceSpaceTypeFlags *type,
- GtkSourceSpaceLocationFlags *location)
-{
- *type = GTK_SOURCE_SPACE_TYPE_NONE;
- *location = GTK_SOURCE_SPACE_LOCATION_NONE;
-
- if (flags & GEDIT_DRAW_SPACES_SPACE)
- *type |= GTK_SOURCE_SPACE_TYPE_SPACE;
- if (flags & GEDIT_DRAW_SPACES_TAB)
- *type |= GTK_SOURCE_SPACE_TYPE_TAB;
- if (flags & GEDIT_DRAW_SPACES_NEWLINE)
- *type |= GTK_SOURCE_SPACE_TYPE_NEWLINE;
- if (flags & GEDIT_DRAW_SPACES_NBSP)
- *type |= GTK_SOURCE_SPACE_TYPE_NBSP;
-
- if (flags & GEDIT_DRAW_SPACES_LEADING)
- *location |= GTK_SOURCE_SPACE_LOCATION_LEADING;
- if (flags & GEDIT_DRAW_SPACES_TEXT)
- *location |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT;
- if (flags & GEDIT_DRAW_SPACES_TRAILING)
- *location |= GTK_SOURCE_SPACE_LOCATION_TRAILING;
-}
-
-static void
-draw_spaces (GeditDrawspacesViewActivatable *activatable)
-{
- GeditDrawspacesViewActivatablePrivate *priv = gedit_drawspaces_view_activatable_get_instance_private
(activatable);
- GtkSourceSpaceDrawer *drawer;
- GtkSourceSpaceTypeFlags type;
- GtkSourceSpaceLocationFlags location;
-
- parse_flags (priv->flags, &type, &location);
-
- drawer = gtk_source_view_get_space_drawer (GTK_SOURCE_VIEW (priv->view));
-
- /* Clear all existing spaces in the matrix before setting */
- gtk_source_space_drawer_set_types_for_locations (drawer, GTK_SOURCE_SPACE_LOCATION_ALL, 0);
- gtk_source_space_drawer_set_types_for_locations (drawer, location, type);
- gtk_source_space_drawer_set_enable_matrix (drawer, priv->enable);
-}
-
-static void
-on_draw_spaces_changed (GSettings *settings,
- const gchar *key,
- GeditDrawspacesViewActivatable *activatable)
+gedit_drawspaces_view_activatable_init (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);
+ priv->settings = g_settings_new ("org.gnome.gedit.plugins.drawspaces");
}
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)
+gedit_drawspaces_view_activatable_activate (GeditViewActivatable *activatable)
{
GeditDrawspacesViewActivatablePrivate *priv;
+ GtkSourceSpaceDrawer *space_drawer;
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);
+ space_drawer = gtk_source_view_get_space_drawer (GTK_SOURCE_VIEW (priv->view));
+ gtk_source_space_drawer_bind_matrix_setting (space_drawer,
+ priv->settings, "matrix",
+ G_SETTINGS_BIND_GET |
+ G_SETTINGS_BIND_NO_SENSITIVITY);
+ gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE);
}
static void
-gedit_drawspaces_view_activatable_window_deactivate (GeditViewActivatable *activatable)
+gedit_drawspaces_view_activatable_deactivate (GeditViewActivatable *activatable)
{
GeditDrawspacesViewActivatablePrivate *priv;
+ GtkSourceSpaceDrawer *space_drawer;
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);
+ space_drawer = gtk_source_view_get_space_drawer (GTK_SOURCE_VIEW (priv->view));
+ g_settings_unbind (space_drawer, "matrix");
+ gtk_source_space_drawer_set_enable_matrix (space_drawer, FALSE);
}
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;
+ iface->activate = gedit_drawspaces_view_activatable_activate;
+ iface->deactivate = gedit_drawspaces_view_activatable_deactivate;
}
void
diff --git a/plugins/drawspaces/gedit-drawspaces-view-activatable.h
b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
index 4968369..e4114ce 100644
--- a/plugins/drawspaces/gedit-drawspaces-view-activatable.h
+++ b/plugins/drawspaces/gedit-drawspaces-view-activatable.h
@@ -1,8 +1,6 @@
/*
- * gedit-drawspaces-view-activatable.h
- * This file is part of gedit
- *
* Copyright (C) 2008-2014 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2020 Sébastien Wilmet <swilmet 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
@@ -18,8 +16,8 @@
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__
-#define __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__
+#ifndef GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H
+#define GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H
#include <glib-object.h>
@@ -27,16 +25,11 @@ 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;
@@ -50,12 +43,12 @@ struct _GeditDrawspacesViewActivatableClass
GObjectClass parent_class;
};
-GType gedit_drawspaces_view_activatable_get_type (void) G_GNUC_CONST;
+GType gedit_drawspaces_view_activatable_get_type (void);
void gedit_drawspaces_view_activatable_register (GTypeModule *module);
G_END_DECLS
-#endif /* __GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H__ */
+#endif /* GEDIT_DRAWSPACES_VIEW_ACTIVATABLE_H */
/* ex:set ts=8 noet: */
diff --git a/plugins/drawspaces/meson.build b/plugins/drawspaces/meson.build
index 75610cb..ff59b28 100644
--- a/plugins/drawspaces/meson.build
+++ b/plugins/drawspaces/meson.build
@@ -4,18 +4,10 @@ libdrawspaces_sources = files(
)
libdrawspaces_deps = [
+ tepl_dep,
gedit_dep,
]
-libdrawspaces_res = gnome.compile_resources(
- 'gedit-drawspaces-resources',
- 'gedit-drawspaces.gresource.xml',
-)
-
-libdrawspaces_sources += [
- libdrawspaces_res.get(0),
-]
-
libdrawspaces_sha = shared_module(
'drawspaces',
sources: libdrawspaces_sources,
diff --git a/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml
b/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml
index a05f96d..3f288d3 100644
--- a/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml
+++ b/plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml
@@ -1,24 +1,8 @@
-<schemalist>
- <flags id='org.gnome.gedit.plugins.drawspaces.GtkSourceDrawSpacesFlags'>
- <value nick='space' value='1'/>
- <value nick='tab' value='2'/>
- <value nick='newline' value='4'/>
- <value nick='nbsp' value='8'/>
- <value nick='leading' value='16'/>
- <value nick='text' value='32'/>
- <value nick='trailing' value='64'/>
- </flags>
-
- <schema gettext-domain="gedit-plugins" id="org.gnome.gedit.plugins.drawspaces"
path="/org/gnome/gedit/plugins/drawspaces/">
- <key name="show-white-space" type="b">
- <default>true</default>
- <summary>Show White Space</summary>
- <description>If TRUE drawing will be enabled.</description>
- </key>
- <key name="draw-spaces" flags="org.gnome.gedit.plugins.drawspaces.GtkSourceDrawSpacesFlags">
- <default>['space', 'tab', 'leading', 'text', 'trailing']</default>
- <summary>Draw Spaces</summary>
- <description>The type of spaces to be drawn.</description>
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist gettext-domain="gedit-plugins">
+ <schema id="org.gnome.gedit.plugins.drawspaces" path="/org/gnome/gedit/plugins/drawspaces/">
+ <key name="matrix" type="au">
+ <default>[uint32 11, 11, 11]</default>
</key>
</schema>
</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5b19b7b..ba022d7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -24,7 +24,6 @@ plugins/commander/commander.plugin.desktop.in.in
plugins/commander/gedit-commander.metainfo.xml.in
plugins/drawspaces/drawspaces.plugin.desktop.in.in
plugins/drawspaces/gedit-drawspaces-app-activatable.c
-plugins/drawspaces/gedit-drawspaces-configurable.ui
plugins/drawspaces/gedit-drawspaces.metainfo.xml.in
plugins/drawspaces/org.gnome.gedit.plugins.drawspaces.gschema.xml
plugins/findinfiles/dialog.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]