From 4e87089af2ce50364a3e6fcfdf8a3c31e172d8aa Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 5 Dec 2010 15:03:28 +0000 Subject: Apply new favorites outline view patch. --- Source/SPDatabaseDocument.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 43d71b01..2901bcd4 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3239,7 +3239,7 @@ if ([connectionController selectedFavorite]) return; // Request the connection controller to add its details to favorites - [connectionController addFavorite:self]; + [connectionController addFavoriteUsingCurrentDetails:self]; } /** @@ -3813,7 +3813,7 @@ { // If the window is being set for the first time - connection controller is visible - update focus if (!parentWindow && !mySQLConnection) { - [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesTable"]]; + [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesOutlineView"]]; [connectionController performSelector:@selector(updateFavoriteSelection:) withObject:self afterDelay:0.0]; } @@ -4092,12 +4092,12 @@ [self updateWindowTitle:self]; // Deselect all favorites on the connection controller - [[connectionController valueForKeyPath:@"favoritesTable"] deselectAll:connectionController]; + [[connectionController valueForKeyPath:@"favoritesOutlineView"] deselectAll:connectionController]; // Suppress the possibility to choose an other connection from the favorites // if a connection should initialized by SPF file. Otherwise it could happen // that the SPF file runs out of sync. - [[connectionController valueForKeyPath:@"favoritesTable"] setEnabled:NO]; + [[connectionController valueForKeyPath:@"favoritesOutlineView"] setEnabled:NO]; // Ensure the connection controller is set to a blank slate [connectionController setName:@""]; -- cgit v1.2.3 From f1f5e84d38e29f2258aa958f55382ef70085843b Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Tue, 1 Feb 2011 20:05:16 +0000 Subject: Bring outline view branch up to date with trunk (r3165:r3177). --- Source/SPDatabaseDocument.m | 49 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index e122205e..1d4b4fc6 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -835,12 +835,12 @@ if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; selectedDatabase = [[NSString alloc] initWithString:dbName]; [chooseDatabaseButton selectItemWithTitle:selectedDatabase]; - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; } } else { if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; [chooseDatabaseButton selectItemAtIndex:0]; - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; } } @@ -871,30 +871,31 @@ */ - (void)toggleConsole:(id)sender { - BOOL isConsoleVisible = [[[SPQueryController sharedQueryController] window] isVisible]; - // If the Console window is not visible data are not reloaded (for speed). - // Due to that update list if user opens the Console window. - if(!isConsoleVisible) { - [[SPQueryController sharedQueryController] updateEntries]; - } + // Toggle Console will show the Console window if it isn't visible or if it isn't + // the front most window and hide it if it is the front most window + if ([[[SPQueryController sharedQueryController] window] isVisible] + && [[[NSApp keyWindow] windowController] isKindOfClass:[SPQueryController class]]) + + [[[SPQueryController sharedQueryController] window] setIsVisible:NO]; + else + + [self showConsole:nil]; - // Show or hide the console - [[[SPQueryController sharedQueryController] window] setIsVisible:(!isConsoleVisible)]; } /** - * Brings the console to the fron + * Brings the console to the front */ - (void)showConsole:(id)sender { - BOOL isConsoleVisible = [[[SPQueryController sharedQueryController] window] isVisible]; - if (!isConsoleVisible) { - [self toggleConsole:sender]; - } else { - [[[SPQueryController sharedQueryController] window] makeKeyAndOrderFront:self]; - } + // If the Console window is not visible data are not reloaded (for speed). + // Due to that update list if user opens the Console window. + if(![[[SPQueryController sharedQueryController] window] isVisible]) + [[SPQueryController sharedQueryController] updateEntries]; + + [[[SPQueryController sharedQueryController] window] makeKeyAndOrderFront:self]; } @@ -3209,7 +3210,7 @@ // Show/hide console if ([menuItem action] == @selector(toggleConsole:)) { - [menuItem setTitle:([[[SPQueryController sharedQueryController] window] isVisible]) ? NSLocalizedString(@"Hide Console", @"hide console") : NSLocalizedString(@"Show Console", @"show console")]; + [menuItem setTitle:([[[SPQueryController sharedQueryController] window] isVisible] && [[[NSApp keyWindow] windowController] isKindOfClass:[SPQueryController class]]) ? NSLocalizedString(@"Hide Console", @"hide console") : NSLocalizedString(@"Show Console", @"show console")]; } // Clear console @@ -3305,6 +3306,10 @@ */ - (void) updateWindowTitle:(id)sender { + + // Ensure a call on the main thread + if (![NSThread isMainThread]) return [[self onMainThread] updateWindowTitle:sender]; + NSMutableString *tabTitle; NSMutableString *windowTitle; SPDatabaseDocument *frontTableDocument = [parentWindowController selectedTableDocument]; @@ -4543,7 +4548,7 @@ - (void)connectionControllerConnectAttemptFailed:(id)controller { // Reset the window title - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; } #pragma mark - @@ -5506,7 +5511,7 @@ [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; } /** @@ -5545,7 +5550,7 @@ [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; } /** @@ -5602,7 +5607,7 @@ [tableDumpInstance setConnection:mySQLConnection]; // Update the window title - [[self onMainThread] updateWindowTitle:self]; + [self updateWindowTitle:self]; // Add a history entry if (!historyStateChanging) { -- cgit v1.2.3 From 2e31a4ad75b8e47a4feacadd567fbfab65eeede9 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Mon, 7 Feb 2011 20:20:41 +0000 Subject: Bring outline view branch up to date with trunk (r3179:r3187). --- Source/SPDatabaseDocument.m | 1 - 1 file changed, 1 deletion(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 1d4b4fc6..4bc82a21 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3795,7 +3795,6 @@ // Add the progress window to this window [self centerTaskWindow]; - [taskProgressWindow orderFront:self]; [parentWindow addChildWindow:taskProgressWindow ordered:NSWindowAbove]; } -- cgit v1.2.3 From 1e5288e9840e201a00bcb5ca3035d7aa807f1f8d Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Mon, 7 Mar 2011 20:12:52 +0000 Subject: Bring outline view branch up to date with trunk (r3203:r3224). --- Source/SPDatabaseDocument.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 4bc82a21..af639127 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -56,7 +56,10 @@ #import "SPDatabaseRename.h" #import "SPServerSupport.h" #import "SPTooltip.h" - +#import "SPDatabaseViewController.h" +#import "SPBundleHTMLOutputController.h" +#import "SPConnectionDelegate.h" +#import "SPWindowController.h" @interface SPDatabaseDocument (PrivateAPI) @@ -2787,15 +2790,19 @@ [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; - return NO; + + return; } NSError *error = nil; + [plist writeToFile:[NSString stringWithFormat:@"%@/info.plist", fileName] options:NSAtomicWrite error:&error]; + if(error != nil){ NSAlert *errorAlert = [NSAlert alertWithError:error]; [errorAlert runModal]; - return NO; + + return; } [[NSApp delegate] setSessionURL:fileName]; @@ -3306,7 +3313,6 @@ */ - (void) updateWindowTitle:(id)sender { - // Ensure a call on the main thread if (![NSThread isMainThread]) return [[self onMainThread] updateWindowTitle:sender]; @@ -4721,7 +4727,7 @@ BOOL isDir; if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { NSError *inError = nil; - NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:&inError]; [fm removeItemAtPath:queryFileName error:nil]; if(inError == nil && query && [query length]) { [tableContentInstance filterTable:query]; @@ -4741,7 +4747,6 @@ NSString *statusFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, docProcessID]; NSFileManager *fm = [NSFileManager defaultManager]; NSString *status = @"0"; - BOOL isDir; BOOL userTerminated = NO; BOOL doSyntaxHighlighting = NO; BOOL doSyntaxHighlightingViaCSS = NO; @@ -4890,7 +4895,7 @@ if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { NSError *inError = nil; - NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:inError]; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:&inError]; [fm removeItemAtPath:queryFileName error:nil]; [fm removeItemAtPath:resultFileName error:nil]; -- cgit v1.2.3 From 4a950f357fb29640b2732ca34c80f81c0b23fbe6 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Tue, 8 Mar 2011 20:41:11 +0000 Subject: Bring outline view branch up to date with trunk (r3227:r3233). --- Source/SPDatabaseDocument.m | 77 +++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index af639127..d582b836 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -60,6 +60,7 @@ #import "SPBundleHTMLOutputController.h" #import "SPConnectionDelegate.h" #import "SPWindowController.h" +#import "SPFileHandle.h" @interface SPDatabaseDocument (PrivateAPI) @@ -236,16 +237,16 @@ // Set up the progress indicator child window and layer - change indicator color and size [taskProgressIndicator setForeColor:[NSColor whiteColor]]; NSShadow *progressIndicatorShadow = [[NSShadow alloc] init]; - [progressIndicatorShadow setShadowOffset:NSMakeSize(1.0, -1.0)]; - [progressIndicatorShadow setShadowBlurRadius:1.0]; - [progressIndicatorShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.75]]; + [progressIndicatorShadow setShadowOffset:NSMakeSize(1.0f, -1.0f)]; + [progressIndicatorShadow setShadowBlurRadius:1.0f]; + [progressIndicatorShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0f alpha:0.75f]]; [taskProgressIndicator setShadow:progressIndicatorShadow]; [progressIndicatorShadow release]; taskProgressWindow = [[NSWindow alloc] initWithContentRect:[taskProgressLayer bounds] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; [taskProgressWindow setReleasedWhenClosed:NO]; [taskProgressWindow setOpaque:NO]; [taskProgressWindow setBackgroundColor:[NSColor clearColor]]; - [taskProgressWindow setAlphaValue:0.0]; + [taskProgressWindow setAlphaValue:0.0f]; [taskProgressWindow setContentView:taskProgressLayer]; [contentViewSplitter setDelegate:self]; @@ -429,7 +430,7 @@ } } - (void *)[self databaseEncoding]; + (void)[self databaseEncoding]; } /** @@ -475,11 +476,11 @@ if (allDatabases) [allDatabases release]; if (allSystemDatabases) [allSystemDatabases release]; - allDatabases = [[NSMutableArray alloc] initWithCapacity:[queryResult numOfRows]]; + allDatabases = [[NSMutableArray alloc] initWithCapacity:(NSUInteger)[queryResult numOfRows]]; allSystemDatabases = [[NSMutableArray alloc] initWithCapacity:2]; - for (NSInteger i = 0 ; i < [queryResult numOfRows] ; i++) + for (NSUInteger i = 0 ; i < [queryResult numOfRows] ; i++) { NSString *database = NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0); @@ -828,7 +829,7 @@ MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; if (![mySQLConnection queryErrored]) { NSInteger i; - NSInteger r = [theResult numOfRows]; + NSInteger r = (NSInteger)[theResult numOfRows]; if (r) [theResult dataSeek:0]; for ( i = 0 ; i < r ; i++ ) { dbName = NSArrayObjectAtIndex([theResult fetchRowAsArray], 0); @@ -1003,7 +1004,7 @@ */ - (void) fadeInTaskProgressWindow:(NSTimer *)theTimer { - float timeSinceFadeInStart = [[NSDate date] timeIntervalSinceDate:taskFadeInStartDate]; + double timeSinceFadeInStart = [[NSDate date] timeIntervalSinceDate:taskFadeInStartDate]; // Keep the window hidden for the first ~0.5 secs if (timeSinceFadeInStart < 0.5) return; @@ -1014,8 +1015,8 @@ if (alphaValue == 0) [self centerTaskWindow]; // Fade in the task window over 0.6 seconds - alphaValue = (timeSinceFadeInStart - 0.5) / 0.6; - if (alphaValue > 1.0) alphaValue = 1.0; + alphaValue = (float)(timeSinceFadeInStart - 0.5) / 0.6f; + if (alphaValue > 1.0f) alphaValue = 1.0f; [taskProgressWindow setAlphaValue:alphaValue]; // If the window has been fully faded in, clean up the timer. @@ -1031,14 +1032,14 @@ */ - (void) setTaskDescription:(NSString *)description { - NSShadow *shadow = [[NSShadow alloc] init]; - [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.75]]; - [shadow setShadowOffset:NSMakeSize(1.0, -1.0)]; - [shadow setShadowBlurRadius:3.0]; + NSShadow *textShadow = [[NSShadow alloc] init]; + [textShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0f alpha:0.75f]]; + [textShadow setShadowOffset:NSMakeSize(1.0f, -1.0f)]; + [textShadow setShadowBlurRadius:3.0f]; NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys: - [NSFont boldSystemFontOfSize:13.0], NSFontAttributeName, - shadow, NSShadowAttributeName, + [NSFont boldSystemFontOfSize:13.0f], NSFontAttributeName, + textShadow, NSShadowAttributeName, nil]; NSAttributedString *string = [[NSAttributedString alloc] initWithString:description attributes:attributes]; @@ -1046,7 +1047,7 @@ [string release]; [attributes release]; - [shadow release]; + [textShadow release]; } /** @@ -1129,7 +1130,7 @@ // Hide the task interface and reset to indeterminate if (taskDisplayIsIndeterminate) [taskProgressIndicator stopAnimation:self]; - [taskProgressWindow setAlphaValue:0.0]; + [taskProgressWindow setAlphaValue:0.0f]; taskDisplayIsIndeterminate = YES; [taskProgressIndicator setIndeterminate:YES]; @@ -1224,8 +1225,8 @@ NSRect mainWindowRect = [parentWindow frame]; NSRect taskWindowRect = [taskProgressWindow frame]; - newBottomLeftPoint.x = round(mainWindowRect.origin.x + mainWindowRect.size.width/2 - taskWindowRect.size.width/2); - newBottomLeftPoint.y = round(mainWindowRect.origin.y + mainWindowRect.size.height/2 - taskWindowRect.size.height/2); + newBottomLeftPoint.x = roundf(mainWindowRect.origin.x + mainWindowRect.size.width/2 - taskWindowRect.size.width/2); + newBottomLeftPoint.y = roundf(mainWindowRect.origin.y + mainWindowRect.size.height/2 - taskWindowRect.size.height/2); [taskProgressWindow setFrameOrigin:newBottomLeftPoint]; } @@ -1407,7 +1408,7 @@ */ - (IBAction)chooseEncoding:(id)sender { - [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:[NSNumber numberWithInt:[(NSMenuItem *)sender tag]]] reloadingViews:YES]; + [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:[NSNumber numberWithInteger:[(NSMenuItem *)sender tag]]] reloadingViews:YES]; } /** @@ -1435,7 +1436,7 @@ NSIndexSet *indexes = [[tablesListInstance valueForKeyPath:@"tablesListView"] selectedRowIndexes]; NSUInteger currentIndex = [indexes firstIndex]; - NSInteger counter = 0; + NSUInteger counter = 0; NSInteger type; NSArray *types = [tablesListInstance selectedTableTypes]; @@ -2794,11 +2795,11 @@ return; } - NSError *error = nil; + error = nil; [plist writeToFile:[NSString stringWithFormat:@"%@/info.plist", fileName] options:NSAtomicWrite error:&error]; - if(error != nil){ + if (error != nil){ NSAlert *errorAlert = [NSAlert alertWithError:error]; [errorAlert runModal]; @@ -2875,7 +2876,7 @@ @"saveDocPrefSheetStatus", [NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")], [NSString stringWithFormat: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"), [fileName lastPathComponent]], - saveDocPrefSheetStatus + &saveDocPrefSheetStatus ); if (spf) [spf release]; @@ -3137,9 +3138,9 @@ } } else { - for (NSNumber *type in [tablesListInstance selectedTableTypes]) + for (NSNumber *eachType in [tablesListInstance selectedTableTypes]) { - if ([type intValue] == SPTableTypeTable || [type intValue] == SPTableTypeView) return enable; + if ([eachType intValue] == SPTableTypeTable || [eachType intValue] == SPTableTypeView) return enable; } return (enable && (tag == SPSQLExport)); @@ -3327,11 +3328,11 @@ } if ([connectionController isConnecting]) { - windowTitle = NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting"); + windowTitle = [NSMutableString stringWithString:NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")]; tabTitle = windowTitle; } else if (!_isConnected) { - windowTitle = [NSString stringWithFormat:@"%@%@", pathName, @"Sequel Pro"]; + windowTitle = [NSMutableString stringWithFormat:@"%@%@", pathName, @"Sequel Pro"]; tabTitle = windowTitle; } else { @@ -4253,6 +4254,8 @@ if ([stateDetails objectForKey:@"auto_connect"] && [[stateDetails valueForKey:@"auto_connect"] boolValue]) { [connectionController initiateConnection:self]; } + + return YES; } /** @@ -4706,7 +4709,7 @@ if([command isEqualToString:@"SelectTableRows"]) { if([params count] > 1 && [[[NSApp mainWindow] firstResponder] respondsToSelector:@selector(selectTableRows:)]) { - [[[NSApp mainWindow] firstResponder] selectTableRows:[params subarrayWithRange:NSMakeRange(1, [params count]-1)]]; + [(SPCopyTable *)[[NSApp mainWindow] firstResponder] selectTableRows:[params subarrayWithRange:NSMakeRange(1, [params count]-1)]]; } return; } @@ -4780,7 +4783,7 @@ NSInteger itemType = SPTableTypeNone; NSString *itemTypeStr = @"TABLE"; - NSInteger i; + NSUInteger i; NSInteger queryCol = 1; // Loop through the unfiltered tables/views to find the desired item @@ -4846,7 +4849,7 @@ return; } if(doSyntaxHighlighting) { - [result appendFormat:@"%@
", [self doSQLSyntaxHighlightForString:[syntaxString createViewSyntaxPrettifier] cssLike:doSyntaxHighlightingViaCSS]]; + [result appendFormat:@"%@
", [[NSApp delegate] doSQLSyntaxHighlightForString:[syntaxString createViewSyntaxPrettifier] cssLike:doSyntaxHighlightingViaCSS]]; } else { [result appendFormat:@"%@\n", [syntaxString createViewSyntaxPrettifier]]; } @@ -4946,7 +4949,7 @@ } // write data - NSInteger i, j; + NSUInteger i, j; NSArray *theRow; NSMutableString *result = [NSMutableString string]; if(writeAsCsv) { @@ -5277,7 +5280,7 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(statusTableView && aTableView == statusTableView && rowIndex < [statusValues count]) { + if (statusTableView && aTableView == statusTableView && rowIndex < (NSInteger)[statusValues count]) { if ([[aTableColumn identifier] isEqualToString:@"table_name"]) { if([[statusValues objectAtIndex:rowIndex] objectForKey:@"table_name"]) return [[statusValues objectAtIndex:rowIndex] objectForKey:@"table_name"]; @@ -5483,7 +5486,7 @@ // If there is an encoding selected other than the default we must specify it in CREATE DATABASE statement if ([databaseEncodingButton indexOfSelectedItem] > 0) { - createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [[self mysqlEncodingFromEncodingTag:[databaseEncodingButton tag]] backtickQuotedString]]; + createStatement = [NSString stringWithFormat:@"%@ DEFAULT CHARACTER SET %@", createStatement, [[self mysqlEncodingFromEncodingTag:[NSNumber numberWithInteger:[databaseEncodingButton tag]]] backtickQuotedString]]; } // Create the database @@ -5649,7 +5652,7 @@ // For HTML output check if corresponding window already exists BOOL stopTrigger = NO; - if([[data objectAtIndex:2] length]) { + if ([(NSString *)[data objectAtIndex:2] length]) { BOOL correspondingWindowFound = NO; NSString *uuid = [data objectAtIndex:2]; for(id win in [NSApp windows]) { -- cgit v1.2.3 From 6d3f21336846d7745e795202c99390832c4220c8 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 19 Mar 2011 15:05:23 +0000 Subject: Bring outline view branch up to date with trunk (r3235:r3245), which should resolve all warnings. --- Source/SPDatabaseDocument.m | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index d582b836..02b59ebd 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -61,6 +61,7 @@ #import "SPConnectionDelegate.h" #import "SPWindowController.h" #import "SPFileHandle.h" +#import "SPConnectionHandler.h" @interface SPDatabaseDocument (PrivateAPI) -- cgit v1.2.3 From 3ed8b33deeadcc98185911f41bc6bcb4e53b4719 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 3 Apr 2011 09:34:29 +0000 Subject: Bring outline view branch up to date with trunk (r3246:r3264). --- Source/SPDatabaseDocument.m | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 02b59ebd..fce0bd3f 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -167,7 +167,7 @@ // Set the connection controller's delegate [connectionController setDelegate:self]; - + // Register observers for when the DisplayTableViewVerticalGridlines preference changes [prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; [prefs addObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL]; @@ -202,6 +202,9 @@ // Hide the tabs in the tab view (we only show them to allow switching tabs in interface builder) [tableTabView setTabViewType:NSNoTabsNoBorder]; + // Hide the activity list + [self setActivityPaneHidden:[NSNumber numberWithInteger:1]]; + // Bind the background color of the create syntax text view to the users preference [createTableSyntaxTextView setAllowsDocumentBackgroundColorChange:YES]; @@ -2173,8 +2176,7 @@ SPBeginAlertSheet(NSLocalizedString(@"Flushed Privileges", @"title of panel when successfully flushed privs"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, NSLocalizedString(@"Successfully flushed privileges.", @"message of panel when successfully flushed privs")); } else { //error while flushing privileges - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), - [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), [mySQLConnection getLastErrorMessage]]); } } @@ -4439,7 +4441,6 @@ if (![self isSaveInBundle]) { [self setFileURL:[NSURL fileURLWithPath:path]]; - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:path]]; } [spfDocData setObject:[NSNumber numberWithBool:([[data objectForKey:@"connection"] objectForKey:@"password"]) ? YES : NO] forKey:@"save_password"]; @@ -5100,9 +5101,9 @@ { if(![hide integerValue] == 1) { [tableInfoScrollView setHidden:YES]; - [activitiesScrollView setHidden:NO]; + [documentActivityScrollView setHidden:NO]; } else { - [activitiesScrollView setHidden:YES]; + [documentActivityScrollView setHidden:YES]; [tableInfoScrollView setHidden:NO]; } } -- cgit v1.2.3 From 4611475c5b255eed9202474dd3bdee147e932946 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 22 Apr 2011 17:44:57 +0000 Subject: Bring outline view branch up to date with trunk (r3234:3277). --- Source/SPDatabaseDocument.m | 255 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 239 insertions(+), 16 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index fce0bd3f..8c05daa0 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -26,8 +26,13 @@ // More info at #import "SPDatabaseDocument.h" +#import "SPConnectionController.h" + #import "SPTablesList.h" #import "SPTableStructure.h" +#ifndef SP_REFACTOR /* headers */ +#import "SPFileHandle.h" +#import "SPKeychain.h" #import "SPTableContent.h" #import "SPCustomQuery.h" #import "SPDataImport.h" @@ -35,13 +40,15 @@ #import "SPGrowlController.h" #import "SPExportController.h" #import "SPQueryController.h" +#import "SPWindowController.h" +#endif #import "SPNavigatorController.h" +#ifndef SP_REFACTOR /* headers */ #import "SPSQLParser.h" #import "SPTableData.h" #import "SPDatabaseData.h" #import "SPAppController.h" #import "SPExtendedTableInfo.h" -#import "SPConnectionController.h" #import "SPHistoryController.h" #import "SPPreferenceController.h" #import "SPUserManager.h" @@ -54,38 +61,58 @@ #import "SPDatabaseCopy.h" #import "SPTableCopy.h" #import "SPDatabaseRename.h" +#endif #import "SPServerSupport.h" +#ifndef SP_REFACTOR /* headers */ #import "SPTooltip.h" +#endif #import "SPDatabaseViewController.h" +#ifndef SP_REFACTOR /* headers */ #import "SPBundleHTMLOutputController.h" #import "SPConnectionDelegate.h" -#import "SPWindowController.h" -#import "SPFileHandle.h" -#import "SPConnectionHandler.h" +#endif + +#ifdef SP_REFACTOR /* headers */ +#import "SPAlertSheets.h" +#import "NSNotificationAdditions.h" +#endif @interface SPDatabaseDocument (PrivateAPI) +#ifndef SP_REFACTOR /* method decls */ - (void)_addDatabase; - (void)_copyDatabase; - (void)_renameDatabase; - (void)_removeDatabase; +#endif - (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails; @end @implementation SPDatabaseDocument +#ifndef SP_REFACTOR /* ivars */ @synthesize parentWindowController; @synthesize parentTabViewItem; +#endif @synthesize isProcessing; @synthesize serverSupport; +#ifndef SP_REFACTOR /* ivars */ @synthesize processID; +#endif + +#ifdef SP_REFACTOR /* ivars */ +@synthesize allDatabases; +@synthesize delegate; +#endif - (id)init { if ((self = [super init])) { +#ifndef SP_REFACTOR /* init ivars */ _mainNibLoaded = NO; +#endif _isConnected = NO; _isWorkingLevel = 0; _isSavedInBundle = NO; @@ -109,14 +136,18 @@ mySQLVersion = nil; allDatabases = nil; allSystemDatabases = nil; +#ifndef SP_REFACTOR /* init ivars */ mainToolbar = nil; parentWindow = nil; +#endif isProcessing = NO; +#ifndef SP_REFACTOR /* init ivars */ printWebView = [[WebView alloc] init]; [printWebView setFrameLoadDelegate:self]; prefs = [NSUserDefaults standardUserDefaults]; +#endif queryEditorInitString = nil; spfFileURL = nil; @@ -138,6 +169,7 @@ taskCancellationCallbackSelector = NULL; keyChainID = nil; +#ifndef SP_REFACTOR /* init ivars */ statusValues = nil; printThread = nil; nibObjectsToRelease = [[NSMutableArray alloc] init]; @@ -149,11 +181,47 @@ [nibLoader instantiateNibWithOwner:self topLevelObjects:&dbViewTopLevelObjects]; [nibLoader release]; [nibObjectsToRelease addObjectsFromArray:dbViewTopLevelObjects]; +#endif } return self; } +#ifdef SP_REFACTOR /* glue */ +- (SPConnectionController*)createConnectionController +{ + // Set up the connection controller + connectionController = [[SPConnectionController alloc] initWithDocument:self]; + + // Set the connection controller's delegate + [connectionController setDelegate:self]; + return connectionController; +} + +- (void)setTableSourceInstance:(SPTableStructure*)source +{ + tableSourceInstance = source; +} + +- (void)setTableContentInstance:(SPTableContent*)content +{ + tableContentInstance = content; +} + +- (void)setTableDataInstance:(SPTableData*)data +{ + tableDataInstance = data; +} + +- (SPTableData*)tableDataInstance +{ + return tableDataInstance; +} + +#endif + +#ifndef SP_REFACTOR /* awakeFromNib */ + - (void)awakeFromNib { if (_mainNibLoaded) return; @@ -255,7 +323,9 @@ [contentViewSplitter setDelegate:self]; } +#endif +#ifndef SP_REFACTOR /* password sheet and history navigation */ /** * Set the return code for entering the encryption passowrd sheet */ @@ -290,6 +360,7 @@ break; } } +#endif #pragma mark - #pragma mark Connection callback and methods @@ -304,12 +375,14 @@ serverSupport = [[SPServerSupport alloc] initWithMajorVersion:[mySQLConnection serverMajorVersion] minor:[mySQLConnection serverMinorVersion] release:[mySQLConnection serverReleaseVersion]]; - + +#ifndef SP_REFACTOR // Set the fileURL and init the preferences (query favs, filters, and history) if available for that URL [self setFileURL:[[SPQueryController sharedQueryController] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences]]; // ...but hide the icon while the document is temporary if ([self isUntitled]) [[parentWindow standardWindowButton:NSWindowDocumentIconButton] setImage:nil]; +#endif // Get the mysql version mySQLVersion = [[NSString alloc] initWithString:[mySQLConnection serverVersionString]]; @@ -318,7 +391,9 @@ if ([connectionController database] && ![[connectionController database] isEqualToString:@""]) { if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; selectedDatabase = [[NSString alloc] initWithString:[connectionController database]]; +#ifndef SP_REFACTOR /* [spHistoryControllerInstance updateHistoryEntries] */ [spHistoryControllerInstance updateHistoryEntries]; +#endif } // Ensure the connection encoding is set to utf8 for database/table name retrieval @@ -331,19 +406,28 @@ [databaseDataInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR /* setServerSupport: */ // Pass the support class to the data instance [databaseDataInstance setServerSupport:serverSupport]; - +#endif + +#ifdef SP_REFACTOR /* glue */ + tablesListInstance = [[SPTablesList alloc] init]; + [tablesListInstance setDatabaseDocument:self]; +#endif + // Set the connection on the tables list instance - this updates the table list while the connection // is still UTF8 [tablesListInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR /* set connection encoding from prefs */ // Set the connection encoding if necessary NSNumber *encodingType = [prefs objectForKey:SPDefaultEncoding]; if ([encodingType intValue] != SPEncodingAutodetect) { [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:encodingType] reloadingViews:NO]; } +#endif // For each of the main controllers, assign the current connection [tableSourceInstance setConnection:mySQLConnection]; @@ -356,6 +440,7 @@ [tableDataInstance setConnection:mySQLConnection]; [extendedTableInfoInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR /* update custom query editor */ // Set the custom query editor's MySQL version [customQueryInstance setMySQLversion:mySQLVersion]; @@ -435,6 +520,11 @@ } (void)[self databaseEncoding]; +#endif +#ifdef SP_REFACTOR /* glue */ + if ( delegate && [delegate respondsToSelector:@selector(databaseDocumentDidConnect:)] ) + [delegate performSelector:@selector(databaseDocumentDidConnect:) withObject:self]; +#endif } /** @@ -463,6 +553,8 @@ */ - (IBAction)setDatabases:(id)sender; { +#ifndef SP_REFACTOR /* ui manipulation */ + if (!chooseDatabaseButton) return; [chooseDatabaseButton removeAllItems]; @@ -472,6 +564,7 @@ [[chooseDatabaseButton menu] addItemWithTitle:NSLocalizedString(@"Add Database...", @"menu item to add db") action:@selector(addDatabase:) keyEquivalent:@""]; [[chooseDatabaseButton menu] addItemWithTitle:NSLocalizedString(@"Refresh Databases", @"menu item to refresh databases") action:@selector(setDatabases:) keyEquivalent:@""]; [[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]]; +#endif MCPResult *queryResult = [mySQLConnection listDBs]; @@ -498,6 +591,7 @@ } } +#ifndef SP_REFACTOR /* ui manipulation */ // Add system databases for (NSString *db in allSystemDatabases) { @@ -516,8 +610,11 @@ } (![self database]) ? [chooseDatabaseButton selectItemAtIndex:0] : [chooseDatabaseButton selectItemWithTitle:[self database]]; +#endif } +#ifndef SP_REFACTOR /* chooseDatabase: */ + /** * Selects the database choosen by the user, using a child task if necessary, * and displaying errors in an alert sheet on failure. @@ -542,12 +639,14 @@ // Select the database [self selectDatabase:[chooseDatabaseButton titleOfSelectedItem] item:[self table]]; } +#endif /** * Select the specified database and, optionally, table. */ - (void)selectDatabase:(NSString *)aDatabase item:(NSString *)anItem { +#ifndef SP_REFACTOR /* update navigator controller */ // Do not update the navigator since nothing is changed [[SPNavigatorController sharedNavigatorController] setIgnoreUpdate:NO]; @@ -561,6 +660,7 @@ } [[SPNavigatorController sharedNavigatorController] selectPath:schemaPath]; } +#endif // Start a task [self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading database '%@'...", @"Loading database task string"), [chooseDatabaseButton titleOfSelectedItem]]]; @@ -576,6 +676,7 @@ } } +#ifndef SP_REFACTOR /* operations on whole databases */ /** * opens the add-db sheet and creates the new db */ @@ -730,6 +831,7 @@ [processListController displayProcessListWindow]; } +#endif /** * Returns an array of all available database names @@ -747,6 +849,7 @@ return allSystemDatabases; } +#ifndef SP_REFACTOR /* sheetDidEnd: */ /** * Alert sheet method. Invoked when an alert sheet is dismissed. * @@ -819,6 +922,7 @@ nil, nil, parentWindow, self, nil, nil, [error objectAtIndex:1]); } +#endif /** * Reset the current selected database name @@ -828,7 +932,11 @@ NSString *dbName = nil; // Notify listeners that a query has started +#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; +#else + [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; +#endif MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; if (![mySQLConnection queryErrored]) { @@ -843,23 +951,33 @@ if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; selectedDatabase = [[NSString alloc] initWithString:dbName]; [chooseDatabaseButton selectItemWithTitle:selectedDatabase]; +#ifndef SP_REFACTOR /* [self updateWindowTitle:self] */ [self updateWindowTitle:self]; +#endif } } else { if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; [chooseDatabaseButton selectItemAtIndex:0]; +#ifndef SP_REFACTOR /* [self updateWindowTitle:self] */ [self updateWindowTitle:self]; +#endif } } //query finished +#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; +#else + [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; +#endif } +#ifndef SP_REFACTOR /* navigatorSchemaPathExistsForDatabase: */ - (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname { return [[SPNavigatorController sharedNavigatorController] schemaPathExistsForConnection:[self connectionID] andDatabase:dbname]; } +#endif - (NSDictionary*)getDbStructure { @@ -871,6 +989,8 @@ return [[SPNavigatorController sharedNavigatorController] allSchemaKeysForConnection:[self connectionID]]; } +#ifndef SP_REFACTOR /* console and navigator methods */ + #pragma mark - #pragma mark Console methods @@ -951,6 +1071,7 @@ [[[SPNavigatorController sharedNavigatorController] window] makeKeyAndOrderFront:self]; } } +#endif #pragma mark - #pragma mark Task progress and notification methods @@ -1425,6 +1546,7 @@ #pragma mark - #pragma mark Table Methods +#ifndef SP_REFACTOR /* whole table operations */ /** * Copies if sender == self or displays or the CREATE TABLE syntax of the selected table(s) to the user . @@ -2187,6 +2309,8 @@ [newTableDocument setStateFromConnectionFile:[[self fileURL] path]]; } +#endif + /** * Ask the connection controller to initiate connection, if it hasn't * already. Used to support automatic connections on window open, @@ -2202,13 +2326,16 @@ [mySQLConnection disconnect]; _isConnected = NO; +#ifndef SP_REFACTOR /* growl */ // Disconnected Growl notification [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Disconnected" description:[NSString stringWithFormat:NSLocalizedString(@"Disconnected from %@",@"description for disconnected growl notification"), [parentTabViewItem label]] document:self notificationName:@"Disconnected"]; +#endif } +#ifndef SP_REFACTOR /* observeValueForKeyPath: */ /** * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface. */ @@ -2218,6 +2345,7 @@ [mySQLConnection setDelegateQueryLogging:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]]; } } +#endif /** * Is current document Untitled? @@ -2339,8 +2467,10 @@ tabTitle = [NSMutableString string]; +#ifndef SP_REFACTOR /* Add the MySQL version to the window title */ // Add the MySQL version to the window title if enabled in prefs if ([prefs boolForKey:SPDisplayServerVersionInWindowTitle]) [tabTitle appendFormat:@"(MySQL %@)\n", [self mySQLVersion]]; +#endif [tabTitle appendString:[self name]]; if ([self database]) { @@ -2420,6 +2550,7 @@ [queryProgressBar stopAnimation:self]; } +#ifndef SP_REFACTOR /* applicationWillTerminate: */ /** * Invoked when the application will terminate */ @@ -3271,7 +3402,7 @@ if ([connectionController selectedFavorite]) return; // Request the connection controller to add its details to favorites - [connectionController addFavoriteUsingCurrentDetails:self]; + [connectionController addFavorite:self]; } /** @@ -3839,6 +3970,7 @@ // If the task interface is visible, and this tab is frontmost, re-center the task child window if (_isWorkingLevel && [parentWindowController selectedTableDocument] == self) [self centerTaskWindow]; } +#endif /** * Set the parent window @@ -3847,7 +3979,9 @@ { // If the window is being set for the first time - connection controller is visible - update focus if (!parentWindow && !mySQLConnection) { - [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesOutlineView"]]; +#ifndef SP_REFACTOR + [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesTable"]]; +#endif [connectionController performSelector:@selector(updateFavoriteSelection:) withObject:self afterDelay:0.0]; } @@ -3864,6 +3998,7 @@ return parentWindow; } +#ifndef SP_REFACTOR #pragma mark - #pragma mark NSDocument compatibility @@ -3881,6 +4016,7 @@ [parentWindow setRepresentedURL:nil]; } } +#endif /** * Retrieve the NSURL for the .spf file for this connection instance (if any) @@ -3890,6 +4026,7 @@ return [[spfFileURL copy] autorelease]; } +#ifndef SP_REFACTOR /* writeSafelyToURL: */ /** * Invoked if user chose "Save" from 'Do you want save changes you made...' sheet * which is called automatically if [self isDocumentEdited] == YES and user wanted to close an Untitled doc. @@ -3916,6 +4053,7 @@ || [[[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] objectForKey:@"string"] count]) ); } +#endif /** * The window title for this document. @@ -3929,7 +4067,7 @@ } return [[[self fileURL] path] lastPathComponent]; } - +#ifndef SP_REFACTOR /* state saving and setting */ #pragma mark - #pragma mark State saving and setting @@ -4115,6 +4253,7 @@ { NSDictionary *connection = nil; NSInteger connectionType = -1; + SPKeychain *keychain = nil; // If this document already has a connection, don't proceed. if (mySQLConnection) return NO; @@ -4123,15 +4262,17 @@ connection = [NSDictionary dictionaryWithDictionary:[stateDetails objectForKey:@"connection"]]; if (!connection) return NO; + if ([connection objectForKey:@"kcid"]) keychain = [[SPKeychain alloc] init]; + [self updateWindowTitle:self]; // Deselect all favorites on the connection controller - [[connectionController valueForKeyPath:@"favoritesOutlineView"] deselectAll:connectionController]; + [[connectionController valueForKeyPath:@"favoritesTable"] deselectAll:connectionController]; // Suppress the possibility to choose an other connection from the favorites // if a connection should initialized by SPF file. Otherwise it could happen // that the SPF file runs out of sync. - [[connectionController valueForKeyPath:@"favoritesOutlineView"] setEnabled:NO]; + [[connectionController valueForKeyPath:@"favoritesTable"] setEnabled:NO]; // Ensure the connection controller is set to a blank slate [connectionController setName:@""]; @@ -4153,7 +4294,11 @@ [connectionController setSshPort:@""]; [connectionController setDatabase:@""]; [connectionController setPassword:nil]; + [connectionController setConnectionKeychainItemName:nil]; + [connectionController setConnectionKeychainItemAccount:nil]; [connectionController setSshPassword:nil]; + [connectionController setConnectionSSHKeychainItemName:nil]; + [connectionController setConnectionSSHKeychainItemAccount:nil]; // Set the correct connection type if ([connection objectForKey:@"type"]) { @@ -4197,8 +4342,11 @@ [connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]]; // Set the keychain details if available - if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) + if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) { [self setKeychainID:[connection objectForKey:@"kcid"]]; + [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keyChainID]]]; + [connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]]; + } // Set password - if not in SPF file try to get it via the KeyChain if ([connection objectForKey:@"password"]) @@ -4229,6 +4377,10 @@ if ([connection objectForKey:@"ssh_password"]) [connectionController setSshPassword:[connection objectForKey:@"ssh_password"]]; else { + if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) { + [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]]]; + [connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]]; + } NSString *sshpw = [self keychainPasswordForSSHConnection:nil]; if(sshpw) [connectionController setSshPassword:sshpw]; @@ -4258,6 +4410,8 @@ [connectionController initiateConnection:self]; } + if (keychain) [keychain release]; + return YES; } @@ -4535,6 +4689,7 @@ [self endTask]; [taskPool drain]; } +#endif #pragma mark - #pragma mark Connection controller delegate methods @@ -4544,12 +4699,14 @@ */ - (void)connectionControllerInitiatingConnection:(id)controller { +#ifndef SP_REFACTOR /* ui manipulation */ // Update the window title to indicate that we are trying to establish a connection [parentTabViewItem setLabel:NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")]; if ([parentWindowController selectedTableDocument] == self) { [parentWindow setTitle:NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")]; } +#endif } /** @@ -4557,10 +4714,15 @@ */ - (void)connectionControllerConnectAttemptFailed:(id)controller { +#ifndef SP_REFACTOR /* updateWindowTitle: */ // Reset the window title [self updateWindowTitle:self]; +#endif } + +#ifndef SP_REFACTOR /* scheme scripting methods */ + #pragma mark - #pragma mark Scheme scripting methods @@ -5061,7 +5223,11 @@ - (void)registerActivity:(NSDictionary*)commandDict { [runningActivitiesArray addObject:commandDict]; +#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; +#else + [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; +#endif if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count]) [self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0]; @@ -5093,7 +5259,11 @@ [self setActivityPaneHidden:[NSNumber numberWithInteger:1]]; } +#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; +#else + [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; +#endif } @@ -5166,6 +5336,7 @@ return (NSDictionary*)env; } +#endif #pragma mark - #pragma mark Text field delegate methods @@ -5194,6 +5365,7 @@ #pragma mark - #pragma mark General sheet delegate methods +#ifndef SP_REFACTOR /* window:willPositionSheet:usingRect: */ - (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect { @@ -5217,10 +5389,11 @@ rect.origin.y -= [[parentWindowController valueForKey:@"tabBar"] frame].size.height - 1; return rect; } +#endif #pragma mark - #pragma mark SplitView delegate methods - +#ifndef SP_REFACTOR /* SplitView delegate methods */ /** * tells the splitView that it can collapse views */ @@ -5348,6 +5521,9 @@ _isSavedInBundle = savedInBundle; } +#endif + + #pragma mark - /** @@ -5355,7 +5531,7 @@ */ - (void)dealloc { - +#ifndef SP_REFACTOR /* Unregister observers */ // Unregister observers [prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines]; [prefs removeObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines]; @@ -5371,23 +5547,30 @@ if (processListController) [prefs removeObserver:processListController forKeyPath:SPDisplayTableViewVerticalGridlines]; if (serverVariablesController) [prefs removeObserver:serverVariablesController forKeyPath:SPDisplayTableViewVerticalGridlines]; +#endif [[NSNotificationCenter defaultCenter] removeObserver:self]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; +#ifndef SP_REFACTOR /* release nib objects */ for (id retainedObject in nibObjectsToRelease) [retainedObject release]; [nibObjectsToRelease release]; +#endif [allDatabases release]; [allSystemDatabases release]; +#ifndef SP_REFACTOR /* dealloc ivars */ [printWebView release]; +#endif [taskProgressWindow close]; if (selectedTableName) [selectedTableName release]; if (connectionController) [connectionController release]; +#ifndef SP_REFACTOR /* dealloc ivars */ if (processListController) [processListController release]; if (serverVariablesController) [serverVariablesController release]; +#endif if (mySQLConnection) [mySQLConnection release]; if (selectedDatabase) [selectedDatabase release]; if (mySQLVersion) [mySQLVersion release]; @@ -5403,16 +5586,30 @@ if (titleAccessoryView) [titleAccessoryView release]; if (taskProgressWindow) [taskProgressWindow release]; if (serverSupport) [serverSupport release]; +#ifndef SP_REFACTOR /* dealloc ivars */ if (processID) [processID release]; +#endif if (runningActivitiesArray) [runningActivitiesArray release]; [super dealloc]; } +- (NSArray*)allTableNames +{ + return [tablesListInstance allTableNames]; +} + +- (SPTablesList*)tablesListInstance +{ + return tablesListInstance; +} + @end @implementation SPDatabaseDocument (PrivateAPI) +#ifndef SP_REFACTOR /* whole database operations */ + - (void)_copyDatabase { if ([[databaseCopyNameField stringValue] isEqualToString:@""]) { @@ -5562,6 +5759,8 @@ [self updateWindowTitle:self]; } +#endif + /** * Select the specified database and, optionally, table. */ @@ -5569,6 +5768,7 @@ { NSAutoreleasePool *taskPool = [[NSAutoreleasePool alloc] init]; NSString *targetDatabaseName = [selectionDetails objectForKey:@"database"]; +#ifndef SP_REFACTOR /* update history controller */ NSString *targetItemName = [selectionDetails objectForKey:@"item"]; // Save existing scroll position and details, and ensure no duplicate entries are created as table list changes @@ -5577,12 +5777,17 @@ [spHistoryControllerInstance updateHistoryEntries]; [spHistoryControllerInstance setModifyingState:YES]; } +#endif if (![targetDatabaseName isEqualToString:selectedDatabase]) { // Attempt to select the specified database, and abort on failure +#ifndef SP_REFACTOR /* patch */ if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound || ![mySQLConnection selectDB:targetDatabaseName]) +#else + if ( ![mySQLConnection selectDB:targetDatabaseName] ) +#endif { // End the task first to ensure the database dropdown can be reselected @@ -5600,21 +5805,30 @@ return; } +#ifndef SP_REFACTOR /* chooseDatabaseButton selectItemWithTitle: */ [[chooseDatabaseButton onMainThread] selectItemWithTitle:targetDatabaseName]; +#endif if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; +#ifndef SP_REFACTOR /* patch */ selectedDatabase = [[NSString alloc] initWithString:[chooseDatabaseButton titleOfSelectedItem]]; +#else + selectedDatabase = [[NSString alloc] initWithString:targetDatabaseName]; +#endif +#ifndef SP_REFACTOR /* clear SPTablesList selection */ // If the item has changed, clear the item selection for cleaner loading if (![targetItemName isEqualToString:[self table]]) { [[tablesListInstance onMainThread] setTableListSelectability:YES]; [[[tablesListInstance valueForKey:@"tablesListView"] onMainThread] deselectAll:self]; [[tablesListInstance onMainThread] setTableListSelectability:NO]; } +#endif // Set the connection of SPTablesList and TablesDump to reload tables in db [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR /* update history controller and ui manip */ // Update the window title [self updateWindowTitle:self]; @@ -5630,8 +5844,10 @@ [[parentWindow onMainThread] makeFirstResponder:listFilterField]; else [[parentWindow onMainThread] makeFirstResponder:[tablesListInstance valueForKeyPath:@"tablesListView"]]; +#endif } +#ifndef SP_REFACTOR /* update selected table in SPTablesList */ // If a the table has changed, update the selection if (![targetItemName isEqualToString:[self table]]) { if (targetItemName) { @@ -5642,8 +5858,9 @@ [[tablesListInstance onMainThread] setTableListSelectability:NO]; } } - +#endif [self endTask]; +#ifndef SP_REFACTOR /* triggered commands */ NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionDatabaseChanged]; for(NSString* cmdPath in triggeredCommands) { @@ -5681,8 +5898,14 @@ } } } +#endif - [taskPool drain]; +#ifdef SP_REFACTOR /* glue */ + if ( delegate && [delegate respondsToSelector:@selector(databaseDidChange:)] ) + [delegate performSelectorOnMainThread:@selector(databaseDidChange:) withObject:self waitUntilDone:NO]; +#endif + [taskPool drain]; } + @end -- cgit v1.2.3 From 160728cd29519794b47b3a09b139ce9d604883f0 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 24 Apr 2011 10:56:52 +0000 Subject: Fix broken build after merge with trunk. --- Source/SPDatabaseDocument.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 8c05daa0..d8eaa100 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -70,6 +70,7 @@ #ifndef SP_REFACTOR /* headers */ #import "SPBundleHTMLOutputController.h" #import "SPConnectionDelegate.h" +#import "SPConnectionHandler.h" #endif #ifdef SP_REFACTOR /* headers */ @@ -3866,7 +3867,6 @@ */ - (void)parentTabDidClose { - // Cancel autocompletion trigger if([prefs boolForKey:SPCustomQueryAutoComplete]) [NSObject cancelPreviousPerformRequestsWithTarget:[customQueryInstance valueForKeyPath:@"textView"] @@ -3885,7 +3885,6 @@ [createTableSyntaxWindow orderOut:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [self setParentWindow:nil]; - } /** -- cgit v1.2.3 From 2dbae24c7735ead0524bd9847af6ea99d8654ec6 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 14 May 2011 17:26:18 +0000 Subject: Bring outline view branch up to date with trunk (r3279:r3306). --- Source/SPDatabaseDocument.m | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index d8eaa100..04d4b3f3 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -78,7 +78,10 @@ #import "NSNotificationAdditions.h" #endif -@interface SPDatabaseDocument (PrivateAPI) +// Constants +static NSString *SPCreateSyntx = @"SPCreateSyntax"; + +@interface SPDatabaseDocument () #ifndef SP_REFACTOR /* method decls */ - (void)_addDatabase; @@ -2135,7 +2138,7 @@ [panel setAllowsOtherFileTypes:YES]; [panel setCanSelectHiddenExtension:YES]; - [panel beginSheetForDirectory:nil file:@"CreateSyntax" modalForWindow:createTableSyntaxWindow modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:@"CreateSyntax"]; + [panel beginSheetForDirectory:nil file:@"CreateSyntax" modalForWindow:createTableSyntaxWindow modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:SPCreateSyntx]; } /** @@ -2716,7 +2719,7 @@ if([[NSApp delegate] sessionURL]) filename = [[[[NSApp delegate] sessionURL] absoluteString] lastPathComponent]; else - filename = [NSString stringWithFormat:@"%@", @"session"]; + filename = [NSString stringWithFormat:NSLocalizedString(@"Session",@"Initial filename for 'Save session' file")]; contextInfo = @"saveSession"; } @@ -3175,7 +3178,6 @@ */ - (IBAction)openDatabaseInNewTab:(id)sender { - // Add a new tab to the window [[parentWindow windowController] addNewConnection:self]; @@ -3282,11 +3284,11 @@ } } - if ([menuItem action] == @selector(import:) || - [menuItem action] == @selector(removeDatabase:) || - [menuItem action] == @selector(copyDatabase:) || - [menuItem action] == @selector(renameDatabase:) || - [menuItem action] == @selector(openDatabaseInNewTab:) || + if ([menuItem action] == @selector(import:) || + [menuItem action] == @selector(removeDatabase:) || + [menuItem action] == @selector(copyDatabase:) || + [menuItem action] == @selector(renameDatabase:) || + [menuItem action] == @selector(openDatabaseInNewTab:) || [menuItem action] == @selector(refreshTables:)) { return ([self database] != nil); @@ -3420,12 +3422,12 @@ - (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { if (returnCode == NSOKButton) { - if ([contextInfo isEqualToString:@"CreateSyntax"]) { + if ([contextInfo isEqualToString:SPCreateSyntx]) { NSString *createSyntax = [createTableSyntaxTextView string]; if ([createSyntax length] > 0) { - NSString *output = [NSString stringWithFormat:@"-- Create syntax for '%@'\n\n%@\n", [self table], createSyntax]; + NSString *output = [NSString stringWithFormat:@"-- %@ '%@'\n\n%@\n", NSLocalizedString(@"Create syntax for", @"create syntax for table comment"), [self table], createSyntax]; [output writeToFile:[sheet filename] atomically:YES encoding:NSUTF8StringEncoding error:NULL]; } @@ -3577,7 +3579,7 @@ /** * Return the identifier for the currently selected toolbar item, or nil if none is selected. */ -- (NSString *)selectedToolbarItemIdentifier; +- (NSString *)selectedToolbarItemIdentifier { return [mainToolbar selectedItemIdentifier]; } @@ -4902,6 +4904,20 @@ return; } + if([command isEqualToString:@"RunQueryInQueryEditor"]) { + NSString *queryFileName = [NSString stringWithFormat:@"%@%@", SPURLSchemeQueryInputPathHeader, docProcessID]; + NSFileManager *fm = [NSFileManager defaultManager]; + BOOL isDir; + if([fm fileExistsAtPath:queryFileName isDirectory:&isDir] && !isDir) { + NSError *inError = nil; + NSString *query = [NSString stringWithContentsOfFile:queryFileName encoding:NSUTF8StringEncoding error:&inError]; + [fm removeItemAtPath:queryFileName error:nil]; + if(inError == nil && query && [query length]) { + [customQueryInstance performQueries:[NSArray arrayWithObject:query] withCallback:NULL]; + } + } + return; + } if([command isEqualToString:@"CreateSyntaxForTables"]) { @@ -5603,10 +5619,6 @@ return tablesListInstance; } -@end - -@implementation SPDatabaseDocument (PrivateAPI) - #ifndef SP_REFACTOR /* whole database operations */ - (void)_copyDatabase -- cgit v1.2.3 From c1de88ac62381469ad01975c0f28e5847a65edb9 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 14 May 2011 18:43:05 +0000 Subject: Fix exceptions being thrown upon launch. --- Source/SPDatabaseDocument.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 04d4b3f3..5a2bff92 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3981,7 +3981,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // If the window is being set for the first time - connection controller is visible - update focus if (!parentWindow && !mySQLConnection) { #ifndef SP_REFACTOR - [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesTable"]]; + [aWindow makeFirstResponder:(NSView *)[connectionController favoritesOutlineView]]; #endif [connectionController performSelector:@selector(updateFavoriteSelection:) withObject:self afterDelay:0.0]; } @@ -4268,12 +4268,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self updateWindowTitle:self]; // Deselect all favorites on the connection controller - [[connectionController valueForKeyPath:@"favoritesTable"] deselectAll:connectionController]; + [[connectionController favoritesOutlineView] deselectAll:connectionController]; // Suppress the possibility to choose an other connection from the favorites // if a connection should initialized by SPF file. Otherwise it could happen // that the SPF file runs out of sync. - [[connectionController valueForKeyPath:@"favoritesTable"] setEnabled:NO]; + [[connectionController favoritesOutlineView] setEnabled:NO]; // Ensure the connection controller is set to a blank slate [connectionController setName:@""]; -- cgit v1.2.3 From b26a4c45cbafedefe0247971c1ae9961abfe24c3 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Wed, 3 Aug 2011 19:40:45 +0000 Subject: Bring outline view up to date with trunk (r3307:r3375). --- Source/SPDatabaseDocument.m | 52 +++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 5a2bff92..7fb04a32 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -39,7 +39,9 @@ #import "ImageAndTextCell.h" #import "SPGrowlController.h" #import "SPExportController.h" +#endif #import "SPQueryController.h" +#ifndef SP_REFACTOR /* headers */ #import "SPWindowController.h" #endif #import "SPNavigatorController.h" @@ -76,10 +78,13 @@ #ifdef SP_REFACTOR /* headers */ #import "SPAlertSheets.h" #import "NSNotificationAdditions.h" +#import "SPCustomQuery.h" #endif // Constants +#ifndef SP_REFACTOR static NSString *SPCreateSyntx = @"SPCreateSyntax"; +#endif @interface SPDatabaseDocument () @@ -108,6 +113,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #ifdef SP_REFACTOR /* ivars */ @synthesize allDatabases; @synthesize delegate; +@synthesize tableDataInstance; +@synthesize customQueryInstance; +@synthesize queryProgressBar; #endif - (id)init @@ -212,22 +220,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; tableContentInstance = content; } -- (void)setTableDataInstance:(SPTableData*)data -{ - tableDataInstance = data; -} - -- (SPTableData*)tableDataInstance -{ - return tableDataInstance; -} - #endif -#ifndef SP_REFACTOR /* awakeFromNib */ - (void)awakeFromNib { +#ifndef SP_REFACTOR if (_mainNibLoaded) return; _mainNibLoaded = YES; @@ -259,7 +257,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Register a second observer for when the logging preference changes so we can tell the current connection about it [prefs addObserver:self forKeyPath:SPConsoleEnableLogging options:NSKeyValueObservingOptionNew context:NULL]; - +#endif // Register for notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:) name:@"SMySQLQueryWillBePerformed" object:self]; @@ -268,6 +266,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:@"NSApplicationWillTerminateNotification" object:nil]; +#ifndef SP_REFACTOR // Find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder) selectEncodingMenu = [[[[[NSApp mainMenu] itemWithTag:SPMainMenuDatabase] submenu] itemWithTag:1] submenu]; @@ -326,8 +325,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [taskProgressWindow setContentView:taskProgressLayer]; [contentViewSplitter setDelegate:self]; -} #endif +} #ifndef SP_REFACTOR /* password sheet and history navigation */ /** @@ -444,10 +443,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tableDataInstance setConnection:mySQLConnection]; [extendedTableInfoInstance setConnection:mySQLConnection]; -#ifndef SP_REFACTOR /* update custom query editor */ // Set the custom query editor's MySQL version [customQueryInstance setMySQLversion:mySQLVersion]; +#ifndef SP_REFACTOR [self updateWindowTitle:self]; // Connected Growl notification @@ -2554,12 +2553,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [queryProgressBar stopAnimation:self]; } -#ifndef SP_REFACTOR /* applicationWillTerminate: */ /** * Invoked when the application will terminate */ - (void)applicationWillTerminate:(NSNotification *)notification { +#ifndef SP_REFACTOR /* applicationWillTerminate: */ // Auto-save preferences to spf file based connection if([self fileURL] && [[[self fileURL] path] length] && ![self isUntitled]) @@ -2573,11 +2572,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Note that this call does not need to be removed in release builds as leaks analysis output is only // dumped if [[SPLogger logger] setDumpLeaksOnTermination]; has been called first. [[SPLogger logger] dumpLeaks]; +#endif } #pragma mark - #pragma mark Menu methods +#ifndef SP_REFACTOR /** * Saves SP session or if Custom Query tab is active the editor's content as SQL file * If sender == nil then the call came from [self writeSafelyToURL:ofType:forSaveOperation:error] @@ -3863,18 +3864,26 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Return YES by default return YES; } +#endif /** * Invoked when the parent tab is about to close */ - (void)parentTabDidClose { +<<<<<<< .working +======= +#ifndef SP_REFACTOR +>>>>>>> .merge-right.r3375 // Cancel autocompletion trigger if([prefs boolForKey:SPCustomQueryAutoComplete]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:[customQueryInstance valueForKeyPath:@"textView"] selector:@selector(doAutoCompletion) object:nil]; +#ifndef SP_REFACTOR if([prefs boolForKey:SPCustomQueryUpdateAutoHelp]) +#endif [NSObject cancelPreviousPerformRequestsWithTarget:[customQueryInstance valueForKeyPath:@"textView"] selector:@selector(autoHelp) object:nil]; @@ -3883,12 +3892,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [mySQLConnection setDelegate:nil]; if (_isConnected) [self closeConnection]; else [connectionController cancelConnection]; +#ifndef SP_REFACTOR if ([[[SPQueryController sharedQueryController] window] isVisible]) [self toggleConsole:self]; +#endif [createTableSyntaxWindow orderOut:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [self setParentWindow:nil]; } +#ifndef SP_REFACTOR /** * Invoked when the parent tab is currently the active tab in the * window, but is being switched away from, to allow cleaning up @@ -4114,7 +4126,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [connection setObject:[connectionController sshHost] forKey:@"ssh_host"]; [connection setObject:[connectionController sshUser] forKey:@"ssh_user"]; [connection setObject:[NSNumber numberWithInt:[connectionController sshKeyLocationEnabled]] forKey:@"ssh_keyLocationEnabled"]; - [connection setObject:[connectionController sshKeyLocation] forKey:@"ssh_keyLocation"]; + if ([connectionController sshKeyLocation]) + [connection setObject:[connectionController sshKeyLocation] forKey:@"ssh_keyLocation"]; if ([connectionController sshPort] && [[connectionController sshPort] length]) [connection setObject:[NSNumber numberWithInteger:[[connectionController sshPort] integerValue]] forKey:@"ssh_port"]; break; @@ -4134,11 +4147,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (includePasswords) { NSString *pw = [self keychainPasswordForConnection:nil]; - if (![pw length]) pw = [connectionController password]; - if (pw) - [connection setObject:pw forKey:@"password"]; - else - [connection setObject:@"" forKey:@"password"]; + if (!pw) pw = [connectionController password]; + if (pw) [connection setObject:pw forKey:@"password"]; if ([connectionController type] == SPSSHTunnelConnection) { NSString *sshpw = [self keychainPasswordForSSHConnection:nil]; -- cgit v1.2.3 From 8a77a195fa6ce3aad15857a2213011bf0e8d7bd5 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 4 Aug 2011 19:35:04 +0000 Subject: Fix compile error. --- Source/SPDatabaseDocument.m | 3 --- 1 file changed, 3 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 7fb04a32..864061c4 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -3871,10 +3871,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void)parentTabDidClose { -<<<<<<< .working -======= #ifndef SP_REFACTOR ->>>>>>> .merge-right.r3375 // Cancel autocompletion trigger if([prefs boolForKey:SPCustomQueryAutoComplete]) #endif -- cgit v1.2.3 From 1d7ed99d602bf9c7aa4ea40a9a2ab6458864e51f Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 22 Jan 2012 12:19:21 +0000 Subject: Bring outlinew view branch up to date with trunk (r3375:3468). --- Source/SPDatabaseDocument.m | 210 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 175 insertions(+), 35 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 864061c4..bf9f96c7 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -25,6 +25,13 @@ // // More info at +// Forward-declare for 10.7 compatibility +#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 +enum { + NSFullScreenWindowMask = 1 << 14 +}; +#endif + #import "SPDatabaseDocument.h" #import "SPConnectionController.h" @@ -41,6 +48,7 @@ #import "SPExportController.h" #endif #import "SPQueryController.h" +#import "SPQueryDocumentsController.h" #ifndef SP_REFACTOR /* headers */ #import "SPWindowController.h" #endif @@ -48,7 +56,9 @@ #ifndef SP_REFACTOR /* headers */ #import "SPSQLParser.h" #import "SPTableData.h" +#endif #import "SPDatabaseData.h" +#ifndef SP_REFACTOR /* headers */ #import "SPAppController.h" #import "SPExtendedTableInfo.h" #import "SPHistoryController.h" @@ -63,6 +73,7 @@ #import "SPDatabaseCopy.h" #import "SPTableCopy.h" #import "SPDatabaseRename.h" +#import "SPTableRelations.h" #endif #import "SPServerSupport.h" #ifndef SP_REFACTOR /* headers */ @@ -79,6 +90,7 @@ #import "SPAlertSheets.h" #import "NSNotificationAdditions.h" #import "SPCustomQuery.h" +#import "SPDatabaseRename.h" #endif // Constants @@ -88,12 +100,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; @interface SPDatabaseDocument () -#ifndef SP_REFACTOR /* method decls */ - (void)_addDatabase; +#ifndef SP_REFACTOR /* method decls */ - (void)_copyDatabase; +#endif - (void)_renameDatabase; - (void)_removeDatabase; -#endif - (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails; @end @@ -116,6 +128,14 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; @synthesize tableDataInstance; @synthesize customQueryInstance; @synthesize queryProgressBar; +@synthesize databaseSheet; +@synthesize databaseNameField; +@synthesize databaseEncodingButton; +@synthesize addDatabaseButton; +@synthesize databaseDataInstance; +@synthesize databaseRenameSheet; +@synthesize databaseRenameNameField; +@synthesize renameDatabaseButton; #endif - (id)init @@ -144,6 +164,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; triggersLoaded = NO; selectedDatabase = nil; + selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"]; mySQLConnection = nil; mySQLVersion = nil; allDatabases = nil; @@ -159,6 +180,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [printWebView setFrameLoadDelegate:self]; prefs = [NSUserDefaults standardUserDefaults]; + undoManager = [[NSUndoManager alloc] init]; #endif queryEditorInitString = nil; @@ -184,6 +206,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #ifndef SP_REFACTOR /* init ivars */ statusValues = nil; printThread = nil; + windowTitleStatusViewIsVisible = NO; nibObjectsToRelease = [[NSMutableArray alloc] init]; // As this object is not an NSWindowController subclass, top-level objects in loaded nibs aren't @@ -207,6 +230,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Set the connection controller's delegate [connectionController setDelegate:self]; + return connectionController; } @@ -325,6 +349,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [taskProgressWindow setContentView:taskProgressLayer]; [contentViewSplitter setDelegate:self]; + + [self updateTitlebarStatusVisibilityForcingHide:NO]; #endif } @@ -409,14 +435,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [databaseDataInstance setConnection:mySQLConnection]; -#ifndef SP_REFACTOR /* setServerSupport: */ // Pass the support class to the data instance [databaseDataInstance setServerSupport:serverSupport]; -#endif #ifdef SP_REFACTOR /* glue */ tablesListInstance = [[SPTablesList alloc] init]; [tablesListInstance setDatabaseDocument:self]; + [tablesListInstance awakeFromNib]; #endif // Set the connection on the tables list instance - this updates the table list while the connection @@ -429,6 +454,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([encodingType intValue] != SPEncodingAutodetect) { [self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:encodingType] reloadingViews:NO]; + } else { +#endif + [[self onMainThread] updateEncodingMenuWithSelectedEncoding:[self encodingTagFromMySQLEncoding:[mySQLConnection encoding]]]; +#ifndef SP_REFACTOR } #endif @@ -450,8 +479,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self updateWindowTitle:self]; // Connected Growl notification + NSString *serverDisplayName = nil; + if ([parentWindowController selectedTableDocument] == self) { + serverDisplayName = [parentWindow title]; + } else { + serverDisplayName = [parentTabViewItem label]; + } + [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Connected" - description:[NSString stringWithFormat:NSLocalizedString(@"Connected to %@",@"description for connected growl notification"), [parentWindow title]] + description:[NSString stringWithFormat:NSLocalizedString(@"Connected to %@",@"description for connected growl notification"), serverDisplayName] document:self notificationName:@"Connected"]; @@ -522,7 +558,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } - (void)[self databaseEncoding]; + if ([self database]) [self detectDatabaseEncoding]; #endif #ifdef SP_REFACTOR /* glue */ if ( delegate && [delegate respondsToSelector:@selector(databaseDocumentDidConnect:)] ) @@ -679,7 +715,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } -#ifndef SP_REFACTOR /* operations on whole databases */ /** * opens the add-db sheet and creates the new db */ @@ -731,6 +766,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } +#ifndef SP_REFACTOR /* operations on whole databases */ /** * opens the copy database sheet and copies the databsae */ @@ -739,7 +775,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (![tablesListInstance selectionShouldChangeInTableView:nil]) return; [databaseCopyNameField setStringValue:selectedDatabase]; - [copyDatabaseMessageField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Duplicate database '%@' to:", @"duplicate database message"), selectedDatabase]]; + [copyDatabaseMessageField setStringValue:selectedDatabase]; [NSApp beginSheet:databaseCopySheet modalForWindow:parentWindow @@ -747,6 +783,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"copyDatabase"]; } +#endif /** * opens the rename database sheet and renames the databsae @@ -770,8 +807,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (IBAction)removeDatabase:(id)sender { +#ifndef SP_REFACTOR // No database selected, bail if ([chooseDatabaseButton indexOfSelectedItem] == 0) return; +#endif if (![tablesListInstance selectionShouldChangeInTableView:nil]) return; @@ -793,6 +832,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [alert beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeDatabase"]; } +#ifndef SP_REFACTOR /** * Refreshes the tables list by calling SPTablesList's updateTables. */ @@ -852,7 +892,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return allSystemDatabases; } -#ifndef SP_REFACTOR /* sheetDidEnd: */ /** * Alert sheet method. Invoked when an alert sheet is dismissed. * @@ -863,11 +902,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { - +#ifndef SP_REFACTOR if([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { saveDocPrefSheetStatus = returnCode; return; } +#endif // Order out current sheet to suppress overlapping of sheets if ([sheet respondsToSelector:@selector(orderOut:)]) @@ -897,23 +937,27 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [chooseDatabaseButton selectItemAtIndex:0]; } } +#ifndef SP_REFACTOR else if ([contextInfo isEqualToString:@"copyDatabase"]) { if (returnCode == NSOKButton) { [self _copyDatabase]; } } +#endif else if ([contextInfo isEqualToString:@"renameDatabase"]) { if (returnCode == NSOKButton) { [self _renameDatabase]; } } +#ifndef SP_REFACTOR // Close error status sheet for OPTIMIZE, CHECK, REPAIR etc. else if ([contextInfo isEqualToString:@"statusError"]) { if (statusValues) [statusValues release], statusValues = nil; } - +#endif } +#ifndef SP_REFACTOR /* sheetDidEnd: */ /** * Show Error sheet (can be called from inside of a endSheet selector) * via [self performSelector:@selector(showErrorSheetWithTitle:) withObject: afterDelay:] @@ -1500,10 +1544,19 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } /** - * Detect and return the database encoding. - * Falls back to Latin1. + * Retrieve the current database encoding. This will return Latin-1 + * for unknown encodings. */ - (NSString *)databaseEncoding +{ + return selectedDatabaseEncoding; +} + +/** + * Detect and store the encoding of the currently selected database. + * Falls back to Latin-1 if the encoding cannot be retrieved. + */ +- (void)detectDatabaseEncoding { MCPResult *charSetResult; NSString *mysqlEncoding = nil; @@ -1521,14 +1574,16 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; } + [selectedDatabaseEncoding release]; + // Fallback or older version? -> set encoding to mysql default encoding latin1 if ( !mysqlEncoding ) { NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]); - mysqlEncoding = @"latin1"; + selectedDatabaseEncoding = [[NSString alloc] initWithString:@"latin1"]; _supportsEncoding = NO; + } else { + selectedDatabaseEncoding = [mysqlEncoding retain]; } - - return mysqlEncoding; } /** @@ -2208,6 +2263,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; { queryEditorInitString = [query retain]; } +#endif /** * Invoked when user hits the cancel button or close button in @@ -2227,6 +2283,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[sender window] orderOut:self]; } +#ifndef SP_REFACTOR /** * Displays the user account manager. */ @@ -3550,6 +3607,34 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [titleImageView setImage:nil]; } +/** + * Update the title bar status area visibility. The status area is visible if the tab is + * frontmost in the window, and if the window is not fullscreen. + */ +- (void)updateTitlebarStatusVisibilityForcingHide:(BOOL)forceHide +{ + BOOL newIsVisible = !forceHide; + if (newIsVisible && [parentWindow styleMask] & NSFullScreenWindowMask) newIsVisible = NO; + if (newIsVisible && [parentWindowController selectedTableDocument] != self) newIsVisible = NO; + if (newIsVisible == windowTitleStatusViewIsVisible) return; + + if (newIsVisible) { + NSView *windowFrame = [[parentWindow contentView] superview]; + NSRect av = [titleAccessoryView frame]; + NSRect initialAccessoryViewFrame = NSMakeRect( + [windowFrame frame].size.width - av.size.width - 30, + [windowFrame frame].size.height - av.size.height, + av.size.width, + av.size.height); + [titleAccessoryView setFrame:initialAccessoryViewFrame]; + [windowFrame addSubview:titleAccessoryView]; + } else { + [titleAccessoryView removeFromSuperview]; + } + + windowTitleStatusViewIsVisible = newIsVisible; +} + #pragma mark - #pragma mark Toolbar Methods @@ -3905,9 +3990,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void)willResignActiveTabInWindow { - - // Remove the icon accessory view from the title bar - [titleAccessoryView removeFromSuperview]; + [self updateTitlebarStatusVisibilityForcingHide:YES]; // Remove the task progress window [parentWindow removeChildWindow:taskProgressWindow]; @@ -3933,16 +4016,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; else [parentWindow setRepresentedURL:nil]; - // Add the icon accessory view to the title bar - NSView *windowFrame = [[parentWindow contentView] superview]; - NSRect av = [titleAccessoryView frame]; - NSRect initialAccessoryViewFrame = NSMakeRect( - [windowFrame frame].size.width - av.size.width - 30, - [windowFrame frame].size.height - av.size.height, - av.size.width, - av.size.height); - [titleAccessoryView setFrame:initialAccessoryViewFrame]; - [windowFrame addSubview:titleAccessoryView]; + [self updateTitlebarStatusVisibilityForcingHide:NO]; // Add the progress window to this window [self centerTaskWindow]; @@ -4077,6 +4151,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } return [[[self fileURL] path] lastPathComponent]; } + +#ifndef SP_REFACTOR +- (NSUndoManager *)undoManager +{ + return undoManager; +} +#endif + + #ifndef SP_REFACTOR /* state saving and setting */ #pragma mark - #pragma mark State saving and setting @@ -5578,13 +5661,16 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; for (id retainedObject in nibObjectsToRelease) [retainedObject release]; [nibObjectsToRelease release]; + #endif [allDatabases release]; [allSystemDatabases release]; #ifndef SP_REFACTOR /* dealloc ivars */ + [undoManager release]; [printWebView release]; #endif + [selectedDatabaseEncoding release]; [taskProgressWindow close]; if (selectedTableName) [selectedTableName release]; @@ -5613,6 +5699,11 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif if (runningActivitiesArray) [runningActivitiesArray release]; +#ifdef SP_REFACTOR + if ( tablesListInstance ) [tablesListInstance release]; + if ( customQueryInstance ) [customQueryInstance release]; +#endif + [super dealloc]; } @@ -5656,6 +5747,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Update DB list [self setDatabases:self]; } +#endif - (void)_renameDatabase { @@ -5682,6 +5774,20 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Update DB list [self setDatabases:self]; + +#ifdef SP_REFACTOR + if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) + [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; + + if ( delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)] ) + { + if ( [allDatabases count] > 0 ) + { + NSString* db = [databaseRenameNameField stringValue]; + [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:db]; + } + } +#endif } /** @@ -5735,7 +5841,21 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR [self updateWindowTitle:self]; +#endif +#ifdef SP_REFACTOR /* glue */ + if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) + [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; + + if ( delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)] ) + { + if ( [allDatabases count] > 0 ) + { + [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:selectedDatabase]; + } + } +#endif } /** @@ -5774,10 +5894,23 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; +#ifndef SP_REFACTOR [self updateWindowTitle:self]; -} - #endif +#ifdef SP_REFACTOR /* glue */ + if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) + [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; + + if ( delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)] ) + { + if ( [allDatabases count] > 0 ) + { + NSString* db = [allDatabases objectAtIndex:0]; + [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:db]; + } + } +#endif +} /** * Select the specified database and, optionally, table. @@ -5811,7 +5944,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // End the task first to ensure the database dropdown can be reselected [self endTask]; - if ( [mySQLConnection isConnected] ) { + if ([mySQLConnection isConnected]) { // Update the database list [[self onMainThread] setDatabases:self]; @@ -5840,6 +5973,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[[tablesListInstance valueForKey:@"tablesListView"] onMainThread] deselectAll:self]; [[tablesListInstance onMainThread] setTableListSelectability:NO]; } + + // Update the stored database encoding, used for views, "default" table encodings, and to allow + // or disallow use of the "View using encoding" menu + [self detectDatabaseEncoding]; #endif // Set the connection of SPTablesList and TablesDump to reload tables in db @@ -5858,10 +5995,12 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Set focus to table list filter field if visible // otherwise set focus to Table List view - if ( [[tablesListInstance tables] count] > 20 ) + if ([[tablesListInstance tables] count] > 20) { [[parentWindow onMainThread] makeFirstResponder:listFilterField]; - else + } + else { [[parentWindow onMainThread] makeFirstResponder:[tablesListInstance valueForKeyPath:@"tablesListView"]]; + } #endif } @@ -5919,8 +6058,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif #ifdef SP_REFACTOR /* glue */ - if ( delegate && [delegate respondsToSelector:@selector(databaseDidChange:)] ) + if (delegate && [delegate respondsToSelector:@selector(databaseDidChange:)]) { [delegate performSelectorOnMainThread:@selector(databaseDidChange:) withObject:self waitUntilDone:NO]; + } #endif [taskPool drain]; -- cgit v1.2.3 From b31bb2c4981d0a44119c43eac7525233a7c3b0e3 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 22 Jan 2012 22:40:05 +0000 Subject: Split out connection controller initialization. --- Source/SPDatabaseDocument.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index bf9f96c7..a70089eb 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -34,6 +34,7 @@ enum { #import "SPDatabaseDocument.h" #import "SPConnectionController.h" +#import "SPConnectionControllerInitializer.h" #import "SPTablesList.h" #import "SPTableStructure.h" @@ -246,7 +247,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif - - (void)awakeFromNib { #ifndef SP_REFACTOR -- cgit v1.2.3 From 2483cd22f74239d2a06c83f1c5d9a25eaab44a7c Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 19 Feb 2012 16:25:19 +0000 Subject: Bring outline view branch up to date with trunk (r3471:r3481). --- Source/SPDatabaseDocument.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index a70089eb..f29727b3 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -2186,7 +2186,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; { NSSavePanel *panel = [NSSavePanel savePanel]; - [panel setRequiredFileType:SPFileExtensionSQL]; + [panel setAllowedFileTypes:[NSArray arrayWithObject:SPFileExtensionSQL]]; [panel setExtensionHidden:NO]; [panel setAllowsOtherFileTypes:YES]; @@ -2818,7 +2818,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; { if ( returnCode ) { - NSString *fileName = [panel filename]; + NSString *fileName = [[panel URL] path]; NSError *error = nil; // Save file as SQL file by using the chosen encoding @@ -3487,7 +3487,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([createSyntax length] > 0) { NSString *output = [NSString stringWithFormat:@"-- %@ '%@'\n\n%@\n", NSLocalizedString(@"Create syntax for", @"create syntax for table comment"), [self table], createSyntax]; - [output writeToFile:[sheet filename] atomically:YES encoding:NSUTF8StringEncoding error:NULL]; + [output writeToURL:[sheet URL] atomically:YES encoding:NSUTF8StringEncoding error:NULL]; } } } -- cgit v1.2.3 From 524e8c356b4074f5be5933b0551374a130a8f6d1 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 18 Mar 2012 20:05:36 +0000 Subject: Bring outline view branch up to date with trunk (r3471:r3517). --- Source/SPDatabaseDocument.m | 259 +++++++++++++++++++++----------------------- 1 file changed, 123 insertions(+), 136 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index f29727b3..38027ac8 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -36,6 +36,8 @@ enum { #import "SPConnectionController.h" #import "SPConnectionControllerInitializer.h" +#import "SPMySQL.h" + #import "SPTablesList.h" #import "SPTableStructure.h" #ifndef SP_REFACTOR /* headers */ @@ -59,6 +61,7 @@ enum { #import "SPTableData.h" #endif #import "SPDatabaseData.h" +#import "SPDatabaseStructure.h" #ifndef SP_REFACTOR /* headers */ #import "SPAppController.h" #import "SPExtendedTableInfo.h" @@ -119,6 +122,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif @synthesize isProcessing; @synthesize serverSupport; +@synthesize databaseStructureRetrieval; #ifndef SP_REFACTOR /* ivars */ @synthesize processID; #endif @@ -218,6 +222,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [nibLoader release]; [nibObjectsToRelease addObjectsFromArray:dbViewTopLevelObjects]; #endif + + databaseStructureRetrieval = [[SPDatabaseStructure alloc] initWithDelegate:self]; } return self; @@ -300,18 +306,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Hide the activity list [self setActivityPaneHidden:[NSNumber numberWithInteger:1]]; - // Bind the background color of the create syntax text view to the users preference - [createTableSyntaxTextView setAllowsDocumentBackgroundColorChange:YES]; - - NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary]; - - [bindingOptions setObject:NSUnarchiveFromDataTransformerName forKey:@"NSValueTransformerName"]; - - [createTableSyntaxTextView bind:@"backgroundColor" - toObject:[NSUserDefaultsController sharedUserDefaultsController] - withKeyPath:@"values.CustomQueryEditorBackgroundColor" - options:bindingOptions]; - // Load additional nibs, keeping track of the top-level objects to allow correct release NSArray *connectionDialogTopLevelObjects = nil; NSNib *nibLoader = [[NSNib alloc] initWithNibNamed:@"ConnectionErrorDialog" bundle:[NSBundle mainBundle]]; @@ -394,7 +388,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #pragma mark - #pragma mark Connection callback and methods -- (void)setConnection:(MCPConnection *)theConnection +- (void)setConnection:(SPMySQLConnection *)theConnection { _isConnected = YES; mySQLConnection = [theConnection retain]; @@ -433,6 +427,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [chooseDatabaseButton setEnabled:!_isWorkingLevel]; + // Set the connection on the database structure builder + [databaseStructureRetrieval setConnectionToClone:mySQLConnection]; + [databaseDataInstance setConnection:mySQLConnection]; // Pass the support class to the data instance @@ -571,7 +568,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; * * @return The document's connection */ -- (MCPConnection *) getConnection +- (SPMySQLConnection *) getConnection { return mySQLConnection; } @@ -605,28 +602,25 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]]; #endif - MCPResult *queryResult = [mySQLConnection listDBs]; - - if ([queryResult numOfRows]) [queryResult dataSeek:0]; - if (allDatabases) [allDatabases release]; if (allSystemDatabases) [allSystemDatabases release]; - allDatabases = [[NSMutableArray alloc] initWithCapacity:(NSUInteger)[queryResult numOfRows]]; + NSArray *theDatabaseList = [mySQLConnection databases]; + allDatabases = [[NSMutableArray alloc] initWithCapacity:[theDatabaseList count]]; allSystemDatabases = [[NSMutableArray alloc] initWithCapacity:2]; - for (NSUInteger i = 0 ; i < [queryResult numOfRows] ; i++) - { - NSString *database = NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0); + for (NSString *databaseName in theDatabaseList) { - // If the database is either information_schema or mysql then it is classed as a system table - // 5.5.3+ performance_schema - if ([database isEqualToString:@"information_schema"] || [database isEqualToString:@"mysql"] || [database isEqualToString:@"performance_schema"]) { - [allSystemDatabases addObject:database]; - } + // If the database is either information_schema or mysql then it is classed as a + // system table; similarly, for 5.5.3+, performance_schema + if ([databaseName isEqualToString:SPMySQLDatabase] || + [databaseName isEqualToString:SPMySQLInformationSchemaDatabase] || + [databaseName isEqualToString:SPMySQLPerformanceSchemaDatabase]) { + [allSystemDatabases addObject:databaseName]; + } else { - [allDatabases addObject:database]; + [allDatabases addObject:databaseName]; } } @@ -927,7 +921,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self _addDatabase]; // Query the structure of all databases in the background (mainly for completion) - [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]]; + [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:databaseStructureRetrieval withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]]; } else { // reset chooseDatabaseButton @@ -979,21 +973,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSString *dbName = nil; // Notify listeners that a query has started -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; -#endif - MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; + SPMySQLResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; + [theResult setDefaultRowReturnType:SPMySQLResultRowAsArray]; if (![mySQLConnection queryErrored]) { - NSInteger i; - NSInteger r = (NSInteger)[theResult numOfRows]; - if (r) [theResult dataSeek:0]; - for ( i = 0 ; i < r ; i++ ) { - dbName = NSArrayObjectAtIndex([theResult fetchRowAsArray], 0); + for (NSArray *eachRow in theResult) { + dbName = NSArrayObjectAtIndex(eachRow, 0); } - if(![dbName isKindOfClass:[NSNull class]]) { + if(![dbName isNSNull]) { if(![dbName isEqualToString:selectedDatabase]) { if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; selectedDatabase = [[NSString alloc] initWithString:dbName]; @@ -1012,11 +1000,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } //query finished -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; -#endif } #ifndef SP_REFACTOR /* navigatorSchemaPathExistsForDatabase: */ @@ -1364,7 +1348,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (!taskCanBeCancelled) return; [taskCancelButton setEnabled:NO]; - [mySQLConnection cancelCurrentQuery]; + + // See whether there is an active database structure task and whether it can be used + // to cancel the query, for speed (no connection overhead!) + if (databaseStructureRetrieval && [databaseStructureRetrieval connection]) { + [mySQLConnection setLastQueryWasCancelled:YES]; + [[databaseStructureRetrieval connection] killQueryOnThreadID:[mySQLConnection mysqlConnectionThreadId]]; + } else { + [mySQLConnection cancelCurrentQuery]; + } if (taskCancellationCallbackObject && taskCancellationCallbackSelector) { [taskCancellationCallbackObject performSelector:taskCancellationCallbackSelector]; @@ -1558,7 +1550,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void)detectDatabaseEncoding { - MCPResult *charSetResult; + SPMySQLResult *charSetResult; NSString *mysqlEncoding = nil; _supportsEncoding = YES; @@ -1567,11 +1559,11 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([serverSupport supportsCharacterSetDatabaseVar]) { charSetResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_database'"]; [charSetResult setReturnDataAsStrings:YES]; - mysqlEncoding = [[charSetResult fetchRowAsDictionary] objectForKey:@"Value"]; + mysqlEncoding = [[charSetResult getRowAsDictionary] objectForKey:@"Value"]; } // MySQL 4.0 or older -> only default character set possible, cannot choose others using "set names xy" else { - mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; + mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] getRowAsDictionary] objectForKey:@"Value"]; } [selectedDatabaseEncoding release]; @@ -1657,13 +1649,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - MCPResult *theResult = [mySQLConnection queryString:query]; + SPMySQLResult *theResult = [mySQLConnection queryString:query]; [theResult setReturnDataAsStrings:YES]; // Check for errors, only displaying if the connection hasn't been terminated if ([mySQLConnection queryErrored]) { if ([mySQLConnection isConnected]) { - NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while creating table syntax.\n\n: %@", @"Error shown when unable to show create table syntax"),[mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + NSRunAlertPanel(@"Error", [NSString stringWithFormat:NSLocalizedString(@"An error occured while creating table syntax.\n\n: %@", @"Error shown when unable to show create table syntax"), [mySQLConnection lastErrorMessage]], @"OK", nil, nil); } return; @@ -1671,9 +1663,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSString *tableSyntax; if (type == SPTableTypeProc) - tableSyntax = [NSString stringWithFormat:@"DELIMITER ;;\n%@;;\nDELIMITER ", [[theResult fetchRowAsArray] objectAtIndex:colOffs]]; + tableSyntax = [NSString stringWithFormat:@"DELIMITER ;;\n%@;;\nDELIMITER ", [[theResult getRowAsArray] objectAtIndex:colOffs]]; else - tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; + tableSyntax = [[theResult getRowAsArray] objectAtIndex:colOffs]; // A NULL value indicates that the user does not have permission to view the syntax if ([tableSyntax isNSNull]) { @@ -1756,7 +1748,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1769,7 +1761,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to check the %@.\n\nMySQL said:%@",@"an error occurred while trying to check the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to check the %@.\n\nMySQL said:%@",@"an error occurred while trying to check the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1779,10 +1771,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in theResult) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } @@ -1790,7 +1782,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Process result if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Check table successfully passed.",@"check table successfully passed message") : NSLocalizedString(@"Check table failed.", @"check table failed message"); @@ -1812,7 +1804,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while checking selected items", @"error while checking selected items message")]; @@ -1832,7 +1824,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1845,7 +1837,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while analyzing the %@.\n\nMySQL said:%@",@"an error occurred while analyzing the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while analyzing the %@.\n\nMySQL said:%@",@"an error occurred while analyzing the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1855,18 +1847,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if(![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully analyzed table.",@"analyze table successfully passed message") : NSLocalizedString(@"Analyze table failed.", @"analyze table failed message"); @@ -1888,7 +1880,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while analyzing selected items", @"error while analyzing selected items message")]; @@ -1908,7 +1900,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1921,7 +1913,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while optimzing the %@.\n\nMySQL said:%@",@"an error occurred while trying to optimze the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while optimzing the %@.\n\nMySQL said:%@",@"an error occurred while trying to optimze the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -1931,18 +1923,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully optimized table.",@"optimize table successfully passed message") : NSLocalizedString(@"Optimize table failed.", @"optimize table failed message"); @@ -1964,7 +1956,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while optimizing selected items", @"error while optimizing selected items message")]; @@ -1983,7 +1975,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -1996,7 +1988,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while repairing the %@.\n\nMySQL said:%@",@"an error occurred while trying to repair the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while repairing the %@.\n\nMySQL said:%@",@"an error occurred while trying to repair the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2006,18 +1998,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully repaired table.",@"repair table successfully passed message") : NSLocalizedString(@"Repair table failed.", @"repair table failed message"); @@ -2026,7 +2018,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; message = NSLocalizedString(@"Successfully repaired all selected items.",@"successfully repaired all selected items message"); } - if(message) { + if (message) { [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Repair %@", @"REPAIR one or more tables - result title"), what] defaultButton:@"OK" alternateButton:nil @@ -2039,7 +2031,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while repairing selected items", @"error while repairing selected items message")]; @@ -2058,7 +2050,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -2071,7 +2063,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while flushing the %@.\n\nMySQL said:%@",@"an error occurred while trying to flush the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while flushing the %@.\n\nMySQL said:%@",@"an error occurred while trying to flush the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2081,18 +2073,18 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + NSArray *resultStatuses = [theResult getAllRows]; BOOL statusOK = YES; - for(id res in result) { - if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + for (NSDictionary *eachRow in resultStatuses) { + if (![[eachRow objectForKey:@"Msg_type"] isEqualToString:@"status"]) { statusOK = NO; break; } } // Process result - if([selectedItems count] == 1) { - NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if ([selectedItems count] == 1) { + NSDictionary *lastresult = [resultStatuses lastObject]; message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully flushed table.",@"flush table successfully passed message") : NSLocalizedString(@"Flush table failed.", @"flush table failed message"); @@ -2101,7 +2093,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; message = NSLocalizedString(@"Successfully flushed all selected items.",@"successfully flushed all selected items message"); } - if(message) { + if (message) { [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Flush %@", @"FLUSH one or more tables - result title"), what] defaultButton:@"OK" alternateButton:nil @@ -2114,7 +2106,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } else { message = NSLocalizedString(@"MySQL said:",@"mysql said message"); if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:message]; [alert setMessageText:NSLocalizedString(@"Error while flushing selected items", @"error while flushing selected items message")]; @@ -2133,7 +2125,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([selectedItems count] == 0) return; - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + SPMySQLResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; @@ -2145,7 +2137,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while performing the checksum on %@.\n\nMySQL said:%@",@"an error occurred while performing the checksum on the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while performing the checksum on %@.\n\nMySQL said:%@",@"an error occurred while performing the checksum on the %@.\n\nMySQL said:%@"), what, [mySQLConnection lastErrorMessage]]] beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:NULL @@ -2156,8 +2148,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Process result - if([selectedItems count] == 1) { - message = [[[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject] objectForKey:@"Checksum"]; + NSArray *resultStatuses = [theResult getAllRows]; + if ([selectedItems count] == 1) { + message = [[resultStatuses lastObject] objectForKey:@"Checksum"]; [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Checksum %@",@"checksum %@ message"), what] defaultButton:@"OK" alternateButton:nil @@ -2168,9 +2161,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; didEndSelector:NULL contextInfo:NULL]; } else { - NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; if (statusValues) [statusValues release], statusValues = nil; - statusValues = [result retain]; + statusValues = [resultStatuses retain]; NSAlert *alert = [[NSAlert new] autorelease]; [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Checksums of %@",@"Checksums of %@ message"), what]]; [alert setMessageText:NSLocalizedString(@"Table checksum",@"table checksum message")]; @@ -2298,9 +2290,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Before displaying the user manager make sure the current user has access to the mysql.user table. - MCPResult *result = [mySQLConnection queryString:@"SELECT * FROM `mysql`.`user` ORDER BY `user`"]; + SPMySQLResult *result = [mySQLConnection queryString:@"SELECT * FROM `mysql`.`user` ORDER BY `user`"]; - if ([mySQLConnection queryErrored] && ([result numOfRows] == 0)) { + if ([mySQLConnection queryErrored] && ([result numberOfRows] == 0)) { NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Unable to get list of users", @"unable to get list of users message") defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -2358,7 +2350,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; SPBeginAlertSheet(NSLocalizedString(@"Flushed Privileges", @"title of panel when successfully flushed privs"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, NSLocalizedString(@"Successfully flushed privileges.", @"message of panel when successfully flushed privs")); } else { //error while flushing privileges - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't flush privileges.\nMySQL said: %@", @"message of panel when flushing privs failed"), [mySQLConnection lastErrorMessage]]); } } @@ -5088,7 +5080,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } // Get create syntax - MCPResult *queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", + SPMySQLResult *queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", itemTypeStr, [item backtickQuotedString] ]]; @@ -5096,15 +5088,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (changeEncoding) [mySQLConnection restoreStoredEncoding]; - if ( ![queryResult numOfRows] ) { + if ( ![queryResult numberOfRows] ) { //error while getting table structure SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't get create syntax.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]); + [NSString stringWithFormat:NSLocalizedString(@"Couldn't get create syntax.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection lastErrorMessage]]); status = @"1"; } else { - NSString *syntaxString = [[queryResult fetchRowAsArray] objectAtIndex:queryCol]; + NSString *syntaxString = [[queryResult getRowAsArray] objectAtIndex:queryCol]; // A NULL value indicates that the user does not have permission to view the syntax if ([syntaxString isNSNull]) { @@ -5179,21 +5171,21 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; SPFileHandle *fh = [SPFileHandle fileHandleForWritingAtPath:resultFileName]; if(!fh) NSLog(@"Couldn't create file handle to %@", resultFileName); - MCPStreamingResult *theResult = [mySQLConnection streamingQueryString:query]; + SPMySQLResult *theResult = [mySQLConnection streamingQueryString:query]; [theResult setReturnDataAsStrings:YES]; if ([mySQLConnection queryErrored]) { - [fh writeData:[[NSString stringWithFormat:@"MySQL said: %@", [mySQLConnection getLastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[NSString stringWithFormat:@"MySQL said: %@", [mySQLConnection lastErrorMessage]] dataUsingEncoding:NSUTF8StringEncoding]]; status = @"1"; } else { // write header if(writeAsCsv) - [fh writeData:[[[theResult fetchFieldNames] componentsJoinedAsCSV] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[[theResult fieldNames] componentsJoinedAsCSV] dataUsingEncoding:NSUTF8StringEncoding]]; else - [fh writeData:[[[theResult fetchFieldNames] componentsJoinedByString:@"\t"] dataUsingEncoding:NSUTF8StringEncoding]]; + [fh writeData:[[[theResult fieldNames] componentsJoinedByString:@"\t"] dataUsingEncoding:NSUTF8StringEncoding]]; [fh writeData:[[NSString stringWithString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]]; - NSArray *columnDefinition = [theResult fetchResultFieldsStructure]; + NSArray *columnDefinition = [theResult fieldDefinitions]; // Write table meta data NSMutableString *tableMetaData = [NSMutableString string]; @@ -5221,10 +5213,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSUInteger i, j; NSArray *theRow; NSMutableString *result = [NSMutableString string]; - if(writeAsCsv) { - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + if (writeAsCsv) { + for ( i = 0 ; i < [theResult numberOfRows] ; i++ ) { [result setString:@""]; - theRow = [theResult fetchNextRowAsArray]; + theRow = [theResult getRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { NSEvent* event = [NSApp currentEvent]; @@ -5238,9 +5230,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([result length]) [result appendString:@","]; id cell = NSArrayObjectAtIndex(theRow, j); - if([cell isKindOfClass:[NSNull class]]) + if([cell isNSNull]) [result appendString:@"\"NULL\""]; - else if([cell isKindOfClass:[MCPGeometryData class]]) + else if([cell isKindOfClass:[SPMySQLGeometryData class]]) [result appendFormat:@"\"%@\"", [cell wktString]]; else if([cell isKindOfClass:[NSData class]]) { NSString *displayString = [[NSString alloc] initWithData:cell encoding:[mySQLConnection stringEncoding]]; @@ -5261,9 +5253,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } else { - for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { + for ( i = 0 ; i < [theResult numberOfRows] ; i++ ) { [result setString:@""]; - theRow = [theResult fetchNextRowAsArray]; + theRow = [theResult getRowAsArray]; for( j = 0 ; j < [theRow count] ; j++ ) { NSEvent* event = [NSApp currentEvent]; @@ -5277,9 +5269,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if([result length]) [result appendString:@"\t"]; id cell = NSArrayObjectAtIndex(theRow, j); - if([cell isKindOfClass:[NSNull class]]) + if([cell isNSNull]) [result appendString:@"NULL"]; - else if([cell isKindOfClass:[MCPGeometryData class]]) + else if([cell isKindOfClass:[SPMySQLGeometryData class]]) [result appendFormat:@"%@", [cell wktString]]; else if([cell isKindOfClass:[NSData class]]) { NSString *displayString = [[NSString alloc] initWithData:cell encoding:[mySQLConnection stringEncoding]]; @@ -5328,11 +5320,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; - (void)registerActivity:(NSDictionary*)commandDict { [runningActivitiesArray addObject:commandDict]; -#ifndef SP_REFACTOR - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; -#endif + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count]) [self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0]; @@ -5364,12 +5352,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self setActivityPaneHidden:[NSNumber numberWithInteger:1]]; } -#ifndef SP_REFACTOR - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; -#endif - + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; } - (void)setActivityPaneHidden:(NSNumber*)hide @@ -5664,6 +5647,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif + [databaseStructureRetrieval destroy]; + [databaseStructureRetrieval release]; + [allDatabases release]; [allSystemDatabases release]; #ifndef SP_REFACTOR /* dealloc ivars */ @@ -5817,13 +5803,13 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([mySQLConnection queryErrored]) { // An error occurred - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't create database.\nMySQL said: %@", @"message of panel when creation of db failed"), [mySQLConnection lastErrorMessage]]); return; } // Error while selecting the new database (is this even possible?) - if (![mySQLConnection selectDB:[databaseNameField stringValue]] ) { + if (![mySQLConnection selectDatabase:[databaseNameField stringValue]] ) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to database %@.\nBe sure that you have the necessary privileges.", @"message of panel when connection to db failed after selecting from popupbutton"), [databaseNameField stringValue]]); [self setDatabases:self]; @@ -5871,7 +5857,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self performSelector:@selector(showErrorSheetWith:) withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Error", @"error"), [NSString stringWithFormat:NSLocalizedString(@"Couldn't delete the database.\nMySQL said: %@", @"message of panel when deleting db failed"), - [mySQLConnection getLastErrorMessage]], + [mySQLConnection lastErrorMessage]], nil] afterDelay:0.3]; @@ -5882,9 +5868,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // do to threading we have to delete it from 'allDatabases' directly // before calling navigator [allDatabases removeObject:[self database]]; + // This only deletes the db and refreshes the navigator since nothing is changed // that's why we can run this on main thread - [mySQLConnection queryDbStructureWithUserInfo:nil]; + [databaseStructureRetrieval queryDbStructureWithUserInfo:nil]; // Delete was successful if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; @@ -5935,7 +5922,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Attempt to select the specified database, and abort on failure #ifndef SP_REFACTOR /* patch */ if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound - || ![mySQLConnection selectDB:targetDatabaseName]) + || ![mySQLConnection selectDatabase:targetDatabaseName]) #else if ( ![mySQLConnection selectDB:targetDatabaseName] ) #endif -- cgit v1.2.3 From 4cad6f0e6e4fb497b480256c2abe3de34ebf225c Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Mon, 16 Apr 2012 20:16:52 +0000 Subject: Bring outline view branch up to date with trunk. --- Source/SPDatabaseDocument.m | 222 ++++++++++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 92 deletions(-) (limited to 'Source/SPDatabaseDocument.m') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 38027ac8..d43be841 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -36,7 +36,7 @@ enum { #import "SPConnectionController.h" #import "SPConnectionControllerInitializer.h" -#import "SPMySQL.h" +#import #import "SPTablesList.h" #import "SPTableStructure.h" @@ -92,7 +92,7 @@ enum { #ifdef SP_REFACTOR /* headers */ #import "SPAlertSheets.h" -#import "NSNotificationAdditions.h" +#import "NSNotificationCenterThreadingAdditions.h" #import "SPCustomQuery.h" #import "SPDatabaseRename.h" #endif @@ -101,6 +101,7 @@ enum { #ifndef SP_REFACTOR static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif +static NSString *SPRenameDatabaseAction = @"SPRenameDatabase"; @interface SPDatabaseDocument () @@ -111,6 +112,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; - (void)_renameDatabase; - (void)_removeDatabase; - (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails; +#ifndef SP_REFACTOR /* method decls */ +- (void)_processDatabaseChangedBundleTriggerActions; +#endif @end @@ -141,6 +145,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; @synthesize databaseRenameSheet; @synthesize databaseRenameNameField; @synthesize renameDatabaseButton; +@synthesize chooseDatabaseButton; #endif - (id)init @@ -568,7 +573,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; * * @return The document's connection */ -- (SPMySQLConnection *) getConnection +- (SPMySQLConnection *)getConnection { return mySQLConnection; } @@ -659,10 +664,11 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return; } - if ( [chooseDatabaseButton indexOfSelectedItem] == 0 ) { + if ([chooseDatabaseButton indexOfSelectedItem] == 0) { if ([self database]) { [chooseDatabaseButton selectItemWithTitle:[self database]]; } + return; } @@ -677,30 +683,32 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; /** * Select the specified database and, optionally, table. */ -- (void)selectDatabase:(NSString *)aDatabase item:(NSString *)anItem +- (void)selectDatabase:(NSString *)database item:(NSString *)item { #ifndef SP_REFACTOR /* update navigator controller */ // Do not update the navigator since nothing is changed [[SPNavigatorController sharedNavigatorController] setIgnoreUpdate:NO]; // If Navigator runs in syncMode let it follow the selection - if([[SPNavigatorController sharedNavigatorController] syncMode]) { + if ([[SPNavigatorController sharedNavigatorController] syncMode]) { NSMutableString *schemaPath = [NSMutableString string]; + [schemaPath setString:[self connectionID]]; - if([chooseDatabaseButton titleOfSelectedItem] && [[chooseDatabaseButton titleOfSelectedItem] length]) { + + if ([chooseDatabaseButton titleOfSelectedItem] && [[chooseDatabaseButton titleOfSelectedItem] length]) { [schemaPath appendString:SPUniqueSchemaDelimiter]; [schemaPath appendString:[chooseDatabaseButton titleOfSelectedItem]]; } + [[SPNavigatorController sharedNavigatorController] selectPath:schemaPath]; } #endif // Start a task [self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading database '%@'...", @"Loading database task string"), [chooseDatabaseButton titleOfSelectedItem]]]; - NSDictionary *selectionDetails = [NSDictionary dictionaryWithObjectsAndKeys: - aDatabase, @"database", - anItem, @"item", - nil]; + + NSDictionary *selectionDetails = [NSDictionary dictionaryWithObjectsAndKeys:database, @"database", item, @"item", nil]; + if ([NSThread isMainThread]) { [NSThread detachNewThreadSelector:@selector(_selectDatabaseAndItem:) toTarget:self withObject:selectionDetails]; } @@ -793,7 +801,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; modalForWindow:parentWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) - contextInfo:@"renameDatabase"]; + contextInfo:SPRenameDatabaseAction]; } /** @@ -816,17 +824,21 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSArray *buttons = [alert buttons]; +#ifndef SP_REFACTOR // Change the alert's cancel button to have the key equivalent of return [[buttons objectAtIndex:0] setKeyEquivalent:@"d"]; [[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask]; [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"]; +#else + [[buttons objectAtIndex:1] setKeyEquivalent:@"\e"]; // Esc = Cancel + [[buttons objectAtIndex:0] setKeyEquivalent:@"\r"]; // Return = OK +#endif [alert setAlertStyle:NSCriticalAlertStyle]; [alert beginSheetModalForWindow:parentWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removeDatabase"]; } -#ifndef SP_REFACTOR /** * Refreshes the tables list by calling SPTablesList's updateTables. */ @@ -835,6 +847,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tablesListInstance updateTables:self]; } +#ifndef SP_REFACTOR /** * Displays the database server variables sheet. */ @@ -897,7 +910,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo { #ifndef SP_REFACTOR - if([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { + if ([contextInfo isEqualToString:@"saveDocPrefSheetStatus"]) { saveDocPrefSheetStatus = returnCode; return; } @@ -914,6 +927,17 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (returnCode == NSAlertDefaultReturn) { [self _removeDatabase]; } +#ifdef SP_REFACTOR + else { + // Reset chooseDatabaseButton + if ([[self database] length]) { + [chooseDatabaseButton selectItemWithTitle:[self database]]; + } + else { + [chooseDatabaseButton selectItemAtIndex:0]; + } + } +#endif } // Add a new database else if ([contextInfo isEqualToString:@"addDatabase"]) { @@ -923,12 +947,15 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Query the structure of all databases in the background (mainly for completion) [NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:databaseStructureRetrieval withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]]; - } else { - // reset chooseDatabaseButton - if([[self database] length]) + } + else { + // Reset chooseDatabaseButton + if ([[self database] length]) { [chooseDatabaseButton selectItemWithTitle:[self database]]; - else + } + else { [chooseDatabaseButton selectItemAtIndex:0]; + } } } #ifndef SP_REFACTOR @@ -938,10 +965,21 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } } #endif - else if ([contextInfo isEqualToString:@"renameDatabase"]) { + else if ([contextInfo isEqualToString:SPRenameDatabaseAction]) { if (returnCode == NSOKButton) { [self _renameDatabase]; } +#ifdef SP_REFACTOR + else { + // Reset chooseDatabaseButton + if ([[self database] length]) { + [chooseDatabaseButton selectItemWithTitle:[self database]]; + } + else { + [chooseDatabaseButton selectItemAtIndex:0]; + } + } +#endif } #ifndef SP_REFACTOR // Close error status sheet for OPTIMIZE, CHECK, REPAIR etc. @@ -1265,7 +1303,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; */ - (void) endTask { - // Ensure a call on the main thread if (![NSThread isMainThread]) return [[self onMainThread] endTask]; @@ -2285,7 +2322,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; { userManagerInstance = [[SPUserManager alloc] init]; - [userManagerInstance setMySqlConnection:mySQLConnection]; + [userManagerInstance setConnection:mySQLConnection]; [userManagerInstance setServerSupport:serverSupport]; } @@ -2581,6 +2618,16 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; return _isSavedInBundle; } +- (NSArray *)allTableNames +{ + return [tablesListInstance allTableNames]; +} + +- (SPTablesList *)tablesListInstance +{ + return tablesListInstance; +} + #pragma mark - #pragma mark Notification center methods @@ -4297,16 +4344,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if ([tableContentInstance filterSettings]) [sessionState setObject:[tableContentInstance filterSettings] forKey:@"contentFilter"]; - NSIndexSet *contentSelectedIndexSet = [tableContentInstance selectedRowIndexes]; - if (contentSelectedIndexSet && [contentSelectedIndexSet count]) { - NSMutableArray *indices = [NSMutableArray array]; - NSUInteger indexBuffer[[contentSelectedIndexSet count]]; - NSUInteger limit = [contentSelectedIndexSet getIndexes:indexBuffer maxCount:[contentSelectedIndexSet count] inIndexRange:NULL]; - NSUInteger idx; - for (idx = 0; idx < limit; idx++) { - [indices addObject:[NSNumber numberWithInteger:indexBuffer[idx]]]; - } - [sessionState setObject:indices forKey:@"contentSelectedIndexSet"]; + NSDictionary *contentSelectedRows = [tableContentInstance selectionDetailsAllowingIndexSelection:YES]; + if (contentSelectedRows) { + [sessionState setObject:contentSelectedRows forKey:@"contentSelection"]; } } @@ -4734,14 +4774,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tablesListInstance selectTableAtIndex:[NSNumber numberWithInteger:[tables indexOfObject:[spfSession objectForKey:@"table"]]]]; // Restore table selection indexes - if([spfSession objectForKey:@"contentSelectedIndexSet"]) { - NSMutableIndexSet *anIndexSet = [NSMutableIndexSet indexSet]; - NSArray *items = [spfSession objectForKey:@"contentSelectedIndexSet"]; - NSUInteger i; - for(i=0; i<[items count]; i++) - [anIndexSet addIndex:[NSArrayObjectAtIndex(items, i) integerValue]]; - - [tableContentInstance setSelectedRowIndexesToRestore:anIndexSet]; + if([spfSession objectForKey:@"contentSelection"]) { + [tableContentInstance setSelectionToRestore:[spfSession objectForKey:@"contentSelection"]]; } [[tablesListInstance valueForKeyPath:@"tablesListView"] scrollRowToVisible:[tables indexOfObject:[spfSession objectForKey:@"selectedTable"]]]; @@ -5578,7 +5612,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #pragma mark - -#pragma mark status accessory view +#pragma mark Status accessory view - (IBAction)copyChecksumFromSheet:(id)sender { @@ -5611,7 +5645,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif - #pragma mark - /** @@ -5693,15 +5726,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [super dealloc]; } -- (NSArray*)allTableNames -{ - return [tablesListInstance allTableNames]; -} - -- (SPTablesList*)tablesListInstance -{ - return tablesListInstance; -} +#pragma mark - #ifndef SP_REFACTOR /* whole database operations */ @@ -5737,7 +5762,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; - (void)_renameDatabase { - if ([[databaseRenameNameField stringValue] isEqualToString:@""]) { + NSString *newDatabaseName = [databaseRenameNameField stringValue]; + + if ([newDatabaseName isEqualToString:@""]) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, NSLocalizedString(@"Database must have a name.", @"message of panel when no db name is given")); return; } @@ -5747,30 +5774,26 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [dbActionRename setConnection:[self getConnection]]; [dbActionRename setMessageWindow:parentWindow]; - if ([dbActionRename renameDatabaseFrom:[self database] to:[databaseRenameNameField stringValue]]) { - [self selectDatabase:[databaseRenameNameField stringValue] item:nil]; + if ([dbActionRename renameDatabaseFrom:[self database] to:newDatabaseName]) { + [self setDatabases:self]; + [self selectDatabase:newDatabaseName item:nil]; } else { SPBeginAlertSheet(NSLocalizedString(@"Unable to rename database", @"unable to rename database message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, parentWindow, self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to rename the database '%@' to '%@'.", @"unable to rename database message informative message"), [self database], [databaseRenameNameField stringValue]]); + [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to rename the database '%@' to '%@'.", @"unable to rename database message informative message"), [self database], newDatabaseName]); } [dbActionRename release]; - - // Update DB list - [self setDatabases:self]; #ifdef SP_REFACTOR - if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) + if (delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)]) { [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; + } - if ( delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)] ) - { - if ( [allDatabases count] > 0 ) - { - NSString* db = [databaseRenameNameField stringValue]; - [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:db]; + if (delegate && [delegate respondsToSelector:@selector(selectDatabaseInPopup:)]) { + if ([allDatabases count] > 0 ) { + [delegate performSelector:@selector(selectDatabaseInPopup:) withObject:newDatabaseName]; } } #endif @@ -5873,7 +5896,6 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // that's why we can run this on main thread [databaseStructureRetrieval queryDbStructureWithUserInfo:nil]; - // Delete was successful if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil; [self setDatabases:self]; @@ -5881,9 +5903,10 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [tablesListInstance setConnection:mySQLConnection]; [tableDumpInstance setConnection:mySQLConnection]; -#ifndef SP_REFACTOR +#ifndef SP_REFACTOR /* ui */ [self updateWindowTitle:self]; #endif + #ifdef SP_REFACTOR /* glue */ if ( delegate && [delegate respondsToSelector:@selector(refreshDatabasePopup)] ) [delegate performSelector:@selector(refreshDatabasePopup) withObject:nil]; @@ -5911,6 +5934,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Save existing scroll position and details, and ensure no duplicate entries are created as table list changes BOOL historyStateChanging = [spHistoryControllerInstance modifyingState]; + if (!historyStateChanging) { [spHistoryControllerInstance updateHistoryEntries]; [spHistoryControllerInstance setModifyingState:YES]; @@ -5921,13 +5945,11 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; // Attempt to select the specified database, and abort on failure #ifndef SP_REFACTOR /* patch */ - if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound - || ![mySQLConnection selectDatabase:targetDatabaseName]) + if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound || ![mySQLConnection selectDatabase:targetDatabaseName]) #else - if ( ![mySQLConnection selectDB:targetDatabaseName] ) + if (![mySQLConnection selectDatabase:targetDatabaseName]) #endif { - // End the task first to ensure the database dropdown can be reselected [self endTask]; @@ -5996,7 +6018,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; if (![targetItemName isEqualToString:[self table]]) { if (targetItemName) { [tablesListInstance selectItemWithName:targetItemName]; - } else { + } + else { [[tablesListInstance onMainThread] setTableListSelectability:YES]; [[[tablesListInstance valueForKey:@"tablesListView"] onMainThread] deselectAll:self]; [[tablesListInstance onMainThread] setTableListSelectability:NO]; @@ -6005,52 +6028,67 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; #endif [self endTask]; #ifndef SP_REFACTOR /* triggered commands */ + [self _processDatabaseChangedBundleTriggerActions]; +#endif + +#ifdef SP_REFACTOR /* glue */ + if (delegate && [delegate respondsToSelector:@selector(databaseDidChange:)]) { + [delegate performSelectorOnMainThread:@selector(databaseDidChange:) withObject:self waitUntilDone:NO]; + } +#endif + [taskPool drain]; +} + +#ifndef SP_REFACTOR +- (void)_processDatabaseChangedBundleTriggerActions +{ NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionDatabaseChanged]; - for(NSString* cmdPath in triggeredCommands) { + + for (NSString* cmdPath in triggeredCommands) + { NSArray *data = [cmdPath componentsSeparatedByString:@"|"]; NSMenuItem *aMenuItem = [[[NSMenuItem alloc] init] autorelease]; + [aMenuItem setTag:0]; [aMenuItem setToolTip:[data objectAtIndex:0]]; - + // For HTML output check if corresponding window already exists BOOL stopTrigger = NO; + if ([(NSString *)[data objectAtIndex:2] length]) { BOOL correspondingWindowFound = NO; NSString *uuid = [data objectAtIndex:2]; - for(id win in [NSApp windows]) { - if([[[[win delegate] class] description] isEqualToString:@"SPBundleHTMLOutputController"]) { - if([[[win delegate] windowUUID] isEqualToString:uuid]) { + + for (id win in [NSApp windows]) + { + if ([[[[win delegate] class] description] isEqualToString:@"SPBundleHTMLOutputController"]) { + if ([[[win delegate] windowUUID] isEqualToString:uuid]) { correspondingWindowFound = YES; break; } } } - if(!correspondingWindowFound) stopTrigger = YES; + + if (!correspondingWindowFound) stopTrigger = YES; } - if(!stopTrigger) { - if([[data objectAtIndex:1] isEqualToString:SPBundleScopeGeneral]) { + if (!stopTrigger) { + if ([[data objectAtIndex:1] isEqualToString:SPBundleScopeGeneral]) { [[[NSApp delegate] onMainThread] executeBundleItemForApp:aMenuItem]; } - else if([[data objectAtIndex:1] isEqualToString:SPBundleScopeDataTable]) { - if([[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SPCopyTable"]) + else if ([[data objectAtIndex:1] isEqualToString:SPBundleScopeDataTable]) { + if ([[[[[NSApp mainWindow] firstResponder] class] description] isEqualToString:@"SPCopyTable"]) { [[[[NSApp mainWindow] firstResponder] onMainThread] executeBundleItemForDataTable:aMenuItem]; + } } - else if([[data objectAtIndex:1] isEqualToString:SPBundleScopeInputField]) { - if([[[NSApp mainWindow] firstResponder] isKindOfClass:[NSTextView class]]) + else if ([[data objectAtIndex:1] isEqualToString:SPBundleScopeInputField]) { + if ([[[NSApp mainWindow] firstResponder] isKindOfClass:[NSTextView class]]) { [[[[NSApp mainWindow] firstResponder] onMainThread] executeBundleItemForInputField:aMenuItem]; + } } } } -#endif - -#ifdef SP_REFACTOR /* glue */ - if (delegate && [delegate respondsToSelector:@selector(databaseDidChange:)]) { - [delegate performSelectorOnMainThread:@selector(databaseDidChange:) withObject:self waitUntilDone:NO]; - } -#endif - - [taskPool drain]; } +#endif @end -- cgit v1.2.3