From 2ca69431f0cc0f5431a10f79303e32f525308b8a Mon Sep 17 00:00:00 2001 From: Mike McFadden Date: Sat, 9 May 2015 15:45:51 -0400 Subject: [PATCH] Show non-running processes as gray The menu items remain gray when selected, though. Still better than not giving the user information about whether the process is still running. --- Loading/MenuDelegate.m | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Loading/MenuDelegate.m b/Loading/MenuDelegate.m index 860bf13..d4d7f03 100644 --- a/Loading/MenuDelegate.m +++ b/Loading/MenuDelegate.m @@ -69,13 +69,8 @@ - (void)open:(id)sender { } } -- (NSAttributedString *)wrappedText:(NSString *)text width:(float)max_width { - NSMutableParagraphStyle* pathStyle = [[NSMutableParagraphStyle alloc] init]; - pathStyle.minimumLineHeight = 13.0; - - NSDictionary *pathAttribs= @{ NSFontAttributeName:[NSFont menuFontOfSize:11.0], NSParagraphStyleAttributeName:pathStyle }; - - NSAttributedString *pathText = [[NSAttributedString alloc] initWithString:text attributes:pathAttribs]; +- (NSAttributedString *)wrappedText:(NSString *)text width:(float)max_width attributes:attribs { + NSAttributedString *pathText = [[NSAttributedString alloc] initWithString:text attributes:attribs]; CTFramesetterRef fs = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)pathText); CGMutablePathRef path2 = CGPathCreateMutable(); @@ -96,7 +91,7 @@ - (NSAttributedString *)wrappedText:(NSString *)text width:(float)max_width { NSString *joiner = @"\n"; if ([[AppDelegate sharedDelegate] isRightToLeft]) joiner = @"\n\u200F"; - return [[NSAttributedString alloc] initWithString:[final componentsJoinedByString:joiner] attributes:pathAttribs]; + return [[NSAttributedString alloc] initWithString:[final componentsJoinedByString:joiner] attributes:attribs]; } - (void)toggleAnimate:(id)obj { @@ -374,6 +369,11 @@ - (void)updateMenu:(NSMenu *)menu { float max_width = [menu size].width; if (max_width < 210) max_width = 210; + NSMutableParagraphStyle* pathStyle = [[NSMutableParagraphStyle alloc] init]; + pathStyle.minimumLineHeight = 13.0; + NSDictionary *attribs= @{ NSFontAttributeName:[NSFont menuFontOfSize:11.0], NSParagraphStyleAttributeName:pathStyle }; + NSDictionary *disabledAttribs= @{ NSFontAttributeName:[NSFont menuFontOfSize:11.0], NSParagraphStyleAttributeName:pathStyle, NSForegroundColorAttributeName:[NSColor tertiaryLabelColor] }; + for (long index = 0; index < [advancedProcesses count]; index++) { ProcessRecord *process = [advancedProcesses objectAtIndex:index]; NSMenuItem *item = [advancedItems objectAtIndex:index]; @@ -404,7 +404,10 @@ - (void)updateMenu:(NSMenu *)menu { joiner = @"\u00A0◁\u202B "; format = @"\u202B%d\u00A0%@"; } - [item setAttributedTitle:[self wrappedText:[NSString stringWithFormat:format, process.pid, [folders componentsJoinedByString:joiner]] width:max_width]]; + NSDictionary *useAttribs = attribs; + if (!process.running) useAttribs = disabledAttribs; + + [item setAttributedTitle:[self wrappedText:[NSString stringWithFormat:format, process.pid, [folders componentsJoinedByString:joiner]] width:max_width attributes:useAttribs]]; [item setIndentationLevel:1]; [item setRepresentedObject:process]; [item setTarget:self];