[gtksourceview/wip/smart-backspace: 1/2] view: add configuration to the smart-backspace



commit 5102f10b2efeef6126a720c03e940b64991a4633
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Aug 16 14:26:47 2015 +0200

    view: add configuration to the smart-backspace

 docs/reference/gtksourceview-3.0-sections.txt |    1 +
 gtksourceview/gtksourceview.c                 |   50 ++++++++++++-------------
 gtksourceview/gtksourceview.h                 |   27 ++++++++++++-
 3 files changed, 49 insertions(+), 29 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index 5d88b23..9bf5791 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -831,6 +831,7 @@ gtk_source_utils_escape_search_text
 GtkSourceView
 GtkSourceSmartHomeEndType
 GtkSourceDrawSpacesFlags
+GtkSourceSpaceLocation
 GtkSourceViewGutterPosition
 GtkSourceBackgroundPatternType
 gtk_source_view_new
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index dc1d958..1db25f3 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -191,6 +191,7 @@ struct _GtkSourceViewPrivate
        GtkSourceSmartHomeEndType smart_home_end;
        GtkSourceBackgroundPatternType background_pattern;
        GdkRGBA background_pattern_color;
+       GtkSourceSpaceLocation smart_backspace;
 
        guint tabs_set : 1;
        guint show_line_numbers : 1;
@@ -203,7 +204,6 @@ struct _GtkSourceViewPrivate
        guint style_scheme_applied : 1;
        guint current_line_color_set : 1;
        guint background_pattern_color_set : 1;
-       guint smart_backspace : 1;
 };
 
 typedef struct _MarkCategory MarkCategory;
@@ -657,17 +657,20 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
        /**
         * GtkSourceView:smart-backspace:
         *
-        * Whether smart Backspace should be used.
+        * Where the smart Backspace is enabled.
         *
         * Since: 3.18
         */
        g_object_class_install_property (object_class,
                                         PROP_SMART_BACKSPACE,
-                                        g_param_spec_boolean ("smart-backspace",
-                                                              "Smart Backspace",
-                                                              "",
-                                                              FALSE,
-                                                              G_PARAM_READWRITE));
+                                        g_param_spec_flags ("smart-backspace",
+                                                            "Smart Backspace",
+                                                            "",
+                                                            GTK_SOURCE_TYPE_SPACE_LOCATION,
+                                                            GTK_SOURCE_SPACE_LOCATION_NOWHERE,
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_CONSTRUCT |
+                                                            G_PARAM_STATIC_STRINGS));
 
        signals[UNDO] =
                g_signal_new ("undo",
@@ -1132,7 +1135,7 @@ gtk_source_view_set_property (GObject      *object,
                        break;
 
                case PROP_SMART_BACKSPACE:
-                       gtk_source_view_set_smart_backspace (view, g_value_get_boolean (value));
+                       gtk_source_view_set_smart_backspace (view, g_value_get_flags (value));
                        break;
 
                default:
@@ -1212,7 +1215,7 @@ gtk_source_view_get_property (GObject    *object,
                        break;
 
                case PROP_SMART_BACKSPACE:
-                       g_value_set_boolean (value, gtk_source_view_get_smart_backspace (view));
+                       g_value_set_flags (value, gtk_source_view_get_smart_backspace (view));
                        break;
 
                default:
@@ -4293,7 +4296,8 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
                return GDK_EVENT_STOP;
        }
 
-       if ((key == GDK_KEY_BackSpace) && view->priv->smart_backspace)
+       if ((key == GDK_KEY_BackSpace) &&
+           view->priv->smart_backspace != GTK_SOURCE_SPACE_LOCATION_NOWHERE)
        {
                if (gtk_source_view_do_smart_backspace (view, (event->state & modifiers)))
                {
@@ -4629,24 +4633,22 @@ gtk_source_view_set_right_margin_position (GtkSourceView *view,
 /**
  * gtk_source_view_set_smart_backspace:
  * @view: a #GtkSourceView.
- * @smart_backspace: whether to enable smart Backspace handling.
+ * @locations: where to enable the smart Backspace.
  *
- * When set to %TRUE, pressing the Backspace key will try to delete spaces
- * up to the previous tab stop.
+ * Where the smart Backspace is enabled, pressing the Backspace key will try to
+ * delete spaces up to the previous tab stop.
  *
  * Since: 3.18
  */
 void
-gtk_source_view_set_smart_backspace (GtkSourceView *view,
-                                     gboolean       smart_backspace)
+gtk_source_view_set_smart_backspace (GtkSourceView          *view,
+                                    GtkSourceSpaceLocation  locations)
 {
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
-       smart_backspace = smart_backspace != FALSE;
-
-       if (smart_backspace != view->priv->smart_backspace)
+       if (locations != view->priv->smart_backspace)
        {
-               view->priv->smart_backspace = smart_backspace;
+               view->priv->smart_backspace = locations;
                g_object_notify (G_OBJECT (view), "smart-backspace");
        }
 }
@@ -4655,17 +4657,13 @@ gtk_source_view_set_smart_backspace (GtkSourceView *view,
  * gtk_source_view_get_smart_backspace:
  * @view: a #GtkSourceView.
  *
- * Returns %TRUE if pressing the Backspace key will try to delete spaces
- * up to the previous tab stop.
- *
- * Returns: %TRUE if smart Backspace handling is enabled.
- *
+ * Returns: the locations where the smart Backspace is enabled.
  * Since: 3.18
  */
-gboolean
+GtkSourceSpaceLocation
 gtk_source_view_get_smart_backspace (GtkSourceView *view)
 {
-       g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+       g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), GTK_SOURCE_SPACE_LOCATION_NOWHERE);
 
        return view->priv->smart_backspace;
 }
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 2e2e9db..5e6e8dd 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -127,6 +127,26 @@ typedef enum
        GTK_SOURCE_DRAW_SPACES_ALL        = 0x7f
 } GtkSourceDrawSpacesFlags;
 
+/**
+ * GtkSourceSpaceLocation:
+ * @GTK_SOURCE_SPACE_LOCATION_NOWHERE: nowhere.
+ * @GTK_SOURCE_SPACE_LOCATION_LEADING: leading whitespaces.
+ * @GTK_SOURCE_SPACE_LOCATION_INTERNAL: whitespaces inside text.
+ * @GTK_SOURCE_SPACE_LOCATION_TRAILING: trailing whitespaces.
+ * @GTK_SOURCE_SPACE_LOCATION_EVERYWHERE: whitespaces everywhere.
+ *
+ * GtkSourceSpaceLocation describes the location of a whitespace on a line.
+ *
+ * Since: 3.18
+ */
+typedef enum
+{
+       GTK_SOURCE_SPACE_LOCATION_NOWHERE       = 0,
+       GTK_SOURCE_SPACE_LOCATION_LEADING       = 1 << 0,
+       GTK_SOURCE_SPACE_LOCATION_INTERNAL      = 1 << 1,
+       GTK_SOURCE_SPACE_LOCATION_TRAILING      = 1 << 2,
+       GTK_SOURCE_SPACE_LOCATION_EVERYWHERE    = 0xff
+} GtkSourceSpaceLocation;
 
 GType           gtk_source_view_get_type               (void) G_GNUC_CONST;
 
@@ -208,10 +228,11 @@ GtkSourceMarkAttributes *
                                                          const gchar             *category,
                                                          gint                    *priority);
 
-void            gtk_source_view_set_smart_backspace    (GtkSourceView   *view,
-                                                        gboolean        smart_backspace);
+void            gtk_source_view_set_smart_backspace    (GtkSourceView          *view,
+                                                        GtkSourceSpaceLocation  locations);
 
-gboolean        gtk_source_view_get_smart_backspace    (GtkSourceView   *view);
+GtkSourceSpaceLocation
+                gtk_source_view_get_smart_backspace    (GtkSourceView *view);
 
 void            gtk_source_view_set_smart_home_end     (GtkSourceView             *view,
                                                         GtkSourceSmartHomeEndType  smart_home_end);


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