[gtk/kill-tree-menu: 39/52] tests: Stop using menus



commit 61d21b1bf488350c25ee235b50a2ff3bf8702538
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 26 23:16:53 2019 -0500

    tests: Stop using menus

 tests/meson.build      |    1 -
 tests/popupat.ui       | 2174 ------------------------------------------------
 tests/print-editor.c   |    5 -
 tests/testgaction.c    |    4 +-
 tests/testgmenu.c      |    1 -
 tests/testgtk.c        |  145 ----
 tests/testiconview.c   |   13 +-
 tests/testmenubutton.c |   31 +-
 tests/testpopover.c    |    1 -
 tests/testpopupat.c    |   64 --
 tests/testtoolbar.c    |   63 +-
 11 files changed, 23 insertions(+), 2479 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index 7b28428102..aa16f4fde7 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -114,7 +114,6 @@ gtk_tests = [
   ['testpopover'],
   ['gdkgears', ['gtkgears.c']],
   ['listmodel'],
-  ['testpopupat'],
   ['testgaction'],
   ['testwidgetfocus'],
   ['testwidgettransforms'],
diff --git a/tests/print-editor.c b/tests/print-editor.c
index f43f1a495f..b141fbb80c 100644
--- a/tests/print-editor.c
+++ b/tests/print-editor.c
@@ -717,7 +717,6 @@ static void
 activate (GApplication *app)
 {
   GtkWidget *box;
-  GtkWidget *bar;
   GtkWidget *sw;
   GtkWidget *contents;
 
@@ -729,10 +728,6 @@ activate (GApplication *app)
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (main_window), box);
 
-  bar = gtk_menu_bar_new ();
-  gtk_widget_show (bar);
-  gtk_container_add (GTK_CONTAINER (box), bar);
-
   /* Create document  */
   sw = gtk_scrolled_window_new (NULL, NULL);
 
diff --git a/tests/testgaction.c b/tests/testgaction.c
index 6eacede580..8591eae2d5 100644
--- a/tests/testgaction.c
+++ b/tests/testgaction.c
@@ -125,10 +125,10 @@ int main (int argc, char **argv)
     GtkBuilder *builder = gtk_builder_new_from_string (menu_data, -1);
     menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "menu_model"));
 
-    menu = gtk_menu_new_from_model (menu_model);
+    menu = gtk_popover_menu_new_from_model (NULL, menu_model);
 
   }
-  gtk_menu_button_set_popup (GTK_MENU_BUTTON (menubutton), menu);
+  gtk_menu_button_set_popover (GTK_MENU_BUTTON (menubutton), menu);
   gtk_container_add (GTK_CONTAINER (box), menubutton);
   gtk_widget_set_halign (button1, GTK_ALIGN_CENTER);
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button1), "win.change-label-button");
diff --git a/tests/testgmenu.c b/tests/testgmenu.c
index af91dc8c2a..ef4702165b 100644
--- a/tests/testgmenu.c
+++ b/tests/testgmenu.c
@@ -674,7 +674,6 @@ main (int argc, char *argv[])
     {
       button = gtk_menu_button_new ();
       gtk_button_set_label (GTK_BUTTON (button), "Click here");
-      gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE);
       gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model);
       gtk_widget_insert_action_group (button, "actions", group);
       gtk_container_add (GTK_CONTAINER (box), button);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 64fda68213..96b80f8d94 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -1604,150 +1604,6 @@ create_listbox (GtkWidget *widget)
 }
 
 
-/*
- * Menu demo
- */
-
-static GtkWidget*
-create_menu (gint depth, gint length)
-{
-  GtkWidget *menu;
-  GtkWidget *menuitem;
-  GtkWidget *image;
-  GtkWidget *box;
-  GtkWidget *label;
-  GSList *group;
-  char buf[32];
-  int i, j;
-
-  if (depth < 1)
-    return NULL;
-
-  menu = gtk_menu_new ();
-
-  group = NULL;
-
-  image = gtk_image_new_from_icon_name ("document-open");
-  menuitem = gtk_menu_item_new ();
-  label = gtk_label_new ("Image Item");
-  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-  gtk_container_add (GTK_CONTAINER (box), image);
-  gtk_container_add (GTK_CONTAINER (box), label);
-  gtk_container_add (GTK_CONTAINER (menuitem), box);
-  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
-  for (i = 0, j = 1; i < length; i++, j++)
-    {
-      sprintf (buf, "item %2d - %d", depth, j);
-
-      menuitem = gtk_radio_menu_item_new_with_label (group, buf);
-      group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
-
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-      if (i == 3)
-       gtk_widget_set_sensitive (menuitem, FALSE);
-
-      if (i == 5)
-        gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (menuitem),
-                                              TRUE);
-
-      if (i < 5)
-       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
-                                  create_menu (depth - 1, 5));
-    }
-
-  return menu;
-}
-
-static void
-create_menus (GtkWidget *widget)
-{
-  static GtkWidget *window = NULL;
-  GtkWidget *box1;
-  GtkWidget *box2;
-  GtkWidget *button;
-  GtkWidget *separator;
-  GtkWidget *box;
-  GtkWidget *label;
-
-  if (!window)
-    {
-      GtkWidget *menubar;
-      GtkWidget *menu;
-      GtkWidget *menuitem;
-      GtkWidget *image;
-      GdkDisplay *display = gtk_widget_get_display (widget);
-
-      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-      gtk_window_set_hide_on_close (GTK_WINDOW (window), TRUE);
-
-      gtk_window_set_display (GTK_WINDOW (window), display);
-
-      g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
-
-      gtk_window_set_title (GTK_WINDOW (window), "menus");
-
-      box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-      gtk_container_add (GTK_CONTAINER (window), box1);
-
-      menubar = gtk_menu_bar_new ();
-      gtk_container_add (GTK_CONTAINER (box1), menubar);
-
-      menu = create_menu (2, 50);
-
-      menuitem = gtk_menu_item_new_with_label ("test\nline2");
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
-      menuitem = gtk_menu_item_new_with_label ("foo");
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, 5));
-      gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
-      image = gtk_image_new_from_icon_name ("help-browser");
-      menuitem = gtk_menu_item_new ();
-      label = gtk_label_new ("Help");
-      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-      gtk_container_add (GTK_CONTAINER (box), label);
-      gtk_container_add (GTK_CONTAINER (box), image);
-      gtk_container_add (GTK_CONTAINER (menuitem), box);
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, 5));
-      gtk_widget_set_hexpand (menuitem, TRUE);
-      gtk_widget_set_halign (menuitem, GTK_ALIGN_END);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
-      menubar = gtk_menu_bar_new ();
-      gtk_container_add (GTK_CONTAINER (box1), menubar);
-
-      menu = create_menu (2, 10);
-
-      menuitem = gtk_menu_item_new_with_label ("Second menu bar");
-      gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
-      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
-      gtk_container_add (GTK_CONTAINER (box1), box2);
-
-      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
-      gtk_container_add (GTK_CONTAINER (box1), separator);
-
-      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
-      gtk_container_add (GTK_CONTAINER (box1), box2);
-
-      button = gtk_button_new_with_label ("close");
-      g_signal_connect_swapped (button, "clicked",
-                               G_CALLBACK (gtk_widget_destroy),
-                               window);
-      gtk_container_add (GTK_CONTAINER (box2), button);
-      gtk_window_set_default_widget (GTK_WINDOW (window), button);
-    }
-
-  if (!gtk_widget_get_visible (window))
-    gtk_widget_show (window);
-  else
-    gtk_widget_destroy (window);
-}
-
-
 static GtkWidget *
 accel_button_new (GtkAccelGroup *accel_group,
                  const gchar   *text,
@@ -6296,7 +6152,6 @@ struct {
   { "key lookup", create_key_lookup },
   { "labels", create_labels },
   { "listbox", create_listbox },
-  { "menus", create_menus },
   { "message dialog", create_message_dialog },
   { "modal window", create_modal_window, TRUE },
   { "native dialogs", create_native_dialogs },
diff --git a/tests/testiconview.c b/tests/testiconview.c
index 3645dc2858..f82d706950 100644
--- a/tests/testiconview.c
+++ b/tests/testiconview.c
@@ -334,25 +334,24 @@ do_popup_menu (GtkWidget   *icon_list,
 {
   GtkIconView *icon_view = GTK_ICON_VIEW (icon_list);
   GtkWidget *menu;
-  GtkWidget *menuitem;
+  GtkWidget *item;
   ItemData *data;
 
   if (!path)
     return;
 
-  menu = gtk_menu_new ();
+  menu = gtk_popover_new (icon_list);
 
   data = g_new0 (ItemData, 1);
   data->icon_list = icon_view;
   data->path = path;
   g_object_set_data_full (G_OBJECT (menu), "item-path", data, (GDestroyNotify)free_item_data);
 
-  menuitem = gtk_menu_item_new_with_label ("Activate");
-  gtk_widget_show (menuitem);
-  gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-  g_signal_connect (menuitem, "activate", G_CALLBACK (item_cb), data);
+  item = gtk_button_new_with_label ("Activate");
+  gtk_container_add (GTK_CONTAINER (menu), item);
+  g_signal_connect (item, "clicked", G_CALLBACK (item_cb), data);
 
-  gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
+  gtk_popover_popup (GTK_POPOVER (menu));
 }
 
 static void
diff --git a/tests/testmenubutton.c b/tests/testmenubutton.c
index 62b9ea2226..7e3d945b73 100644
--- a/tests/testmenubutton.c
+++ b/tests/testmenubutton.c
@@ -12,7 +12,7 @@ horizontal_alignment_changed (GtkComboBox *box)
        GList *l;
 
        for (l = menubuttons; l != NULL; l = l->next) {
-               GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
+               GtkPopover *popup = gtk_menu_button_get_popover (GTK_MENU_BUTTON (l->data));
                if (popup != NULL)
                        gtk_widget_set_halign (GTK_WIDGET (popup), alignment);
        }
@@ -25,7 +25,7 @@ vertical_alignment_changed (GtkComboBox *box)
        GList *l;
 
        for (l = menubuttons; l != NULL; l = l->next) {
-               GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
+               GtkPopover *popup = gtk_menu_button_get_popover (GTK_MENU_BUTTON (l->data));
                if (popup != NULL)
                        gtk_widget_set_valign (GTK_WIDGET (popup), alignment);
        }
@@ -40,7 +40,6 @@ int main (int argc, char **argv)
        GtkWidget *label;
        GtkWidget *check;
        GtkWidget *combo;
-       GtkWidget *menu_widget;
        GtkAccelGroup *accel_group;
        guint i;
        guint row = 0;
@@ -102,32 +101,6 @@ int main (int argc, char **argv)
        gtk_grid_attach_next_to (GTK_GRID (grid), button, entry, GTK_POS_RIGHT, 1, 1);
        menubuttons = g_list_prepend (menubuttons, button);
 
-       /* Button with GtkMenu */
-       menu_widget = gtk_menu_new ();
-       for (i = 0; i < 5; ++i) {
-               GtkWidget *item;
-
-               if (i == 2) {
-                       item = gtk_menu_item_new_with_mnemonic ("_Copy");
-               } else {
-                       char *label;
-
-                       label = g_strdup_printf ("Item _%d", i + 1);
-                       item = gtk_menu_item_new_with_mnemonic (label);
-                       g_free (label);
-               }
-
-               gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE);
-               gtk_container_add (GTK_CONTAINER (menu_widget), item);
-       }
-       gtk_widget_show (menu_widget);
-
-       button = gtk_menu_button_new ();
-       gtk_widget_set_halign (button, GTK_ALIGN_START);
-       menubuttons = g_list_prepend (menubuttons, button);
-       gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
-       gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1);
-
         check = gtk_check_button_new_with_label ("Popover");
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
        gtk_grid_attach (GTK_GRID (grid), check, 0, row, 1, 1);
diff --git a/tests/testpopover.c b/tests/testpopover.c
index 88a37d1571..7927362d57 100644
--- a/tests/testpopover.c
+++ b/tests/testpopover.c
@@ -101,7 +101,6 @@ main (int argc, char *argv[])
   gtk_container_add (GTK_CONTAINER (box), button2);
 
   gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), model);
-  gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE);
   popover = GTK_WIDGET (gtk_menu_button_get_popover (GTK_MENU_BUTTON (button)));
 
   popover1 = gtk_popover_menu_new_from_model_full (NULL, model, GTK_POPOVER_MENU_NESTED);
diff --git a/tests/testtoolbar.c b/tests/testtoolbar.c
index 19e4694ca0..a26f8a842b 100644
--- a/tests/testtoolbar.c
+++ b/tests/testtoolbar.c
@@ -320,44 +320,6 @@ rtl_toggled (GtkCheckButton *check)
     gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
 }
 
-static gboolean
-popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
-{
-  GtkMenu *menu = GTK_MENU (gtk_menu_new ());
-  int i;
-
-  for (i = 0; i < 5; i++)
-    {
-      GtkWidget *item;
-      gchar *label = g_strdup_printf ("Item _%d", i);
-      item = gtk_menu_item_new_with_mnemonic (label);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-    }
-
-  if (button_number != -1)
-    {
-      gtk_menu_popup_at_pointer (menu, NULL);
-    }
-  else
-    {
-      GtkWindow *window;
-      GtkWidget *widget;
-
-      window = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (toolbar)));
-      widget = gtk_root_get_focus (GTK_ROOT (window));
-      if (!widget)
-        widget = GTK_WIDGET (toolbar);
-
-      gtk_menu_popup_at_widget (menu,
-                                widget,
-                                GDK_GRAVITY_SOUTH_EAST,
-                                GDK_GRAVITY_NORTH_WEST,
-                                NULL);
-    }
-
-  return TRUE;
-}
-
 static GtkToolItem *drag_item = NULL;
 
 static gboolean
@@ -433,6 +395,7 @@ main (gint argc, gchar **argv)
   GtkListStore *store;
   GtkWidget *image;
   GtkWidget *menuitem;
+  GtkWidget *box;
   GtkWidget *button;
   GtkWidget *label;
   GIcon *gicon;
@@ -501,40 +464,42 @@ main (gint argc, gchar **argv)
   g_timeout_add (3000, (GSourceFunc) timeout_cb, item);
   gtk_tool_item_set_expand (item, TRUE);
 
-  menu = gtk_menu_new ();
+  menu = gtk_popover_new (NULL);
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_container_add (GTK_CONTAINER (menu), box);
   for (i = 0; i < 20; i++)
     {
       char *text;
       text = g_strdup_printf ("Menuitem %d", i);
-      menuitem = gtk_menu_item_new_with_label (text);
+      menuitem = gtk_button_new_with_label (text);
       g_free (text);
-      gtk_widget_show (menuitem);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+      gtk_container_add (GTK_CONTAINER (box), menuitem);
     }
 
   item = gtk_menu_tool_button_new (NULL, NULL);
   gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open");
   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Open");
-  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
+  gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
   add_item_to_list (store, item, "Open");
   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
   g_timeout_add (3000, (GSourceFunc) timeout_cb1, item);
  
-  menu = gtk_menu_new ();
+  menu = gtk_popover_new (NULL);
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  gtk_container_add (GTK_CONTAINER (menu), box);
   for (i = 0; i < 20; i++)
     {
       char *text;
       text = g_strdup_printf ("A%d", i);
-      menuitem = gtk_menu_item_new_with_label (text);
+      menuitem = gtk_button_new_with_label (text);
       g_free (text);
-      gtk_widget_show (menuitem);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+      gtk_container_add (GTK_CONTAINER (box), menuitem);
     }
 
   item = gtk_menu_tool_button_new (NULL, NULL);
   gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous");
   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back");
-  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
+  gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
   add_item_to_list (store, item, "BackWithHistory");
   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
  
@@ -669,8 +634,6 @@ main (gint argc, gchar **argv)
 
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
   
-  g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL);
-  
   gtk_main ();
   
   return 0;


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