diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-03-23 09:51:46 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-03-23 09:51:46 +0000 |
commit | 331d5f6d8a9bbb16089da8522d97d584e9921d73 (patch) | |
tree | 3f6186034703520de310b8a1255acddb1eea03f4 /Source | |
parent | e47a76c457528fb2ef9fb20cf0f02d09a488a8a8 (diff) | |
download | sequelpro-331d5f6d8a9bbb16089da8522d97d584e9921d73.tar.gz sequelpro-331d5f6d8a9bbb16089da8522d97d584e9921d73.tar.bz2 sequelpro-331d5f6d8a9bbb16089da8522d97d584e9921d73.zip |
• Navigator
- gather more information
- show infos for proc/func
- improved error handling
- reduced jittering while closing a connection window
- still hidden - if navigator is not visible no navigator code will be executed
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPNavigatorController.h | 3 | ||||
-rw-r--r-- | Source/SPNavigatorController.m | 185 | ||||
-rw-r--r-- | Source/TableDocument.m | 7 |
3 files changed, 161 insertions, 34 deletions
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h index 6895a9f2..def32cba 100644 --- a/Source/SPNavigatorController.h +++ b/Source/SPNavigatorController.h @@ -59,11 +59,12 @@ - (IBAction)filterTree:(id)sender; - (IBAction)syncButtonAction:(id)sender; -- (NSString*)tableInfoLabelForIndex:(NSInteger)index; +- (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(NSInteger)type; - (void)restoreSelectedItems; - (void)setIgnoreUpdate:(BOOL)flag; - (void)selectPath:(NSString*)schemaPath; - (BOOL)syncMode; +- (void)removeConnection:(NSString*)connectionID; @end diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m index 56c51438..21389757 100644 --- a/Source/SPNavigatorController.m +++ b/Source/SPNavigatorController.m @@ -29,6 +29,7 @@ #import "ImageAndTextCell.h" #import "TableDocument.h" #import "SPArrayAdditions.h" +#import "SPLogger.h" static SPNavigatorController *sharedNavigatorController = nil; @@ -187,6 +188,7 @@ static SPNavigatorController *sharedNavigatorController = nil; id item = schemaData; NSArray *pathArray = [schemaPath componentsSeparatedByString:SPUniqueSchemaDelimiter]; + if(!pathArray || [pathArray count] == 0) return; NSMutableString *aKey = [NSMutableString string]; [outlineSchema2 collapseItem:[item objectForKey:[pathArray objectAtIndex:0]] collapseChildren:YES]; for(NSInteger i=0; i < [pathArray count]; i++) { @@ -200,6 +202,7 @@ static SPNavigatorController *sharedNavigatorController = nil; NSInteger itemIndex = [outlineSchema2 rowForItem:item]; if (itemIndex >= 0) { [outlineSchema2 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO]; + if([outlineSchema2 numberOfSelectedRows] != 1) return; [outlineSchema2 scrollRowToVisible:[outlineSchema2 selectedRow]]; id item = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]]; // Try to scroll the view that all children of schemaPath are visible if possible @@ -271,6 +274,31 @@ static SPNavigatorController *sharedNavigatorController = nil; ignoreUpdate = flag; } +- (void)removeConnection:(NSString*)connectionID +{ + if(schemaData && [schemaData objectForKey:connectionID]) { + + NSInteger docCounter = 0; + + if ([[[NSDocumentController sharedDocumentController] documents] count]) { + for(id doc in [[NSDocumentController sharedDocumentController] documents]) { + if(![[doc valueForKeyPath:@"mySQLConnection"] isConnected]) continue; + if([[doc connectionID] isEqualToString:connectionID]) + docCounter++; + if(docCounter > 1) break; + } + } + + if(docCounter > 1) return; + + [schemaData removeObjectForKey:connectionID]; + [self saveSelectedItems]; + [outlineSchema1 reloadData]; + [outlineSchema2 reloadData]; + [self restoreSelectedItems]; + } +} + #pragma mark - #pragma mark IBActions @@ -322,6 +350,10 @@ static SPNavigatorController *sharedNavigatorController = nil; [self restoreSelectedItems]; } + + [self syncButtonAction:self]; + + } - (IBAction)reloadAllStructures:(id)sender @@ -361,6 +393,9 @@ static SPNavigatorController *sharedNavigatorController = nil; - (IBAction)syncButtonAction:(id)sender { + + if(!schemaData) return; + if([syncButton state] == NSOnState) { if ([[[NSDocumentController sharedDocumentController] documents] count]) { TableDocument *doc = [[NSDocumentController sharedDocumentController] currentDocument]; @@ -389,6 +424,8 @@ static SPNavigatorController *sharedNavigatorController = nil; id parentObject = [ov parentForItem:item] ? [ov parentForItem:item] : schemaData; + if(!parentObject || ![parentObject allKeysForObject:item] || ![[parentObject allKeysForObject:item] count]) return; + if(ov == outlineSchema1) { [expandStatus1 setObject:@"" forKey:[[parentObject allKeysForObject:item] objectAtIndex:0]]; @@ -405,7 +442,9 @@ static SPNavigatorController *sharedNavigatorController = nil; id item = [[notification userInfo] objectForKey:@"NSObject"]; id parentObject = [ov parentForItem:item] ? [ov parentForItem:item] : schemaData; - + + if(!parentObject || ![parentObject allKeysForObject:item] || ![[parentObject allKeysForObject:item] count]) return; + if(ov == outlineSchema1) [expandStatus1 removeObjectForKey:[[parentObject allKeysForObject:item] objectAtIndex:0]]; else if(ov == outlineSchema2) @@ -463,6 +502,8 @@ static SPNavigatorController *sharedNavigatorController = nil; id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData; + if(!parentObject) return @"…"; + if ([[tableColumn identifier] isEqualToString:@"field"]) { // top level is connection @@ -503,17 +544,23 @@ static SPNavigatorController *sharedNavigatorController = nil; } else { [[tableColumn dataCell] setImage:[NSImage imageNamed:@"database-small"]]; } - return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject]; + if([[parentObject allKeysForObject:item] count]) + return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject]; + else + return @"…"; } else { - // It's a field and use the key " struct_type " to increase the distance between node and first child - if(![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "]) { - [[tableColumn dataCell] setImage:[NSImage imageNamed:@"field-small-square"]]; - return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject]; - } else { - [[tableColumn dataCell] setImage:[NSImage imageNamed:@"dummy-small"]]; - return nil; + if([[parentObject allKeysForObject:item] count]) { + // It's a field and use the key " struct_type " to increase the distance between node and first child + if(![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "]) { + [[tableColumn dataCell] setImage:[NSImage imageNamed:@"field-small-square"]]; + return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject]; + } else { + [[tableColumn dataCell] setImage:[NSImage imageNamed:@"dummy-small"]]; + return nil; + } } + return @"…"; } } return [item description]; @@ -535,9 +582,9 @@ static SPNavigatorController *sharedNavigatorController = nil; } } - if ([item isKindOfClass:[NSArray class]] && ![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "]) + if ([item isKindOfClass:[NSArray class]] && [item count]>5 && [[parentObject allKeysForObject:item] count] && ![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "]) { - NSString *typ = [NSString stringWithFormat:@"%@,%@,%@", [[item objectAtIndex:0] stringByReplacingOccurrencesOfRegex:@"\\(.*?,.*?\\)" withString:@"(…)"], [item objectAtIndex:1], [item objectAtIndex:2]]; + NSString *typ = [NSString stringWithFormat:@"%@,%@,%@", [[item objectAtIndex:0] stringByReplacingOccurrencesOfRegex:@"\\(.*?,.*?\\)" withString:@"(…)"], [item objectAtIndex:3], [item objectAtIndex:5]]; NSTokenFieldCell *b = [[[NSTokenFieldCell alloc] initTextCell:typ] autorelease]; [b setEditable:NO]; [b setAlignment:NSRightTextAlignment]; @@ -618,17 +665,39 @@ static SPNavigatorController *sharedNavigatorController = nil; if(selectedItem) { [infoArray removeAllObjects]; + // First object is used as dummy to increase the distance between first item and header [infoArray addObject:@""]; + + // selected item is a field if([selectedItem isKindOfClass:[NSArray class]]) { - [infoTable setRowHeight:18.0]; NSInteger i = 0; for(id item in selectedItem) { if([item isKindOfClass:[NSString class]] && [(NSString*)item length]) { - [infoArray addObject:[NSString stringWithFormat:@"%@: %@", [self tableInfoLabelForIndex:i], [item stringByReplacingOccurrencesOfString:@"," withString:@", "]]]; + [infoArray addObject:[NSString stringWithFormat:@"%@: %@", [self tableInfoLabelForIndex:i ofType:0], [item stringByReplacingOccurrencesOfString:@"," withString:@", "]]]; } i++; } } + + // check if selected item is a PROCEDURE or FUNCTION + else if([selectedItem isKindOfClass:[NSDictionary class]] && [selectedItem objectForKey:@" struct_type "] && [[selectedItem objectForKey:@" struct_type "] intValue] > 1) { + NSInteger i = 0; + NSInteger type = [[selectedItem objectForKey:@" struct_type "] intValue]; + NSArray *keys = [selectedItem allKeys]; + NSInteger keyIndex = 0; + if(keys && [keys count] == 2) { + // there only are two keys, get that key which doesn't begin with " " due to it's the struct_type key + if([[keys objectAtIndex:keyIndex] hasPrefix:@" "]) keyIndex++; + if([keys objectAtIndex:keyIndex] && [[selectedItem objectForKey:[keys objectAtIndex:keyIndex]] isKindOfClass:[NSArray class]]) { + for(id item in [selectedItem objectForKey:[keys objectAtIndex:keyIndex]]) { + if([item isKindOfClass:[NSString class]] && [(NSString*)item length]) { + [infoArray addObject:[NSString stringWithFormat:@"%@: %@", [self tableInfoLabelForIndex:i ofType:type], item]]; + } + i++; + } + } + } + } } [infoTable reloadData]; } @@ -672,7 +741,7 @@ static SPNavigatorController *sharedNavigatorController = nil; - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { - if(aTableView == infoTable) + if(aTableView == infoTable && infoArray) return [infoArray count]; return 0; @@ -687,7 +756,7 @@ static SPNavigatorController *sharedNavigatorController = nil; - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex { - if(aTableView == infoTable) + if(aTableView == infoTable && infoArray) return NO; return YES; @@ -711,27 +780,83 @@ static SPNavigatorController *sharedNavigatorController = nil; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(aTableView == infoTable) { + if(aTableView == infoTable && infoArray && rowIndex < [infoArray count]) { return [infoArray objectAtIndex:rowIndex]; } return nil; } -- (NSString*)tableInfoLabelForIndex:(NSInteger)index -{ - switch(index) { - case 0: - return NSLocalizedString(@"Type", @"type label"); - case 1: - return NSLocalizedString(@"Encoding", @"encoding label"); - case 2: - return NSLocalizedString(@"Key", @"key label"); - case 3: - return NSLocalizedString(@"Extra", @"extra label"); - case 4: - return NSLocalizedString(@"Privileges", @"Privileges label"); - } +#pragma mark - +#pragma mark others + +- (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(NSInteger)type +{ + + if(type == 0 || type == 1) // TABLE / VIEW + switch(index) { + case 0: + return NSLocalizedString(@"Type", @"type label"); + case 1: + return NSLocalizedString(@"Default", @"default label"); + case 2: + return NSLocalizedString(@"Is Nullable", @"is nullable label"); + case 3: + return NSLocalizedString(@"Encoding", @"encoding label"); + case 4: + return NSLocalizedString(@"Collation", @"collation label"); + case 5: + return NSLocalizedString(@"Key", @"key label"); + case 6: + return NSLocalizedString(@"Extra", @"extra label"); + case 7: + return NSLocalizedString(@"Privileges", @"privileges label"); + case 8: + return NSLocalizedString(@"Comment", @"comment label"); + } + + if(type == 2) // PROCEDURE + switch(index) { + case 0: + return @"DTD Identifier"; + case 1: + return NSLocalizedString(@"Default", @"default label"); + case 2: + return @"SQL Data Access"; + case 3: + return NSLocalizedString(@"Encoding", @"encoding label"); + case 4: + return NSLocalizedString(@"Collation", @"collation label"); + case 5: + return @"Is Deterministic"; + case 6: + return @"Security Type"; + case 7: + return @"Definer"; + case 8: + return NSLocalizedString(@"Comment", @"comment label"); + } + if(type == 3) // FUNCTION + switch(index) { + case 0: + return NSLocalizedString(@"Return Type", @"return type label"); + case 1: + return NSLocalizedString(@"Default", @"default label"); + case 2: + return @"SQL Data Access"; + case 3: + return NSLocalizedString(@"Encoding", @"encoding label"); + case 4: + return NSLocalizedString(@"Collation", @"collation label"); + case 5: + return @"Is Deterministic"; + case 6: + return NSLocalizedString(@"Execution Privilege", @"execution privilege label"); + case 7: + return @"Definer"; + case 8: + return NSLocalizedString(@"Comment", @"comment label"); + } return @""; } @end diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 4580e392..797631e3 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1176,8 +1176,6 @@ { BOOL isNavigatorVisible = [[[SPNavigatorController sharedNavigatorController] window] isVisible]; - // If the Console window is not visible data are not reloaded (for speed). - // Due to that update list if user opens the Console window. if(!isNavigatorVisible) { [[SPNavigatorController sharedNavigatorController] updateEntries:self]; } @@ -3668,11 +3666,14 @@ */ - (void)windowWillClose:(NSNotification *)aNotification { + if ([[[SPNavigatorController sharedNavigatorController] window] isVisible]) { + [[SPNavigatorController sharedNavigatorController] removeConnection:[self connectionID]]; + } + [mySQLConnection setDelegate:nil]; if (_isConnected) [self closeConnection]; else [connectionController cancelConnection]; if ([[[SPQueryController sharedQueryController] window] isVisible]) [self toggleConsole:self]; - if ([[[SPNavigatorController sharedNavigatorController] window] isVisible]) [self updateNavigator:self]; [createTableSyntaxWindow orderOut:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } |