[gnome-builder/gnome-builder-3-18] libide: add .has-indenter class to IdeSourceViewMode



commit 61c7b649d05fd840e978019b0c3f20868e3351c7
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 10 22:51:26 2015 -0400

    libide: add .has-indenter class to IdeSourceViewMode
    
    This can be used by keybindings to further select what keybindings to
    apply. For example, emacs can use this to determine if Tab should reindent
    a line (based on an indenter being available).
    
    IdeSourceViewMode.has-indenter { }

 libide/ide-source-view-mode.c |   16 ++++++++++++++++
 libide/ide-source-view-mode.h |    2 ++
 libide/ide-source-view.c      |   20 ++++++++++++++++++--
 3 files changed, 36 insertions(+), 2 deletions(-)
---
diff --git a/libide/ide-source-view-mode.c b/libide/ide-source-view-mode.c
index 9505d61..5216bd1 100644
--- a/libide/ide-source-view-mode.c
+++ b/libide/ide-source-view-mode.c
@@ -504,3 +504,19 @@ ide_source_view_mode_get_mode_type (IdeSourceViewMode *self)
   g_return_val_if_fail (IDE_IS_SOURCE_VIEW_MODE (self), 0);
   return self->type;
 }
+
+void
+ide_source_view_mode_set_has_indenter (IdeSourceViewMode *self,
+                                       gboolean           has_indenter)
+{
+  GtkStyleContext *style_context;
+
+  g_assert (IDE_IS_SOURCE_VIEW_MODE (self));
+
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+  if (has_indenter)
+    gtk_style_context_add_class (style_context, "has-indenter");
+  else
+    gtk_style_context_remove_class (style_context, "has-indenter");
+}
diff --git a/libide/ide-source-view-mode.h b/libide/ide-source-view-mode.h
index 9e3ceeb..f93411d 100644
--- a/libide/ide-source-view-mode.h
+++ b/libide/ide-source-view-mode.h
@@ -39,6 +39,8 @@ const gchar           *ide_source_view_mode_get_default_mode             (IdeSou
 const gchar           *ide_source_view_mode_get_display_name             (IdeSourceViewMode *self);
 gboolean               ide_source_view_mode_get_keep_mark_on_char        (IdeSourceViewMode *self);
 IdeSourceViewModeType  ide_source_view_mode_get_mode_type                (IdeSourceViewMode *self);
+void                   ide_source_view_mode_set_has_indenter             (IdeSourceViewMode *self,
+                                                                          gboolean           has_indenter);
 
 G_END_DECLS
 
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 01bff7a..b1d833f 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -878,10 +878,24 @@ ide_source_view_update_auto_indent_override (IdeSourceView *self)
 
   indenter = ide_source_view_get_indenter (self);
 
+  /*
+   * Updates our override of auto-indent from the GtkSourceView underneath us.
+   * Also updates our mode which needs to know if we have an indenter to
+   * provide different CSS selectors.
+   */
+
   if (priv->auto_indent && (indenter == NULL))
-    gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (self), TRUE);
+    {
+      gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (self), TRUE);
+      if (priv->mode != NULL)
+        ide_source_view_mode_set_has_indenter (priv->mode, FALSE);
+    }
   else
-    gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (self), FALSE);
+    {
+      gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (self), FALSE);
+      if (priv->mode != NULL)
+        ide_source_view_mode_set_has_indenter (priv->mode, (indenter != NULL));
+    }
 }
 
 static void
@@ -3070,6 +3084,8 @@ ide_source_view_real_set_mode (IdeSourceView         *self,
     gtk_text_view_set_overwrite (GTK_TEXT_VIEW (self), overwrite);
   g_object_notify (G_OBJECT (self), "overwrite");
 
+  ide_source_view_update_auto_indent_override (self);
+
   ide_source_view_update_display_name (self);
 
   IDE_EXIT;


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