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



commit 688e3f26803248dbdc87e6b0280fd1d105d4313d
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 0b354fb68f..124a520186 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -5212,10 +5212,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));
     }
 }
 
@@ -5613,6 +5618,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)
 {
@@ -5625,6 +5639,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]