]> Pileus Git - ~andy/gtk/commitdiff
GtkApplication: add menu API
authorRyan Lortie <desrt@desrt.ca>
Mon, 19 Dec 2011 17:33:21 +0000 (12:33 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 19 Dec 2011 17:51:12 +0000 (12:51 -0500)
We add the app-menu and menubar public APIs to GtkApplication while
leaving the implementation in GApplication.

The actual implementation will be moved soon.

docs/reference/gtk/gtk3-sections.txt
examples/bloatpad.c
examples/plugman.c
gtk/gtkapplication.c
gtk/gtkapplication.h
gtk/gtkapplicationwindow.c

index acf9c92e5c5288e3cdbdcd6b10de06d9f9c12054..02e7ce5615d869e347fb1c1986cf52b989551a53 100644 (file)
@@ -7006,6 +7006,12 @@ gtk_application_add_window
 gtk_application_remove_window
 gtk_application_get_windows
 
+<SUBSECTION>
+gtk_application_get_app_menu
+gtk_application_set_app_menu
+gtk_application_get_menubar
+gtk_application_set_menubar
+
 <SUBSECTION Standard>
 GtkApplicationClass
 GTK_TYPE_APPLICATION
index ddd87caf8e5fa87df0a7e59d3954a82db618af4b..1f2a913c74e9e195e2265e48aff302db7c0639ad 100644 (file)
@@ -223,8 +223,8 @@ bloat_pad_startup (GApplication *application)
                                "    </submenu>"
                                "  </menu>"
                                "</interface>", -1, NULL);
-  g_application_set_app_menu (application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  g_application_set_menubar (application, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+  gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   g_object_unref (builder);
 }
 
index ee49a172ef024cbd3f0a601b5590f6b33d6a30af..23c034fac0c185ea5ec9264f4482be91d8d1852a 100644 (file)
@@ -415,8 +415,8 @@ plug_man_startup (GApplication *application)
                                "    </submenu>"
                                "  </menu>"
                                "</interface>", -1, NULL);
-  g_application_set_app_menu (application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  g_application_set_menubar (application, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+  gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   g_object_set_data_full (G_OBJECT (application), "plugin-menu", gtk_builder_get_object (builder, "plugins"), g_object_unref);
   g_object_unref (builder);
 }
index b6fe1b88b5c25f039770982b59cb572f6179a861..17ba543e0550ab37b8b9ba275285956cc286503b 100644 (file)
@@ -216,8 +216,8 @@ gtk_application_menu_changed_quartz (GObject    *object,
   GMenu *combined;
 
   combined = g_menu_new ();
-  g_menu_append_submenu (combined, "Application", g_application_get_app_menu (G_APPLICATION (object)));
-  g_menu_append_section (combined, NULL, g_application_get_menubar (G_APPLICATION (object)));
+  g_menu_append_submenu (combined, "Application", g_application_get_app_menu (application));
+  g_menu_append_section (combined, NULL, gtk_application_get_menubar (application));
 
   gtk_quartz_set_main_menu (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (application->priv->muxer));
 }
@@ -748,3 +748,98 @@ gtk_application_remove_accelerator (GtkApplication *application,
   gtk_accel_map_change_entry (accel_path, 0, 0, FALSE);
   g_free (accel_path);
 }
+
+/**
+ * gtk_application_set_app_menu:
+ * @application: a #GtkApplication
+ * @app_menu: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the application menu for @application.
+ *
+ * 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.
+ *
+ * Since: 3.4
+ */
+void
+gtk_application_set_app_menu (GtkApplication *application,
+                              GMenuModel     *app_menu)
+{
+  g_object_set (application, "app-menu", app_menu, NULL);
+}
+
+/**
+ * gtk_application_get_app_menu:
+ * @application: a #GtkApplication
+ *
+ * Returns the menu model that has been set with
+ * g_application_set_app_menu().
+ *
+ * Returns: the application menu of @application
+ *
+ * Since: 3.4
+ */
+GMenuModel *
+gtk_application_get_app_menu (GtkApplication *application)
+{
+  GMenuModel *app_menu;
+
+  g_object_get (application, "app-menu", &app_menu, NULL);
+  g_object_unref (app_menu);
+
+  return app_menu;
+}
+
+/**
+ * gtk_application_set_menubar:
+ * @application: a #GtkApplication
+ * @menubar: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the menubar for windows of @application.
+ *
+ * This is a menubar in the traditional sense.
+ *
+ * Depending on the desktop environment, this may appear at the top of
+ * each window, or at the top of the screen.  In some environments, if
+ * both the application menu and the menubar are set, the application
+ * menu will be presented as if it were the first item of the menubar.
+ * Other environments treat the two as completely separate -- for
+ * example, the application menu may be rendered by the desktop shell
+ * while the menubar (if set) remains in each individual window.
+ *
+ * Since: 3.4
+ */
+void
+gtk_application_set_menubar (GtkApplication *application,
+                             GMenuModel     *menubar)
+{
+  g_object_set (application, "menubar", menubar, NULL);
+}
+
+/**
+ * gtk_application_get_menubar:
+ * @application: a #GtkApplication
+ *
+ * Returns the menu model that has been set with
+ * g_application_set_menubar().
+ *
+ * Returns: the menubar for windows of @application
+ *
+ * Since: 3.4
+ */
+GMenuModel *
+gtk_application_get_menubar (GtkApplication *application)
+{
+  GMenuModel *menubar;
+
+  g_object_get (application, "menubar", &menubar, NULL);
+  g_object_unref (menubar);
+
+  return menubar;
+}
index a75d66c41136daa360b6e0b221baeb448ed19409..2f87bb9b9cd26eff4e96c5bbb083d1860533f6fc 100644 (file)
@@ -73,9 +73,16 @@ void             gtk_application_add_window    (GtkApplication    *application,
 
 void             gtk_application_remove_window (GtkApplication    *application,
                                                 GtkWindow         *window);
-
 GList *          gtk_application_get_windows   (GtkApplication    *application);
 
+GMenuModel *     gtk_application_get_app_menu  (GtkApplication    *application);
+void             gtk_application_set_app_menu  (GtkApplication    *application,
+                                                GMenuModel        *model);
+
+GMenuModel *     gtk_application_get_menubar   (GtkApplication    *application);
+void             gtk_application_set_menubar   (GtkApplication    *application,
+                                                GMenuModel        *model);
+
 void             gtk_application_add_accelerator    (GtkApplication  *application,
                                                      const gchar     *accelerator,
                                                      const gchar     *action_name,
index 829d959be207ef3f1d08ff1968ee8aba74d1148b..e11fc6ca6c164c72666a9688a1c5aef741be0f42 100644 (file)
@@ -251,7 +251,7 @@ gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window
         {
           GMenuModel *app_menu;
 
-          app_menu = g_application_get_app_menu (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
+          app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
 
           if (app_menu != NULL)
             g_menu_append_submenu (window->priv->app_menu_section, _("Application"), app_menu);
@@ -280,7 +280,7 @@ gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
         {
           GMenuModel *menubar;
 
-          menubar = g_application_get_menubar (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
+          menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window)));
 
           if (menubar != NULL)
             g_menu_append_section (window->priv->menubar_section, NULL, menubar);