aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/Navigator.xib12
-rw-r--r--Source/SPNavigatorController.h10
-rw-r--r--Source/SPNavigatorController.m188
-rw-r--r--Source/TableDocument.m3
4 files changed, 167 insertions, 46 deletions
diff --git a/Interfaces/English.lproj/Navigator.xib b/Interfaces/English.lproj/Navigator.xib
index 5c96d372..d4dd1904 100644
--- a/Interfaces/English.lproj/Navigator.xib
+++ b/Interfaces/English.lproj/Navigator.xib
@@ -21,7 +21,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="15"/>
+ <integer value="97"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -66,7 +66,7 @@
<object class="NSSearchField" id="701533802">
<reference key="NSNextResponder" ref="881437593"/>
<int key="NSvFlags">270</int>
- <string key="NSFrame">{{20, 337}, {241, 19}}</string>
+ <string key="NSFrame">{{20, 336}, {241, 19}}</string>
<reference key="NSSuperview" ref="881437593"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
<bool key="NSEnabled">YES</bool>
@@ -167,7 +167,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSScrollView" id="667909124">
<reference key="NSNextResponder" ref="978368259"/>
- <int key="NSvFlags">274</int>
+ <int key="NSvFlags">4370</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSClipView" id="415327048">
@@ -375,7 +375,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSScrollView" id="1023753551">
<reference key="NSNextResponder" ref="556163261"/>
- <int key="NSvFlags">274</int>
+ <int key="NSvFlags">4370</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSClipView" id="817352949">
@@ -385,7 +385,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSOutlineView" id="771350217">
<reference key="NSNextResponder" ref="817352949"/>
- <int key="NSvFlags">4352</int>
+ <int key="NSvFlags">256</int>
<string key="NSFrameSize">{394, 177}</string>
<reference key="NSSuperview" ref="817352949"/>
<int key="NSViewLayerContentsRedrawPolicy">2</int>
@@ -674,7 +674,7 @@
</object>
<object class="NSTextFieldCell" key="NSDataCell" id="1070719064">
<int key="NSCellFlags">67239488</int>
- <int key="NSCellFlags2">133120</int>
+ <int key="NSCellFlags2">268568576</int>
<string key="NSContents">Text Cell</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSControlView" ref="501833340"/>
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h
index 43b7a1a8..c0789c4f 100644
--- a/Source/SPNavigatorController.h
+++ b/Source/SPNavigatorController.h
@@ -42,6 +42,12 @@
NSMutableDictionary *expandStatus1;
NSMutableDictionary *expandStatus2;
+ NSString *selectedKey1;
+ NSString *selectedKey2;
+ NSRect selectionViewPort1;
+ NSRect selectionViewPort2;
+ BOOL ignoreUpdate;
+
}
+ (SPNavigatorController *)sharedNavigatorController;
@@ -52,4 +58,8 @@
- (IBAction)filterTree:(id)sender;
- (NSString*)tableInfoLabelForIndex:(NSInteger)index;
+
+- (void)restoreSelectedItems;
+- (void)setIgnoreUpdate:(BOOL)flag;
+
@end
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index eb3afb48..050df716 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -63,7 +63,9 @@ static SPNavigatorController *sharedNavigatorController = nil;
expandStatus1 = [[NSMutableDictionary alloc] init];
expandStatus2 = [[NSMutableDictionary alloc] init];
infoArray = [[NSMutableArray alloc] init];
-
+ selectedKey1 = @"";
+ selectedKey2 = @"";
+ ignoreUpdate = NO;
}
return self;
@@ -109,6 +111,9 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (void)restoreExpandStatus
{
+
+ if(!schemaData) return;
+
NSInteger i;
for( i = 0; i < [outlineSchema1 numberOfRows]; i++ ) {
id item = [outlineSchema1 itemAtRow:i];
@@ -120,7 +125,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
for( i = 0; i < [outlineSchema2 numberOfRows]; i++ ) {
id item = [outlineSchema2 itemAtRow:i];
- id parentObject = [outlineSchema1 parentForItem:item] ? [outlineSchema2 parentForItem:item] : schemaData;
+ id parentObject = [outlineSchema2 parentForItem:item] ? [outlineSchema2 parentForItem:item] : schemaData;
id parentKeys = [parentObject allKeysForObject:item];
if(parentKeys && [parentKeys count] == 1)
if( [expandStatus2 objectForKey:[parentKeys objectAtIndex:0]] )
@@ -128,20 +133,107 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
}
+- (void)saveSelectedItems
+{
+ selectedKey1 = @"";
+ selectedKey2 = @"";
+ selectionViewPort1 = [outlineSchema1 visibleRect];
+ selectionViewPort2 = [outlineSchema2 visibleRect];
+ if(schemaData) {
+ id selection = nil;
+ selection = [outlineSchema1 itemAtRow:[outlineSchema1 selectedRow]];
+ 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]];
+ if(selection) {
+ id parentObject = [outlineSchema2 parentForItem:selection] ? [outlineSchema2 parentForItem:selection] : schemaData;
+ id parentKeys = [parentObject allKeysForObject:selection];
+ if(parentKeys && [parentKeys count] == 1)
+ selectedKey2 = [[parentKeys objectAtIndex:0] description];
+ }
+ }
+
+}
+
+- (void)restoreSelectedItems
+{
+
+ if(!schemaData) return;
+
+ BOOL viewportWasValid1 = NO;
+ BOOL viewportWasValid2 = NO;
+ selectionViewPort1.size = [outlineSchema1 visibleRect].size;
+ selectionViewPort2.size = [outlineSchema2 visibleRect].size;
+ viewportWasValid1 = [outlineSchema1 scrollRectToVisible:selectionViewPort1];
+ viewportWasValid2 = [outlineSchema2 scrollRectToVisible:selectionViewPort2];
+ if(selectedKey1 && [selectedKey1 length]) {
+ id item = schemaData;
+ NSArray *pathArray = [selectedKey1 componentsSeparatedByString:SPUniqueSchemaDelimiter];
+ NSMutableString *aKey = [NSMutableString string];
+ for(NSInteger i=0; i < [pathArray count]; i++) {
+ [aKey appendString:[pathArray objectAtIndex:i]];
+ if(![item objectForKey:aKey]) break;
+ item = [item objectForKey:aKey];
+ [aKey appendString:SPUniqueSchemaDelimiter];
+ }
+ if(item != nil) {
+ NSInteger itemIndex = [outlineSchema1 rowForItem:item];
+ if (itemIndex >= 0) {
+ [outlineSchema1 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
+ if(!viewportWasValid1)
+ [outlineSchema1 scrollRowToVisible:[outlineSchema1 selectedRow]];
+ }
+ }
+ }
+ if(selectedKey2 && [selectedKey2 length]) {
+ id item = schemaData;
+ NSArray *pathArray = [selectedKey2 componentsSeparatedByString:SPUniqueSchemaDelimiter];
+ NSMutableString *aKey = [NSMutableString string];
+ for(NSInteger i=0; i < [pathArray count]; i++) {
+ [aKey appendString:[pathArray objectAtIndex:i]];
+ if(![item objectForKey:aKey]) break;
+ item = [item objectForKey:aKey];
+ [aKey appendString:SPUniqueSchemaDelimiter];
+ }
+ if(item != nil) {
+ NSInteger itemIndex = [outlineSchema2 rowForItem:item];
+ if (itemIndex >= 0) {
+ [outlineSchema2 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
+ if(!viewportWasValid2)
+ [outlineSchema2 scrollRowToVisible:[outlineSchema2 selectedRow]];
+ }
+ }
+ }
+}
+
+- (void)setIgnoreUpdate:(BOOL)flag
+{
+ ignoreUpdate = flag;
+}
+
#pragma mark -
#pragma mark IBActions
- (IBAction)updateEntries:(id)sender;
{
- id selectedItem1 = nil;
- id selectedItem2 = nil;
- if(schemaData) {
- selectedItem1 = [outlineSchema1 itemAtRow:[outlineSchema1 selectedRow]];
- selectedItem2 = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]];
- [schemaData release];
- schemaData = nil;
+
+ if(ignoreUpdate) {
+ ignoreUpdate = NO;
+ return;
}
- schemaData = [[NSMutableDictionary alloc] init];
+
+ [self saveSelectedItems];
+
+ [infoArray removeAllObjects];
+ [schemaData removeAllObjects];
+
+ [outlineSchema1 reloadData];
+ [outlineSchema2 reloadData];
+
if ([[[NSDocumentController sharedDocumentController] documents] count]) {
for(id doc in [[NSDocumentController sharedDocumentController] documents]) {
@@ -158,9 +250,9 @@ static SPNavigatorController *sharedNavigatorController = nil;
} else {
if([[doc valueForKeyPath:@"mySQLConnection"] serverMajorVersion] > 4) {
- [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@ – no data loaded yet", connectionName]];
+ [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data loaded yet", connectionName]];
} else {
- [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@ – no data for this server version", connectionName]];
+ [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data for this server version", connectionName]];
}
}
@@ -169,39 +261,27 @@ static SPNavigatorController *sharedNavigatorController = nil;
[outlineSchema1 reloadData];
[outlineSchema2 reloadData];
- // [self performSelector:@selector(restoreExpandStatus) withObject:nil afterDelay:0.2];
- [self restoreExpandStatus];
- if(selectedItem1) {
- NSInteger itemIndex = [outlineSchema1 rowForItem:selectedItem1];
- if (itemIndex < 0) {
- return;
- }
- [outlineSchema1 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
- }
- if(selectedItem2) {
- NSInteger itemIndex = [outlineSchema2 rowForItem:selectedItem2];
- if (itemIndex < 0) {
- return;
- }
+ [self restoreExpandStatus];
+ [self restoreSelectedItems];
- [outlineSchema2 selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
- }
}
}
- (IBAction)reloadAllStructures:(id)sender
{
- if(schemaData) {
- [schemaData release];
- schemaData = nil;
- }
- schemaData = [[NSMutableDictionary alloc] init];
+ // Reset everything
+ [schemaData removeAllObjects];
[infoArray removeAllObjects];
-
+ [expandStatus1 removeAllObjects];
+ [expandStatus2 removeAllObjects];
[outlineSchema1 reloadData];
[outlineSchema2 reloadData];
+ selectedKey1 = @"";
+ selectedKey2 = @"";
+ selectionViewPort1 = NSZeroRect;
+ selectionViewPort2 = NSZeroRect;
if ([[[NSDocumentController sharedDocumentController] documents] count]) {
for(id doc in [[NSDocumentController sharedDocumentController] documents]) {
@@ -288,6 +368,8 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (NSInteger)outlineView:(id)outlineView numberOfChildrenOfItem:(id)item
{
+ if(!schemaData) return 0;
+
if(item == nil)
return [schemaData count];
@@ -300,6 +382,8 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (id)outlineView:(id)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
+ if(!schemaData) return @"";
+
id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData;
if ([[tableColumn identifier] isEqualToString:@"field"]) {
@@ -307,7 +391,17 @@ static SPNavigatorController *sharedNavigatorController = nil;
// top level is connection
if([outlineView levelForItem:item] == 0) {
[[tableColumn dataCell] setImage:[NSImage imageNamed:@"network-small"]];
- return [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:@"&SSH&"] objectAtIndex:0];
+ if([parentObject allKeysForObject:item] && [[parentObject allKeysForObject:item] count]) {
+ NSString *key = [[parentObject allKeysForObject:item] objectAtIndex:0];
+ if([key rangeOfString:@"&SSH&"].length)
+ return [[key componentsSeparatedByString:@"&SSH&"] objectAtIndex:0];
+ else if([key rangeOfString:@"&DEL&"].length)
+ return [[key componentsSeparatedByString:@"&DEL&"] objectAtIndex:0];
+ else
+ return key;
+ } else {
+ return @"";
+ }
}
if ([parentObject isKindOfClass:[NSDictionary class]]) {
@@ -349,8 +443,19 @@ static SPNavigatorController *sharedNavigatorController = nil;
}
else if ([[tableColumn identifier] isEqualToString:@"type"]) {
- if([outlineView levelForItem:item] == 0 && [[[parentObject allKeysForObject:item] objectAtIndex:0] rangeOfString:@"&SSH&"].length) {
- return [NSString stringWithFormat:@"ssh: %@", [[[[parentObject allKeysForObject:item] objectAtIndex:0] componentsSeparatedByString:@"&SSH&"] lastObject]];
+ // top level is connection
+ if([outlineView levelForItem:item] == 0) {
+ 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]];
+ else if([key rangeOfString:@"&DEL&"].length)
+ return [[key componentsSeparatedByString:@"&DEL&"] lastObject];
+ else
+ return @"";
+ } else {
+ return @"";
+ }
}
if ([item isKindOfClass:[NSArray class]] && ![[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "])
@@ -383,7 +488,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData;
// Use " struct_type " as placeholder to increase distance between table and first field name otherwise it looks ugly
- if([[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "])
+ if([parentObject allKeysForObject:item] && [[parentObject allKeysForObject:item] count] && [[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "])
return 5.0;
return 18.0;
@@ -397,7 +502,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData;
- if([[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "])
+ if([parentObject allKeysForObject:item] && [[parentObject allKeysForObject:item] count] && [[[parentObject allKeysForObject:item] objectAtIndex:0] hasPrefix:@" "])
return NO;
return YES;
}
@@ -411,6 +516,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
} else if (ov == outlineSchema2) {
selectedItem = [outlineSchema2 itemAtRow:[outlineSchema2 selectedRow]];
}
+
if(selectedItem) {
[infoArray removeAllObjects];
[infoArray addObject:@""];
@@ -442,7 +548,8 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
- return (row == 0) ? 5.0 : [tableView rowHeight];
+ // Use first row as dummy to increase the distance between content and header
+ return (row == 0) ? 5.0 : 15; //[tableView rowHeight];
}
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
@@ -459,6 +566,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
if(aTableView == infoTable) {
if(rowIndex == 0) {
[(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"dummy-small"]];
+ [(ImageAndTextCell*)aCell setIndentationLevel:0];
[(ImageAndTextCell*)aCell setDrawsBackground:NO];
} else {
[(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-property"]];
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index bd9998b2..36291911 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -854,6 +854,9 @@
// Lock editability again if performing a task
if (_isWorkingLevel) databaseListIsSelectable = NO;
+ // Do not update the navigator since nothing is changed
+ [[SPNavigatorController sharedNavigatorController] setIgnoreUpdate:YES];
+
// Start a task
[self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading database '%@'...", @"Loading database task string"), [chooseDatabaseButton titleOfSelectedItem]]];
if ([NSThread isMainThread]) {