diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-12-16 11:05:17 -0500 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2014-01-17 22:37:04 -0500 |
commit | 5d63ee8e0eb39cacc19461c45ff93d3e37e81e20 (patch) | |
tree | 05317e305b56435949d3f086a006a0fff19b0596 /gtk/gtkapplication-quartz-menu.c | |
parent | ceeef03004468a03ff9816493ca2f3a7fee287d9 (diff) | |
download | gtk+-5d63ee8e0eb39cacc19461c45ff93d3e37e81e20.tar.gz |
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
Diffstat (limited to 'gtk/gtkapplication-quartz-menu.c')
-rw-r--r-- | gtk/gtkapplication-quartz-menu.c | 26 |
1 files changed, 25 insertions, 1 deletions
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); } |