aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-03 15:18:37 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-03 15:18:37 +0000
commit623b55eeb355aaceb3ffe3e13197944bef6fb1d4 (patch)
tree11c8538c58a4fc37d7de7821162b5dcc983abe2d /Source/TableDocument.m
parent8a8ba1fecaf8d51a964d09c04d6065b3769dea5f (diff)
downloadsequelpro-623b55eeb355aaceb3ffe3e13197944bef6fb1d4.tar.gz
sequelpro-623b55eeb355aaceb3ffe3e13197944bef6fb1d4.tar.bz2
sequelpro-623b55eeb355aaceb3ffe3e13197944bef6fb1d4.zip
• fixed document registering with its query favorites and history
• added and applied removeRegisteredDocumentWithURL to remove a registered document from the app-wide query fav/history controller • saveDocumentWithFilePath now returns the success status after saving - if saving fails for some reasons SP suggests to save that doc under a new name • fixed issues for "Save" an Untitled doc • improved error handling
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m65
1 files changed, 39 insertions, 26 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index c2b7e45f..8d0ad62b 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -87,7 +87,7 @@
queryEditorInitString = nil;
spfSession = nil;
- spfPreferences = nil;
+ spfPreferences = [[NSMutableDictionary alloc] init];
spfDocData = [[NSMutableDictionary alloc] init];
}
@@ -411,13 +411,10 @@
[self setFileURL:[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
- if([spf objectForKey:@"queryFavorites"] || [spf objectForKey:@"queryHistory"]) {
- spfPreferences = [NSDictionary dictionaryWithObjectsAndKeys:
- [spf objectForKey:@"queryFavorites"], @"queryFavorites",
- [spf objectForKey:@"queryHistory"], @"queryHistory",
- nil];
- }
-
+ if([spf objectForKey:@"queryFavorites"])
+ [spfPreferences setObject:[spf objectForKey:@"queryFavorites"] forKey:@"queryFavorites"];
+ if([spf objectForKey:@"queryHistory"])
+ [spfPreferences setObject:[spf objectForKey:@"queryHistory"] forKey:@"queryHistory"];
[spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"auto_connect"];
if([spf objectForKey:@"auto_connect"] && [[spf valueForKey:@"auto_connect"] boolValue]) {
@@ -600,9 +597,11 @@
else
[tableWindow makeFirstResponder:[tablesListInstance valueForKeyPath:@"tablesListView"]];
- NSURL *anURL = [[SPQueryConsole sharedQueryConsole] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences];
+ NSURL *anURL = [[SPQueryConsole sharedQueryConsole] registerDocumentWithFileURL:[self fileURL] andContextInfo:[spfPreferences retain]];
[self setFileURL:anURL];
+ [spfPreferences release];
+
if(spfSession != nil)
[self restoreSession];
@@ -1924,9 +1923,12 @@
*/
- (void)applicationWillTerminate:(NSNotification *)notification
{
- // Auto-save spf file based connection
+ // Auto-save preferences to spf file based connection
if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
- [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
+ if(![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) {
+ NSLog(@"Preference data for file ‘%@’ could not be saved.", [[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
+ NSBeep();
+ }
[tablesListInstance selectionShouldChangeInTableView:nil];
}
@@ -1975,9 +1977,9 @@
// Save As… or Save
} else if([sender tag] == 1005 || [sender tag] == 1004) {
- // If Save was invoked check for fileURL and save the spf file without save panel
+ // If Save was invoked check for fileURL and Untitled docs and save the spf file without save panel
// otherwise ask for file name
- if([sender tag] == 1004 && [[[self fileURL] absoluteString] length]) {
+ if([sender tag] == 1004 && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) {
[self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:NO];
return;
}
@@ -2096,11 +2098,11 @@
}
}
-- (void)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences
+- (BOOL)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences
{
// Do not save if no connection is/was available
if(saveInBackground && ([self mySQLVersion] == nil || ![[self mySQLVersion] length]))
- return;
+ return NO;
NSMutableDictionary *spfDocData_temp = [NSMutableDictionary dictionary];
@@ -2128,7 +2130,7 @@
// Check for save file URL
// TODO maybe alert ?
- if(![[[self fileURL] absoluteString] length]) return;
+ if(![[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) return NO;
NSError *readError = nil;
NSString *convError = nil;
@@ -2145,19 +2147,19 @@
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")];
+ informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read. Please try to save the document under a different name.", @"message error while reading connection data file and suggesting to save it under a differnet name")];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
- [self close];
- return;
+ // [self close];
+ return NO;
}
// For dispatching later
if(![[spf objectForKey:@"format"] isEqualToString:@"connection"]) {
NSLog(@"SPF file format is not 'connection'.");
- [self close];
- return;
+ // [self close];
+ return NO;
}
// Update the keys
@@ -2179,7 +2181,7 @@
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
- return;
+ return NO;
}
NSError *error = nil;
@@ -2187,11 +2189,12 @@
if(error != nil){
NSAlert *errorAlert = [NSAlert alertWithError:error];
[errorAlert runModal];
+ return NO;
}
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[self fileURL]];
- return;
+ return YES;
}
@@ -2346,7 +2349,7 @@
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
- return;
+ return NO;
}
NSError *error = nil;
@@ -2354,6 +2357,7 @@
if(error != nil){
NSAlert *errorAlert = [NSAlert alertWithError:error];
[errorAlert runModal];
+ return NO;
}
// TODO take favs and history frm untitle or old file name with me
@@ -2366,6 +2370,8 @@
// Store doc data permanently
[spfDocData removeAllObjects];
[spfDocData addEntriesFromDictionary:spfDocData_temp];
+
+ return YES;
}
@@ -2966,8 +2972,15 @@
return NO;
} else {
// Auto-save spf file based connection
- if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
- [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
+ if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ BOOL isSaved = [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
+ if(isSaved)
+ [[SPQueryConsole sharedQueryConsole] removeRegisteredDocumentWithFileURL:[self fileURL]];
+ return isSaved;
+ } else if([self fileURL] && [[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ [[SPQueryConsole sharedQueryConsole] removeRegisteredDocumentWithFileURL:[self fileURL]];
+ return YES;
+ }
}
return YES;
}