[gtksourceview/wip/chergert/gsv-gtk4: 116/125] view: update change-case action enabled state



commit 7736ffe8d09d16f418ab4a544cf9b60f0587ac15
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 15 15:30:56 2020 -0800

    view: update change-case action enabled state
    
    When the selection changes, we need to change the activation sensitivity
    of the underlying GAction exposed by the view.

 gtksourceview/gtksourceview.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 7fd2dd9b..ef993fa3 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -1528,6 +1528,17 @@ buffer_style_scheme_changed_cb (GtkSourceBuffer *buffer,
        gtk_source_view_update_style_scheme (view);
 }
 
+static void
+buffer_has_selection_changed_cb (GtkSourceBuffer *buffer,
+                                GParamSpec      *pspec,
+                                GtkSourceView   *view)
+{
+       gtk_widget_action_set_enabled (GTK_WIDGET (view),
+                                      "source.change-case",
+                                      (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
+                                       gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer))));
+}
+
 static void
 implicit_trailing_newline_changed_cb (GtkSourceBuffer *buffer,
                                       GParamSpec      *pspec,
@@ -1558,6 +1569,9 @@ remove_source_buffer (GtkSourceView *view)
                                                      buffer_style_scheme_changed_cb,
                                                      view);
 
+               g_signal_handlers_disconnect_by_func (priv->source_buffer,
+                                                     buffer_has_selection_changed_cb,
+                                                     view);
                g_signal_handlers_disconnect_by_func (priv->source_buffer,
                                                      implicit_trailing_newline_changed_cb,
                                                      view);
@@ -1612,6 +1626,11 @@ set_source_buffer (GtkSourceView *view,
                                  G_CALLBACK (implicit_trailing_newline_changed_cb),
                                  view);
 
+               g_signal_connect (buffer,
+                                 "notify::has-selection",
+                                 G_CALLBACK (buffer_has_selection_changed_cb),
+                                 view);
+
                buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
 
                g_signal_connect (buffer_internal,


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