diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-12-16 10:14:44 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-12-17 17:17:09 -0500 |
commit | f68f2900fa21cd54ff07d719174a1854c3517d45 (patch) | |
tree | fef620ab86f979652f5664583d9b3b614d0ba0f2 | |
parent | 255d3a1826f500384af9ba25107938cc7718c7a9 (diff) | |
download | gtk+-wip/quartzwork.tar.gz |
quartz: add a default application menuwip/quartzwork
When running on quartz, it is no longer expected for applications to
provide their own application menu. Instead, they should simply ensure
that they provide "app.about", "app.preferences" and "app.quit" actions
(which many apps are already doing).
A default menu will be shown that looks like the one presented by all
other Mac OS applications, containing menu items for the above actions,
as well as the typical "Hide app", "Hide Others and "Show All" items and
the "Services" submenu.
If an application does explicitly set an application menu (via
gtk_application_set_app_menu()) then it will be respected, as before.
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtk.gresource.xml | 1 | ||||
-rw-r--r-- | gtk/gtkapplication-quartz.c | 31 | ||||
-rw-r--r-- | gtk/gtkapplication-quartz.ui | 45 |
4 files changed, 74 insertions, 5 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 63b97aceec..437ed9f40b 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1208,7 +1208,7 @@ gtktypebuiltins.c: $(gtk_public_h_sources) $(deprecated_h_sources) gtktypebuilti gtkresources.h: gtk.gresource.xml $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/gtk.gresource.xml \ --target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-header --manual-register -gtkresources.c: gtk.gresource.xml gtk-default.css gtk-win32.css gtk-win32-xp.css gtk-win32-base.css gtk-win32-classic.css $(DND_CURSORS) $(COMPOSITE_TEMPLATES) $(template_headers) +gtkresources.c: gtk.gresource.xml gtk-default.css gtk-win32.css gtk-win32-xp.css gtk-win32-base.css gtk-win32-classic.css $(DND_CURSORS) $(COMPOSITE_TEMPLATES) $(template_headers) gtkapplication-quartz.ui $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/gtk.gresource.xml \ --target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-source --manual-register diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml index 549385f2c1..ae37486289 100644 --- a/gtk/gtk.gresource.xml +++ b/gtk/gtk.gresource.xml @@ -35,5 +35,6 @@ <file compressed="true">gtkscalebutton.ui</file> <file compressed="true">gtkstatusbar.ui</file> <file compressed="true">gtkvolumebutton.ui</file> + <file compressed="true">gtkapplication-quartz.ui</file> </gresource> </gresources> diff --git a/gtk/gtkapplication-quartz.c b/gtk/gtkapplication-quartz.c index 8d2bea97e0..2f14ee7ef7 100644 --- a/gtk/gtkapplication-quartz.c +++ b/gtk/gtkapplication-quartz.c @@ -21,6 +21,7 @@ #include "config.h" #include "gtkapplicationprivate.h" +#include "gtkbuilder.h" #import <Cocoa/Cocoa.h> typedef struct @@ -88,6 +89,8 @@ gtk_application_impl_quartz_startup (GtkApplicationImpl *impl, gboolean register_session) { GtkApplicationImplQuartz *quartz = (GtkApplicationImplQuartz *) impl; + GSimpleActionGroup *gtkinternal; + GMenuModel *app_menu; if (register_session) [NSApp setDelegate: [[GtkApplicationQuartzDelegate alloc] initWithImpl:quartz]]; @@ -95,10 +98,30 @@ gtk_application_impl_quartz_startup (GtkApplicationImpl *impl, quartz->muxer = gtk_action_muxer_new (); gtk_action_muxer_set_parent (quartz->muxer, gtk_application_get_action_muxer (impl->application)); - /* app menu must come first so that we always see index '0' in - * 'combined' as being the app menu. - */ - gtk_application_impl_set_app_menu (impl, gtk_application_get_app_menu (impl->application)); + /* Add the default accels */ + gtk_application_add_accelerator (impl->application, "<Primary>comma", "app.preferences", NULL); + gtk_application_add_accelerator (impl->application, "<Primary><Alt>h", "gtkinternal.hide-others", NULL); + gtk_application_add_accelerator (impl->application, "<Primary>h", "gtkinternal.hide", NULL); + gtk_application_add_accelerator (impl->application, "<Primary>q", "app.quit", NULL); + + app_menu = gtk_application_get_app_menu (impl->application); + if (app_menu == NULL) + { + GtkBuilder *builder; + + /* If the user didn't fill in their own menu yet, add ours. + * + * The fact that we do this here ensures that we will always have the + * app menu at index 0 in 'combined'. + */ + builder = gtk_builder_new_from_resource ("/org/gtk/libgtk/gtkapplication-quartz.ui"); + gtk_application_set_app_menu (impl->application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"))); + g_object_unref (builder); + } + else + gtk_application_impl_set_app_menu (impl, app_menu); + + /* This may or may not add an item to 'combined' */ gtk_application_impl_set_menubar (impl, gtk_application_get_menubar (impl->application)); /* OK. Now put it in the menu. */ diff --git a/gtk/gtkapplication-quartz.ui b/gtk/gtkapplication-quartz.ui new file mode 100644 index 0000000000..79c4ff178d --- /dev/null +++ b/gtk/gtkapplication-quartz.ui @@ -0,0 +1,45 @@ +<interface> + <menu id='app-menu'> + <section> + <item> + <attribute name='label' translatable='yes'>About `gtk-private-appname`</attribute> + <attribute name='action'>app.about</attribute> + </item> + </section> + <section> + <item> + <attribute name='label' translatable='yes'>Preferences</attribute> + <attribute name='action'>app.preferences</attribute> + </item> + </section> + <section> + <submenu> + <attribute name='label' translatable='yes'>Services</attribute> + <attribute name='gtk-private-special'>services-submenu</attribute> + </submenu> + </section> + <section> + <item> + <attribute name='label' translatable='yes'>Hide `gtk-private-appname`</attribute> + <attribute name='gtk-private-special'>hide-this</attribute> + <attribute name='action'>gtkinternal.hide</attribute> + </item> + <item> + <attribute name='label' translatable='yes'>Hide Others</attribute> + <attribute name='gtk-private-special'>hide-others</attribute> + <attribute name='action'>gtkinternal.hide-others</attribute> + </item> + <item> + <attribute name='label' translatable='yes'>Show All</attribute> + <attribute name='gtk-private-special'>show-all</attribute> + <attribute name='action'>gtkinternal.show-all</attribute> + </item> + </section> + <section> + <item> + <attribute name='label' translatable='yes'>Quit `gtk-private-appname`</attribute> + <attribute name='action'>app.quit</attribute> + </item> + </section> + </menu> +</interface> |