diff options
-rwxr-xr-x | ImageAndTextCell.h | 59 | ||||
-rwxr-xr-x | ImageAndTextCell.m | 135 | ||||
-rw-r--r-- | SPTableInfo.h | 24 | ||||
-rw-r--r-- | SPTableInfo.m | 184 | ||||
-rw-r--r-- | sl-icon_table.tiff | bin | 0 -> 3820 bytes |
5 files changed, 402 insertions, 0 deletions
diff --git a/ImageAndTextCell.h b/ImageAndTextCell.h new file mode 100755 index 00000000..897549cd --- /dev/null +++ b/ImageAndTextCell.h @@ -0,0 +1,59 @@ +// +// ImageAndTextCell.h +// +// Copyright © 2006, Apple. All rights reserved. +// + +/* + IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in + consideration of your agreement to the following terms, and your use, installation, + modification or redistribution of this Apple software constitutes acceptance of these + terms. If you do not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and subject to these + terms, Apple grants you a personal, non-exclusive license, under Apple’s copyrights in + this original Apple software (the "Apple Software"), to use, reproduce, modify and + redistribute the Apple Software, with or without modifications, in source and/or binary + forms; provided that if you redistribute the Apple Software in its entirety and without + modifications, you must retain this notice and the following text and disclaimers in all + such redistributions of the Apple Software. Neither the name, trademarks, service marks + or logos of Apple Computer, Inc. may be used to endorse or promote products derived from + the Apple Software without specific prior written permission from Apple. Except as expressly + stated in this notice, no other rights or licenses, express or implied, are granted by Apple + herein, including but not limited to any patent rights that may be infringed by your + derivative works or by other works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, + EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS + USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, + REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND + WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR + OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#import <Cocoa/Cocoa.h> + +#define INDENT_AMOUNT 17 + +@interface ImageAndTextCell : NSTextFieldCell +{ +@private + NSImage *image; + int _indentationLevel; +} + +- (void)setImage:(NSImage *)anImage; +- (NSImage *)image; + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView; +- (NSSize)cellSize; + +- (void)setIndentationLevel:(int)level; +- (int)IndentationLevel; +@end diff --git a/ImageAndTextCell.m b/ImageAndTextCell.m new file mode 100755 index 00000000..96c0ff9d --- /dev/null +++ b/ImageAndTextCell.m @@ -0,0 +1,135 @@ +/* + ImageAndTextCell.m + Copyright © 2006, Apple Computer, Inc., all rights reserved. + + Subclass of NSTextFieldCell which can display text and an image simultaneously. +*/ + +#import "ImageAndTextCell.h" + +@implementation ImageAndTextCell + +- (void)dealloc { + [image release]; + image = nil; + [super dealloc]; +} + +- copyWithZone:(NSZone *)zone +{ + ImageAndTextCell *cell = (ImageAndTextCell *)[super copyWithZone:zone]; + cell->image = [image retain]; + return cell; +} + +- (void)setImage:(NSImage *)anImage +{ + if (anImage != image) + { + [image release]; + image = [anImage retain]; + } +} + +- (NSImage *)image +{ + return image; +} + +- (NSRect)imageFrameForCellFrame:(NSRect)cellFrame +{ + if (image != nil) + { + NSRect imageFrame; + imageFrame.size = [image size]; + imageFrame.origin = cellFrame.origin; + imageFrame.origin.x += ((1 - MIN(1,INDENT_AMOUNT)) * 3) + (INDENT_AMOUNT * _indentationLevel); + imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); + return imageFrame; + } + else + return NSZeroRect; +} + +- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent +{ + if (_indentationLevel != 0) { + NSRect indentationFrame; + NSDivideRect(aRect, &indentationFrame, &aRect, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + if (image != nil) { + NSRect imageFrame; + NSDivideRect (aRect, &imageFrame, &aRect, 3 + [image size].width, NSMinXEdge); + } + + [super editWithFrame:aRect inView: controlView editor:textObj delegate:anObject event:theEvent]; +} + +- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength +{ + if (_indentationLevel != 0) { + NSRect indentationFrame; + NSDivideRect(aRect, &indentationFrame, &aRect, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + if (image != nil) { + NSRect imageFrame; + NSDivideRect (aRect, &imageFrame, &aRect, 3 + [image size].width, NSMinXEdge); + } + + [super selectWithFrame:aRect inView: controlView editor:textObj delegate:anObject start:selStart length:selLength]; +} + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView +{ + if (_indentationLevel != 0) + { + NSRect indentationFrame; + NSDivideRect(cellFrame, &indentationFrame, &cellFrame, (INDENT_AMOUNT * _indentationLevel), NSMinXEdge); + } + + if (image != nil) + { + NSSize imageSize; + NSRect imageFrame; + + imageSize = [image size]; + NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge); + if ([self drawsBackground]) + { + [[self backgroundColor] set]; + NSRectFill(imageFrame); + } + imageFrame.origin.x += 3; + imageFrame.size = imageSize; + + if ([controlView isFlipped]) + imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2); + else + imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2); + + [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver]; + } + [super drawWithFrame:cellFrame inView:controlView]; +} + +- (NSSize)cellSize +{ + NSSize cellSize = [super cellSize]; + cellSize.width += (image ? [image size].width : 0) + ((1 - MIN(1,INDENT_AMOUNT)) * 3) + (INDENT_AMOUNT * _indentationLevel); + return cellSize; +} + +- (void)setIndentationLevel:(int)level +{ + _indentationLevel = MAX(0,level); +} + +- (int)IndentationLevel +{ + return _indentationLevel; +} + +@end + diff --git a/SPTableInfo.h b/SPTableInfo.h new file mode 100644 index 00000000..49e62d28 --- /dev/null +++ b/SPTableInfo.h @@ -0,0 +1,24 @@ +// +// SPTableInfo.h +// sequel-pro +// +// Created by Ben Perry on 6/05/08. +// Copyright 2008 Ben Perry. All rights reserved. +// + +#import <Cocoa/Cocoa.h> + + +@interface SPTableInfo : NSObject { + IBOutlet id infoTable; + + IBOutlet id tableListInstance; + IBOutlet id tableDocumentInstance; + + NSMutableArray *info; +} + +- (NSString *)sizeFromBytes:(int)bytes; + + +@end diff --git a/SPTableInfo.m b/SPTableInfo.m new file mode 100644 index 00000000..c1050937 --- /dev/null +++ b/SPTableInfo.m @@ -0,0 +1,184 @@ +// +// SPTableInfo.m +// sequel-pro +// +// Created by Ben Perry on 6/05/08. +// Copyright 2008 Ben Perry. All rights reserved. +// + +#import "SPTableInfo.h" +#import "ImageAndTextCell.h" +#import <MCPKit_bundled/MCPKit_bundled.h> +#import "CMMCPConnection.h" +#import "CMMCPResult.h" +#import "TableDocument.h" + +@implementation SPTableInfo + +- (id)init +{ + self = [super init]; + info = [[NSMutableArray alloc] init]; + return self; +} + +- (void)awakeFromNib +{ +// [[NSNotificationCenter defaultCenter] addObserver:self +// selector:@selector(tableChanged:) +// name:NSTableViewSelectionDidChangeNotification +// object:nil]; + [info addObject:@"TABLE INFORMATION"]; + [infoTable reloadData]; +} + + +- (void)dealloc +{ + //[[NSNotificationCenter defaultCenter] removeObserver:self]; + + [tableListInstance release]; + + [info release]; + [infoTable release]; + [tableDocumentInstance release]; + + [super dealloc]; +} + +- (int)numberOfRowsInTableView:(NSTableView *)aTableView +{ + return [info count]; +} + +- (id)tableView:(NSTableView *)aTableView +objectValueForTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex +{ + return [info objectAtIndex:rowIndex]; +} + +- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex +{ + // row 1 and 6 should be editable - ie be able to rename the table and change the auto_increment value. + return NO;//(rowIndex == 1 || rowIndex == 6 ); +} + + +- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(int)row +{ + // This makes the top row (TABLE INFORMATION) have the diff styling + return (row == 0); +} + +- (void)tableView:(NSTableView *)aTableView + willDisplayCell:(id)aCell + forTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex +{ + if ((rowIndex > 0) && [[aTableColumn identifier] isEqualToString:@"info"]) { + [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"CodeAssistantProtocol"]]; + [(ImageAndTextCell*)aCell setIndentationLevel:1]; + } else { + [(ImageAndTextCell*)aCell setImage:nil]; + [(ImageAndTextCell*)aCell setIndentationLevel:0]; + } +} + +- (void)tableChanged:(NSNotification *)notification +{ + NSString *query; + CMMCPResult *theResult; + NSDictionary *theRow; + + [info removeAllObjects]; + [info addObject:@"TABLE INFORMATION"]; + + if ([tableListInstance table]) + { + if ([(NSString *)[tableListInstance table] isEqualToString:@""]) { + [info addObject:@"multiple tables"]; + + } else { + // Notify that we are about to perform a query + [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self]; + + // Create the query and get results + query = [NSString stringWithFormat:@"SHOW TABLE STATUS LIKE '%@'", [tableListInstance table]]; + + // This line triggers a bug when opening a new window. but only after having closed a window + theResult = [[tableDocumentInstance sharedConnection] queryString:query]; + + // Check for errors + if (![[[tableDocumentInstance sharedConnection] getLastErrorMessage] isEqualToString:@""]) { + [info addObject:@"error occurred"]; + return; + } + + // Process result + theRow = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + // Add the table name to the infoTable + [info addObject:[NSString stringWithFormat:@"name: %@", [tableListInstance table]]]; + + // Check for "Create_time" == NULL + if (![[theRow objectForKey:@"Create_time"] isNSNull]) { + // Setup our data formatter + NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; + [dateFormatter setDateStyle:NSDateFormatterShortStyle]; + [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; + + // Convert our string dates from the results to NSDates. + NSDate *create_date = [NSDate dateWithNaturalLanguageString:[theRow objectForKey:@"Create_time"]]; + NSDate *update_date = [NSDate dateWithNaturalLanguageString:[theRow objectForKey:@"Update_time"]]; + + // Add the create date and update date to the infoTable + [info addObject:[NSString stringWithFormat:@"created: %@", [dateFormatter stringFromDate:create_date]]]; + [info addObject:[NSString stringWithFormat:@"updated: %@", [dateFormatter stringFromDate:update_date]]]; + } + + [info addObject:[NSString stringWithFormat:@"rows: %@", [theRow objectForKey:@"Rows"]]]; + [info addObject:[NSString stringWithFormat:@"size: %@", [self sizeFromBytes:[[theRow objectForKey:@"Data_length"] intValue]]]]; + [info addObject:[NSString stringWithFormat:@"auto_increment: %@", [theRow objectForKey:@"Auto_increment"]]]; + + // Notify that we've finished performing the query + [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; + } + } + + [infoTable reloadData]; +} + +- (NSString *)sizeFromBytes:(int)theSize +{ + NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + float floatSize = theSize; + + [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; + + if (theSize < 1023) { + [numberFormatter setFormat:@"#,##0 B"]; + return [numberFormatter stringFromNumber:[NSNumber numberWithInt:theSize]]; + } + + floatSize = floatSize / 1024; + + if (floatSize < 1023) { + [numberFormatter setFormat:@"#,##0.0 KB"]; + return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatSize]]; + } + + floatSize = floatSize / 1024; + + if (floatSize < 1023) { + [numberFormatter setFormat:@"#,##0.0 MB"]; + return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatSize]]; + } + + floatSize = floatSize / 1024; + + [numberFormatter setFormat:@"#,##0.0 GB"]; + return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatSize]]; +} + +@end diff --git a/sl-icon_table.tiff b/sl-icon_table.tiff Binary files differnew file mode 100644 index 00000000..6c0e7d69 --- /dev/null +++ b/sl-icon_table.tiff |