From 7280c2ffaf22f20e4aa8bd1057487b4c3d847c98 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 1 Nov 2009 22:06:45 +0000 Subject: Improve truncating of table names (by appending ...) using SPTableTextFieldCell. --- Interfaces/English.lproj/DBView.xib | 76 +++++++++++++++++++----------------- Source/SPTableTextFieldCell.h | 31 +++++++++++++++ Source/SPTableTextFieldCell.m | 57 +++++++++++++++++++++++++++ sequel-pro.xcodeproj/project.pbxproj | 26 +++++++++--- 4 files changed, 149 insertions(+), 41 deletions(-) create mode 100644 Source/SPTableTextFieldCell.h create mode 100644 Source/SPTableTextFieldCell.m diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 6dd4ef73..391963e5 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -3,7 +3,7 @@ 1050 10B504 - 732 + 740 1038.2 437.00 @@ -16,20 +16,20 @@ YES - 732 - 732 - 1.2.2 + 740 + 740 + 1.2.1 YES - + YES com.brandonwalkin.BWToolkit - com.apple.InterfaceBuilder.CocoaPlugin com.apple.WebKitIBPlugin + com.apple.InterfaceBuilder.CocoaPlugin YES @@ -59,7 +59,7 @@ Connecting... NSWindow View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {780, 480} @@ -237,7 +237,7 @@ controlColor 3 - MC42NjY2NjY2NjY3AA + MC42NjY2NjY2ODY1AA @@ -4847,7 +4847,7 @@ {{0, 0}, {1920, 1178}} {780, 502} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} @@ -6018,7 +6018,7 @@ View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {213, 107} @@ -6297,7 +6297,7 @@ {{0, 0}, {1440, 878}} {213, 129} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 1 @@ -6309,7 +6309,7 @@ View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {213, 107} @@ -6465,7 +6465,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1440, 878}} {213, 129} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 1 @@ -6475,7 +6475,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 New Relation NSPanel - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 256 @@ -7076,7 +7076,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {302, 307} {{0, 0}, {1440, 878}} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 3 @@ -7088,7 +7088,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {213, 50} @@ -7208,7 +7208,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1920, 1178}} {213, 72} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 9 @@ -7220,7 +7220,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {213, 107} @@ -7355,7 +7355,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1440, 878}} {213, 129} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 15 @@ -7367,7 +7367,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {350, 200} @@ -7671,7 +7671,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1440, 878}} {350, 222} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 15 @@ -7683,7 +7683,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {350, 200} @@ -7885,7 +7885,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1680, 1028}} {350, 222} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 9 @@ -7897,7 +7897,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {213, 107} @@ -8046,7 +8046,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1440, 878}} {213, 129} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 31 @@ -8056,7 +8056,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 MySQL Help NSPanel - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {351, 120} @@ -8450,7 +8450,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1280, 1002}} {351, 136} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} MYSQL_HELP_WINDOW @@ -8463,7 +8463,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 View - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {350, 250} @@ -8854,7 +8854,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{0, 0}, {1920, 1178}} {350, 272} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 9 @@ -8987,7 +8987,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 Secure Text Input Sheet NSPanel - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} 256 @@ -9091,7 +9091,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {338, 138} {{0, 0}, {1280, 778}} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} @@ -10957,7 +10957,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 disabledControlTextColor 3 - MC4zMzMzMzMzMzMzAA + MC4zMzMzMzMzNDMzAA @@ -22774,7 +22774,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 662.ImportedFromIB2 663.IBPluginDependency 663.ImportedFromIB2 - 6638.IBPluginDependency 669.IBPluginDependency 669.ImportedFromIB2 67.ImportedFromIB2 @@ -23526,7 +23525,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin {{273, 775}, {200, 23}} com.apple.InterfaceBuilder.CocoaPlugin - ImageAndTextCell + SPTableTextFieldCell com.apple.InterfaceBuilder.CocoaPlugin {{355, 517}, {306, 122}} com.apple.InterfaceBuilder.CocoaPlugin @@ -24633,7 +24632,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -25510,6 +25508,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 Source/SPTableRelations.h + + SPTableTextFieldCell + ImageAndTextCell + + IBProjectSource + Source/SPTableTextFieldCell.h + + SPTableView NSTableView diff --git a/Source/SPTableTextFieldCell.h b/Source/SPTableTextFieldCell.h new file mode 100644 index 00000000..51ca62d2 --- /dev/null +++ b/Source/SPTableTextFieldCell.h @@ -0,0 +1,31 @@ +// +// $Id$ +// +// SPTableTextFieldCell.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 1, 2009 +// Copyright (c) 2009 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at + +#import +#import "ImageAndTextCell.h" + +@interface SPTableTextFieldCell : ImageAndTextCell + +@end diff --git a/Source/SPTableTextFieldCell.m b/Source/SPTableTextFieldCell.m new file mode 100644 index 00000000..47160fa4 --- /dev/null +++ b/Source/SPTableTextFieldCell.m @@ -0,0 +1,57 @@ +// +// $Id$ +// +// SPTableTextFieldCell.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 1, 2009 +// Copyright (c) 2009 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at + +#import "SPTableTextFieldCell.h" + +@implementation SPTableTextFieldCell + +/** + * Implements nicer cell truncating by appending '...' to the table name, before asking super to draw it. + */ +- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + // Construct and get the sub text attributed string + NSAttributedString *string = [self attributedStringValue]; + + int i; + float maxWidth = cellFrame.size.width; + float stringWidth = [string size].width; + + // Set a right padding + maxWidth -= 5; + + if (maxWidth < stringWidth) { + for (i = 0; i <= [string length]; i++) { + if (([[string attributedSubstringFromRange:NSMakeRange(0, i)] size].width >= maxWidth) && (i >= 3)) { + string = [[[NSMutableAttributedString alloc] initWithString:[[[string attributedSubstringFromRange:NSMakeRange(0, i - 3)] string] stringByAppendingString:@"..."] attributes:[string attributesAtIndex:0 effectiveRange:NULL]] autorelease]; + } + } + } + + [self setAttributedStringValue:string]; + [super drawInteriorWithFrame:cellFrame inView:controlView]; +} + +@end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 6fe3c131..57559046 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */; }; 17292443107AC41000B21980 /* SPXMLExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 17292442107AC41000B21980 /* SPXMLExporter.m */; }; 172A65110F7BED7A001E861A /* SPConsoleMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 172A65100F7BED7A001E861A /* SPConsoleMessage.m */; }; 173284EA1088FEDE0062E892 /* SPConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173284E91088FEDE0062E892 /* SPConstants.m */; }; @@ -340,6 +341,8 @@ 1703EF400F0B0742005BBE7E /* tables.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = tables.html; sourceTree = ""; }; 17128B8A0FE6E0210035DD75 /* QLPreviewPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QLPreviewPanel.h; sourceTree = ""; }; 1713122F109C7DF600FB465F /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = ""; }; + 171312CC109D23C700FB465F /* SPTableTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTextFieldCell.h; sourceTree = ""; }; + 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableTextFieldCell.m; sourceTree = ""; }; 17292441107AC41000B21980 /* SPXMLExporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPXMLExporter.h; sourceTree = ""; }; 17292442107AC41000B21980 /* SPXMLExporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPXMLExporter.m; sourceTree = ""; }; 172A650F0F7BED7A001E861A /* SPConsoleMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConsoleMessage.h; sourceTree = ""; }; @@ -773,6 +776,21 @@ name = QuickLook; sourceTree = ""; }; + 171312CF109D23CA00FB465F /* Cells */ = { + isa = PBXGroup; + children = ( + 17E641680EF01F37001BC333 /* ImageAndTextCell.h */, + 17E641690EF01F37001BC333 /* ImageAndTextCell.m */, + 58D2E228101222670063EF1D /* SPTextAndLinkCell.h */, + 58D2E227101222670063EF1D /* SPTextAndLinkCell.m */, + 171312CC109D23C700FB465F /* SPTableTextFieldCell.h */, + 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */, + B57747DA0F7A89D0003B34F9 /* SPFavoriteTextFieldCell.h */, + B57747DB0F7A89D0003B34F9 /* SPFavoriteTextFieldCell.m */, + ); + name = Cells; + sourceTree = ""; + }; 173284E51088FEC20062E892 /* Data */ = { isa = PBXGroup; children = ( @@ -1060,12 +1078,9 @@ 17E641670EF01F19001BC333 /* Views */ = { isa = PBXGroup; children = ( - 17E641680EF01F37001BC333 /* ImageAndTextCell.h */, - 17E641690EF01F37001BC333 /* ImageAndTextCell.m */, + 171312CF109D23CA00FB465F /* Cells */, BC01BCCD104024BE006BDEE7 /* SPEncodingPopupAccessory.h */, BC01BCCE104024BE006BDEE7 /* SPEncodingPopupAccessory.m */, - B57747DA0F7A89D0003B34F9 /* SPFavoriteTextFieldCell.h */, - B57747DB0F7A89D0003B34F9 /* SPFavoriteTextFieldCell.m */, 173C44D61044A6AF001F3A30 /* SPOutlineView.h */, 173C44D71044A6B0001F3A30 /* SPOutlineView.m */, 29A1B7E30FD1293A000B88E8 /* SPPrintAccessory.h */, @@ -1120,8 +1135,6 @@ 5841423E0F97E11000A34B47 /* NoodleLineNumberView.m */, BC1847E80FE6EC8400094BFB /* SPEditSheetTextView.h */, BC1847E90FE6EC8400094BFB /* SPEditSheetTextView.m */, - 58D2E228101222670063EF1D /* SPTextAndLinkCell.h */, - 58D2E227101222670063EF1D /* SPTextAndLinkCell.m */, ); name = GUI; sourceTree = ""; @@ -1799,6 +1812,7 @@ 17292443107AC41000B21980 /* SPXMLExporter.m in Sources */, 582A01E9107C0C170027D42B /* SPNotLoaded.m in Sources */, 173284EA1088FEDE0062E892 /* SPConstants.m in Sources */, + 171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; -- cgit v1.2.3