[gtk/no-app-menu: 17/17] gtkapplication: Drop app menu support



commit 79d6a77d5856b702bec3378bb2a88ecca6b7bccf
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 22 17:06:30 2020 -0400

    gtkapplication: Drop app menu support
    
    Drop apis and code related to appmenus from
    both GtkApplication and GtkApplicationWindow.
    
    We still keep the menubar support, since it
    is needed for system integration on OS X.
    
    Fixes: #2731

 docs/reference/gtk/gtk4-sections.txt |   3 -
 gtk/gtkapplication.c                 | 183 +----------------------------------
 gtk/gtkapplication.h                 |   9 --
 gtk/gtkapplicationwindow.c           | 110 +--------------------
 4 files changed, 10 insertions(+), 295 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 641582d021..1506252c12 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5180,9 +5180,6 @@ gtk_application_inhibit
 gtk_application_uninhibit
 
 <SUBSECTION>
-gtk_application_prefers_app_menu
-gtk_application_get_app_menu
-gtk_application_set_app_menu
 gtk_application_get_menubar
 gtk_application_set_menubar
 gtk_application_get_menu_by_id
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index f4ca2b1744..6104467594 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -78,22 +78,14 @@
  *
  * #GtkApplication will automatically load menus from the #GtkBuilder
  * resource located at "gtk/menus.ui", relative to the application's
- * resource base path (see g_application_set_resource_base_path()).  The
- * menu with the ID "app-menu" is taken as the application's app menu
- * and the menu with the ID "menubar" is taken as the application's
+ * resource base path (see g_application_set_resource_base_path()).
+ * The menu with the ID "menubar" is taken as the application's
  * menubar.  Additional menus (most interesting submenus) can be named
  * and accessed via gtk_application_get_menu_by_id() which allows for
  * dynamic population of a part of the menu structure.
  *
- * If the resources "gtk/menus-appmenu.ui" or "gtk/menus-traditional.ui" are
- * present then these files will be used in preference, depending on the value
- * of gtk_application_prefers_app_menu(). If the resource "gtk/menus-common.ui"
- * is present it will be loaded as well. This is useful for storing items that
- * are referenced from both "gtk/menus-appmenu.ui" and
- * "gtk/menus-traditional.ui".
- *
- * It is also possible to provide the menus manually using
- * gtk_application_set_app_menu() and gtk_application_set_menubar().
+ * It is also possible to provide the menubar manually using
+ * gtk_application_set_menubar().
  *
  * #GtkApplication will also automatically setup an icon search path for
  * the default icon theme by appending "icons" to the resource base
@@ -143,7 +135,6 @@ enum {
   PROP_ZERO,
   PROP_REGISTER_SESSION,
   PROP_SCREENSAVER_ACTIVE,
-  PROP_APP_MENU,
   PROP_MENUBAR,
   PROP_ACTIVE_WINDOW,
   NUM_PROPERTIES
@@ -158,7 +149,6 @@ typedef struct
 
   GList *windows;
 
-  GMenuModel      *app_menu;
   GMenuModel      *menubar;
   guint            last_window_id;
 
@@ -223,48 +213,15 @@ gtk_application_load_resources (GtkApplication *application)
   {
     gchar *menuspath;
 
-    /* If the user has given a specific file for the variant of menu
-     * that we are looking for, use it with preference.
-     */
-    if (gtk_application_prefers_app_menu (application))
-      menuspath = g_strconcat (base_path, "/gtk/menus-appmenu.ui", NULL);
-    else
-      menuspath = g_strconcat (base_path, "/gtk/menus-traditional.ui", NULL);
-
+    menuspath = g_strconcat (base_path, "/gtk/menus.ui", NULL);
     if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
       priv->menus_builder = gtk_builder_new_from_resource (menuspath);
     g_free (menuspath);
 
-    /* If we didn't get the specific file, fall back. */
-    if (priv->menus_builder == NULL)
-      {
-        menuspath = g_strconcat (base_path, "/gtk/menus.ui", NULL);
-        if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
-          priv->menus_builder = gtk_builder_new_from_resource (menuspath);
-        g_free (menuspath);
-      }
-
-    /* Always load from -common as well, if we have it */
-    menuspath = g_strconcat (base_path, "/gtk/menus-common.ui", NULL);
-    if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
-      {
-        GError *error = NULL;
-
-        if (priv->menus_builder == NULL)
-          priv->menus_builder = gtk_builder_new ();
-
-        if (!gtk_builder_add_from_resource (priv->menus_builder, menuspath, &error))
-          g_error ("failed to load menus-common.ui: %s", error->message);
-      }
-    g_free (menuspath);
-
     if (priv->menus_builder)
       {
         GObject *menu;
 
-        menu = gtk_builder_get_object (priv->menus_builder, "app-menu");
-        if (menu != NULL && G_IS_MENU_MODEL (menu))
-          gtk_application_set_app_menu (application, G_MENU_MODEL (menu));
         menu = gtk_builder_get_object (priv->menus_builder, "menubar");
         if (menu != NULL && G_IS_MENU_MODEL (menu))
           gtk_application_set_menubar (application, G_MENU_MODEL (menu));
@@ -490,10 +447,6 @@ gtk_application_get_property (GObject    *object,
       g_value_set_boolean (value, priv->screensaver_active);
       break;
 
-    case PROP_APP_MENU:
-      g_value_set_object (value, gtk_application_get_app_menu (application));
-      break;
-
     case PROP_MENUBAR:
       g_value_set_object (value, gtk_application_get_menubar (application));
       break;
@@ -523,10 +476,6 @@ gtk_application_set_property (GObject      *object,
       priv->register_session = g_value_get_boolean (value);
       break;
 
-    case PROP_APP_MENU:
-      gtk_application_set_app_menu (application, g_value_get_object (value));
-      break;
-
     case PROP_MENUBAR:
       gtk_application_set_menubar (application, g_value_get_object (value));
       break;
@@ -544,7 +493,6 @@ gtk_application_finalize (GObject *object)
   GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
 
   g_clear_object (&priv->menus_builder);
-  g_clear_object (&priv->app_menu);
   g_clear_object (&priv->menubar);
   g_clear_object (&priv->muxer);
   g_clear_object (&priv->accels);
@@ -800,13 +748,6 @@ gtk_application_class_init (GtkApplicationClass *class)
                           FALSE,
                           G_PARAM_READABLE|G_PARAM_STATIC_STRINGS);
 
-  gtk_application_props[PROP_APP_MENU] =
-    g_param_spec_object ("app-menu",
-                         P_("Application menu"),
-                         P_("The GMenuModel for the application menu"),
-                         G_TYPE_MENU_MODEL,
-                         G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
-
   gtk_application_props[PROP_MENUBAR] =
     g_param_spec_object ("menubar",
                          P_("Menubar"),
@@ -1029,120 +970,6 @@ gtk_application_update_accels (GtkApplication *application)
     _gtk_window_notify_keys_changed (l->data);
 }
 
-/**
- * gtk_application_prefers_app_menu:
- * @application: a #GtkApplication
- *
- * Determines if the desktop environment in which the application is
- * running would prefer an application menu be shown.
- *
- * If this function returns %TRUE then the application should call
- * gtk_application_set_app_menu() with the contents of an application
- * menu, which will be shown by the desktop environment.  If it returns
- * %FALSE then you should consider using an alternate approach, such as
- * a menubar.
- *
- * The value returned by this function is purely advisory and you are
- * free to ignore it.  If you call gtk_application_set_app_menu() even
- * if the desktop environment doesn't support app menus, then a fallback
- * will be provided.
- *
- * Applications are similarly free not to set an app menu even if the
- * desktop environment wants to show one.  In that case, a fallback will
- * also be created by the desktop environment (GNOME, for example, uses
- * a menu with only a "Quit" item in it).
- *
- * The value returned by this function never changes.  Once it returns a
- * particular value, it is guaranteed to always return the same value.
- *
- * You may only call this function after the application has been
- * registered and after the base startup handler has run.  You're most
- * likely to want to use this from your own startup handler.  It may
- * also make sense to consult this function while constructing UI (in
- * activate, open or an action activation handler) in order to determine
- * if you should show a gear menu or not.
- *
- * This function will return %FALSE on Mac OS and a default app menu
- * will be created automatically with the "usual" contents of that menu
- * typical to most Mac OS applications.  If you call
- * gtk_application_set_app_menu() anyway, then this menu will be
- * replaced with your own.
- *
- * Returns: %TRUE if you should set an app menu
- **/
-gboolean
-gtk_application_prefers_app_menu (GtkApplication *application)
-{
-  GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
-  g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
-  g_return_val_if_fail (priv->impl != NULL, FALSE);
-
-  return gtk_application_impl_prefers_app_menu (priv->impl);
-}
-
-/**
- * gtk_application_set_app_menu:
- * @application: a #GtkApplication
- * @app_menu: (allow-none): a #GMenuModel, or %NULL
- *
- * Sets or unsets the application menu for @application.
- *
- * This can only be done in the primary instance of the application,
- * after it has been registered.  #GApplication::startup is a good place
- * to call this.
- *
- * The application menu is a single menu containing items that typically
- * impact the application as a whole, rather than acting on a specific
- * window or document.  For example, you would expect to see
- * “Preferences” or “Quit” in an application menu, but not “Save” or
- * “Print”.
- *
- * If supported, the application menu will be rendered by the desktop
- * environment.
- *
- * Use the base #GActionMap interface to add actions, to respond to the user
- * selecting these menu items.
- */
-void
-gtk_application_set_app_menu (GtkApplication *application,
-                              GMenuModel     *app_menu)
-{
-  GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
-  g_return_if_fail (GTK_IS_APPLICATION (application));
-  g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)));
-  g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
-  g_return_if_fail (app_menu == NULL || G_IS_MENU_MODEL (app_menu));
-
-  if (g_set_object (&priv->app_menu, app_menu))
-    {
-      gtk_application_impl_set_app_menu (priv->impl, app_menu);
-
-      g_object_notify_by_pspec (G_OBJECT (application), gtk_application_props[PROP_APP_MENU]);
-    }
-}
-
-/**
- * gtk_application_get_app_menu:
- * @application: a #GtkApplication
- *
- * Returns the menu model that has been set with
- * gtk_application_set_app_menu().
- *
- * Returns: (transfer none) (nullable): the application menu of @application
- *   or %NULL if no application menu has been set.
- */
-GMenuModel *
-gtk_application_get_app_menu (GtkApplication *application)
-{
-  GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
-  g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
-
-  return priv->app_menu;
-}
-
 /**
  * gtk_application_set_menubar:
  * @application: a #GtkApplication
diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h
index 9678b6bf38..a749adfd2a 100644
--- a/gtk/gtkapplication.h
+++ b/gtk/gtkapplication.h
@@ -85,12 +85,6 @@ void             gtk_application_remove_window (GtkApplication    *application,
 GDK_AVAILABLE_IN_ALL
 GList *          gtk_application_get_windows   (GtkApplication    *application);
 
-GDK_AVAILABLE_IN_ALL
-GMenuModel *     gtk_application_get_app_menu  (GtkApplication    *application);
-GDK_AVAILABLE_IN_ALL
-void             gtk_application_set_app_menu  (GtkApplication    *application,
-                                                GMenuModel        *app_menu);
-
 GDK_AVAILABLE_IN_ALL
 GMenuModel *     gtk_application_get_menubar   (GtkApplication    *application);
 GDK_AVAILABLE_IN_ALL
@@ -137,9 +131,6 @@ void             gtk_application_set_accels_for_action           (GtkApplication
                                                                   const gchar          *detailed_action_name,
                                                                   const gchar * const  *accels);
 
-GDK_AVAILABLE_IN_ALL
-gboolean         gtk_application_prefers_app_menu                (GtkApplication       *application);
-
 GDK_AVAILABLE_IN_ALL
 GMenu *          gtk_application_get_menu_by_id                  (GtkApplication       *application,
                                                                   const gchar          *id);
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 9f13ef1799..8858d7ec04 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -41,9 +41,8 @@
  *
  * #GtkApplicationWindow is a #GtkWindow subclass that offers some
  * extra functionality for better integration with #GtkApplication
- * features.  Notably, it can handle both the application menu as well
- * as the menubar. See gtk_application_set_app_menu() and
- * gtk_application_set_menubar().
+ * features.  Notably, it can handle an application menubar.
+ * See gtk_application_set_menubar().
  *
  * This class implements the #GActionGroup and #GActionMap interfaces,
  * to let you add window-specific actions that will be exported by the
@@ -191,7 +190,6 @@ struct _GtkApplicationWindowPrivate
   GtkWidget *menubar;
 
   gboolean show_menubar;
-  GMenu *app_menu_section;
   GMenu *menubar_section;
 
   guint            id;
@@ -217,8 +215,7 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
   have_menubar = priv->menubar != NULL;
 
   should_have_menubar = priv->show_menubar &&
-                        (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) ||
-                         g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)));
+                        g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section));
 
   if (have_menubar && !should_have_menubar)
     {
@@ -231,7 +228,6 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
       GMenu *combined;
 
       combined = g_menu_new ();
-      g_menu_append_section (combined, NULL, G_MENU_MODEL (priv->app_menu_section));
       g_menu_append_section (combined, NULL, G_MENU_MODEL (priv->menubar_section));
 
       priv->menubar = gtk_popover_menu_bar_new_from_model (G_MENU_MODEL (combined));
@@ -240,83 +236,6 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
     }
 }
 
-static gchar *
-gtk_application_window_get_app_desktop_name (void)
-{
-  gchar *retval = NULL;
-
-#if defined(HAVE_GIO_UNIX) && !defined(__APPLE__)
-  GDesktopAppInfo *app_info;
-  const gchar *app_name = NULL;
-  gchar *desktop_file;
-
-  desktop_file = g_strconcat (g_get_prgname (), ".desktop", NULL);
-  app_info = g_desktop_app_info_new (desktop_file);
-  g_free (desktop_file);
-
-  if (app_info != NULL)
-    app_name = g_app_info_get_name (G_APP_INFO (app_info));
-
-  if (app_name != NULL)
-    retval = g_strdup (app_name);
-
-  g_clear_object (&app_info);
-#endif /* HAVE_GIO_UNIX */
-
-  return retval;
-}
-
-static void
-gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
-                                                    GtkSettings          *settings)
-{
-  GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-  gboolean shown_by_shell;
-
-  g_object_get (settings, "gtk-shell-shows-app-menu", &shown_by_shell, NULL);
-
-  if (shown_by_shell)
-    {
-      /* the shell shows it, so don't show it locally */
-      if (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) != 0)
-        g_menu_remove (priv->app_menu_section, 0);
-    }
-  else
-    {
-      /* the shell does not show it, so make sure we show it */
-      if (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) == 0)
-        {
-          GMenuModel *app_menu = NULL;
-
-          if (gtk_window_get_application (GTK_WINDOW (window)) != NULL)
-            app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
-
-          if (app_menu != NULL)
-            {
-              const gchar *app_name;
-              gchar *name;
-
-              app_name = g_get_application_name ();
-              if (app_name != g_get_prgname ())
-                {
-                  /* the app has set its application name, use it */
-                  name = g_strdup (app_name);
-                }
-              else
-                {
-                  /* get the name from .desktop file */
-                  name = gtk_application_window_get_app_desktop_name ();
-                  if (name == NULL)
-                    name = g_strdup (_("Application"));
-                }
-
-              g_menu_append_submenu (priv->app_menu_section, name, app_menu);
-              g_free (name);
-            }
-        }
-    }
-}
-
 static void
 gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
                                                    GtkSettings          *settings)
@@ -348,17 +267,6 @@ gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
     }
 }
 
-static void
-gtk_application_window_shell_shows_app_menu_changed (GObject    *object,
-                                                     GParamSpec *pspec,
-                                                     gpointer    user_data)
-{
-  GtkApplicationWindow *window = user_data;
-
-  gtk_application_window_update_shell_shows_app_menu (window, GTK_SETTINGS (object));
-  gtk_application_window_update_menubar (window);
-}
-
 static void
 gtk_application_window_shell_shows_menubar_changed (GObject    *object,
                                                     GParamSpec *pspec,
@@ -610,14 +518,11 @@ gtk_application_window_real_realize (GtkWidget *widget)
 
   settings = gtk_widget_get_settings (widget);
 
-  g_signal_connect (settings, "notify::gtk-shell-shows-app-menu",
-                    G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window);
   g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
                     G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);
 
   GTK_WIDGET_CLASS (gtk_application_window_parent_class)->realize (widget);
 
-  gtk_application_window_update_shell_shows_app_menu (window, settings);
   gtk_application_window_update_shell_shows_menubar (window, settings);
   gtk_application_window_update_menubar (window);
 }
@@ -629,7 +534,6 @@ gtk_application_window_real_unrealize (GtkWidget *widget)
 
   settings = gtk_widget_get_settings (widget);
 
-  g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_app_menu_changed, 
widget);
   g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_menubar_changed, 
widget);
 
   GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unrealize (widget);
@@ -719,7 +623,6 @@ gtk_application_window_dispose (GObject *object)
       priv->menubar = NULL;
     }
 
-  g_clear_object (&priv->app_menu_section);
   g_clear_object (&priv->menubar_section);
 
   if (priv->help_overlay)
@@ -746,7 +649,6 @@ gtk_application_window_init (GtkApplicationWindow *window)
   GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
 
   priv->actions = gtk_application_window_actions_new (window);
-  priv->app_menu_section = g_menu_new ();
   priv->menubar_section = g_menu_new ();
 
   gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (priv->actions));
@@ -785,12 +687,10 @@ gtk_application_window_class_init (GtkApplicationWindowClass *class)
    * GtkApplicationWindow:show-menubar:
    *
    * If this property is %TRUE, the window will display a menubar
-   * that includes the app menu and menubar, unless these are
-   * shown by the desktop shell. See gtk_application_set_app_menu()
-   * and gtk_application_set_menubar().
+   * unless it is shown by the desktop shell. See gtk_application_set_menubar().
    *
    * If %FALSE, the window will not display a menubar, regardless
-   * of whether the desktop shell is showing the menus or not.
+   * of whether the desktop shell is showing it or not.
    */
   gtk_application_window_properties[PROP_SHOW_MENUBAR] =
     g_param_spec_boolean ("show-menubar",


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