diff options
author | Max <post@wickenrode.com> | 2015-02-15 02:59:14 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-02-15 02:59:14 +0100 |
commit | baa1593d4bd84b2eebc41821d5ff2b70013371bf (patch) | |
tree | 33b06aed0f180784e5b827c40013af9cbb3744ea | |
parent | 085b381858dcd3cda5c0b00527d3b7a77641345a (diff) | |
download | sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.tar.gz sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.tar.bz2 sequelpro-baa1593d4bd84b2eebc41821d5ff2b70013371bf.zip |
Add basic color highlighting in favorites list
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 8 | ||||
-rw-r--r-- | Source/SPFavoriteTextFieldCell.h | 2 | ||||
-rw-r--r-- | Source/SPFavoriteTextFieldCell.m | 45 |
3 files changed, 55 insertions, 0 deletions
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index a28a27b7..8cef86e9 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -32,6 +32,7 @@ #ifndef SP_CODA #import "SPFavoritesController.h" #import "SPTableTextFieldCell.h" +#import "SPFavoriteTextFieldCell.h" #import "SPPreferenceController.h" #import "SPGeneralPreferencePane.h" #import "SPAppController.h" @@ -39,6 +40,7 @@ #import "SPGroupNode.h" #import "SPTreeNode.h" #import "SPFavoritesOutlineView.h" +#import "SPFavoriteColorSupport.h" #endif #ifndef SP_CODA @@ -171,6 +173,12 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf"; } else { [(SPTableTextFieldCell *)cell setImage:[NSImage imageNamed:SPDatabaseImage]]; + NSColor *bgColor = nil; + NSNumber *colorIndexObj = [[[node representedObject] nodeFavorite] objectForKey:SPFavoriteColorIndexKey]; + if(colorIndexObj != nil) { + bgColor = [[SPFavoriteColorSupport sharedInstance] colorForIndex:[colorIndexObj integerValue]]; + } + [(SPFavoriteTextFieldCell *)cell setLabelColor:bgColor]; } } diff --git a/Source/SPFavoriteTextFieldCell.h b/Source/SPFavoriteTextFieldCell.h index afc32bcb..931d767d 100644 --- a/Source/SPFavoriteTextFieldCell.h +++ b/Source/SPFavoriteTextFieldCell.h @@ -38,4 +38,6 @@ - (BOOL)drawsDividerUnderCell; - (void)setDrawsDividerUnderCell:(BOOL)drawsDivider; +@property(copy)NSColor *labelColor; + @end diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index 41511c8c..c5ec9150 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -29,6 +29,9 @@ // More info at <https://github.com/sequelpro/sequelpro> #import "SPFavoriteTextFieldCell.h" +#import "SPOSInfo.h" + +extern BOOL isOSAtLeast10_10_0(void); @implementation SPFavoriteTextFieldCell @@ -46,6 +49,7 @@ SPFavoriteTextFieldCell *cell = (SPFavoriteTextFieldCell *)[super copyWithZone:zone]; cell->drawsDividerUnderCell = drawsDividerUnderCell; + cell->labelColor = nil; //TODO copying the color sometimes causes a drawing bug return cell; } @@ -68,8 +72,37 @@ drawsDividerUnderCell = drawsDivider; } +@synthesize labelColor; + #pragma mark - +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + if([self labelColor]) { + CGFloat round = (cellFrame.size.height/2); + NSBezierPath *bg = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:round yRadius:round]; + + if(isOSAtLeast10_10_0()) { + CGFloat h,s,b,a; + [[self labelColor] getHue:&h saturation:&s brightness:&b alpha:&a]; + + [[NSColor colorWithCalibratedHue:h saturation:s*1.21 brightness:b*1.1 alpha:a] set]; + [bg fill]; + } + else { + NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: + [[self labelColor] highlightWithLevel:0.33], 0.0, + [self labelColor], 0.5, + [[self labelColor] shadowWithLevel:0.15], 1.0, nil]; + [gradient drawInBezierPath:bg angle:90.0]; + [gradient release]; + } + } + + [super drawWithFrame:cellFrame inView:controlView]; +} + + /** * Draws the actual cell, with a divider if appropriate. */ @@ -110,4 +143,16 @@ } } +- (void)dealloc +{ + [self setLabelColor:nil]; + + [super dealloc]; +} + @end + +BOOL isOSAtLeast10_10_0() { + const BOOL value = [SPOSInfo isOSVersionAtLeastMajor:10 minor:10 patch:0]; + return value; +} |