[gtksourceview/wip/chergert/gsv-gtk4: 99/118] view: add source.change-case(s) GAction to GtkSourceView



commit 688e52a0ec06d1ba85a5d5568bc7cda00ae2fca8
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 15 15:22:08 2020 -0800

    view: add source.change-case(s) GAction to GtkSourceView
    
    This allows activating the change-case operation via a GAction which
    in turn allows for it to be activated via GMenuModel.

 gtksourceview/gtksourceview.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 344da175..d87ea75e 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -438,6 +438,27 @@ gtk_source_view_change_case (GtkSourceView           *view,
        gtk_source_buffer_change_case (buffer, case_type, &start, &end);
 }
 
+static void
+gtk_source_view_activate_change_case (GtkWidget   *widget,
+                                      const gchar *action_name,
+                                      GVariant    *parameter)
+{
+       GEnumClass *klass;
+       GEnumValue *value;
+       const gchar *nick;
+
+       nick = g_variant_get_string (parameter, NULL);
+       klass = g_type_class_ref (GTK_SOURCE_TYPE_CHANGE_CASE_TYPE);
+       value = g_enum_get_value_by_nick (klass, nick);
+
+       if (value != NULL)
+       {
+               gtk_source_view_change_case (GTK_SOURCE_VIEW (widget), value->value);
+       }
+
+       g_type_class_unref (klass);
+}
+
 static void
 gtk_source_view_join_lines (GtkSourceView *view)
 {
@@ -918,6 +939,9 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                    G_TYPE_FROM_CLASS (klass),
                                    g_cclosure_marshal_VOID__VOIDv);
 
+       gtk_widget_class_install_action (widget_class, "source.change-case", "s",
+                                        gtk_source_view_activate_change_case);
+
        binding_set = gtk_binding_set_by_class (klass);
 
        gtk_binding_entry_add_signal (binding_set,


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