[gtk/matthiasc/for-master: 7/7] widget-factory: Make sure we close popover on page 3




commit 7624f66feccdd29df9d026d3821e3e21de173d16
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 3 12:09:43 2020 -0500

    widget-factory: Make sure we close popover on page 3
    
    We don't want the popover to stay open when we open
    an about dialog or shortcuts window. Since cascade-popdown
    would also affect e.g. the context menu of the text widgets,
    do this explicitly.

 demos/widget-factory/widget-factory.c  | 22 ++++++++++++++++++++++
 demos/widget-factory/widget-factory.ui |  2 +-
 2 files changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index e86ebf6ee4..6d022bb203 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -260,6 +260,8 @@ activate_about (GSimpleAction *action,
                 gpointer       user_data)
 {
   GtkApplication *app = user_data;
+  GtkWindow *window;
+  GtkWidget *button;
   const char *authors[] = {
     "Andrea Cimitan",
     "Cosimo Cecchi",
@@ -277,6 +279,10 @@ activate_about (GSimpleAction *action,
 
   s = g_string_new ("");
 
+  window = gtk_application_get_active_window (app);
+  button = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "open_menubutton"));
+  gtk_menu_button_popdown (GTK_MENU_BUTTON (button));
+
   os_name = g_get_os_info (G_OS_INFO_KEY_NAME);
   os_version = g_get_os_info (G_OS_INFO_KEY_VERSION_ID);
   if (os_name && os_version)
@@ -326,6 +332,21 @@ activate_about (GSimpleAction *action,
   g_free (os_version);
 }
 
+static void
+activate_shortcuts_window (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GtkWindow *window;
+  GtkWidget *button;
+
+  window = gtk_application_get_active_window (app);
+  button = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "open_menubutton"));
+  gtk_menu_button_popdown (GTK_MENU_BUTTON (button));
+  gtk_widget_activate_action (GTK_WIDGET (window), "win.show-help-overlay", NULL);
+}
+
 static void
 activate_quit (GSimpleAction *action,
                GVariant      *parameter,
@@ -2371,6 +2392,7 @@ main (int argc, char *argv[])
   GAction *action;
   static GActionEntry app_entries[] = {
     { "about", activate_about, NULL, NULL, NULL },
+    { "shortcuts", activate_shortcuts_window, NULL, NULL, NULL },
     { "quit", activate_quit, NULL, NULL, NULL },
     { "inspector", activate_inspector, NULL, NULL, NULL },
     { "main", NULL, "s", "'steak'", NULL },
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index c4410a1ab2..3a7e2533fa 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -51,7 +51,7 @@
       </item>
       <item>
         <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
-        <attribute name="action">win.show-help-overlay</attribute>
+        <attribute name="action">app.shortcuts</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_About Widget Factory</attribute>


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