diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-03-24 12:31:16 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-03-24 12:31:16 +0000 |
commit | 47f354070f1fa8dfeb46c4065075ee53de4c1626 (patch) | |
tree | f3fd6c947d3966baa4cf59d08b8ca02f0a756256 /Source | |
parent | 1ddc896d2f88bea86e4b0457d63f7a53b846851d (diff) | |
download | sequelpro-47f354070f1fa8dfeb46c4065075ee53de4c1626.tar.gz sequelpro-47f354070f1fa8dfeb46c4065075ee53de4c1626.tar.bz2 sequelpro-47f354070f1fa8dfeb46c4065075ee53de4c1626.zip |
• Navigator
- ENTER and RETURN selects schema path in active connection window
- outsourced some stuff to SPNavigatorOutlineView
• added rotating sync arrows to project for future usage
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPNavigatorController.h | 6 | ||||
-rw-r--r-- | Source/SPNavigatorController.m | 122 | ||||
-rw-r--r-- | Source/SPNavigatorOutlineView.h | 2 | ||||
-rw-r--r-- | Source/SPNavigatorOutlineView.m | 18 |
4 files changed, 99 insertions, 49 deletions
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h index def32cba..52ce30ef 100644 --- a/Source/SPNavigatorController.h +++ b/Source/SPNavigatorController.h @@ -36,9 +36,14 @@ IBOutlet id searchField; IBOutlet id syncButton; + IBOutlet id infoQuickAccessSplitView; + IBOutlet id schemaStatusSplitView; + IBOutlet id schema12SplitView; + NSUserDefaults *prefs; NSMutableDictionary *schemaData; + NSMutableDictionary *schemaDataUnFiltered; NSMutableArray *infoArray; NSMutableDictionary *expandStatus1; NSMutableDictionary *expandStatus2; @@ -66,5 +71,6 @@ - (void)selectPath:(NSString*)schemaPath; - (BOOL)syncMode; - (void)removeConnection:(NSString*)connectionID; +- (void)selectInActiveDocumentItem:(id)item fromView:(id)outlineView; @end diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m index 757797ee..46780402 100644 --- a/Source/SPNavigatorController.m +++ b/Source/SPNavigatorController.m @@ -33,6 +33,7 @@ #import "SPLogger.h" #import "SPTooltip.h" + static SPNavigatorController *sharedNavigatorController = nil; #define DragFromNavigatorPboardType @"SPDragFromNavigatorPboardType" @@ -66,6 +67,7 @@ static SPNavigatorController *sharedNavigatorController = nil; if((self = [super initWithWindowNibName:@"Navigator"])) { schemaData = [[NSMutableDictionary alloc] init]; + schemaDataUnFiltered = [[NSMutableDictionary alloc] init]; expandStatus1 = [[NSMutableDictionary alloc] init]; expandStatus2 = [[NSMutableDictionary alloc] init]; infoArray = [[NSMutableArray alloc] init]; @@ -73,6 +75,7 @@ static SPNavigatorController *sharedNavigatorController = nil; selectedKey2 = @""; ignoreUpdate = NO; [syncButton setState:NSOffState]; + } return self; @@ -82,6 +85,7 @@ static SPNavigatorController *sharedNavigatorController = nil; - (void)dealloc { if(schemaData) [schemaData release]; + if(schemaDataUnFiltered) [schemaDataUnFiltered release]; if(infoArray) [infoArray release]; if(expandStatus1) [expandStatus1 release]; if(expandStatus2) [expandStatus2 release]; @@ -122,6 +126,8 @@ static SPNavigatorController *sharedNavigatorController = nil; return @"SPNavigator"; } +#pragma mark - + - (BOOL)syncMode { if([[self window] isVisible]) @@ -161,14 +167,14 @@ static SPNavigatorController *sharedNavigatorController = nil; selectionViewPort2 = [outlineSchema2 visibleRect]; if(schemaData) { id selection = nil; - selection = [outlineSchema1 itemAtRow:[outlineSchema1 selectedRow]]; + selection = [outlineSchema1 selectedItem]; if(selection) { id parentObject = [outlineSchema1 parentForItem:selection] ? [outlineSchema1 parentForItem:selection] : schemaData; id parentKeys = [parentObject allKeysForObject:selection]; if(parentKeys && [parentKeys count] == 1) selectedKey1 = [[parentKeys objectAtIndex:0] description]; } - selection = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]]; + selection = [outlineSchema2 selectedItem]; if(selection) { id parentObject = [outlineSchema2 parentForItem:selection] ? [outlineSchema2 parentForItem:selection] : schemaData; id parentKeys = [parentObject allKeysForObject:selection]; @@ -206,7 +212,7 @@ static SPNavigatorController *sharedNavigatorController = nil; [outlineSchema2 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO]; if([outlineSchema2 numberOfSelectedRows] != 1) return; [outlineSchema2 scrollRowToVisible:[outlineSchema2 selectedRow]]; - id item = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]]; + id item = [outlineSchema2 selectedItem]; // Try to scroll the view that all children of schemaPath are visible if possible NSInteger cnt = [item count]+1; NSRange r = [outlineSchema2 rowsInRect:[outlineSchema2 visibleRect]]; @@ -301,6 +307,43 @@ static SPNavigatorController *sharedNavigatorController = nil; } } +- (void)selectInActiveDocumentItem:(id)item fromView:(id)outlineView +{ + if([outlineView levelForItem:item] == 0) return; + + id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData; + id parentKeys = [parentObject allKeysForObject:item]; + if(parentKeys && [parentKeys count] == 1) { + + NSPoint pos = [NSEvent mouseLocation]; + pos.y -= 20; + + NSArray *pathArray = [[[parentKeys objectAtIndex:0] description] componentsSeparatedByString:SPUniqueSchemaDelimiter]; + if([pathArray count] > 1) { + + TableDocument *doc = [[NSDocumentController sharedDocumentController] currentDocument]; + if([doc isWorking]) { + [SPTooltip showWithObject:NSLocalizedString(@"Active connection window is busy. Please wait and try again.", @"active connection window is busy. please wait and try again. tooltip") + atLocation:pos + ofType:@"text"]; + return; + } + if([[doc connectionID] isEqualToString:[pathArray objectAtIndex:0]]) { + + // Select the database and table + [doc selectDatabase:[pathArray objectAtIndex:1] item:([pathArray count] > 2)?[pathArray objectAtIndex:2]:nil]; + + } else { + + [SPTooltip showWithObject:NSLocalizedString(@"The connection of the active connection window is not identical.", @"the connection of the active connection window is not identical tooltip") + atLocation:pos + ofType:@"text"]; + + } + } + } +} + #pragma mark - #pragma mark IBActions @@ -574,7 +617,7 @@ static SPNavigatorController *sharedNavigatorController = nil; if([parentObject allKeysForObject:item] && [[parentObject allKeysForObject:item] count]) { NSString *key = [[parentObject allKeysForObject:item] objectAtIndex:0]; if([key rangeOfString:@"&SSH&"].length) - return [NSString stringWithFormat:@"ssh: %@", [[key componentsSeparatedByString:@"&SSH&"] lastObject]]; + return [NSString stringWithFormat:@"ssh: %@", [[[key componentsSeparatedByString:@"&SSH&"] lastObject] stringByReplacingOccurrencesOfString:@"&DEL&" withString:@" - "]]; else if([key rangeOfString:@"&DEL&"].length) return [[key componentsSeparatedByString:@"&DEL&"] lastObject]; else @@ -637,48 +680,7 @@ static SPNavigatorController *sharedNavigatorController = nil; */ - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item { - if([outlineView levelForItem:item] == 0) return NO; - - id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData; - id parentKeys = [parentObject allKeysForObject:item]; - if(parentKeys && [parentKeys count] == 1) { - - NSPoint pos = [NSEvent mouseLocation]; - pos.y -= 20; - - // Do not allow to double-click at PROCs and FUNCs since it doesn't make sense - if([item isKindOfClass:[NSDictionary class]] && [item objectForKey:@" struct_type "] && [[item objectForKey:@" struct_type "] intValue] > 1) { - [SPTooltip showWithObject:NSLocalizedString(@"You only can select tables or views.", @"you only can select tables or views tooltip") - atLocation:pos - ofType:@"text"]; - return NO; - } - - NSArray *pathArray = [[[parentKeys objectAtIndex:0] description] componentsSeparatedByString:SPUniqueSchemaDelimiter]; - if([pathArray count] > 1) { - - TableDocument *doc = [[NSDocumentController sharedDocumentController] currentDocument]; - if([doc isWorking]) { - [SPTooltip showWithObject:NSLocalizedString(@"Active connection window is busy. Please wait and try again.", @"active connection window is busy. please wait and try again. tooltip") - atLocation:pos - ofType:@"text"]; - return NO; - } - if([[doc connectionID] isEqualToString:[pathArray objectAtIndex:0]]) { - - // Select the database and table - [doc selectDatabase:[pathArray objectAtIndex:1] item:([pathArray count] > 2)?[pathArray objectAtIndex:2]:nil]; - - } else { - [SPTooltip showWithObject:NSLocalizedString(@"The connection of the active connection window is not identical.", @"the connection of the active connection window is not identical tooltip") - atLocation:pos - ofType:@"text"]; - } - return YES; - } - } - - + [self selectInActiveDocumentItem:item fromView:outlineView]; return NO; } @@ -687,9 +689,9 @@ static SPNavigatorController *sharedNavigatorController = nil; id ov = [aNotification object]; id selectedItem; if(ov == outlineSchema1) { - selectedItem = [outlineSchema1 itemAtRow:[outlineSchema1 selectedRow]]; + selectedItem = [outlineSchema1 selectedItem]; } else if (ov == outlineSchema2) { - selectedItem = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]]; + selectedItem = [outlineSchema2 selectedItem]; } if(selectedItem) { @@ -731,6 +733,19 @@ static SPNavigatorController *sharedNavigatorController = nil; [infoTable reloadData]; } +- (void)outlineView:(NSOutlineView *)outlineView didClickTableColumn:(NSTableColumn *)tableColumn +{ + if(outlineView == outlineSchema1) { + [infoQuickAccessSplitView setPosition:0 ofDividerAtIndex:0]; + [schemaStatusSplitView setPosition:1000 ofDividerAtIndex:0]; + [schema12SplitView setPosition:1000 ofDividerAtIndex:0]; + } else if(outlineView == outlineSchema2) { + [infoQuickAccessSplitView setPosition:0 ofDividerAtIndex:0]; + [schemaStatusSplitView setPosition:1000 ofDividerAtIndex:0]; + [schema12SplitView setPosition:0 ofDividerAtIndex:0]; + } +} + - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard { // Provide data for our custom type, and simple NSStrings. @@ -816,6 +831,17 @@ static SPNavigatorController *sharedNavigatorController = nil; return nil; } +- (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)tableColumn +{ + + if(tableView == infoTable || tableView == quickAccessTable) { + [infoQuickAccessSplitView setPosition:1000 ofDividerAtIndex:0]; + [schemaStatusSplitView setPosition:200 ofDividerAtIndex:0]; + [outlineSchema1 scrollRowToVisible:[outlineSchema1 selectedRow]]; + [outlineSchema2 scrollRowToVisible:[outlineSchema2 selectedRow]]; + } +} + #pragma mark - #pragma mark others diff --git a/Source/SPNavigatorOutlineView.h b/Source/SPNavigatorOutlineView.h index 70c5d28f..a87fa195 100644 --- a/Source/SPNavigatorOutlineView.h +++ b/Source/SPNavigatorOutlineView.h @@ -30,4 +30,6 @@ } +- (id)selectedItem; + @end diff --git a/Source/SPNavigatorOutlineView.m b/Source/SPNavigatorOutlineView.m index 26a37198..ee41620f 100644 --- a/Source/SPNavigatorOutlineView.m +++ b/Source/SPNavigatorOutlineView.m @@ -24,6 +24,7 @@ // More info at <http://code.google.com/p/sequel-pro/> #import "SPNavigatorOutlineView.h" +#import "SPNavigatorController.h" @implementation SPNavigatorOutlineView @@ -35,10 +36,25 @@ - (void)keyDown:(NSEvent *)theEvent { + // Enter or Return selects in active document the chosen item if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) { - ; + [[self delegate] selectInActiveDocumentItem:[self itemAtRow:[self selectedRow]] fromView:self]; + return; } + [super keyDown:theEvent]; } +/* + * Return the data source item of the selected row, if no or multiple selections + * return nil + */ +- (id)selectedItem +{ + if([self numberOfSelectedRows] == 1) + return [self itemAtRow:[self selectedRow]]; + + return nil; +} + @end |