diff options
author | Ryan Lortie <desrt@desrt.ca> | 2011-12-19 12:33:21 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2011-12-19 12:51:12 -0500 |
commit | 8578fefaa5c1dee41d0b3743065edf12925fff66 (patch) | |
tree | 0c6c45a4546998212b6464afb62a6d6d8860aad8 /gtk | |
parent | 4e5e47931d0474c03b7e6c8450de783a2ff120b4 (diff) | |
download | gtk+-8578fefaa5c1dee41d0b3743065edf12925fff66.tar.gz |
GtkApplication: add menu API
We add the app-menu and menubar public APIs to GtkApplication while
leaving the implementation in GApplication.
The actual implementation will be moved soon.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkapplication.c | 99 | ||||
-rw-r--r-- | gtk/gtkapplication.h | 9 | ||||
-rw-r--r-- | gtk/gtkapplicationwindow.c | 4 |
3 files changed, 107 insertions, 5 deletions
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c index b6fe1b88b5..17ba543e05 100644 --- a/gtk/gtkapplication.c +++ b/gtk/gtkapplication.c @@ -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; +} diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h index a75d66c411..2f87bb9b9c 100644 --- a/gtk/gtkapplication.h +++ b/gtk/gtkapplication.h @@ -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, diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c index 829d959be2..e11fc6ca6c 100644 --- a/gtk/gtkapplicationwindow.c +++ b/gtk/gtkapplicationwindow.c @@ -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); |