From 5d63ee8e0eb39cacc19461c45ff93d3e37e81e20 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 16 Dec 2013 11:05:17 -0500 Subject: [PATCH] quartz menu: add a hack for application name Add a private hack to allow the insertion of the name of the application into the label of menu items. If it appears in the label of any menu item, "%s" will be replaced with the name of the application. We will use this for the "Hide myapp", "Quit myapp" and "About myapp" labels typically found on Mac OS programs. https://bugzilla.gnome.org/show_bug.cgi?id=720552 --- gtk/gtkapplication-quartz-menu.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gtk/gtkapplication-quartz-menu.c b/gtk/gtkapplication-quartz-menu.c index 60e13d0286..41fbea6a3e 100644 --- a/gtk/gtkapplication-quartz-menu.c +++ b/gtk/gtkapplication-quartz-menu.c @@ -59,6 +59,7 @@ GtkMenuTrackerItem *trackerItem; gulong trackerItemChangedHandler; GCancellable *cancellable; + BOOL isSpecial; } - (id)initWithTrackerItem:(GtkMenuTrackerItem *)aTrackerItem; @@ -167,6 +168,7 @@ icon_loaded (GObject *object, trackerItem = g_object_ref (aTrackerItem); trackerItemChangedHandler = g_signal_connect (trackerItem, "notify", G_CALLBACK (tracker_item_changed), self); + isSpecial = (special != NULL); [self didChangeLabel]; [self didChangeIcon]; @@ -199,7 +201,29 @@ icon_loaded (GObject *object, { gchar *label = _gtk_toolbar_elide_underscores (gtk_menu_tracker_item_get_label (trackerItem)); - [self setTitle:[NSString stringWithUTF8String:label ? : ""]]; + NSString *title = [NSString stringWithUTF8String:label ? : ""]; + + if (isSpecial) + { + NSRange range = [title rangeOfString:@"%s"]; + + if (range.location != NSNotFound) + { + NSBundle *bundle = [NSBundle mainBundle]; + NSString *name = [[bundle localizedInfoDictionary] objectForKey:@"CFBundleName"]; + + if (name == nil) + name = [[bundle infoDictionary] objectForKey:@"CFBundleName"]; + + if (name == nil) + name = [[NSProcessInfo processInfo] processName]; + + if (name != nil) + title = [title stringByReplacingCharactersInRange:range withString:name]; + } + } + + [self setTitle:title]; g_free (label); }