aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m255
1 files changed, 239 insertions, 16 deletions
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 <http://code.google.com/p/sequel-pro/>
#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