Skip to content

Commit

Permalink
add code to apply text preferences
Browse files Browse the repository at this point in the history
* rename the rankedStringIsName to showRankedStringOnly to better reflect its new behavior
* rearrange boolean tests so faster ones are tried first

fixes #1391, fixes #2133
  • Loading branch information
skurfer committed Nov 21, 2015
1 parent 71a58d0 commit f8698ef
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions Quicksilver/Code-QuickStepInterface/QSObjectCell.m
Expand Up @@ -392,6 +392,9 @@ - (void)buildStylesForFrame:(NSRect)cellFrame inView:(NSView *)controlView {
[style setFirstLineHeadIndent:1.0];
[style setHeadIndent:1.0];
[style setAlignment:[self alignment]];
if ([NSApplication isYosemite] && ![[NSUserDefaults standardUserDefaults] boolForKey:kQSTextAllowTightening]) {

This comment has been minimized.

Copy link
@pjrobertson

pjrobertson Jan 28, 2016

Member

did we have a convention of // Drop 10.10 ... or something whenever we used [NSApplication isSomeOS]?

This comment has been minimized.

Copy link
@skurfer

skurfer Jan 28, 2016

Author Member

We have a convention like // drop10.10. I think we only talked about what it was for, but not necessarily when it should be used. I think if there’s a call to isSomeOS, we can find it. The comment is for the less obvious ones.

[style setTighteningFactorForTruncation:0.0];
}
//
/// NSLog(@"%d %d", [self isHighlighted] , [self state]);

Expand Down Expand Up @@ -444,7 +447,9 @@ - (void)drawTextForObject:(QSObject *)drawObject withFrame:(NSRect)cellFrame inV
}

if (!nameString) nameString = [drawObject displayName];
BOOL rankedStringIsName = [nameString isEqualToString:[drawObject displayName]] || nameString == nil;
BOOL showRankedStringOnly = nameString == nil

This comment has been minimized.

Copy link
@pjrobertson

pjrobertson Jan 28, 2016

Member

This isn't very readable. Any chance we can make it an if/else?

Never mind if you don't want to change it

This comment has been minimized.

Copy link
@skurfer

skurfer Jan 28, 2016

Author Member

Wouldn’t that be the same character soup with more (parentheses) added to the mix? Or did you have something else in mind?

This comment has been minimized.

Copy link
@pjrobertson

pjrobertson Jan 28, 2016

Member

Yeah, actually once I figured out what it'd be then it would be exactly the same just with more parentheses. Yeah, maybe you can call me a ()() lover

|| ![[NSUserDefaults standardUserDefaults] boolForKey:kQSTextMatchedAlwaysShowName]
|| [nameString isEqualToString:[drawObject displayName]];
if (!nameString) {
// fall back to the identifier if no reasonable name can be found
nameString = [drawObject identifier];
Expand All @@ -459,24 +464,34 @@ - (void)drawTextForObject:(QSObject *)drawObject withFrame:(NSRect)cellFrame inV
NSRect textDrawRect = [self titleRectForBounds:cellFrame];

NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:nameString];
[titleString setAttributes:rankedStringIsName ? nameAttributes : detailsAttributes range:NSMakeRange(0, [titleString length])];
[titleString setAttributes:showRankedStringOnly ? nameAttributes : detailsAttributes range:NSMakeRange(0, [titleString length])];


if (abbreviationString && ![abbreviationString hasPrefix:@"QSActionMnemonic"]) {
[titleString addAttribute:NSForegroundColorAttributeName value:rankedStringIsName ? fadedColor : [fadedColor colorWithAlphaComponent:0.8] range:NSMakeRange(0, [titleString length])];
[titleString addAttribute:NSForegroundColorAttributeName value:showRankedStringOnly ? fadedColor : [fadedColor colorWithAlphaComponent:0.8] range:NSMakeRange(0, [titleString length])];

// Organise displaying the text, underlining the letters typed (in the name)
NSUInteger i = 0;
NSUInteger j = 0;
NSUInteger hits[[titleString length]];
NSUInteger count = [hitMask getIndexes:(NSUInteger *)&hits maxCount:[titleString length] inIndexRange:nil];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
rankedStringIsName ? mainColor : fadedColor, NSForegroundColorAttributeName,
rankedStringIsName ? mainColor : fadedColor, NSUnderlineColorAttributeName,
[NSNumber numberWithInteger:2.0] , NSUnderlineStyleAttributeName,
[NSNumber numberWithDouble:1.0] , NSBaselineOffsetAttributeName,
nil];

NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
showRankedStringOnly ? mainColor : fadedColor, NSForegroundColorAttributeName,
nil];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:kQSTextMatchedUnderline]) {
[attributes setObject:showRankedStringOnly ? mainColor : fadedColor forKey:NSUnderlineColorAttributeName];
[attributes setObject:[NSNumber numberWithFloat:2.0] forKey:NSUnderlineStyleAttributeName];
[attributes setObject:[NSNumber numberWithFloat:1.0] forKey:NSBaselineOffsetAttributeName];
}
if ([defaults boolForKey:kQSTextMatchedGlow]) {
NSShadow *glow = [[NSShadow alloc] init];
CGFloat radius = self.nameFont.pointSize/16.0;

This comment has been minimized.

Copy link
@pjrobertson

pjrobertson Jan 28, 2016

Member

how did you calculation the radius? Why /16?

This comment has been minimized.

Copy link
@skurfer

skurfer Jan 28, 2016

Author Member

Eh… trial and error? It was over a year ago when I first did that. I only made it public recently. 😃

I’m open to discussing it, or making it a hidden pref. Or maybe even a slider?

This comment has been minimized.

Copy link
@pjrobertson

pjrobertson Jan 28, 2016

Member

Haha, alright! I was just wanting to know if there was any fanciness about this. Maybe it could be made a hidden pref? Don't think it's that crucial to be a slider.

[glow setShadowBlurRadius:radius];
[glow setShadowColor:fadedColor];
[attributes setObject:glow forKey:NSShadowAttributeName];
}

for(i = 0; i<count; i += j) {
for (j = 1; i+j<count && hits[i+j-1] +1 == hits[i+j]; j++);
[titleString addAttributes:attributes range:NSMakeRange(hits[i], j)];
Expand All @@ -486,7 +501,7 @@ - (void)drawTextForObject:(QSObject *)drawObject withFrame:(NSRect)cellFrame inV
}

// Ranked string and nameString aren't the same. Show 'nameString ⟷ rankedString' in the UI
if (!rankedStringIsName && [drawObject displayName].length) {
if (!showRankedStringOnly && [drawObject displayName].length) {
[titleString addAttribute:NSFontAttributeName value:detailsFont range:NSMakeRange(0,[titleString length])];
NSMutableAttributedString *attributedNameString = [[NSMutableAttributedString alloc] initWithString:[drawObject displayName]];
[attributedNameString setAttributes:nameAttributes range:NSMakeRange(0, [[drawObject displayName] length])];
Expand Down

0 comments on commit f8698ef

Please sign in to comment.