diff options
author | rowanbeentje <rowan@beent.je> | 2012-10-06 11:48:15 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-10-06 11:48:15 +0000 |
commit | ecb5c70566d1303288e4faf170bda40672a799e1 (patch) | |
tree | 2882fa5fd6f25eed9c754e810785f5834225b95f /Source/SPFavoriteTextFieldCell.m | |
parent | ada181f6fe5b010a5ab56030d16b35e92e58af10 (diff) | |
download | sequelpro-ecb5c70566d1303288e4faf170bda40672a799e1.tar.gz sequelpro-ecb5c70566d1303288e4faf170bda40672a799e1.tar.bz2 sequelpro-ecb5c70566d1303288e4faf170bda40672a799e1.zip |
Change the connection screen interface, particularly relating to favourite editing on the connection screen (Issue #1339, Issue #1440):
- No longer save changes made to connection favourites as soon as the interface is updated
- Alter the interfaace if favourites are editing, offering to save the changes either to the old connection favourite or to a new favourite
- Add a "Test connection" button to verify changes before saving
- Add a "Quick Connect" entry to the top of the connection view's favourites list so a blank form is always available
- Use a custom highlight when editing favourites to show the favourite has changed but is still linked
- Reduce the margin on the left-hand side of the connection favourites list to increase the available space
- Alter favourite name generation, making it less aggressive when generating names from partial details (eg creating names of just "@") and removing the user
- Alter key icon usage to correctly update the button appearance if an SSL or SSH key is selected
Diffstat (limited to 'Source/SPFavoriteTextFieldCell.m')
-rw-r--r-- | Source/SPFavoriteTextFieldCell.m | 208 |
1 files changed, 36 insertions, 172 deletions
diff --git a/Source/SPFavoriteTextFieldCell.m b/Source/SPFavoriteTextFieldCell.m index e084d173..f9ebd280 100644 --- a/Source/SPFavoriteTextFieldCell.m +++ b/Source/SPFavoriteTextFieldCell.m @@ -32,17 +32,6 @@ #import "SPFavoriteTextFieldCell.h" -#define FAVORITE_NAME_FONT_SIZE 12.0f - -@interface SPFavoriteTextFieldCell (PrivateAPI) - -- (NSAttributedString *)constructSubStringAttributedString; -- (NSAttributedString *)attributedStringForFavoriteName; -- (NSDictionary *)mainStringAttributedStringAttributes; -- (NSDictionary *)subStringAttributedStringAttributes; - -@end - @implementation SPFavoriteTextFieldCell /** @@ -51,10 +40,7 @@ - (id)init { if ((self = [super init])) { - mainStringColor = [NSColor blackColor]; - subStringColor = [NSColor grayColor]; - favoriteName = nil; - favoriteHost = nil; + drawsDividerUnderCell = NO; } return self; @@ -63,186 +49,64 @@ - (id)copyWithZone:(NSZone *)zone { SPFavoriteTextFieldCell *cell = (SPFavoriteTextFieldCell *)[super copyWithZone:zone]; - - cell->favoriteName = nil; - if (favoriteName) cell->favoriteName = [favoriteName copyWithZone:zone]; - cell->favoriteHost = nil; - if (favoriteHost) cell->favoriteHost = [favoriteHost copyWithZone:zone]; + cell->drawsDividerUnderCell = drawsDividerUnderCell; return cell; } /** - * Get the cell's favorite name. - */ -- (NSString *)favoriteName -{ - return favoriteName; -} - -/** - * Set the cell's favorite name to the supplied name. + * Returns whether this cell is set to draw a divider in the space directly below + * the cell (whatever currently populates that space). */ -- (void)setFavoriteName:(NSString *)name +- (BOOL)drawsDividerUnderCell { - if (favoriteName != name) { - [favoriteName release]; - favoriteName = [name retain]; - } + return drawsDividerUnderCell; } /** - * Get the cell's favorite host. + * Set whether this cell should draw a divider in the space directly below + * the cell (whatever currently populates that space). */ -- (NSString *)favoriteHost +- (void)setDrawsDividerUnderCell:(BOOL)drawsDivider { - return favoriteHost; + drawsDividerUnderCell = drawsDivider; } -/** - * Set the cell's favorite host to the supplied name. - */ -- (void)setFavoriteHost:(NSString *)host -{ - if (favoriteHost != host) { - [favoriteHost release]; - favoriteHost = [host retain]; - } -} +#pragma mark - /** - * Draws the actual cell. + * Draws the actual cell, with a divider if appropriate. */ - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { - (([self isHighlighted]) && (![[self highlightColorWithFrame:cellFrame inView:controlView] isEqualTo:[NSColor secondarySelectedControlColor]])) ? [self invertFontColors] : [self restoreFontColors]; - - // Construct and get the sub text attributed string - NSAttributedString *mainString = [self attributedStringForFavoriteName]; - NSAttributedString *subString = [self constructSubStringAttributedString]; - - NSRect subFrame = NSMakeRect(0.0f, 0.0f, [subString size].width, [subString size].height); - - // Total height of both strings with a 2 pixel separation space - CGFloat totalHeight = [mainString size].height + [subString size].height + 1.0f; - - cellFrame.origin.y += (cellFrame.size.height - totalHeight) / 2.0f; - cellFrame.origin.x += 10.0f; // Indent main string from image - - // Position the sub text's frame rect - subFrame.origin.y = [mainString size].height + cellFrame.origin.y + 1.0f; - subFrame.origin.x = cellFrame.origin.x; - - cellFrame.size.height = totalHeight; - - NSUInteger i; - CGFloat maxWidth = cellFrame.size.width; - CGFloat mainStringWidth = [mainString size].width; - CGFloat subStringWidth = [subString size].width; - - // Set a right-padding - maxWidth -= 10; - - if (maxWidth < mainStringWidth) { - for (i = 0; i <= [mainString length]; i++) { - if ([[mainString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth && i >= 3) { - mainString = [[[NSMutableAttributedString alloc] initWithString:[[[mainString attributedSubstringFromRange:NSMakeRange(0, i - 3)] string] stringByAppendingString:@"..."] attributes:[self mainStringAttributedStringAttributes]] autorelease]; - } - } - } - - if (maxWidth < subStringWidth) { - for (i = 0; i <= [subString length]; i++) { - if ([[subString attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth && i >= 3) { - subString = [[[NSMutableAttributedString alloc] initWithString:[[[subString attributedSubstringFromRange:NSMakeRange(0, i - 3)] string] stringByAppendingString:@"..."] attributes:[self subStringAttributedStringAttributes]] autorelease]; - } - } - } - - [mainString drawInRect:cellFrame]; - [subString drawInRect:subFrame]; -} + [super drawInteriorWithFrame:cellFrame inView:controlView]; -- (NSSize)cellSize -{ - NSSize cellSize = [super cellSize]; - NSAttributedString *mainString = [self attributedStringForFavoriteName]; - NSAttributedString *subString = [self constructSubStringAttributedString]; - - // 15 := indention 10 from image to string plus 5 px padding - CGFloat theWidth = MAX([mainString size].width, [subString size].width) + (([self image] != nil) ? [[self image] size].width : 0) + 15; + if (drawsDividerUnderCell) { + NSRect viewFrame = [controlView frame]; - CGFloat totalHeight = [mainString size].height + [subString size].height + 1.0f; - - cellSize.width = theWidth; - cellSize.height = totalHeight + 13.0f; - return cellSize; -} + NSPoint startPoint = NSMakePoint(viewFrame.origin.x + 7.f, viewFrame.origin.y); + NSPoint endPoint = NSMakePoint(viewFrame.origin.x + viewFrame.size.width - 7.f, viewFrame.origin.y); -/** - * Inverts the displayed font colors when the cell is selected. - */ -- (void)invertFontColors -{ - mainStringColor = [NSColor whiteColor]; - subStringColor = [NSColor whiteColor]; -} - -/** - * Restores the displayed font colors once the cell is no longer selected. - */ -- (void)restoreFontColors -{ - mainStringColor = [NSColor blackColor]; - subStringColor = [NSColor grayColor]; -} - -/** - * Dealloc. - */ -- (void)dealloc -{ - [favoriteName release], favoriteName = nil; - [favoriteHost release], favoriteHost = nil; - - [super dealloc]; -} - -@end - -@implementation SPFavoriteTextFieldCell (PrivateAPI) - -/** - * Constructs the attributed string to be used as the cell's substring. - */ -- (NSAttributedString *)constructSubStringAttributedString -{ - return [[[NSAttributedString alloc] initWithString:favoriteHost attributes:[self subStringAttributedStringAttributes]] autorelease]; -} - -/** - * Constructs the attributed string for the cell's favorite name. - */ -- (NSAttributedString *)attributedStringForFavoriteName -{ - return [[[NSAttributedString alloc] initWithString:favoriteName attributes:[self mainStringAttributedStringAttributes]] autorelease]; -} - -/** - * Returns the attributes of the cell's main string. - */ -- (NSDictionary *)mainStringAttributedStringAttributes -{ - return [NSDictionary dictionaryWithObjectsAndKeys:mainStringColor, NSForegroundColorAttributeName, [NSFont systemFontOfSize:FAVORITE_NAME_FONT_SIZE], NSFontAttributeName, nil]; -} + if ([controlView isFlipped]) { + startPoint.y += cellFrame.size.height + 8.5f; + endPoint.y += cellFrame.size.height + 8.5f; + } else { + startPoint.y -= cellFrame.size.height + 8.5f; + endPoint.y -= cellFrame.size.height + 8.5f; + } -/** - * Returns the attributes of the cell's sub string. - */ -- (NSDictionary *)subStringAttributedStringAttributes -{ - return [NSDictionary dictionaryWithObjectsAndKeys:subStringColor, NSForegroundColorAttributeName, [NSFont systemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName, nil]; + [NSGraphicsContext saveGraphicsState]; + [[NSColor gridColor] set]; + NSShadow *lineGlow = [[NSShadow alloc] init]; + [lineGlow setShadowBlurRadius:1]; + [lineGlow setShadowColor:[[NSColor controlLightHighlightColor] colorWithAlphaComponent:0.75f]]; + [lineGlow setShadowOffset:NSMakeSize(0, -1)]; + [lineGlow set]; + [NSBezierPath strokeLineFromPoint:startPoint toPoint:endPoint]; + [lineGlow release]; + [NSGraphicsContext restoreGraphicsState]; + } } -@end +@end
\ No newline at end of file |