mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-15 05:00:09 +00:00
Merge branch 'no-app-menu' into 'master'
Drop the app menu Closes #2731 See merge request GNOME/gtk!1951
This commit is contained in:
commit
5e25ba6c5a
@ -328,19 +328,14 @@ static void
|
||||
startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *appmenu;
|
||||
GMenuModel *menubar;
|
||||
|
||||
G_APPLICATION_CLASS (demo_application_parent_class)->startup (app);
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_resource (builder, "/application_demo/menus.ui", NULL);
|
||||
|
||||
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
|
||||
menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
|
||||
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
|
||||
gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
|
||||
gtk_application_set_menubar (GTK_APPLICATION (app),
|
||||
G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
|
||||
|
||||
g_object_unref (builder);
|
||||
}
|
||||
@ -353,6 +348,7 @@ create_window (GApplication *app,
|
||||
|
||||
window = (DemoApplicationWindow *)g_object_new (demo_application_window_get_type (),
|
||||
"application", app,
|
||||
"show-menubar", TRUE,
|
||||
NULL);
|
||||
if (content)
|
||||
gtk_text_buffer_set_text (window->buffer, content, -1);
|
||||
|
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<menu id="appmenu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">About</attribute>
|
||||
<attribute name="action">app.about</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><Control>q</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
</interface>
|
@ -2,7 +2,6 @@
|
||||
<gresources>
|
||||
<gresource prefix="/ui">
|
||||
<file preprocess="xml-stripblanks">main.ui</file>
|
||||
<file preprocess="xml-stripblanks">appmenu.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/application_demo">
|
||||
<file>application.c</file>
|
||||
|
@ -972,23 +972,6 @@ populate_model (GtkTreeModel *model)
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *appmenu;
|
||||
const char *ids[] = { "appmenu", NULL };
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_objects_from_resource (builder, "/ui/appmenu.ui", ids, NULL);
|
||||
|
||||
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
|
||||
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
|
||||
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
row_activated_cb (GtkWidget *tree_view,
|
||||
GtkTreePath *path,
|
||||
@ -1219,7 +1202,6 @@ main (int argc, char **argv)
|
||||
g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", NULL);
|
||||
g_application_add_main_option (G_APPLICATION (app), "autoquit", 0, 0, G_OPTION_ARG_NONE, "Quit after a delay", NULL);
|
||||
|
||||
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
|
||||
g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);
|
||||
|
@ -1,38 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<menu id="appmenu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_New</attribute>
|
||||
<attribute name="action">app.new</attribute>
|
||||
<attribute name="accel"><Control>n</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Open</attribute>
|
||||
<attribute name="action">app.open</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Save</attribute>
|
||||
<attribute name="action">app.save</attribute>
|
||||
<attribute name="accel"><Control>s</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Save _As...</attribute>
|
||||
<attribute name="action">app.save-as</attribute>
|
||||
<attribute name="accel"><Control>s</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><Control>q</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
<menu id="menubar">
|
||||
<submenu>
|
||||
<attribute name="label" translatable="yes">_Preferences</attribute>
|
||||
<attribute name="label" translatable="yes">_Application</attribute>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_New</attribute>
|
||||
<attribute name="action">app.new</attribute>
|
||||
<attribute name="accel"><Control>n</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Open</attribute>
|
||||
<attribute name="action">app.open</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Save</attribute>
|
||||
<attribute name="action">app.save</attribute>
|
||||
<attribute name="accel"><Control>s</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Save _As...</attribute>
|
||||
<attribute name="action">app.save-as</attribute>
|
||||
<attribute name="accel"><Control>s</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Quit</attribute>
|
||||
<attribute name="action">app.quit</attribute>
|
||||
<attribute name="accel"><Control>q</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</submenu>
|
||||
<submenu>
|
||||
<attribute name="label" translatable="yes">_File</attribute>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Prefer Dark Theme</attribute>
|
||||
|
@ -641,24 +641,25 @@ static GActionEntry app_entries[] = {
|
||||
|
||||
static const gchar ui_info[] =
|
||||
"<interface>"
|
||||
" <menu id='appmenu'>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label'>_About</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" <attribute name='accel'><Primary>a</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" </menu>"
|
||||
" <menu id='menubar'>"
|
||||
" <submenu>"
|
||||
" <attribute name='label'>_Application</attribute>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label'>_About</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" <attribute name='accel'><Primary>a</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" </submenu>"
|
||||
" <submenu>"
|
||||
" <attribute name='label'>_File</attribute>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
@ -738,16 +739,13 @@ static void
|
||||
startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *appmenu;
|
||||
GMenuModel *menubar;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder, ui_info, -1, NULL);
|
||||
|
||||
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
|
||||
menubar = (GMenuModel *)gtk_builder_get_object (builder, "menubar");
|
||||
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
|
||||
gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
|
||||
|
||||
g_object_unref (builder);
|
||||
|
@ -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
|
||||
|
@ -245,6 +245,17 @@
|
||||
the amount of work you have to do at the time of the switch.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Stop using app menus</title>
|
||||
<para>
|
||||
GNOME has stopped using exported app menus some time ago, and GTK 4 is
|
||||
dropping the GtkApplication APIs that are related to app menus. If you
|
||||
want to transparently support menubars on OS X, you can integrate the
|
||||
items from your app menu into your menubar, and keep using
|
||||
gtk_application_set_menubar().
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
|
||||
static const char *red_css =
|
||||
"textview>text {"
|
||||
"textview {"
|
||||
" color: red;"
|
||||
"}";
|
||||
|
||||
static const char *black_css =
|
||||
"textview>text {"
|
||||
"textview {"
|
||||
" color: black;"
|
||||
"}";
|
||||
|
||||
@ -81,6 +81,7 @@ new_window (GApplication *app,
|
||||
gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (window), win_entries, G_N_ELEMENTS (win_entries), window);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Plugman");
|
||||
gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), TRUE);
|
||||
|
||||
grid = gtk_grid_new ();
|
||||
gtk_window_set_child (GTK_WINDOW (window), grid);
|
||||
@ -334,9 +335,10 @@ configure_plugins (GSimpleAction *action,
|
||||
"<interface>"
|
||||
" <object class='GtkDialog' id='plugin-dialog'>"
|
||||
" <property name='title'>Plugins</property>"
|
||||
" <child internal-child='vbox'>"
|
||||
" <child internal-child='content_area'>"
|
||||
" <object class='GtkBox' id='content-area'>"
|
||||
" <property name='visible'>True</property>"
|
||||
" <property name='orientation'>vertical</property>"
|
||||
" <child>"
|
||||
" <object class='GtkCheckButton' id='red-plugin'>"
|
||||
" <property name='label' translatable='yes'>Red Plugin - turn your text red</property>"
|
||||
@ -352,7 +354,7 @@ configure_plugins (GSimpleAction *action,
|
||||
" </object>"
|
||||
" </child>"
|
||||
" <child internal-child='action_area'>"
|
||||
" <object class='GtkButtonBox' id='action-area'>"
|
||||
" <object class='GtkBox' id='action-area'>"
|
||||
" <property name='visible'>True</property>"
|
||||
" <child>"
|
||||
" <object class='GtkButton' id='close-button'>"
|
||||
@ -409,23 +411,24 @@ plug_man_startup (GApplication *application)
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder,
|
||||
"<interface>"
|
||||
" <menu id='app-menu'>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_About Plugman</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" </menu>"
|
||||
" <menu id='menubar'>"
|
||||
" <submenu>"
|
||||
" <attribute name='label' translatable='yes'>_Plugman</attribute>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_About Plugman</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" </submenu>"
|
||||
" <submenu>"
|
||||
" <attribute name='label' translatable='yes'>_Edit</attribute>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
@ -457,7 +460,6 @@ plug_man_startup (GApplication *application)
|
||||
" </submenu>"
|
||||
" </menu>"
|
||||
"</interface>", -1, NULL);
|
||||
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);
|
||||
|
@ -9,7 +9,7 @@ new_window (GApplication *app,
|
||||
GtkWidget *header;
|
||||
|
||||
window = gtk_application_window_new (GTK_APPLICATION (app));
|
||||
gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
|
||||
gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), TRUE);
|
||||
gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Sunny");
|
||||
gtk_window_set_icon_name (GTK_WINDOW (window), "sunny");
|
||||
@ -138,25 +138,28 @@ startup (GApplication *application)
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder,
|
||||
"<interface>"
|
||||
" <menu id='app-menu'>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_New Window</attribute>"
|
||||
" <attribute name='action'>app.new</attribute>"
|
||||
" </item>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_About Sunny</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" </item>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" <menu id='menubar'>"
|
||||
" <submenu>"
|
||||
" <attribute name='label' translatable='yes'>Sunny</attribute>"
|
||||
" <section>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_New Window</attribute>"
|
||||
" <attribute name='action'>app.new</attribute>"
|
||||
" </item>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_About Sunny</attribute>"
|
||||
" <attribute name='action'>app.about</attribute>"
|
||||
" </item>"
|
||||
" <item>"
|
||||
" <attribute name='label' translatable='yes'>_Quit</attribute>"
|
||||
" <attribute name='action'>app.quit</attribute>"
|
||||
" <attribute name='accel'><Primary>q</attribute>"
|
||||
" </item>"
|
||||
" </section>"
|
||||
" </submenu>"
|
||||
" </menu>"
|
||||
"</interface>", -1, NULL);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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",
|
||||
|
@ -452,7 +452,7 @@ object_tree_text_tag_table_get_children (GObject *object)
|
||||
static GListModel *
|
||||
object_tree_application_get_children (GObject *object)
|
||||
{
|
||||
return list_model_for_properties (object, (const char *[3]) { "app-menu", "menubar", NULL });
|
||||
return list_model_for_properties (object, (const char *[2]) { "menubar", NULL });
|
||||
}
|
||||
|
||||
static GObject *
|
||||
|
Loading…
Reference in New Issue
Block a user