From abbd5a52c00538ef93f4222a3e2489ee5e4c23aa Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 21 Aug 2009 13:01:46 +0000 Subject: =?UTF-8?q?=E2=80=A2=20first=20preparations=20to=20save=20the=20cu?= =?UTF-8?q?rrent=20connection=20window=20as=20SPF=20file=20=E2=80=A2=20add?= =?UTF-8?q?ed=20to=20TableContent's=20method=20filterSettings=20the=20dict?= =?UTF-8?q?=20key=20'filterComparisonTag'=20in=20order=20to=20be=20able=20?= =?UTF-8?q?to=20rely=20on=20menu=20item=20tags=20instead=20on=20the=20titl?= =?UTF-8?q?e=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableDocument.m | 70 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'Source/TableDocument.m') diff --git a/Source/TableDocument.m b/Source/TableDocument.m index ea1b418a..3abd32aa 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1806,7 +1806,75 @@ return; } else if(contextInfo == @"saveSPFfile") { - NSLog(@"Save SPF file"); + + NSMutableDictionary *spf = [NSMutableDictionary dictionary]; + + NSIndexSet *contentSelectedIndexSet = [tableContentInstance selectedRowIndexes]; + NSIndexSet *customQuerySelectedIndexSet = [[customQueryInstance valueForKeyPath:@"customQueryView"] selectedRowIndexes]; + + [spf setObject:[NSNumber numberWithInt:1] forKey:@"version"]; + + [spf setObject:[self name] forKey:@"name"]; + [spf setObject:[self host] forKey:@"host"]; + [spf setObject:[self user] forKey:@"user"]; + + [spf setObject:[NSNumber numberWithInt:[connectionController type]] forKey:@"connectionType"]; + if([connectionController type] == 2) { + [spf setObject:[connectionController sshHost] forKey:@"sshHost"]; + [spf setObject:[connectionController sshUser] forKey:@"sshUser"]; + [spf setObject:[connectionController sshPort] forKey:@"sshPort"]; + } + + if([connectionController port] &&[[connectionController port] length]) + [spf setObject:[connectionController port] forKey:@"port"]; + + if([[self database] length]) + [spf setObject:[self database] forKey:@"selectedDatabase"]; + if([[self table] length]) + [spf setObject:[self table] forKey:@"selectedTable"]; + if([tableContentInstance sortColumnName]) + [spf setObject:[tableContentInstance sortColumnName] forKey:@"contentSortCol"]; + + [spf setObject:[NSNumber numberWithInt:[spHistoryControllerInstance currentlySelectedView]] forKey:@"view"]; + [spf setObject:[NSNumber numberWithBool:[tableContentInstance sortColumnIsAscending]] forKey:@"contentSortColIsAsc"]; + [spf setObject:[NSNumber numberWithInt:[tableContentInstance limitStart]] forKey:@"contentLimitStartPosition"]; + [spf setObject:NSStringFromRect([tableContentInstance viewport]) forKey:@"contentViewport"]; + if([tableContentInstance filterSettings]) + [spf setObject:[tableContentInstance filterSettings] forKey:@"contentFilter"]; + + if([[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string] length]) + [spf setObject:[[[customQueryInstance valueForKeyPath:@"textView"] textStorage] string] forKey:@"queries"]; + + if (contentSelectedIndexSet && [contentSelectedIndexSet count]) + [spf setObject:contentSelectedIndexSet forKey:@"contentSelectedIndexSet"]; + if (customQuerySelectedIndexSet && [customQuerySelectedIndexSet count]) + [spf setObject:customQuerySelectedIndexSet forKey:@"customQuerySelectedIndexSet"]; + + NSString *err = nil; + NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spf + format:NSPropertyListBinaryFormat_v1_0 + errorDescription:&err]; + + if(err != nil) { + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data")] + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:err]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + return; + } + + NSError *error = nil; + [plist writeToFile:fileName options:NSAtomicWrite error:&error]; + if(error != nil){ + NSAlert *errorAlert = [NSAlert alertWithError:error]; + [errorAlert runModal]; + return; + } + return; } } -- cgit v1.2.3