Skip to content

Commit

Permalink
Merge pull request #2162 from quicksilver/textprefs
Browse files Browse the repository at this point in the history
Text preferences
  • Loading branch information
pjrobertson committed Jan 29, 2016
2 parents 22cb509 + 1d4ae6f commit aaad643
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 47 deletions.
7 changes: 7 additions & 0 deletions Quicksilver/Code-QuickStepCore/QSPreferenceKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ Following lines are no longer used in this project.
#define kQSAppearance3A @"QSAppearance3A"
#define kQSAppearance3T @"QSAppearance3T"

// Text Appearance Properties
#define kQSTextMatchedGlow @"Text Matched Glow"
#define kQSTextMatchedUnderline @"Text Matched Underline"
#define kQSTextMatchedAlwaysShowName @"Text Matched Always Show Name"
#define kQSTextAllowTightening @"Text Allow Tightening"
#define kQSTextGlowDivisor @"Text Glow Divisor"

#define kResultTableSplit @"Result Table Split Width"

// Date of last known Quicksilver Crash
Expand Down
38 changes: 27 additions & 11 deletions Quicksilver/Code-QuickStepInterface/QSObjectCell.m
Original file line number Diff line number Diff line change
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]) {
[style setTighteningFactorForTruncation:0.0];
}
//
/// NSLog(@"%d %d", [self isHighlighted] , [self state]);

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

if (!nameString) nameString = [drawObject displayName];
BOOL rankedStringIsName = [nameString isEqualToString:[drawObject displayName]] || nameString == nil;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL showRankedStringOnly = nameString == nil
|| ![defaults 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 +465,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];
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 divisor = [[defaults objectForKey:kQSTextGlowDivisor] floatValue];
CGFloat radius = self.nameFont.pointSize/divisor;
[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 +502,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
Loading

0 comments on commit aaad643

Please sign in to comment.