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



commit 2a53c85fb5079dc5a1def7fa606516058bc75815
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]