diff options
author | stuconnolly <stuart02@gmail.com> | 2012-08-13 11:21:27 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-08-13 11:21:27 +0000 |
commit | f342cbb6c42aa92b4f2224c1158ad242475bdcb9 (patch) | |
tree | 7993d464df13d8e90491f82b218f1fb5caed766d /Source | |
parent | 34efdf17577ee6a930b4cd60908eadd63e988097 (diff) | |
download | sequelpro-f342cbb6c42aa92b4f2224c1158ad242475bdcb9.tar.gz sequelpro-f342cbb6c42aa92b4f2224c1158ad242475bdcb9.tar.bz2 sequelpro-f342cbb6c42aa92b4f2224c1158ad242475bdcb9.zip |
Default grayed out column encodings should use monospaced fonts if enabled.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTableStructureDelegate.m | 78 | ||||
-rw-r--r-- | Source/SPTableStructureLoading.m | 8 |
2 files changed, 54 insertions, 32 deletions
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index a220b85e..f6a2b454 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -76,22 +76,29 @@ if ([collations count] > 0) { NSString *defaultCollation = [[tableDataInstance statusValues] objectForKey:@"collation"]; + if (!defaultCollation) { defaultCollation = [databaseDataInstance getDatabaseDefaultCollation]; } + [[tableColumn dataCell] addItemWithTitle:@""]; // Populate collation popup button for (NSDictionary *collation in collations) { NSString *collationName = [collation objectForKey:@"COLLATION_NAME"]; + [[tableColumn dataCell] addItemWithTitle:collationName]; // If this matches the table's collation, draw in gray if ([collationName length] && [collationName isEqualToString:defaultCollation]) { NSMenuItem *collationMenuItem = [(NSPopUpButtonCell *)[tableColumn dataCell] itemAtIndex:([[tableColumn dataCell] numberOfItems] - 1)]; - NSDictionary *menuAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize: [NSFont smallSystemFontSize]], NSFontAttributeName, nil]; + NSMutableDictionary *menuAttributes = [NSMutableDictionary dictionaryWithObject:[NSColor lightGrayColor] forKey:NSForegroundColorAttributeName]; + + [menuAttributes setObject:[prefs boolForKey:SPUseMonospacedFonts] ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]; + NSAttributedString *itemString = [[[NSAttributedString alloc] initWithString:collationName attributes:menuAttributes] autorelease]; + [collationMenuItem setAttributedTitle:itemString]; } } @@ -128,27 +135,29 @@ NSMutableDictionary *currentRow = [tableFields objectAtIndex:rowIndex]; // Reset collation if encoding was changed - if([[aTableColumn identifier] isEqualToString:@"encoding"]) { - if([[currentRow objectForKey:@"encoding"] integerValue] != [anObject integerValue]) { + if ([[aTableColumn identifier] isEqualToString:@"encoding"]) { + if ([[currentRow objectForKey:@"encoding"] integerValue] != [anObject integerValue]) { [currentRow setObject:[NSNumber numberWithInteger:0] forKey:@"collation"]; [tableSourceView reloadData]; } } // Reset collation if BINARY was set to 1 since BINARY sets collation to *_bin - else if([[aTableColumn identifier] isEqualToString:@"binary"]) { - if([[currentRow objectForKey:@"binary"] integerValue] != [anObject integerValue]) { - if([anObject integerValue] == 1) { + else if ([[aTableColumn identifier] isEqualToString:@"binary"]) { + if ([[currentRow objectForKey:@"binary"] integerValue] != [anObject integerValue]) { + if ([anObject integerValue] == 1) { [currentRow setObject:[NSNumber numberWithInteger:0] forKey:@"collation"]; } + [tableSourceView reloadData]; } } // Set null field to "do not allow NULL" for auto_increment Extra and reset Extra suggestion list - else if([[aTableColumn identifier] isEqualToString:@"Extra"]) { - if(![[currentRow objectForKey:@"Extra"] isEqualToString:anObject]) { + else if ([[aTableColumn identifier] isEqualToString:@"Extra"]) { + if (![[currentRow objectForKey:@"Extra"] isEqualToString:anObject]) { isCurrentExtraAutoIncrement = [[[anObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString] isEqualToString:@"AUTO_INCREMENT"]; - if(isCurrentExtraAutoIncrement) { + + if (isCurrentExtraAutoIncrement) { [currentRow setObject:[NSNumber numberWithInteger:0] forKey:@"null"]; // Asks the user to add an index to query if AUTO_INCREMENT is set and field isn't indexed @@ -162,15 +171,18 @@ contextInfo:@"autoincrementindex" ]; #endif } - } else { + } + else { autoIncrementIndex = nil; } id dataCell = [aTableColumn dataCell]; + [dataCell removeAllItems]; [dataCell addItemsWithObjectValues:extraFieldSuggestions]; [dataCell noteNumberOfItemsChanged]; [dataCell reloadData]; + [tableSourceView reloadData]; } @@ -178,10 +190,12 @@ // Reset default to "" if field doesn't allow NULL and current default is set to NULL else if ([[aTableColumn identifier] isEqualToString:@"null"]) { if ([[currentRow objectForKey:@"null"] integerValue] != [anObject integerValue]) { - if([anObject integerValue] == 0) { - if([[currentRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) + if ([anObject integerValue] == 0) { + if ([[currentRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { [currentRow setObject:@"" forKey:@"default"]; + } } + [tableSourceView reloadData]; } } @@ -238,9 +252,8 @@ return YES; } - else { - return NO; - } + + return NO; } /** @@ -457,16 +470,17 @@ column = [tableSourceView editedColumn]; // Trap the tab key, selecting the next item in the line - if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] && [tableSourceView numberOfColumns] - 1 == column) + if ([textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] && [tableSourceView numberOfColumns] - 1 == column) { //save current line [[control window] makeFirstResponder:control]; - if ( [self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) { - if ( row < ([tableSourceView numberOfRows] - 1) ) { - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row+1] byExtendingSelection:NO]; - [tableSourceView editColumn:0 row:row+1 withEvent:nil select:YES]; - } else { + if ([self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)]) { + if (row < ([tableSourceView numberOfRows] - 1)) { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row + 1] byExtendingSelection:NO]; + [tableSourceView editColumn:0 row:row + 1 withEvent:nil select:YES]; + } + else { [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO]; [tableSourceView editColumn:0 row:0 withEvent:nil select:YES]; } @@ -474,18 +488,19 @@ return YES; } - // Trap shift-tab key - else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] && column < 1) + else if ([textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] && column < 1) { - if ( [self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)] ) { + if ([self addRowToDB] && [textView methodForSelector:command] == [textView methodForSelector:@selector(insertBacktab:)]) { [[control window] makeFirstResponder:control]; - if ( row > 0) { - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row-1] byExtendingSelection:NO]; - [tableSourceView editColumn:([tableFields count]-1) row:row-1 withEvent:nil select:YES]; - } else { - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:([tableFields count]-1)] byExtendingSelection:NO]; - [tableSourceView editColumn:([tableFields count]-1) row:([tableSourceView numberOfRows]-1) withEvent:nil select:YES]; + + if (row > 0) { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row - 1] byExtendingSelection:NO]; + [tableSourceView editColumn:([tableFields count] - 1) row:row - 1 withEvent:nil select:YES]; + } + else { + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:([tableFields count] - 1)] byExtendingSelection:NO]; + [tableSourceView editColumn:([tableFields count] - 1) row:([tableSourceView numberOfRows] - 1) withEvent:nil select:YES]; } } @@ -496,8 +511,9 @@ else if ([textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)]) { // Suppress enter for non-text fields to allow selecting of chosen items from comboboxes or popups - if (![[[[[[tableSourceView tableColumns] objectAtIndex:column] dataCell] class] description] isEqualToString:@"NSTextFieldCell"]) + if (![[[[[[tableSourceView tableColumns] objectAtIndex:column] dataCell] class] description] isEqualToString:@"NSTextFieldCell"]) { return YES; + } [[control window] makeFirstResponder:control]; [self addRowToDB]; diff --git a/Source/SPTableStructureLoading.m b/Source/SPTableStructureLoading.m index d9aa6765..99406f7a 100644 --- a/Source/SPTableStructureLoading.m +++ b/Source/SPTableStructureLoading.m @@ -138,9 +138,15 @@ if (defaultEncodingDescription) { NSMenuItem *tableEncodingMenuItem = [[encodingPopupCell menu] itemWithTitle:defaultEncodingDescription]; NSMutableParagraphStyle *menuStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; + [menuStyle setLineBreakMode:NSLineBreakByTruncatingTail]; - NSDictionary *menuAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize: [NSFont smallSystemFontSize]], NSFontAttributeName, menuStyle, NSParagraphStyleAttributeName, nil]; + + NSMutableDictionary *menuAttributes = [NSMutableDictionary dictionaryWithObject:[NSColor lightGrayColor] forKey:NSForegroundColorAttributeName]; + + [menuAttributes setObject:[prefs boolForKey:SPUseMonospacedFonts] ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]; + NSAttributedString *itemString = [[[NSAttributedString alloc] initWithString:defaultEncodingDescription attributes:menuAttributes] autorelease]; + [[tableEncodingMenuItem onMainThread] setAttributedTitle:itemString]; } |