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



commit 88c3ed2252219d53b76669f503f4614b96a6eaeb
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 fb846bcb..4a404b2a 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -1533,6 +1533,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,
@@ -1563,6 +1574,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);
@@ -1617,6 +1631,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]