aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDocument.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-09-04 17:40:56 +0000
committerBibiko <bibiko@eva.mpg.de>2009-09-04 17:40:56 +0000
commit9683c9df3cb0b1128429f42f108d4e03ca4550f1 (patch)
treee1ed970699a4d71e7dce31247ef45cc7c17e0810 /Source/TableDocument.m
parente00013ffbf5fb252a11fc6e2c68a1af0b9886317 (diff)
downloadsequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.tar.gz
sequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.tar.bz2
sequelpro-9683c9df3cb0b1128429f42f108d4e03ca4550f1.zip
• improved behavior while closing a document window
- if not connected close it without any checks - if an Untitled document contains stored query favorites - What should be done? - up to now it saves them to the global prefs • header in query favorites list keep visible while filtering • code cleaning
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r--Source/TableDocument.m27
1 files changed, 23 insertions, 4 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 9c56ff04..a546333a 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1925,7 +1925,7 @@
{
// Auto-save preferences to spf file based connection
if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
- if(![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) {
+ if(_isConnected && ![self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES]) {
NSLog(@"Preference data for file ‘%@’ could not be saved.", [[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
NSBeep();
}
@@ -2128,9 +2128,12 @@
// Update only query favourites, history, etc. by reading the file again
if(saveOnlyPreferences) {
- // Check for save file URL
- // TODO maybe alert ?
- if(![[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) return NO;
+ // Check URL for safety reasons
+ if(![[[self fileURL] absoluteString] length] || ![[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ NSLog(@"Couldn't save data. No file URL found!");
+ NSBeep();
+ return NO;
+ }
NSError *readError = nil;
NSString *convError = nil;
@@ -2976,13 +2979,29 @@
if ( ![tablesListInstance selectionShouldChangeInTableView:nil] ) {
return NO;
} else {
+
+ if(!_isConnected) return YES;
+
// Auto-save spf file based connection
if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"]) {
BOOL isSaved = [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
if(isSaved)
[[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]];
return isSaved;
+
+ // Before removing an Untitled doc check if it contains any defined query favorites.
+ // If so save them globally. TODO: How to do it better ?
} else if([self fileURL] && [[[self fileURL] absoluteString] length] && ![[[self fileURL] absoluteString] hasPrefix:@"/"]) {
+ if([[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]] count]) {
+
+ NSMutableArray *favs = [[[NSMutableArray alloc] init] autorelease];
+ [favs addObjectsFromArray:[prefs objectForKey:@"queryFavorites"]];
+ [favs addObjectsFromArray:[[SPQueryController sharedQueryController] favoritesForFileURL:[self fileURL]]];
+ [prefs setObject:favs forKey:@"queryFavorites"];
+
+ if(![prefs synchronize])
+ NSLog(@"Sorry, couldn't backup query favorites from Untitled document.");
+ }
[[SPQueryController sharedQueryController] removeRegisteredDocumentWithFileURL:[self fileURL]];
return YES;
}