summaryrefslogtreecommitdiff
path: root/gtk/gtkapplication-quartz-menu.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-12-16 11:05:17 -0500
committerRyan Lortie <desrt@desrt.ca>2014-01-17 22:37:04 -0500
commit5d63ee8e0eb39cacc19461c45ff93d3e37e81e20 (patch)
tree05317e305b56435949d3f086a006a0fff19b0596 /gtk/gtkapplication-quartz-menu.c
parentceeef03004468a03ff9816493ca2f3a7fee287d9 (diff)
downloadgtk+-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.c26
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);
}