[gtk/wip/matthiasc/context-menu: 12/23] text: Add a context action for visibility



commit 59f0105c23946f5f477d7d7abdd4e9b43b1dade0
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 11 14:47:20 2019 -0400

    text: Add a context action for visibility
    
    This will be used by GtkPasswordEntry for amending
    the context menu.

 gtk/gtktext.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
---
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index ec53a5209b..0cf564bc46 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -5239,10 +5239,15 @@ gtk_text_set_visibility (GtkText  *self,
 
   if (priv->visible != visible)
     {
+      GAction *action;
+
       priv->visible = visible;
 
       g_object_notify (G_OBJECT (self), "visibility");
       gtk_text_recompute (self);
+
+      action = g_action_map_lookup_action (priv->context_actions, "toggle-visibility");
+      g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (visible));
     }
 }
 
@@ -5640,6 +5645,15 @@ insert_emoji_activated (GSimpleAction *action,
   hide_selection_bubble (GTK_TEXT (user_data));
 }
 
+static void
+toggle_visibility (GSimpleAction *action,
+                   GVariant      *parameter,
+                   gpointer       user_data)
+{
+  GtkText *text = GTK_TEXT (user_data);
+  gtk_text_set_visibility (text, !gtk_text_get_visibility (text));
+}
+
 static void
 gtk_text_add_context_actions (GtkText *self)
 {
@@ -5652,6 +5666,7 @@ gtk_text_add_context_actions (GtkText *self)
     { "delete-selection", delete_selection_activated, NULL, NULL, NULL },
     { "select-all", select_all_activated, NULL, NULL, NULL },
     { "insert-emoji", insert_emoji_activated, NULL, NULL, NULL },
+    { "toggle-visibility", toggle_visibility, NULL, "true", NULL },
   };
 
   GSimpleActionGroup *actions = g_simple_action_group_new ();


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