aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPQueryConsole.h12
-rw-r--r--Source/SPQueryConsole.m64
-rw-r--r--Source/TableDocument.h5
-rw-r--r--Source/TableDocument.m47
4 files changed, 110 insertions, 18 deletions
diff --git a/Source/SPQueryConsole.h b/Source/SPQueryConsole.h
index 85ea7cbe..e5cb1156 100644
--- a/Source/SPQueryConsole.h
+++ b/Source/SPQueryConsole.h
@@ -42,6 +42,11 @@
BOOL filterIsActive;
NSMutableString *activeFilterString;
+
+ NSUInteger untitledDocumentCounter;
+ NSMutableDictionary *favoritesContainer;
+ NSMutableDictionary *historyContainer;
+
}
@property (readwrite, retain) NSFont *consoleFont;
@@ -60,6 +65,13 @@
- (void)showMessageInConsole:(NSString *)message;
- (void)showErrorInConsole:(NSString *)error;
+- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSDictionary *)contextInfo;
+- (void)addFavorite:(NSString *)favorite forFileURL:(NSURL *)fileURL;
+- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL;
+- (void)favoritesForFileURL:(NSURL *)fileURL;
+- (void)historyForFileURL:(NSURL *)fileURL;
+
+
- (NSUInteger)consoleMessageCount;
@end
diff --git a/Source/SPQueryConsole.m b/Source/SPQueryConsole.m
index d7f29811..312b637b 100644
--- a/Source/SPQueryConsole.m
+++ b/Source/SPQueryConsole.m
@@ -95,6 +95,11 @@ static SPQueryConsole *sharedQueryConsole = nil;
// Weak reference to active messages set - starts off as full set
messagesVisibleSet = messagesFullSet;
+
+ untitledDocumentCounter = 1;
+
+ favoritesContainer = [[NSMutableDictionary alloc] init];
+ historyContainer = [[NSMutableDictionary alloc] init];
}
return self;
@@ -321,6 +326,62 @@ static SPQueryConsole *sharedQueryConsole = nil;
}
#pragma mark -
+#pragma mark DocumentsController
+
+- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSDictionary *)contextInfo
+{
+
+ // Register a new untiled document and return its URL
+ if(fileURL == nil) {
+ NSURL *new = [NSURL URLWithString:[[NSString stringWithFormat:@"Untitled %d", untitledDocumentCounter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ untitledDocumentCounter++;
+ if(![favoritesContainer objectForKey:[new absoluteString]])
+ [favoritesContainer setObject:[NSMutableArray array] forKey:[new absoluteString]];
+ if(![historyContainer objectForKey:[new absoluteString]])
+ [historyContainer setObject:[NSMutableArray array] forKey:[new absoluteString]];
+
+ return new;
+ }
+
+ // Register a spf file
+ if(![favoritesContainer objectForKey:[fileURL absoluteString]]) {
+ if(contextInfo != nil && [contextInfo objectForKey:@"queryFavorites"] != nil)
+ [favoritesContainer setObject:[[contextInfo objectForKey:@"queryFavorites"] mutableCopy] forKey:[fileURL absoluteString]];
+ else
+ [favoritesContainer setObject:[NSMutableArray array] forKey:[fileURL absoluteString]];
+ }
+ if(![historyContainer objectForKey:[fileURL absoluteString]]) {
+ if(contextInfo != nil && [contextInfo objectForKey:@"queryHistory"] != nil)
+ [historyContainer setObject:[[contextInfo objectForKey:@"queryHistory"] mutableCopy] forKey:[fileURL absoluteString]];
+ else
+ [historyContainer setObject:[NSMutableArray array] forKey:[fileURL absoluteString]];
+ }
+ NSLog(@"shared %@ %@", historyContainer, favoritesContainer);
+ return fileURL;
+
+}
+
+- (void)addFavorite:(NSString *)favorite forFileURL:(NSURL *)fileURL
+{
+
+}
+
+- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL
+{
+
+}
+
+- (void)favoritesForFileURL:(NSURL *)fileURL
+{
+
+}
+
+- (void)historyForFileURL:(NSURL *)fileURL
+{
+
+}
+
+#pragma mark -
#pragma mark Other
/**
@@ -383,6 +444,9 @@ static SPQueryConsole *sharedQueryConsole = nil;
[messagesFilteredSet release], messagesFilteredSet = nil;
[activeFilterString release], activeFilterString = nil;
+ [favoritesContainer release];
+ [historyContainer release];
+
[super dealloc];
}
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index fc99bf23..09401cea 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -143,8 +143,9 @@ enum sp_current_query_mode
NSString *queryEditorInitString;
NSDictionary *spfSession;
+ NSDictionary *spfPreferences;
NSMutableDictionary *spfDocData;
-
+
}
- (NSString *)getHTMLforPrint;
@@ -203,7 +204,7 @@ enum sp_current_query_mode
- (void)refreshCurrentDatabase;
- (void)saveConnectionPanelDidEnd:(NSSavePanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo;
- (IBAction)validateSaveConnectionAccessory:(id)sender;
-- (void)saveSPFtoFile:(NSString *)fileName saveInBackground:(BOOL)saveInBackground saveOnlyPreferences:(BOOL)saveOnlyPreferences;
+- (void)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences;
- (IBAction)closePasswordSheet:(id)sender;
// Getter methods
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 233a292b..87f027b7 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -87,6 +87,7 @@
queryEditorInitString = nil;
spfSession = nil;
+ spfPreferences = nil;
spfDocData = [[NSMutableDictionary alloc] init];
}
@@ -407,8 +408,16 @@
return;
}
- [self setFileURL:[NSURL URLWithString:path]];
- [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:path]];
+ [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];
+ }
+
[spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"auto_connect"];
if([spf objectForKey:@"auto_connect"] && [[spf valueForKey:@"auto_connect"] boolValue]) {
@@ -591,9 +600,11 @@
else
[tableWindow makeFirstResponder:[tablesListInstance valueForKeyPath:@"tablesListView"]];
+ NSURL *anURL = [[SPQueryConsole sharedQueryConsole] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences];
+ [self setFileURL:anURL];
+
if(spfSession != nil)
[self restoreSession];
- // [self performSelector:@selector(restoreSession) withObject:nil afterDelay:0.3];
}
@@ -1914,8 +1925,8 @@
- (void)applicationWillTerminate:(NSNotification *)notification
{
// Auto-save spf file based connection
- if([self fileURL] && [[[self fileURL] absoluteString] length])
- [self saveSPFtoFile:[[self fileURL] absoluteString] saveInBackground:YES saveOnlyPreferences:YES];
+ if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
+ [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
[tablesListInstance selectionShouldChangeInTableView:nil];
}
@@ -1967,7 +1978,7 @@
// If Save was invoked check for fileURL and save the spf file without save panel
// otherwise ask for file name
if([sender tag] == 1004 && [[[self fileURL] absoluteString] length]) {
- [self saveSPFtoFile:[[self fileURL] absoluteString] saveInBackground:YES saveOnlyPreferences:NO];
+ [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:NO];
return;
}
@@ -2079,19 +2090,20 @@
// Save changes of saveConnectionEncryptString
[[saveConnectionEncryptString window] makeFirstResponder:[[saveConnectionEncryptString window] initialFirstResponder]];
- [self saveSPFtoFile:fileName saveInBackground:NO saveOnlyPreferences:NO];
+ [self saveDocumentWithFilePath:fileName inBackground:NO onlyPreferences:NO];
}
}
}
-- (void)saveSPFtoFile:(NSString *)fileName saveInBackground:(BOOL)saveInBackground saveOnlyPreferences:(BOOL)saveOnlyPreferences
+- (void)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;
NSMutableDictionary *spfDocData_temp = [NSMutableDictionary dictionary];
+ NSString *myFilePath = [[[self fileURL] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// Store save panel settings or take them from spfDocData
if(!saveInBackground) {
@@ -2121,7 +2133,7 @@
NSPropertyListFormat format;
NSMutableDictionary *spf = [[NSMutableDictionary alloc] init];
- NSData *pData = [NSData dataWithContentsOfFile:[[self fileURL] absoluteString] options:NSUncachedRead error:&readError];
+ NSData *pData = [NSData dataWithContentsOfFile:myFilePath options:NSUncachedRead error:&readError];
[spf addEntriesFromDictionary:[NSPropertyListSerialization propertyListFromData:pData
mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]];
@@ -2169,7 +2181,7 @@
}
NSError *error = nil;
- [plist writeToFile:[[self fileURL] absoluteString] options:NSAtomicWrite error:&error];
+ [plist writeToFile:myFilePath options:NSAtomicWrite error:&error];
if(error != nil){
NSAlert *errorAlert = [NSAlert alertWithError:error];
[errorAlert runModal];
@@ -2342,8 +2354,11 @@
[errorAlert runModal];
}
- [self setFileURL:[NSURL URLWithString:fileName]];
-
+ // TODO take favs and history frm untitle or old file name with me
+ [[SPQueryConsole sharedQueryConsole] registerDocumentWithFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] andContextInfo:nil];
+
+ [self setFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
+
[tableWindow setTitle:[self displayName]];
// Store doc data permanently
@@ -2949,8 +2964,8 @@
return NO;
} else {
// Auto-save spf file based connection
- if([self fileURL] && [[[self fileURL] absoluteString] length])
- [self saveSPFtoFile:[[self fileURL] absoluteString] saveInBackground:YES saveOnlyPreferences:YES];
+ if([self fileURL] && [[[self fileURL] absoluteString] length] && [[[self fileURL] absoluteString] hasPrefix:@"/"])
+ [self saveDocumentWithFilePath:nil inBackground:YES onlyPreferences:YES];
}
return YES;
}
@@ -2970,11 +2985,11 @@
- (NSString *)displayName
{
if (!_isConnected) return [NSString stringWithFormat:@"%@%@",
- ([[[self fileURL] absoluteString] length]) ? [NSString stringWithFormat:@"%@ – ",[[[self fileURL] absoluteString] lastPathComponent]] : @"",
+ ([[[self fileURL] absoluteString] length]) ? [NSString stringWithFormat:@"%@ — ",[[[[self fileURL] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] : @"",
NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")];
return [NSString stringWithFormat:@"%@(MySQL %@) %@%@%@",
- ([[[self fileURL] absoluteString] length]) ? [NSString stringWithFormat:@"%@ – ",[[[self fileURL] absoluteString] lastPathComponent]] : @"",
+ ([[[self fileURL] absoluteString] length]) ? [NSString stringWithFormat:@"%@ — ",[[[[self fileURL] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] : @"",
mySQLVersion,
[self name],
([self database]?[NSString stringWithFormat:@"/%@",[self database]]:@""),