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



commit e5531e56262f4a189ef3d1f25dcb6c7bd920994c
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 9e24dda497..cd2f6e68de 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -5217,10 +5217,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));
     }
 }
 
@@ -5618,6 +5623,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)
 {
@@ -5630,6 +5644,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]