aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsqlprodev <sqlprodev@northofthree.com>2011-05-19 22:47:53 +0000
committersqlprodev <sqlprodev@northofthree.com>2011-05-19 22:47:53 +0000
commitc80db3a0d26b394b9c88fc6ef19a90cda5340440 (patch)
treed79af344b053e24393864382958e490f4b844735
parent838faafed7af37723e8f900a6cba846a29507db2 (diff)
downloadsequelpro-c80db3a0d26b394b9c88fc6ef19a90cda5340440.tar.gz
sequelpro-c80db3a0d26b394b9c88fc6ef19a90cda5340440.tar.bz2
sequelpro-c80db3a0d26b394b9c88fc6ef19a90cda5340440.zip
merging SP_REFACTOR branch with trunk
-rw-r--r--Source/NoodleLineNumberView.m1
-rw-r--r--Source/SPConnectionController.h15
-rw-r--r--Source/SPConnectionController.m54
-rw-r--r--Source/SPConstants.m6
-rw-r--r--Source/SPCustomQuery.h13
-rw-r--r--Source/SPCustomQuery.m14
-rw-r--r--Source/SPDatabaseDocument.h14
-rw-r--r--Source/SPDatabaseDocument.m40
-rw-r--r--Source/SPFieldEditorController.h2
-rw-r--r--Source/SPFieldEditorController.m16
-rw-r--r--Source/SPIndexesController.h23
-rw-r--r--Source/SPIndexesController.m55
-rw-r--r--Source/SPNavigatorController.m3
-rw-r--r--Source/SPNotLoaded.m3
-rw-r--r--Source/SPQueryController.h4
-rw-r--r--Source/SPQueryController.m141
-rw-r--r--Source/SPTableContent.h49
-rw-r--r--Source/SPTableContent.m220
-rw-r--r--Source/SPTableStructure.h26
-rw-r--r--Source/SPTableStructure.m53
-rw-r--r--Source/SPTableStructureDelegate.m2
-rw-r--r--Source/SPTablesList.m4
-rw-r--r--Source/SPTextView.h6
-rw-r--r--Source/SPTextView.m18
24 files changed, 626 insertions, 156 deletions
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m
index 0213c151..2d93fa8c 100644
--- a/Source/NoodleLineNumberView.m
+++ b/Source/NoodleLineNumberView.m
@@ -327,7 +327,6 @@ typedef NSRange (*RangeOfLineIMP)(id object, SEL selector, NSRange range);
CGFloat yinsetMinY = yinset - NSMinY(visibleRect);
CGFloat rectHeight;
-
for (line = (NSUInteger)(*lineNumberForCharacterIndexIMP)(self, lineNumberForCharacterIndexSel, range.location); line < count; line++)
{
lineIndex = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue];
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index bded0b66..3f9cf866 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -30,9 +30,9 @@
#import "SPFavoritesOutlineView.h"
#endif
-@class SPDatabaseDocument, SPSSHTunnel
+@class SPDatabaseDocument, SPSSHTunnel, SPKeychain
#ifndef SP_REFACTOR /* class decl */
-, SPKeychain, BWAnchoredButtonBar, SPFavoriteNode
+, BWAnchoredButtonBar, SPFavoriteNode
#endif
;
@@ -59,8 +59,10 @@
#ifndef SP_REFACTOR /* ivars */
NSView *databaseConnectionSuperview;
NSSplitView *databaseConnectionView;
+#endif
SPKeychain *keychain;
NSUserDefaults *prefs;
+#ifndef SP_REFACTOR
NSMutableArray *favorites;
#endif
SPSSHTunnel *sshTunnel;
@@ -100,11 +102,11 @@
NSString *connectionKeychainID;
NSString *connectionKeychainItemName;
-#ifndef SP_REFACTOR /* ivars */
NSString *connectionKeychainItemAccount;
NSString *connectionSSHKeychainItemName;
NSString *connectionSSHKeychainItemAccount;
+#ifndef SP_REFACTOR /* ivars */
NSMutableArray *nibObjectsToRelease;
IBOutlet NSView *connectionView;
@@ -181,13 +183,10 @@
@property (readwrite, assign) int sshKeyLocationEnabled;
@property (readwrite, retain) NSString *sshKeyLocation;
@property (readwrite, retain) NSString *sshPort;
-#ifndef SP_REFACTOR /* ivars */
-
@property (readwrite, retain) NSString *connectionKeychainItemName;
@property (readwrite, retain) NSString *connectionKeychainItemAccount;
@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
@property (readwrite, retain) NSString *connectionSSHKeychainItemAccount;
-#endif
@property (readonly, assign) BOOL isConnecting;
#ifndef SP_REFACTOR /* ivars */
@@ -198,7 +197,6 @@
// Connection processes
- (IBAction)initiateConnection:(id)sender;
-#ifndef SP_REFACTOR /* method decls */
- (IBAction)cancelMySQLConnection:(id)sender;
- (void)initiateSSHTunnelConnection;
- (void)sshTunnelCallback:(SPSSHTunnel *)theTunnel;
@@ -209,16 +207,19 @@
// Interface interaction
- (IBAction)chooseKeyLocation:(id)sender;
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)editFavorites:(id)sender;
- (IBAction)showHelp:(id)sender;
- (IBAction)updateSSLInterface:(id)sender;
- (void)resizeTabViewToConnectionType:(NSUInteger)theType animating:(BOOL)animate;
- (IBAction)sortFavorites:(id)sender;
- (IBAction)reverseSortFavorites:(id)sender;
+#endif
// Connection details interaction
- (BOOL)checkHost;
+#ifndef SP_REFACTOR
// Favorites interaction
- (void)updateFavorites;
- (void)updateFavoriteSelection:(id)sender;
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 728c621e..50d42ee1 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -33,8 +33,8 @@
#import "RegexKitLite.h"
#endif
#import "SPAlertSheets.h"
-#ifndef SP_REFACTOR /* headers */
#import "SPKeychain.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPFavoritesPreferencePane.h"
#endif
#import "SPSSHTunnel.h"
@@ -82,12 +82,10 @@
@synthesize sshKeyLocation;
@synthesize sshPort;
-#ifndef SP_REFACTOR /* ivars */
@synthesize connectionKeychainItemName;
@synthesize connectionKeychainItemAccount;
@synthesize connectionSSHKeychainItemName;
@synthesize connectionSSHKeychainItemAccount;
-#endif
@synthesize isConnecting;
#ifndef SP_REFACTOR /* ivars */
@@ -110,11 +108,9 @@
#endif
connectionKeychainID = nil;
connectionKeychainItemName = nil;
-#ifndef SP_REFACTOR /* ivars */
connectionKeychainItemAccount = nil;
connectionSSHKeychainItemName = nil;
connectionSSHKeychainItemAccount = nil;
-#endif
mySQLConnection = nil;
sshTunnel = nil;
cancellingConnection = NO;
@@ -140,9 +136,10 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollViewFrameChanged:) name:NSViewFrameDidChangeNotification object:nil];
// Set up a keychain instance and preferences reference, and create the initial favorites list
+#endif
keychain = [[SPKeychain alloc] init];
prefs = [[NSUserDefaults standardUserDefaults] retain];
-
+#ifndef SP_REFACTOR
favorites = nil;
// Load favorites
@@ -190,8 +187,8 @@
[prefs removeObserver:self forKeyPath:SPFavorites];
#endif
[[NSNotificationCenter defaultCenter] removeObserver:self];
-#ifndef SP_REFACTOR /* dealloc ivars */
[keychain release];
+#ifndef SP_REFACTOR /* dealloc ivars */
[prefs release];
for (id retainedObject in nibObjectsToRelease) [retainedObject release];
@@ -203,11 +200,9 @@
if (sshTunnel) [sshTunnel setConnectionStateChangeSelector:nil delegate:nil], [sshTunnel disconnect], [sshTunnel release];
if (connectionKeychainID) [connectionKeychainID release];
if (connectionKeychainItemName) [connectionKeychainItemName release];
-#ifndef SP_REFACTOR /* dealloc ivars */
if (connectionKeychainItemAccount) [connectionKeychainItemAccount release];
if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
-#endif
[super dealloc];
}
@@ -222,7 +217,6 @@
*/
- (IBAction)initiateConnection:(id)sender
{
-#ifndef SP_REFACTOR /* validate connection details */
// Ensure that host is not empty if this is a TCP/IP or SSH connection
if (([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) {
SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocument parentWindow], self, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter at least the hostname.", @"insufficient details informative message"));
@@ -279,6 +273,7 @@
isConnecting = YES;
cancellingConnection = NO;
+#ifndef SP_REFACTOR
// Disable the favorites outline view to prevent further connections attempts
[favoritesTable setEnabled:NO];
@@ -287,6 +282,7 @@
[connectButton setEnabled:NO];
[progressIndicator startAnimation:self];
[progressIndicatorText setHidden:NO];
+#endif
// Start the current tab's progress indicator
[tableDocument setIsProcessing:YES];
@@ -297,9 +293,11 @@
if (connectionKeychainItemName) {
if ([[keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount] isEqualToString:[self password]]) {
[self setPassword:[[NSString string] stringByPaddingToLength:[[self password] length] withString:@"sp" startingAtIndex:0]];
+#ifndef SP_REFACTOR
[[standardPasswordField undoManager] removeAllActionsWithTarget:standardPasswordField];
[[socketPasswordField undoManager] removeAllActionsWithTarget:socketPasswordField];
[[sshPasswordField undoManager] removeAllActionsWithTarget:sshPasswordField];
+#endif
} else {
[connectionKeychainItemName release], connectionKeychainItemName = nil;
[connectionKeychainItemAccount release], connectionKeychainItemAccount = nil;
@@ -308,7 +306,9 @@
if (connectionSSHKeychainItemName) {
if ([[keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount] isEqualToString:[self sshPassword]]) {
[self setSshPassword:[[NSString string] stringByPaddingToLength:[[self sshPassword] length] withString:@"sp" startingAtIndex:0]];
+#ifndef SP_REFACTOR
[[sshSSHPasswordField undoManager] removeAllActionsWithTarget:sshSSHPasswordField];
+#endif
} else {
[connectionSSHKeychainItemName release], connectionSSHKeychainItemName = nil;
[connectionSSHKeychainItemAccount release], connectionSSHKeychainItemAccount = nil;
@@ -328,12 +328,11 @@
[self performSelector:@selector(initiateSSHTunnelConnection) withObject:nil afterDelay:0.0];
return;
}
-#endif
+
// ...or start the MySQL connection process directly
[self performSelector:@selector(initiateMySQLConnection) withObject:nil afterDelay:0.0];
}
-#ifndef SP_REFACTOR /* cancelMySQLConnection: */
/**
* Cancels (or rather marks) the current connection is to be cancelled once established.
*
@@ -343,16 +342,16 @@
*/
- (IBAction)cancelMySQLConnection:(id)sender
{
+#ifndef SP_REFACTOR
[connectButton setEnabled:NO];
[progressIndicatorText setStringValue:NSLocalizedString(@"Cancelling...", @"cancelling task status message")];
[progressIndicatorText display];
+#endif
mySQLConnectionCancelled = YES;
}
-#endif
-#ifndef SP_REFACTOR /* initiateSSHTunnelConnection */
/*
* Initiate the SSH connection process.
* This should only be called as part of initiateConnection:, and will indirectly
@@ -360,8 +359,10 @@
*/
- (void)initiateSSHTunnelConnection
{
+#ifndef SP_REFACTOR
[progressIndicatorText setStringValue:NSLocalizedString(@"SSH connecting...", @"SSH connecting very short status message")];
[progressIndicatorText display];
+#endif
// Trim whitespace and newlines from the SSH host field before attempting to connect
[self setSshHost:[[self sshHost] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
@@ -389,7 +390,6 @@
// itself as an argument - retain count should be one at this point.
[sshTunnel connect];
}
-#endif
/*
* Cancel connection.
@@ -407,7 +407,6 @@
sshTunnel = nil;
}
-#ifndef SP_REFACTOR /* sshTunnelCallback: */
/*
* A callback function for the SSH Tunnel setup process - will be called on a connection
* state change, allowing connection to fail or proceed as appropriate. If successful,
@@ -427,22 +426,27 @@
}
if (newState == PROXY_STATE_IDLE) {
+#ifndef SP_REFACTOR
[tableDocument setTitlebarStatus:NSLocalizedString(@"SSH Disconnected", @"SSH disconnected titlebar marker")];
+#endif
[self failConnectionWithTitle:NSLocalizedString(@"SSH connection failed!", @"SSH connection failed title") errorMessage:[theTunnel lastError] detail:[sshTunnel debugMessages]];
[self _restoreConnectionInterface];
}
else if (newState == PROXY_STATE_CONNECTED) {
+#ifndef SP_REFACTOR
[tableDocument setTitlebarStatus:NSLocalizedString(@"SSH Connected", @"SSH connected titlebar marker")];
+#endif
[self initiateMySQLConnection];
}
else {
+#ifndef SP_REFACTOR
[tableDocument setTitlebarStatus:NSLocalizedString(@"SSH Connecting…", @"SSH connecting titlebar marker")];
+#endif
}
}
-#endif
/*
* Set up the MySQL connection, either through a successful tunnel or directly in the background.
@@ -578,8 +582,6 @@
[tableDocument setConnection:mySQLConnection];
}
-#ifndef SP_REFACTOR /* connection favorites and ssh key handling */
-
#pragma mark -
#pragma mark Interface interaction
@@ -588,12 +590,15 @@
*/
- (IBAction)chooseKeyLocation:(id)sender
{
+#ifndef SP_REFACTOR /* favorites */
[favoritesTable deselectAll:self];
+#endif
NSString *directoryPath = nil;
NSString *filePath = nil;
NSArray *permittedFileTypes = nil;
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
+#ifndef SP_REFACTOR /* !!! ssh keys */
// Switch details by sender.
// First, SSH keys:
if (sender == sshSSHKeyButton) {
@@ -640,6 +645,7 @@
permittedFileTypes = [NSArray arrayWithObjects:@"pem", @"cert", @"crt", @"", nil];
[openPanel setAccessoryView:sslCACertLocationHelp];
}
+#endif
[openPanel beginSheetForDirectory:directoryPath
file:filePath
@@ -655,6 +661,7 @@
*/
- (void)chooseKeyLocationSheetDidEnd:(NSOpenPanel *)openPanel returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
+#ifndef SP_REFACTOR /* !!! ssh key location */
NSString *abbreviatedFileName = [[openPanel filename] stringByAbbreviatingWithTildeInPath];
// SSH key file selection
@@ -692,8 +699,11 @@
}
[self setSslCACertFileLocation:abbreviatedFileName];
}
+#endif
}
+
+#ifndef SP_REFACTOR /* connection favorites and ssh key handling */
/**
* Opens the preferences window, or brings it to the front, and switch to the favorites tab.
* If a favorite is selected in the connection sheet, it is also select in the prefs window.
@@ -837,6 +847,7 @@
[connectionResizeContainer setFrame:frameRect];
}
}
+#endif
/**
* Check the host field and ensure it isn't set to "localhost" for
@@ -873,6 +884,7 @@
}
}
+#ifndef SP_REFACTOR
#pragma mark -
#pragma mark Favorites interaction
@@ -1393,12 +1405,12 @@
#ifndef SP_REFACTOR /* set mysql connection settings from prefs */
// Set whether or not we should enable delegate logging according to the prefs
[mySQLConnection setDelegateQueryLogging:[prefs boolForKey:SPConsoleEnableLogging]];
+#endif
// Set options from preferences
[mySQLConnection setConnectionTimeout:[[prefs objectForKey:SPConnectionTimeoutValue] integerValue]];
[mySQLConnection setUseKeepAlive:[[prefs objectForKey:SPUseKeepAlive] boolValue]];
[mySQLConnection setKeepAliveInterval:[[prefs objectForKey:SPKeepAliveInterval] doubleValue]];
-#endif
// Connect
[mySQLConnection connect];
@@ -1436,10 +1448,8 @@
errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection getLastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil];
} else {
-#ifndef SP_REFACTOR /* error message requiring prefs access */
errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %ld seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], (long)[[prefs objectForKey:SPConnectionTimeoutValue] integerValue], [mySQLConnection getLastErrorMessage]];
[[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil];
-#endif
}
// Tidy up
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index ef263d98..372987ed 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -111,9 +111,15 @@ NSString *SPConsoleEnableImportExportLogging = @"ConsoleEnableImportExportLo
NSString *SPConsoleEnableErrorLogging = @"ConsoleEnableErrorLogging";
// Network Prefpane
+#ifndef SP_REFACTOR
NSString *SPConnectionTimeoutValue = @"ConnectionTimeoutValue";
NSString *SPUseKeepAlive = @"UseKeepAlive";
NSString *SPKeepAliveInterval = @"KeepAliveInterval";
+#else
+NSString *SPConnectionTimeoutValue = @"SPConnectionTimeoutValue";
+NSString *SPUseKeepAlive = @"SPUseKeepAlive";
+NSString *SPKeepAliveInterval = @"SPKeepAliveInterval";
+#endif
// Editor Prefpane
NSString *SPCustomQueryEditorFont = @"CustomQueryEditorFont";
diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h
index f001d364..16aaca14 100644
--- a/Source/SPCustomQuery.h
+++ b/Source/SPCustomQuery.h
@@ -52,9 +52,10 @@
@class SPCopyTable, SPQueryFavoriteManager, SPDataStorage, NSSplitView, SPFieldEditorController;
#endif
+#ifndef SP_REFACTOR
@interface SPCustomQuery : NSObject
-#ifdef SP_REFACTOR
-<NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate>
+#else
+@interface SPCustomQuery : NSObject <NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate>
#endif
{
IBOutlet id tableDocumentInstance;
@@ -186,6 +187,14 @@
NSString *kCellEditorErrorTooManyMatches;
}
+#ifdef SP_REFACTOR
+@property (assign) SPDatabaseDocument* tableDocumentInstance;
+@property (assign) SPTablesList* tablesListInstance;
+@property (assign) SPTextView *textView;
+@property (assign) SPCopyTable *customQueryView;
+@property (assign) NSButton* runAllButton;
+#endif
+
@property(assign) BOOL textViewWasChanged;
// IBAction methods
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 26810323..507de79f 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -35,7 +35,9 @@
#import "SPFieldEditorController.h"
#import "SPTextAndLinkCell.h"
#import "SPTooltip.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPQueryFavoriteManager.h"
+#endif
#import "SPQueryController.h"
#import "SPEncodingPopupAccessory.h"
#import "SPDataStorage.h"
@@ -51,6 +53,15 @@
@implementation SPCustomQuery
+#ifdef SP_REFACTOR
+@synthesize textView;
+@synthesize customQueryView;
+@synthesize runAllButton;
+@synthesize tableDocumentInstance;
+@synthesize tablesListInstance;
+#endif
+
+
@synthesize textViewWasChanged;
#pragma mark IBAction methods
@@ -250,7 +261,7 @@
// init query favorites controller
#ifndef SP_REFACTOR
[prefs synchronize];
-#endif
+
if(favoritesManager) [favoritesManager release];
favoritesManager = [[SPQueryFavoriteManager alloc] initWithDelegate:self];
@@ -260,6 +271,7 @@
modalDelegate:favoritesManager
didEndSelector:nil
contextInfo:nil];
+#endif
}
else if ([queryFavoritesButton indexOfSelectedItem] > 5) {
// Choose favorite
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index ebdac213..8f67ccc4 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -34,7 +34,7 @@
#ifndef SP_REFACTOR /* class forward decls */
SPProcessListController, SPServerVariablesController, SPUserManager, SPWindowController,
#endif
-SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
+SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport, SPCustomQuery;
#import "SPConnectionControllerDelegateProtocol.h"
@@ -85,7 +85,7 @@ SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
IBOutlet id databaseCopySheet;
IBOutlet id databaseRenameSheet;
- IBOutlet id queryProgressBar;
+ IBOutlet NSProgressIndicator* queryProgressBar;
IBOutlet NSBox *taskProgressLayer;
IBOutlet id taskProgressIndicator;
IBOutlet id taskDescriptionText;
@@ -234,8 +234,9 @@ SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
}
#ifdef SP_REFACTOR /* ivars */
-@property (readwrite, assign) id delegate;
+@property (assign) id delegate;
@property (readonly) NSMutableArray* allDatabases;
+@property (assign) NSProgressIndicator* queryProgressBar;
#endif
#ifndef SP_REFACTOR /* ivars */
@@ -397,7 +398,9 @@ SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
// Tab methods
- (void)makeKeyDocument;
- (BOOL)parentTabShouldClose;
+#endif
- (void)parentTabDidClose;
+#ifndef SP_REFACTOR
- (void)willResignActiveTabInWindow;
- (void)didBecomeActiveTabInWindow;
- (void)tabDidBecomeKey;
@@ -430,10 +433,11 @@ SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
- (void)connect;
- (NSArray*)allTableNames;
- (SPTablesList*)tablesListInstance;
-- (SPTableData*)tableDataInstance;
- (void)setTableSourceInstance:(SPTableStructure*)source;
- (void)setTableContentInstance:(SPTableContent*)content;
-- (void)setTableDataInstance:(SPTableData*)data;
+
+@property (assign) SPTableData* tableDataInstance;
+@property (assign) SPCustomQuery* customQueryInstance;
#endif
@end
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 8f63f163..4d6e4bda 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"
@@ -75,10 +77,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 ()
@@ -107,6 +112,9 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax";
#ifdef SP_REFACTOR /* ivars */
@synthesize allDatabases;
@synthesize delegate;
+@synthesize tableDataInstance;
+@synthesize customQueryInstance;
+@synthesize queryProgressBar;
#endif
- (id)init
@@ -211,22 +219,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;
@@ -258,7 +256,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];
@@ -267,6 +265,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];
@@ -325,8 +324,8 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax";
[taskProgressWindow setContentView:taskProgressLayer];
[contentViewSplitter setDelegate:self];
-}
#endif
+}
#ifndef SP_REFACTOR /* password sheet and history navigation */
/**
@@ -443,10 +442,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
@@ -2553,12 +2552,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])
@@ -2572,11 +2571,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]
@@ -3862,19 +3863,23 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax";
// Return YES by default
return YES;
}
+#endif
/**
* Invoked when the parent tab is about to close
*/
- (void)parentTabDidClose
{
-
+#ifndef SP_REFACTOR
// 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,13 +3888,16 @@ 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
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index b629acbf..e2cc3195 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -161,7 +161,9 @@
NSUserDefaults *prefs;
+#ifndef SP_REFACTOR
NSDictionary *qlTypes;
+#endif
NSInteger editSheetReturnCode;
BOOL _isGeometry;
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index 7bdd2eb9..1cb925e2 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -51,7 +51,11 @@
*/
- (id)init
{
+#ifndef SP_REFACTOR
if ((self = [super initWithWindowNibName:@"FieldEditorSheet"])) {
+#else
+ if ((self = [super initWithWindowNibName:@"SQLFieldEditorSheet"])) {
+#endif
// force the nib to be loaded
(void) [self window];
counter = 0;
@@ -86,6 +90,7 @@
[menuItem setEnabled:NO];
[menu addItem:menuItem];
[menuItem release];
+#ifndef SP_REFACTOR
NSUInteger tag = 2;
// Load default QL types
@@ -112,7 +117,6 @@
[qlTypesItems addObject:type];
}
}
-#ifndef SP_REFACTOR
// Load user-defined QL types
if([prefs objectForKey:SPQuickLookTypes]) {
for(id type in [prefs objectForKey:SPQuickLookTypes]) {
@@ -125,10 +129,10 @@
[qlTypesItems addObject:type];
}
}
-#endif
qlTypes = [[NSDictionary dictionaryWithObject:qlTypesItems forKey:SPQuickLookTypes] retain];
[qlTypesItems release];
+#endif
fieldType = @"";
fieldEncoding = @"";
@@ -150,7 +154,9 @@
[[NSClassFromString(@"QLPreviewPanel") sharedPreviewPanel] orderOut:nil];
if ( sheetEditData ) [sheetEditData release];
+#ifndef SP_REFACTOR
if ( qlTypes ) [qlTypes release];
+#endif
if ( tmpDirPath ) [tmpDirPath release];
if ( esUndoManager ) [esUndoManager release];
if ( contextInfo ) [contextInfo release];
@@ -420,8 +426,10 @@
// After ordering out this sheet SPCopyTable remains the first responder thus set it hard.
// This only works in conjunction with [NSTextView becomeFirstResponder] and [NSTextView resignFirstResponder]
// which has to return YES.
+#ifndef SP_REFACTOR
if([[self window] firstResponder] == editTextView)
[[NSApp mainWindow] makeFirstResponder:[[self window] firstResponder]];
+#endif
}
@@ -480,7 +488,9 @@
[hexTextView setHidden:YES];
[hexTextScrollView setHidden:YES];
[usedSheet makeFirstResponder:editTextView];
+#ifndef SP_REFACTOR
[[NSApp mainWindow] makeFirstResponder:editTextView];
+#endif
break;
case 1: // image
[editTextView setHidden:YES];
@@ -750,10 +760,12 @@
*/
- (IBAction)quickLookFormatButton:(id)sender
{
+#ifndef SP_REFACTOR
if(qlTypes != nil && [[qlTypes objectForKey:@"QuickLookTypes"] count] > (NSUInteger)[sender tag] - 2) {
NSDictionary *type = [[qlTypes objectForKey:@"QuickLookTypes"] objectAtIndex:[sender tag] - 2];
[self invokeQuickLookOfType:[type objectForKey:@"Extension"] treatAsText:([[type objectForKey:@"treatAsText"] integerValue])];
}
+#endif
}
/**
diff --git a/Source/SPIndexesController.h b/Source/SPIndexesController.h
index 65cbb207..6b755bcc 100644
--- a/Source/SPIndexesController.h
+++ b/Source/SPIndexesController.h
@@ -23,9 +23,17 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-@class SPDatabaseDocument, SPTablesList, SPTableData, SPTableStructure, SPTableView, MCPConnection, BWAnchoredButtonBar;
+#ifndef SP_REFACTOR
+@class SPDatabaseDocument, SPTablesList, SPTableData, SPTableStructure, MCPConnection, BWAnchoredButtonBar, SPTableView;
+#else
+@class SPDatabaseDocument, SPTablesList, SPTableData, SPTableStructure, MCPConnection, SPTableView;
+#endif
+#ifndef SP_REFACTOR
@interface SPIndexesController : NSWindowController
+#else
+@interface SPIndexesController : NSWindowController <NSTableViewDelegate, NSTableViewDataSource>
+#endif
{
// Controllers
IBOutlet SPDatabaseDocument *dbDocument;
@@ -49,6 +57,7 @@
IBOutlet NSButton *addIndexedColumnButton;
IBOutlet NSButton *removeIndexedColumnButton;
IBOutlet NSButton *confirmAddIndexButton;
+#ifndef SP_REFACTOR
IBOutlet BWAnchoredButtonBar *anchoredButtonBar;
// Advanced options view
@@ -57,6 +66,7 @@
IBOutlet NSButton *indexAdvancedOptionsViewLabelButton;
IBOutlet NSPopUpButton *indexStorageTypePopUpButton;
IBOutlet NSTextField *indexKeyBlockSizeTextField;
+#endif
NSString *table;
@@ -68,13 +78,24 @@
MCPConnection *connection;
+#ifndef SP_REFACTOR /* ivars */
BOOL showAdvancedView;
NSInteger heightOffset;
NSUInteger windowMinWidth;
NSUInteger windowMinHeigth;
+#endif
}
+#ifdef SP_REFACTOR
+@property (assign) SPTableView* indexesTableView;
+@property (assign) SPTableStructure* tableStructure;
+@property (assign) NSButton* addIndexButton;
+@property (assign) NSButton* removeIndexButton;
+
+- (void)setDatabaseDocument:(SPDatabaseDocument*)db;
+#endif
+
/**
* @property table The table currently being viewed
*/
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index 989ec02c..f045c9b3 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -58,6 +58,13 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
@synthesize table;
@synthesize connection;
+#ifdef SP_REFACTOR
+@synthesize indexesTableView;
+@synthesize tableStructure;
+@synthesize addIndexButton;
+@synthesize removeIndexButton;
+#endif
+
#pragma mark -
/**
@@ -65,8 +72,13 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
*/
- (id)init
{
- if ((self = [super initWithWindowNibName:@"IndexesView"])) {
+#ifndef SP_REFACTOR
+ NSString* nibName = @"IndexesView";
+#else
+ NSString* nibName = @"SQLIndexes";
+#endif
+ if ((self = [super initWithWindowNibName:nibName])) {
table = @"";
fields = [[NSMutableArray alloc] init];
@@ -75,13 +87,13 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
#ifndef SP_REFACTOR /* init ivars */
prefs = [NSUserDefaults standardUserDefaults];
-#endif
showAdvancedView = NO;
heightOffset = 0;
windowMinWidth = [[self window] minSize].width;
windowMinHeigth = [[self window] minSize].height;
+#endif
// Create an array of field types that supporting specifying an index length prefix
supportsLength = [[NSArray alloc] initWithObjects:
@@ -233,6 +245,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[addIndexedColumnButton setEnabled:([indexedFields count] < [fields count])];
+#ifndef SP_REFACTOR
// MyISAM and InnoDB tables only support BTREE storage types so disable the storage type popup button
// as it's the default anyway.
[indexStorageTypePopUpButton setEnabled:(!([engine isEqualToString:@"MyISAM"] || [engine isEqualToString:@"InnoDB"]))];
@@ -240,6 +253,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
// The ability to specify an index's key block size was added in MySQL 5.1.10 so disable the textfield
// if it's not supported.
[indexKeyBlockSizeTextField setEnabled:[[dbDocument serverSupport] supportsIndexKeyBlockSize]];
+#endif
// Begin the sheet
[NSApp beginSheet:[self window]
@@ -314,7 +328,9 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
if (indexType == SPPrimaryKeyMenuTag) {
[indexNameTextField setEnabled:NO];
[indexNameTextField setStringValue:@"PRIMARY"];
+#ifndef SP_REFACTOR
[indexStorageTypePopUpButton setEnabled:NO];
+#endif
}
else {
[indexNameTextField setEnabled:YES];
@@ -323,8 +339,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexNameTextField setStringValue:@""];
}
+#ifndef SP_REFACTOR
// Specifiying an index storage type (i.e. HASH or BTREE) is not permitted with SPATIAL indexes
[indexStorageTypePopUpButton setEnabled:(indexType != SPSpatialMenuTag)];
+#endif
}
}
@@ -333,10 +351,12 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
*/
- (IBAction)closeSheet:(id)sender
{
+#ifndef SP_REFACTOR
// Close the advanced options view if it's open
[indexAdvancedOptionsView setHidden:YES];
[indexAdvancedOptionsViewButton setState:NSOffState];
showAdvancedView = NO;
+#endif
// Hide the size column
[indexSizeTableColumn setHidden:YES];
@@ -346,8 +366,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[NSApp endSheet:[sender window] returnCode:[sender tag]];
[[sender window] orderOut:self];
+#ifndef SP_REFACTOR
// Clear the index key block size field
[indexKeyBlockSizeTextField setStringValue:@""];
+#endif
}
/**
@@ -396,6 +418,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
*/
- (IBAction)toggleAdvancedIndexOptionsView:(id)sender
{
+#ifndef SP_REFACTOR
showAdvancedView = (!showAdvancedView);
[indexAdvancedOptionsViewButton setState:showAdvancedView];
@@ -404,6 +427,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexSizeTableColumn setHidden:(!showAdvancedView)];
[self _resizeWindowForAdvancedOptionsViewByHeightDelta:(showAdvancedView) ? ([indexAdvancedOptionsView frame].size.height + 10) : 0];
+#endif
}
#pragma mark -
@@ -586,6 +610,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
break;
}
+#ifndef SP_REFACTOR
// If there is a key block size set it means the database version supports it
if ([[indexKeyBlockSizeTextField stringValue] length]) {
[indexDetails setObject:[NSNumber numberWithInteger:[indexKeyBlockSizeTextField integerValue]] forKey:SPNewIndexKeyBlockSize];
@@ -594,6 +619,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
if (([indexStorageTypePopUpButton indexOfSelectedItem] > 0) && ([[indexTypePopUpButton selectedItem] tag] != SPSpatialMenuTag)) {
[indexDetails setObject:[indexStorageTypePopUpButton titleOfSelectedItem] forKey:SPNewIndexStorageType];
}
+#endif
if ([NSThread isMainThread]) {
[NSThread detachNewThreadSelector:@selector(_addIndexUsingDetails:) toTarget:self withObject:indexDetails];
@@ -708,8 +734,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
}
}
+#ifndef SP_REFACTOR
// Only toggle the sizes column if the advanced view is hidden and at least one field requires a size
if (!showAdvancedView) [indexSizeTableColumn setHidden:(!sizeRequired)];
+#endif
// Validate Add Button
[confirmAddIndexButton setEnabled:(!sizeRequiredFieldAndNotYetSet)];
@@ -908,11 +936,14 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
NSUInteger popUpMask = [indexTypePopUpButton autoresizingMask];
NSUInteger nameFieldMask = [indexNameTextField autoresizingMask];
NSUInteger scrollMask = [indexedColumnsScrollView autoresizingMask];
+#ifndef SP_REFACTOR
NSUInteger buttonMask = [indexAdvancedOptionsViewButton autoresizingMask];
NSUInteger textFieldMask = [indexAdvancedOptionsViewLabelButton autoresizingMask];
NSUInteger advancedViewMask = [indexAdvancedOptionsView autoresizingMask];
+#endif
NSUInteger typeLabelMask = [indexTypeLabel autoresizingMask];
NSUInteger nameLabelMask = [indexNameLabel autoresizingMask];
+#ifndef SP_REFACTOR
NSUInteger buttonBarMask = [(NSView*)anchoredButtonBar autoresizingMask];
NSRect frame = [[self window] frame];
@@ -923,21 +954,27 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[[self window] setFrame:frame display:YES animate:YES];
}
+#endif
[indexTypePopUpButton setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexNameTextField setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexedColumnsScrollView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
+#ifndef SP_REFACTOR
[indexAdvancedOptionsViewButton setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexAdvancedOptionsViewLabelButton setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexAdvancedOptionsView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
+#endif
[indexTypeLabel setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexNameLabel setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
+#ifndef SP_REFACTOR
[(NSView*)anchoredButtonBar setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
NSInteger newMinHeight = (windowMinHeigth - heightOffset + delta < windowMinHeigth) ? windowMinHeigth : windowMinHeigth - heightOffset + delta;
[[self window] setMinSize:NSMakeSize(windowMinWidth, newMinHeight)];
+#endif
+#ifndef SP_REFACTOR
frame.origin.y += heightOffset;
frame.size.height -= heightOffset;
@@ -947,16 +984,21 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
frame.size.height += heightOffset;
[[self window] setFrame:frame display:YES animate:YES];
+#endif
[indexTypePopUpButton setAutoresizingMask:popUpMask];
[indexNameTextField setAutoresizingMask:nameFieldMask];
[indexedColumnsScrollView setAutoresizingMask:scrollMask];
+#ifndef SP_REFACTOR
[indexAdvancedOptionsViewButton setAutoresizingMask:buttonMask];
[indexAdvancedOptionsViewLabelButton setAutoresizingMask:textFieldMask];
[indexAdvancedOptionsView setAutoresizingMask:advancedViewMask];
+#endif
[indexTypeLabel setAutoresizingMask:typeLabelMask];
[indexNameLabel setAutoresizingMask:nameLabelMask];
+#ifndef SP_REFACTOR
[(NSView*)anchoredButtonBar setAutoresizingMask:buttonBarMask];
+#endif
}
#pragma mark -
@@ -978,4 +1020,13 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[super dealloc];
}
+
+#ifdef SP_REFACTOR
+- (void)setDatabaseDocument:(SPDatabaseDocument*)db
+{
+ dbDocument = db;
+}
+#endif
+
+
@end
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 1c17dd25..ca0a0c69 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -68,6 +68,9 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
@synchronized(self) {
return [[self sharedNavigatorController] retain];
}
+#ifdef SP_REFACTOR
+ return nil; // only here to stop clang's "can reach end of non-void function"
+#endif
}
- (id)init
diff --git a/Source/SPNotLoaded.m b/Source/SPNotLoaded.m
index 4e2925a7..66d6f209 100644
--- a/Source/SPNotLoaded.m
+++ b/Source/SPNotLoaded.m
@@ -45,6 +45,9 @@ static SPNotLoaded *notLoaded = nil;
@synchronized(self) {
return [[self notLoaded] retain];
}
+#ifdef SP_REFACTOR
+ return nil; // only here to stop clang's "can reach end of non-void function"
+#endif
}
- (id) init
diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h
index c80da762..27756708 100644
--- a/Source/SPQueryController.h
+++ b/Source/SPQueryController.h
@@ -25,6 +25,7 @@
@interface SPQueryController : NSWindowController
{
+#ifndef SP_REFACTOR /* ivars */
// QueryConsoleController
IBOutlet NSView *saveLogView;
IBOutlet NSTableView *consoleTableView;
@@ -48,6 +49,7 @@
NSMutableDictionary *historyContainer;
NSMutableDictionary *contentFilterContainer;
NSUInteger numberOfMaxAllowedHistory;
+#endif
NSArray *completionKeywordList;
NSArray *completionFunctionList;
@@ -55,10 +57,10 @@
#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
-#endif
NSDateFormatter *dateFormatter;
pthread_mutex_t consoleLock;
+#endif
}
@property (readwrite, retain) NSFont *consoleFont;
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index 3a003f82..6ff942f1 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -31,9 +31,11 @@
#define MESSAGE_TRUNCATE_CHARACTER_LENGTH 256
+#ifndef SP_REFACTOR
// Table view column identifier constants
static NSString *SPTableViewDateColumnID = @"messageDate";
static NSString *SPTableViewConnectionColumnID = @"messageConnection";
+#endif
@interface SPQueryController (PrivateAPI)
@@ -69,11 +71,15 @@ static SPQueryController *sharedQueryController = nil;
@synchronized(self) {
return [[self sharedQueryController] retain];
}
+#ifdef SP_REFACTOR
+ return nil; // only here to stop clang's "can reach end of non-void function"
+#endif
}
- (id)init
{
if ((self = [super initWithWindowNibName:@"Console"])) {
+#ifndef SP_REFACTOR
messagesFullSet = [[NSMutableArray alloc] init];
messagesFilteredSet = [[NSMutableArray alloc] init];
@@ -92,11 +98,14 @@ static SPQueryController *sharedQueryController = nil;
favoritesContainer = [[NSMutableDictionary alloc] init];
historyContainer = [[NSMutableDictionary alloc] init];
contentFilterContainer = [[NSMutableDictionary alloc] init];
+#endif
completionKeywordList = nil;
completionFunctionList = nil;
functionArgumentSnippets = nil;
+#ifndef SP_REFACTOR
pthread_mutex_init(&consoleLock, NULL);
+#endif
NSError *readError = nil;
NSString *convError = nil;
@@ -159,39 +168,19 @@ static SPQueryController *sharedQueryController = nil;
{
#ifndef SP_REFACTOR /* init ivars */
prefs = [NSUserDefaults standardUserDefaults];
-#endif
[self setWindowFrameAutosaveName:@"QueryConsole"];
// Show/hide table columns
- [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:
-#ifndef SP_REFACTOR
- ![prefs boolForKey:SPConsoleShowTimestamps]
-#else
- YES
-#endif
- ];
- [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:
-#ifndef SP_REFACTOR
- ![prefs boolForKey:SPConsoleShowConnections]
-#else
- YES
-#endif
- ];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
+ [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
-#ifndef SP_REFACTOR
showSelectStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowSelectsAndShows];
showHelpStatementsAreDisabled = ![prefs boolForKey:SPConsoleShowHelps];
-#else
- showSelectStatementsAreDisabled = YES;
- showHelpStatementsAreDisabled = YES;
-#endif
[self _updateFilterState];
-#ifndef SP_REFACTOR
[loggingDisabledTextField setStringValue:([prefs boolForKey:SPConsoleEnableLogging]) ? @"" : NSLocalizedString(@"Query logging is currently disabled", @"query logging disabled label")];
-#endif
// Setup data formatter
dateFormatter = [[NSDateFormatter alloc] init];
@@ -201,22 +190,17 @@ static SPQueryController *sharedQueryController = nil;
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
-#ifndef SP_REFACTOR
// Set the process table view's vertical gridlines if required
[consoleTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
-#endif
// Set the strutcture and index view's font
-#ifndef SP_REFACTOR
BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
-#else
- BOOL useMonospacedFont = YES;
-#endif
for (NSTableColumn *column in [consoleTableView tableColumns])
{
[[column dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
+#endif
}
#pragma mark -
@@ -227,6 +211,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)copy:(id)sender
{
+#ifndef SP_REFACTOR
NSResponder *firstResponder = [[self window] firstResponder];
if ((firstResponder == consoleTableView) && ([consoleTableView numberOfSelectedRows] > 0)) {
@@ -267,6 +252,7 @@ static SPQueryController *sharedQueryController = nil;
[pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
[pasteBoard setString:string forType:NSStringPboardType];
}
+#endif
}
/**
@@ -274,10 +260,12 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)clearConsole:(id)sender
{
+#ifndef SP_REFACTOR
[messagesFullSet removeAllObjects];
[messagesFilteredSet removeAllObjects];
[consoleTableView reloadData];
+#endif
}
/**
@@ -285,6 +273,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)saveConsoleAs:(id)sender
{
+#ifndef SP_REFACTOR
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setRequiredFileType:SPFileExtensionSQL];
@@ -295,7 +284,8 @@ static SPQueryController *sharedQueryController = nil;
[panel setAccessoryView:saveLogView];
- [panel beginSheetForDirectory:nil file:NSLocalizedString(@"ConsoleLog",@"Console : Save as : Initial filename") modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
+ [panel beginSheetForDirectory:nil file:@"untitled" modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
+#endif
}
/**
@@ -303,7 +293,9 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)toggleShowTimeStamps:(id)sender
{
+#ifndef SP_REFACTOR
[[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:([sender state])];
+#endif
}
/**
@@ -311,7 +303,9 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)toggleShowConnections:(id)sender
{
+#ifndef SP_REFACTOR
[[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:([sender state])];
+#endif
}
/**
@@ -319,10 +313,12 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)toggleShowSelectShowStatements:(id)sender
{
+#ifndef SP_REFACTOR
// Store the state of the toggle for later quick reference
showSelectStatementsAreDisabled = [sender state];
[self _updateFilterState];
+#endif
}
/**
@@ -330,10 +326,12 @@ static SPQueryController *sharedQueryController = nil;
*/
- (IBAction)toggleShowHelpStatements:(id)sender
{
+#ifndef SP_REFACTOR
// Store the state of the toggle for later quick reference
showHelpStatementsAreDisabled = [sender state];
[self _updateFilterState];
+#endif
}
/**
@@ -341,7 +339,9 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)showMessageInConsole:(NSString *)message connection:(NSString *)connection
{
+#ifndef SP_REFACTOR
[self _addMessageToConsole:message connection:connection isError:NO];
+#endif
}
/**
@@ -349,7 +349,9 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)showErrorInConsole:(NSString *)error connection:(NSString *)connection
{
+#ifndef SP_REFACTOR
[self _addMessageToConsole:error connection:connection isError:YES];
+#endif
}
/**
@@ -357,7 +359,11 @@ static SPQueryController *sharedQueryController = nil;
*/
- (NSUInteger)consoleMessageCount
{
+#ifndef SP_REFACTOR
return [messagesFullSet count];
+#else
+ return 0;
+#endif
}
/**
@@ -365,9 +371,11 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
+#ifndef SP_REFACTOR
if (returnCode == NSOKButton) {
[[self _getConsoleStringWithTimeStamps:[includeTimeStampsButton integerValue] connections:[includeConnectionButton integerValue]] writeToFile:[sheet filename] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
+#endif
}
#pragma mark -
@@ -378,7 +386,11 @@ static SPQueryController *sharedQueryController = nil;
*/
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
+#ifndef SP_REFACTOR
return [messagesVisibleSet count];
+#else
+ return 0;
+#endif
}
/**
@@ -386,6 +398,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
+#ifndef SP_REFACTOR
NSString *returnValue = nil;
id object = [[messagesVisibleSet objectAtIndex:row] valueForKey:[tableColumn identifier]];
@@ -419,6 +432,9 @@ static SPQueryController *sharedQueryController = nil;
}
return [[[NSAttributedString alloc] initWithString:returnValue attributes:stringAtributes] autorelease];
+#else
+ return nil;
+#endif
}
#pragma mark -
@@ -429,6 +445,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)controlTextDidChange:(NSNotification *)notification
{
+#ifndef SP_REFACTOR
id object = [notification object];
if ([object isEqualTo:consoleSearchField]) {
@@ -439,6 +456,7 @@ static SPQueryController *sharedQueryController = nil;
[self _updateFilterState];
}
+#endif
}
/**
@@ -446,6 +464,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
+#ifndef SP_REFACTOR
// Show/hide logging disabled label
if ([keyPath isEqualToString:SPConsoleEnableLogging]) {
[loggingDisabledTextField setStringValue:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? @"" : @"Query logging is currently disabled"];
@@ -466,6 +485,7 @@ static SPQueryController *sharedQueryController = nil;
[consoleTableView reloadData];
}
+#endif
}
/**
@@ -473,6 +493,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
+#ifndef SP_REFACTOR
if ([menuItem action] == @selector(copy:)) {
return ([consoleTableView numberOfSelectedRows] > 0);
}
@@ -481,19 +502,26 @@ static SPQueryController *sharedQueryController = nil;
if ([menuItem action] == @selector(clearConsole:)) {
return ([self consoleMessageCount] > 0);
}
+#endif
return [[self window] validateMenuItem:menuItem];
}
- (BOOL) allowConsoleUpdate
{
+#ifndef SP_REFACTOR
return allowConsoleUpdate;
+#else
+ return NO;
+#endif
}
- (void) setAllowConsoleUpdate:(BOOL)allowUpdate
{
+#ifndef SP_REFACTOR
allowConsoleUpdate = allowUpdate;
if (allowUpdate && [[self window] isVisible]) [self updateEntries];
+#endif
}
/**
@@ -501,8 +529,10 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)updateEntries
{
+#ifndef SP_REFACTOR
[consoleTableView reloadData];
[consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)];
+#endif
}
/**
@@ -553,6 +583,7 @@ static SPQueryController *sharedQueryController = nil;
- (NSURL *)registerDocumentWithFileURL:(NSURL *)fileURL andContextInfo:(NSMutableDictionary *)contextInfo
{
+#ifndef SP_REFACTOR
// Register a new untiled document and return its URL
if(fileURL == nil) {
NSURL *new = [NSURL URLWithString:[[NSString stringWithFormat:NSLocalizedString(@"Untitled %ld",@"Title of a new Sequel Pro Document"), (unsigned long)untitledDocumentCounter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
@@ -566,20 +597,16 @@ static SPQueryController *sharedQueryController = nil;
// Set the global history coming from the Prefs as default if available
if(![historyContainer objectForKey:[new absoluteString]]) {
-#ifndef SP_REFACTOR
if([prefs objectForKey:SPQueryHistory]) {
NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObjectsFromArray:[prefs objectForKey:SPQueryHistory]];
[historyContainer setObject:arr forKey:[new absoluteString]];
[arr release];
} else {
-#endif
NSMutableArray *arr = [[NSMutableArray alloc] init];
[historyContainer setObject:[NSMutableArray array] forKey:[new absoluteString]];
[arr release];
-#ifndef SP_REFACTOR
}
-#endif
}
// Set the doc-based content filters
@@ -630,10 +657,14 @@ static SPQueryController *sharedQueryController = nil;
}
return fileURL;
+#else
+ return nil;
+#endif
}
- (void)removeRegisteredDocumentWithFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
// Check for multiple instance of the same document.
// Remove it if only one instance was registerd.
NSArray *allDocs = [[NSApp delegate] orderedDocuments];
@@ -652,10 +683,12 @@ static SPQueryController *sharedQueryController = nil;
[historyContainer removeObjectForKey:[fileURL absoluteString]];
if([contentFilterContainer objectForKey:[fileURL absoluteString]])
[contentFilterContainer removeObjectForKey:[fileURL absoluteString]];
+#endif
}
- (void)replaceContentFilterByArray:(NSArray *)contentFilterArray ofType:(NSString *)filterType forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([contentFilterContainer objectForKey:[fileURL absoluteString]]) {
NSMutableDictionary *c = [[NSMutableDictionary alloc] init];
[c setDictionary:[contentFilterContainer objectForKey:[fileURL absoluteString]]];
@@ -663,16 +696,20 @@ static SPQueryController *sharedQueryController = nil;
[contentFilterContainer setObject:c forKey:[fileURL absoluteString]];
[c release];
}
+#endif
}
- (void)replaceFavoritesByArray:(NSArray *)favoritesArray forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([favoritesContainer objectForKey:[fileURL absoluteString]])
[favoritesContainer setObject:favoritesArray forKey:[fileURL absoluteString]];
+#endif
}
- (void)replaceHistoryByArray:(NSArray *)historyArray forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([historyContainer objectForKey:[fileURL absoluteString]])
[historyContainer setObject:historyArray forKey:[fileURL absoluteString]];
@@ -681,8 +718,6 @@ static SPQueryController *sharedQueryController = nil;
if([[doc valueForKeyPath:@"customQueryInstance"] respondsToSelector:@selector(historyItemsHaveBeenUpdated:)])
[[doc valueForKeyPath:@"customQueryInstance"] performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:NO];
-
-#ifndef SP_REFACTOR
// User did choose to clear the global history list
if(![fileURL isFileURL] && ![historyArray count])
[prefs setObject:historyArray forKey:SPQueryHistory];
@@ -691,17 +726,16 @@ static SPQueryController *sharedQueryController = nil;
- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([favoritesContainer objectForKey:[fileURL absoluteString]])
[[favoritesContainer objectForKey:[fileURL absoluteString]] addObject:favorite];
+#endif
}
- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL
{
#ifndef SP_REFACTOR
NSUInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] integerValue];
-#else
- NSUInteger maxHistoryItems = 20;
-#endif
// Save each history item due to its document source
if([historyContainer objectForKey:[fileURL absoluteString]]) {
@@ -721,7 +755,6 @@ static SPQueryController *sharedQueryController = nil;
// Save history items coming from each Untitled document in the global Preferences successively
// regardingless of the source document.
if(![fileURL isFileURL]) {
-#ifndef SP_REFACTOR
// Remove all duplicates by using a NSPopUpButton
NSPopUpButton *uniquifier = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0,0,0,0) pullsDown:YES];
@@ -733,28 +766,33 @@ static SPQueryController *sharedQueryController = nil;
[prefs setObject:[uniquifier itemTitles] forKey:SPQueryHistory];
[uniquifier release];
-#endif
}
+#endif
}
- (NSMutableArray *)favoritesForFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([favoritesContainer objectForKey:[fileURL absoluteString]])
return [favoritesContainer objectForKey:[fileURL absoluteString]];
+#endif
return [NSMutableArray array];
}
- (NSMutableArray *)historyForFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([historyContainer objectForKey:[fileURL absoluteString]])
return [historyContainer objectForKey:[fileURL absoluteString]];
+#endif
return [NSMutableArray array];
}
- (NSArray *)historyMenuItemsForFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([historyContainer objectForKey:[fileURL absoluteString]]) {
NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:[[historyContainer objectForKey:[fileURL absoluteString]] count]];
NSMenuItem *historyMenuItem;
@@ -768,6 +806,7 @@ static SPQueryController *sharedQueryController = nil;
return returnArray;
}
+#endif
return [NSArray array];
}
@@ -780,9 +819,11 @@ static SPQueryController *sharedQueryController = nil;
*/
- (NSUInteger)numberOfHistoryItemsForFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([historyContainer objectForKey:[fileURL absoluteString]])
return [[historyContainer objectForKey:[fileURL absoluteString]] count];
else
+#endif
return 0;
}
@@ -795,8 +836,10 @@ static SPQueryController *sharedQueryController = nil;
*/
- (NSMutableDictionary *)contentFilterForFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
if([contentFilterContainer objectForKey:[fileURL absoluteString]])
return [contentFilterContainer objectForKey:[fileURL absoluteString]];
+#endif
return [NSMutableDictionary dictionary];
}
@@ -835,12 +878,16 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)removeFavoriteAtIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
[[favoritesContainer objectForKey:[fileURL absoluteString]] removeObjectAtIndex:index];
+#endif
}
- (void)insertFavorite:(NSDictionary *)favorite atIndex:(NSUInteger)index forFileURL:(NSURL *)fileURL
{
+#ifndef SP_REFACTOR
[[favoritesContainer objectForKey:[fileURL absoluteString]] insertObject:favorite atIndex:index];
+#endif
}
#pragma mark -
@@ -850,9 +897,12 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)dealloc
{
+#ifndef SP_REFACTOR
messagesVisibleSet = nil;
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self];
+#ifndef SP_REFACTOR
[dateFormatter release], dateFormatter = nil;
[messagesFullSet release], messagesFullSet = nil;
@@ -862,12 +912,15 @@ static SPQueryController *sharedQueryController = nil;
[favoritesContainer release], favoritesContainer = nil;
[historyContainer release], historyContainer = nil;
[contentFilterContainer release], contentFilterContainer = nil;
+#endif
if(completionKeywordList) [completionKeywordList release];
if(completionFunctionList) [completionFunctionList release];
if(functionArgumentSnippets) [functionArgumentSnippets release];
+#ifndef SP_REFACTOR
pthread_mutex_destroy(&consoleLock);
+#endif
[super dealloc];
}
@@ -882,6 +935,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)_updateFilterState
{
+#ifndef SP_REFACTOR
// Display start progress spinner
[progressIndicator setHidden:NO];
@@ -942,6 +996,7 @@ static SPQueryController *sharedQueryController = nil;
// Hide progress spinner
[progressIndicator setHidden:YES];
[progressIndicator stopAnimation:self];
+#endif
}
/**
@@ -952,6 +1007,7 @@ static SPQueryController *sharedQueryController = nil;
{
BOOL messageMatchesCurrentFilters = YES;
+#ifndef SP_REFACTOR
// Check whether to hide the message based on the current filter text, if any
if (filterIsActive
&& [message rangeOfString:activeFilterString options:NSCaseInsensitiveSearch].location == NSNotFound)
@@ -974,6 +1030,7 @@ static SPQueryController *sharedQueryController = nil;
{
messageMatchesCurrentFilters = NO;
}
+#endif
return messageMatchesCurrentFilters;
}
@@ -986,6 +1043,7 @@ static SPQueryController *sharedQueryController = nil;
{
NSMutableString *consoleString = [NSMutableString string];
+#ifndef SP_REFACTOR
for (SPConsoleMessage *message in messagesVisibleSet)
{
// As we are going to save the messages as an SQL file we need to comment
@@ -1006,6 +1064,7 @@ static SPQueryController *sharedQueryController = nil;
[consoleString appendFormat:@"%@\n", [message message]];
}
+#endif
return consoleString;
}
@@ -1015,6 +1074,7 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)_addMessageToConsole:(NSString *)message connection:(NSString *)connection isError:(BOOL)error
{
+#ifndef SP_REFACTOR
NSString *messageTemp = [[message stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
// Only append a semi-colon (;) if the supplied message is not an error
@@ -1047,6 +1107,7 @@ static SPQueryController *sharedQueryController = nil;
}
pthread_mutex_unlock(&consoleLock);
+#endif
}
@end
diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h
index 9045772e..9220b21d 100644
--- a/Source/SPTableContent.h
+++ b/Source/SPTableContent.h
@@ -29,11 +29,12 @@
@class SPDatabaseDocument, SPCopyTable, SPTextAndLinkCell, SPHistoryController, SPTableInfo, SPDataStorage, SPTextView, SPFieldEditorController;
-@class SPTableData, SPDatabaseDocument, SPTablesList;
+@class SPTableData, SPDatabaseDocument, SPTablesList, SPTableStructure, SPTableList;
+#ifndef SP_REFACTOR
@interface SPTableContent : NSObject
-#ifdef SP_REFACTOR
-<NSTableViewDelegate, NSTableViewDataSource>
+#else
+@interface SPTableContent : NSObject <NSTableViewDelegate, NSTableViewDataSource, NSComboBoxDataSource, NSComboBoxDelegate>
#endif
{
IBOutlet SPDatabaseDocument *tableDocumentInstance;
@@ -41,8 +42,10 @@
IBOutlet SPTableData* tableDataInstance;
IBOutlet id tableSourceInstance;
+#ifndef SP_REFACTOR
IBOutlet SPTableInfo *tableInfoInstance;
IBOutlet SPHistoryController *spHistoryControllerInstance;
+#endif
IBOutlet SPCopyTable *tableContentView;
IBOutlet NSPopUpButton *fieldField;
@@ -53,21 +56,28 @@
IBOutlet id copyButton;
IBOutlet id removeButton;
IBOutlet id reloadButton;
+#ifndef SP_REFACTOR
IBOutlet id multipleLineEditingButton;
IBOutlet id countText;
IBOutlet id limitRowsField;
IBOutlet id limitRowsButton;
IBOutlet id limitRowsStepper;
+#endif
IBOutlet id firstBetweenField;
IBOutlet id secondBetweenField;
IBOutlet id betweenTextField;
IBOutlet NSButton *paginationPreviousButton;
+#ifndef SP_REFACTOR
IBOutlet NSButton *paginationButton;
+#endif
IBOutlet NSButton *paginationNextButton;
+#ifndef SP_REFACTOR
IBOutlet NSView *contentViewPane;
IBOutlet NSView *paginationView;
+#endif
IBOutlet NSTextField *paginationPageField;
+#ifndef SP_REFACTOR
IBOutlet NSStepper *paginationPageStepper;
IBOutlet SPCopyTable *filterTableView;
@@ -81,13 +91,15 @@
IBOutlet NSMenuItem *filterTableGearLookAllFields;
IBOutlet NSPanel *filterTableSetDefaultOperatorSheet;
IBOutlet NSComboBox* filterTableSetDefaultOperatorValue;
-
+#endif
MCPConnection *mySQLConnection;
BOOL _mainNibLoaded;
BOOL isWorking;
pthread_mutex_t tableValuesLock;
+#ifndef SP_REFACTOR
NSMutableArray *nibObjectsToRelease;
+#endif
NSString *selectedTable, *usedQuery;
SPDataStorage *tableValues;
@@ -106,6 +118,7 @@
id contentFilterManager;
NSUInteger contentPage;
+#ifndef SP_REFACTOR
NSMutableDictionary *filterTableData;
BOOL filterTableNegate;
BOOL filterTableDistinct;
@@ -114,6 +127,7 @@
NSString *lastEditedFilterTableValue;
NSInteger activeFilter; // 0 = default filter; 1 = filter table; 2 = sequelpro url scheme
NSString *schemeFilter;
+#endif
BOOL sortColumnToRestoreIsAsc;
BOOL tableRowsSelectable;
@@ -123,7 +137,9 @@
NSRect selectionViewportToRestore;
NSString *filterFieldToRestore, *filterComparisonToRestore, *filterValueToRestore, *firstBetweenValueToRestore, *secondBetweenValueToRestore;
+#ifndef SP_REFACTOR
NSInteger paginationViewHeight;
+#endif
NSTimer *tableLoadTimer;
NSUInteger tableLoadInterfaceUpdateInterval, tableLoadTimerTicksSinceLastUpdate, tableLoadLastRowCount, tableLoadTargetRowCount;
@@ -144,7 +160,6 @@
}
-
- (void)setFieldEditorSelectedRange:(NSRange)aRange;
- (NSRange)fieldEditorSelectedRange;
@@ -169,7 +184,9 @@
// Pagination
- (IBAction) navigatePaginationFromButton:(id)sender;
+#ifndef SP_REFACTOR
- (IBAction) togglePagination:(id)sender;
+#endif
- (void) setPaginationViewVisibility:(BOOL)makeVisible;
- (void) updatePaginationState;
@@ -247,9 +264,25 @@
- (NSString*)escapeFilterTableDefaultOperator:(NSString*)anOperator;
#ifdef SP_REFACTOR /* glue */
-- (void)setDatabaseDocument:(SPDatabaseDocument*)doc;
-- (void)setTableListInstance:(SPTablesList*)list;
-- (void)setConnection:(MCPConnection *)theConnection;
+@property (assign) id filterButton;
+@property (assign) id fieldField;
+@property (assign) id compareField;
+@property (assign) id betweenTextField;
+@property (assign) id firstBetweenField;
+@property (assign) id secondBetweenField;
+@property (assign) id argumentField;
+@property (assign) NSButton* addButton;
+@property (assign) NSButton* copyButton;
+@property (assign) NSButton* removeButton;
+@property (assign) NSButton* reloadButton;
+@property (assign) NSButton* paginationNextButton;
+@property (assign) NSButton* paginationPreviousButton;
+@property (assign) NSTextField* paginationPageField;
+@property (assign) SPDatabaseDocument* tableDocumentInstance;
+@property (assign) SPTablesList* tablesListInstance;
+@property (assign) SPCopyTable* tableContentView;
+@property (assign) SPTableData* tableDataInstance;
+@property (assign) SPTableStructure* tableSourceInstance;
#endif
@end
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index df4eccf7..ac3b1fc6 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -59,6 +59,28 @@
@implementation SPTableContent
+#ifdef SP_REFACTOR
+@synthesize addButton;
+@synthesize argumentField;
+@synthesize betweenTextField;
+@synthesize compareField;
+@synthesize copyButton;
+@synthesize fieldField;
+@synthesize filterButton;
+@synthesize firstBetweenField;
+@synthesize paginationNextButton;
+@synthesize paginationPageField;
+@synthesize paginationPreviousButton;
+@synthesize reloadButton;
+@synthesize removeButton;
+@synthesize secondBetweenField;
+@synthesize tableContentView;
+@synthesize tableDataInstance;
+@synthesize tableDocumentInstance;
+@synthesize tableSourceInstance;
+@synthesize tablesListInstance;
+#endif
+
/**
* Standard init method. Initialize various ivars.
*/
@@ -68,22 +90,28 @@
_mainNibLoaded = NO;
isWorking = NO;
pthread_mutex_init(&tableValuesLock, NULL);
+#ifndef SP_REFACTOR
nibObjectsToRelease = [[NSMutableArray alloc] init];
+#endif
tableValues = [[SPDataStorage alloc] init];
dataColumns = [[NSMutableArray alloc] init];
oldRow = [[NSMutableArray alloc] init];
+#ifndef SP_REFACTOR
filterTableData = [[NSMutableDictionary alloc] initWithCapacity:1];
+#endif
tableRowsCount = 0;
previousTableRowsCount = 0;
+#ifndef SP_REFACTOR
filterTableNegate = NO;
filterTableDistinct = NO;
filterTableIsSwapped = NO;
lastEditedFilterTableValue = nil;
activeFilter = 0;
schemeFilter = nil;
+#endif
selectedTable = nil;
sortCol = nil;
@@ -163,7 +191,6 @@
#ifndef SP_REFACTOR /* ui manipulation */
// Set the table content view's vertical gridlines if required
[tableContentView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
-#endif
// Set the double-click action in blank areas of the table to create new rows
[tableContentView setEmptyDoubleClickAction:@selector(addRow:)];
@@ -187,17 +214,20 @@
paginationViewFrame.size.height = 0;
[paginationView setFrame:paginationViewFrame];
[contentViewPane addSubview:paginationView];
+#endif
[tableContentView setFieldEditorSelectedRange:NSMakeRange(0,0)];
+#ifndef SP_REFACTOR
// Init Filter Table GUI
[filterTableDistinctMenuItem setState:(filterTableDistinct) ? NSOnState : NSOffState];
[filterTableNegateCheckbox setState:(filterTableNegate) ? NSOnState : NSOffState];
[filterTableLiveSearchCheckbox setState:NSOffState];
+#endif
#ifndef SP_REFACTOR /* patch */
filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:[prefs objectForKey:SPFilterTableDefaultOperator]] retain];
#else
- filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:nil] retain];
+// filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:nil] retain];
#endif
// Add observers for document task activity
@@ -223,6 +253,7 @@
*/
- (void)loadTable:(NSString *)aTable
{
+
// Abort the reload if the user is still editing a row
if ( isEditingRow )
return;
@@ -314,7 +345,10 @@
*sortColumnNumberToRestore = nil;
NSArray *columnNames;
NSDictionary *columnDefinition;
- NSTableColumn *theCol, *filterCol;
+ NSTableColumn *theCol;
+#ifndef SP_REFACTOR
+ NSTableColumn *filterCol;
+#endif
BOOL enableInteraction =
#ifndef SP_REFACTOR /* checking toolbar state */
![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableContent] ||
@@ -331,8 +365,10 @@
newTableName = [tableDetails objectForKey:@"name"];
}
+#ifndef SP_REFACTOR
// Ensure the pagination view hides itself if visible, after a tiny delay for smoothness
[self performSelector:@selector(setPaginationViewVisibility:) withObject:nil afterDelay:0.1];
+#endif
// Reset table key store for use in argumentForRow:
if (keys) [keys release], keys = nil;
@@ -379,7 +415,9 @@
[tableContentView reloadData];
isFiltered = NO;
isLimited = NO;
+#ifndef SP_REFACTOR
[countText setStringValue:@""];
+#endif
// Reset sort column
if (sortCol) [sortCol release]; sortCol = nil;
@@ -408,8 +446,10 @@
// Disable pagination
[paginationPreviousButton setEnabled:NO];
+#ifndef SP_REFACTOR
[paginationButton setEnabled:NO];
[paginationButton setTitle:@""];
+#endif
[paginationNextButton setEnabled:NO];
// Disable table action buttons
@@ -420,6 +460,7 @@
// Clear restoration settings
[self clearDetailsToRestore];
+#ifndef SP_REFACTOR
// Clear filter table
while ([[filterTableView tableColumns] count]) {
[filterTableView removeTableColumn:NSArrayObjectAtIndex([filterTableView tableColumns], 0)];
@@ -428,6 +469,7 @@
[filterTableData removeAllObjects];
[filterTableWhereClause setString:@""];
activeFilter = 0;
+#endif
return;
}
@@ -437,6 +479,7 @@
while ([[tableContentView tableColumns] count]) {
[tableContentView removeTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], 0)];
}
+#ifndef SP_REFACTOR
// Remove existing columns from the filter table
[filterTableView abortEditing];
while ([[filterTableView tableColumns] count]) {
@@ -446,6 +489,7 @@
[filterTableData removeAllObjects];
[filterTableWhereClause setString:@""];
activeFilter = 0;
+#endif
// Retrieve the field names and types for this table from the data cache. This is used when requesting all data as part
// of the fieldListForQuery method, and also to decide whether or not to preserve the current filter/sort settings.
@@ -496,6 +540,7 @@
]];
[theCol setEditable:YES];
+#ifndef SP_REFACTOR
// Set up column for filterTable
filterCol = [[NSTableColumn alloc] initWithIdentifier:[columnDefinition objectForKey:@"datacolumnindex"]];
[[filterCol headerCell] setStringValue:[columnDefinition objectForKey:@"name"]];
@@ -511,6 +556,7 @@
[columnDefinition objectForKey:@"typegrouping"], @"typegrouping",
[NSMutableArray arrayWithObjects:@"", @"", @"", @"", @"", @"", @"", @"", @"", @"", nil], @"filter",
nil] forKey:[columnDefinition objectForKey:@"datacolumnindex"]];
+#endif
// Set up the data cell depending on the column type
id dataCell;
@@ -581,9 +627,11 @@
[theCol release];
}
+#ifndef SP_REFACTOR
[filterTableView setDelegate:self];
[filterTableView setDataSource:self];
[filterTableView reloadData];
+#endif
// If the table has been reloaded and the previously selected sort column is still present, reselect it.
if (sortColumnNumberToRestore) {
@@ -660,7 +708,9 @@
if (!previousTableRowsCount) {
[self clearTableValues];
}
+#ifndef SP_REFACTOR
[filterTableView reloadData];
+#endif
}
@@ -699,7 +749,9 @@
MCPStreamingResult *streamingResult;
NSInteger rowsToLoad = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
+#ifndef SP_REFACTOR
[countText setStringValue:NSLocalizedString(@"Loading table data...", @"Loading table data string")];
+#endif
// Notify any listeners that a query has started
#ifndef SP_REFACTOR
@@ -709,7 +761,12 @@
#endif
// Start construction of the query string
- queryString = [NSMutableString stringWithFormat:@"SELECT %@%@ FROM %@", (activeFilter == 1 && [self tableFilterString] && filterTableDistinct) ? @"DISTINCT " : @"", [self fieldListForQuery], [selectedTable backtickQuotedString]];
+ queryString = [NSMutableString stringWithFormat:@"SELECT %@%@ FROM %@",
+#ifndef SP_REFACTOR
+ (activeFilter == 1 && [self tableFilterString] && filterTableDistinct) ? @"DISTINCT " :
+#endif
+ @"",
+ [self fieldListForQuery], [selectedTable backtickQuotedString]];
// Add a filter string if appropriate
filterString = [self tableFilterString];
@@ -824,7 +881,9 @@
#endif
if ([mySQLConnection queryErrored] && ![mySQLConnection queryCancelled]) {
+#ifndef SP_REFACTOR
if(activeFilter == 0) {
+#endif
if(filterString)
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"The table data couldn't be loaded presumably due to used filter clause. \n\nMySQL said: %@", @"message of panel when loading of table failed and presumably due to used filter argument"), [mySQLConnection getLastErrorMessage]]);
@@ -832,14 +891,20 @@
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"The table data couldn't be loaded.\n\nMySQL said: %@", @"message of panel when loading of table failed"), [mySQLConnection getLastErrorMessage]]);
}
+#ifndef SP_REFACTOR
// Filter task came from filter table
else if(activeFilter == 1){
[filterTableWindow setTitle:[NSString stringWithFormat:@"%@ – %@", NSLocalizedString(@"Filter", @"filter label"), NSLocalizedString(@"WHERE clause not valid", @"WHERE clause not valid")]];
}
- } else {
+ }
+#endif
+ else
+ {
+#ifndef SP_REFACTOR
// Trigger a full reload if required
if (fullTableReloadRequired) [self reloadTable:self];
[[filterTableWindow onMainThread] setTitle:NSLocalizedString(@"Filter", @"filter label")];
+#endif
}
}
@@ -862,7 +927,11 @@
[[self onMainThread] initTableLoadTimer];
NSAutoreleasePool *dataLoadingPool;
+#ifndef SP_REFACTOR
NSProgressIndicator *dataLoadingIndicator = [tableDocumentInstance valueForKey:@"queryProgressBar"];
+#else
+ NSProgressIndicator *dataLoadingIndicator = [tableDocumentInstance queryProgressBar];
+#endif
BOOL prefsLoadBlobsAsNeeded =
#ifndef SP_REFACTOR
[prefs boolForKey:SPLoadBlobsAsNeeded]
@@ -945,6 +1014,7 @@
- (NSString *)tableFilterString
{
+#ifndef SP_REFACTOR
// If filter command was passed by sequelpro url scheme
if(activeFilter == 2) {
if(schemeFilter)
@@ -963,6 +1033,7 @@
return nil;
}
+#endif
// If the clause has the placeholder $BINARY that placeholder will be replaced
// by BINARY if the user pressed ⇧ while invoking 'Filter' otherwise it will
@@ -1202,7 +1273,9 @@
[countString appendFormat:NSLocalizedString(@"%@ %@ selected", @"text showing how many rows are selected"), [numberFormatter stringFromNumber:[NSNumber numberWithInteger:[tableContentView numberOfSelectedRows]]], rowString];
}
+#ifndef SP_REFACTOR
[[countText onMainThread] setStringValue:countString];
+#endif
}
/**
@@ -1337,6 +1410,8 @@
*/
- (IBAction)filterTable:(id)sender
{
+#ifndef SP_REFACTOR
+
if(sender == filterTableFilterButton)
activeFilter = 1;
else if([sender isKindOfClass:[NSString class]] && [(NSString *)sender length]) {
@@ -1346,12 +1421,15 @@
}
else
activeFilter = 0;
+#endif
NSString *taskString;
if ([tableDocumentInstance isWorking]) return;
if (![self saveRowOnDeselect]) return;
+#ifndef SP_REFACTOR
[self setPaginationViewVisibility:FALSE];
+#endif
// Select the correct pagination value
if (![prefs boolForKey:SPLimitResults] || [paginationPageField integerValue] <= 0)
@@ -1384,8 +1462,10 @@
// Check whether a save of the current row is required.
if (![[self onMainThread] saveRowOnDeselect]) return;
+#ifndef SP_REFACTOR
// Update history
[spHistoryControllerInstance updateHistoryEntries];
+#endif
// Reset and reload data using the new filter settings
previousTableRowsCount = 0;
@@ -1489,17 +1569,20 @@
* When the Pagination button is pressed, show or hide the pagination
* layer depending on the current state.
*/
+#ifndef SP_REFACTOR
- (IBAction) togglePagination:(id)sender
{
if ([sender state] == NSOnState) [self setPaginationViewVisibility:YES];
else [self setPaginationViewVisibility:NO];
}
+#endif
/**
* Show or hide the pagination layer, also changing the first responder as appropriate.
*/
- (void) setPaginationViewVisibility:(BOOL)makeVisible
{
+#ifndef SP_REFACTOR
NSRect paginationViewFrame = [paginationView frame];
if (makeVisible) {
@@ -1524,6 +1607,7 @@
}
[[paginationView animator] setFrame:paginationViewFrame];
+#endif
}
/**
@@ -1553,14 +1637,18 @@
else
[paginationNextButton setEnabled:NO];
+#ifndef SP_REFACTOR
// As long as a table is selected (which it will be if this is called), enable pagination detail button
[paginationButton setEnabled:enabledMode];
+#endif
// Set the values and maximums for the text field and associated pager
[paginationPageField setStringValue:[numberFormatter stringFromNumber:[NSNumber numberWithUnsignedInteger:contentPage]]];
[[paginationPageField formatter] setMaximum:[NSNumber numberWithUnsignedInteger:maxPage]];
+#ifndef SP_REFACTOR
[paginationPageStepper setIntegerValue:contentPage];
[paginationPageStepper setMaxValue:maxPage];
+#endif
}
#pragma mark -
@@ -1692,7 +1780,9 @@
isEditingRow = YES;
isEditingNewRow = YES;
currentlyEditingRow = [tableContentView selectedRow];
+#ifndef SP_REFACTOR
if ( [multipleLineEditingButton state] == NSOffState )
+#endif
[tableContentView editColumn:0 row:[tableContentView numberOfRows]-1 withEvent:nil select:YES];
}
@@ -1762,7 +1852,9 @@
isEditingRow = YES;
isEditingNewRow = YES;
currentlyEditingRow = [tableContentView selectedRow];
+#ifndef SP_REFACTOR
if ( [multipleLineEditingButton state] == NSOffState )
+#endif
[tableContentView editColumn:0 row:[tableContentView selectedRow] withEvent:nil select:YES];
}
@@ -2281,9 +2373,11 @@
return;
}
+#ifndef SP_REFACTOR
// Save existing scroll position and details and mark that state is being modified
[spHistoryControllerInstance updateHistoryEntries];
[spHistoryControllerInstance setModifyingState:YES];
+#endif
NSString *targetFilterValue = [tableValues cellDataAtRow:[theArrowCell getClickedRow] column:dataColumnIndex];
@@ -2314,16 +2408,20 @@
}
}
+#ifndef SP_REFACTOR
// End state and ensure a new history entry
[spHistoryControllerInstance setModifyingState:NO];
[spHistoryControllerInstance updateHistoryEntries];
+#endif
// End the task
[tableDocumentInstance endTask];
+#ifndef SP_REFACTOR
// If the same table is the target, trigger a filter task on the main thread
if (tableFilterRequired)
[self performSelectorOnMainThread:@selector(filterTable:) withObject:self waitUntilDone:NO];
+#endif
// Empty the loading pool and exit the thread
[linkPool drain];
@@ -2463,12 +2561,14 @@
i++;
}
+#ifndef SP_REFACTOR
[menu addItem:[NSMenuItem separatorItem]];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Edit Filters…", @"edit filter") action:NULL keyEquivalent:@""];
[item setToolTip:NSLocalizedString(@"Edit user-defined Filters…", @"edit user-defined filter")];
[item setTag:i];
[menu addItem:item];
[item release];
+#endif
// Attempt to reselect the previously selected title, falling back to the first
// item on failure, as long as there is no filter selection to be restored.
@@ -3037,6 +3137,7 @@
*/
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+#ifndef SP_REFACTOR
[sheet orderOut:self];
if([contextInfo isEqualToString:@"setdefaultoperator"]) {
@@ -3044,18 +3145,15 @@
if(filterTableDefaultOperator) [filterTableDefaultOperator release];
NSString *newOperator = [filterTableSetDefaultOperatorValue stringValue];
filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:newOperator] retain];
-#ifndef SP_REFACTOR
[prefs setObject:newOperator forKey:SPFilterTableDefaultOperator];
-#endif
+
if(![newOperator isMatchedByRegex:@"(?i)like\\s+['\"]%@%['\"]\\s*"]) {
-#ifndef SP_REFACTOR
if(![prefs objectForKey:SPFilterTableDefaultOperatorLastItems])
[prefs setObject:[NSMutableArray array] forKey:SPFilterTableDefaultOperatorLastItems];
-#endif
+
NSMutableArray *lastItems = [NSMutableArray array];
-#ifndef SP_REFACTOR
[lastItems setArray:[prefs objectForKey:SPFilterTableDefaultOperatorLastItems]];
-#endif
+
if([lastItems containsObject:newOperator])
[lastItems removeObject:newOperator];
if([lastItems count] > 0)
@@ -3066,13 +3164,13 @@
if([lastItems count] > 15)
while([lastItems count] > 15)
[filterTableSetDefaultOperatorValue removeItemAtIndex:[lastItems count]-1];
-#ifndef SP_REFACTOR
+
[prefs setObject:lastItems forKey:SPFilterTableDefaultOperatorLastItems];
-#endif
}
[self updateFilterTableClause:nil];
}
}
+#endif
}
/**
@@ -3144,6 +3242,7 @@
*/
- (IBAction)tableFilterClear:(id)sender
{
+#ifndef SP_REFACTOR
[filterTableView abortEditing];
@@ -3162,6 +3261,7 @@
}
+#endif
}
/**
@@ -3169,19 +3269,19 @@
*/
- (IBAction)showFilterTable:(id)sender
{
+#ifndef SP_REFACTOR
[filterTableWindow makeKeyAndOrderFront:nil];
[filterTableWhereClause setContinuousSpellCheckingEnabled:NO];
[filterTableWhereClause setAutoindent:NO];
[filterTableWhereClause setAutoindentIgnoresEnter:NO];
-#ifndef SP_REFACTOR
[filterTableWhereClause setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]];
[filterTableWhereClause setAutohelp:NO];
[filterTableWhereClause setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]];
-#endif
[filterTableWhereClause setCompletionWasReinvokedAutomatically:NO];
[filterTableWhereClause insertText:@""];
[filterTableWhereClause didChangeText];
[[filterTableView window] makeFirstResponder:filterTableView];
+#endif
}
/**
@@ -3189,11 +3289,13 @@
*/
- (IBAction)toggleNegateClause:(id)sender
{
+#ifndef SP_REFACTOR
filterTableNegate = !filterTableNegate;
// If live search is set perform filtering
if([filterTableLiveSearchCheckbox state] == NSOnState)
[self filterTable:filterTableFilterButton];
+#endif
}
@@ -3202,6 +3304,7 @@
*/
- (IBAction)toggleDistinctSelect:(id)sender
{
+#ifndef SP_REFACTOR
filterTableDistinct = !filterTableDistinct;
[filterTableDistinctMenuItem setState:(filterTableDistinct) ? NSOnState : NSOffState];
@@ -3209,6 +3312,7 @@
// If live search is set perform filtering
if([filterTableLiveSearchCheckbox state] == NSOnState)
[self filterTable:filterTableFilterButton];
+#endif
}
@@ -3217,11 +3321,11 @@
*/
- (IBAction)setDefaultOperator:(id)sender
{
+#ifndef SP_REFACTOR
[filterTableWindow makeFirstResponder:filterTableView];
// Load history
-#ifndef SP_REFACTOR
if([prefs objectForKey:SPFilterTableDefaultOperatorLastItems]) {
NSMutableArray *lastItems = [NSMutableArray array];
NSString *defaultItem = @"LIKE '%@%'";
@@ -3234,13 +3338,13 @@
}
[filterTableSetDefaultOperatorValue setStringValue:[prefs objectForKey:SPFilterTableDefaultOperator]];
-#endif
[NSApp beginSheet:filterTableSetDefaultOperatorSheet
modalForWindow:filterTableWindow
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:@"setdefaultoperator"];
+#endif
}
@@ -3256,9 +3360,11 @@
{
[self updateFilterTableClause:sender];
+#ifndef SP_REFACTOR
// If live search is set perform filtering
if([filterTableLiveSearchCheckbox state] == NSOnState)
[self filterTable:filterTableFilterButton];
+#endif
}
@@ -3458,21 +3564,27 @@
- (void) setFilterTableData:(NSData*)arcData
{
+#ifndef SP_REFACTOR
if(!arcData) return;
NSDictionary *filterData = [NSUnarchiver unarchiveObjectWithData:arcData];
[filterTableData removeAllObjects];
[filterTableData addEntriesFromDictionary:filterData];
[filterTableWindow makeKeyAndOrderFront:nil];
// [filterTableView reloadData];
+#endif
}
- (NSData*) filterTableData
{
+#ifndef SP_REFACTOR
if(![filterTableWindow isVisible]) return nil;
[filterTableView deselectAll:nil];
return [NSArchiver archivedDataWithRootObject:filterTableData];
+#else
+ return nil;
+#endif
}
#pragma mark -
@@ -3496,8 +3608,8 @@
maxNumRowsIsEstimate = NO;
[tableDataInstance setStatusValue:[NSString stringWithFormat:@"%ld", (long)maxNumRows] forKey:@"Rows"];
[tableDataInstance setStatusValue:@"y" forKey:@"RowsCountAccurate"];
- [[tableInfoInstance onMainThread] tableChanged:nil];
#ifndef SP_REFACTOR
+ [[tableInfoInstance onMainThread] tableChanged:nil];
[[[tableDocumentInstance valueForKey:@"extendedTableInfoInstance"] onMainThread] loadTable:selectedTable];
#endif
@@ -3530,7 +3642,9 @@
maxNumRowsIsEstimate = NO;
[tableDataInstance setStatusValue:[NSString stringWithFormat:@"%ld", (long)maxNumRows] forKey:@"Rows"];
[tableDataInstance setStatusValue:@"y" forKey:@"RowsCountAccurate"];
+#ifndef SP_REFACTOR
[[tableInfoInstance onMainThread] tableChanged:nil];
+#endif
[[[tableDocumentInstance valueForKey:@"extendedTableInfoInstance"] onMainThread] loadTable:selectedTable];
// Use the estimate count
@@ -3565,7 +3679,9 @@
}
[tableDataInstance setStatusValue:[NSString stringWithFormat:@"%ld", (long)maxNumRows] forKey:@"Rows"];
[tableDataInstance setStatusValue:maxNumRowsIsEstimate?@"n":@"y" forKey:@"RowsCountAccurate"];
+#ifndef SP_REFACTOR
[[tableInfoInstance onMainThread] tableChanged:nil];
+#endif
}
}
@@ -3691,13 +3807,16 @@
- (NSInteger)numberOfRowsInTableView:(SPCopyTable *)aTableView
{
+#ifndef SP_REFACTOR
if (aTableView == filterTableView) {
if (filterTableIsSwapped)
return [filterTableData count];
else
return [[[filterTableData objectForKey:[NSNumber numberWithInteger:0]] objectForKey:@"filter"] count];
}
- else if (aTableView == tableContentView) {
+ else
+#endif
+ if (aTableView == tableContentView) {
return tableRowsCount;
}
@@ -3706,6 +3825,7 @@
- (id)tableView:(SPCopyTable *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
if (aTableView == filterTableView) {
if (filterTableIsSwapped)
// First column shows the field names
@@ -3718,7 +3838,9 @@
return NSArrayObjectAtIndex([[filterTableData objectForKey:[aTableColumn identifier]] objectForKey:@"filter"], rowIndex);
}
}
- else if (aTableView == tableContentView) {
+ else
+#endif
+ if (aTableView == tableContentView) {
NSUInteger columnIndex = [[aTableColumn identifier] integerValue];
id theValue = nil;
@@ -3763,6 +3885,7 @@
- (void)tableView:(SPCopyTable *)aTableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
if(aTableView == filterTableView) {
if(filterTableIsSwapped && [[aTableColumn identifier] integerValue] == 0) {
[cell setDrawsBackground:YES];
@@ -3772,7 +3895,9 @@
}
return;
}
- else if(aTableView == tableContentView) {
+ else
+#endif
+ if(aTableView == tableContentView) {
if (![cell respondsToSelector:@selector(setTextColor:)]) return;
@@ -3819,6 +3944,7 @@
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
if(aTableView == filterTableView) {
if(filterTableIsSwapped)
[[[filterTableData objectForKey:[NSNumber numberWithInteger:rowIndex]] objectForKey:@"filter"] replaceObjectAtIndex:([[aTableColumn identifier] integerValue]-1) withObject:(NSString*)anObject];
@@ -3827,7 +3953,9 @@
[self updateFilterTableClause:nil];
return;
}
- else if(aTableView == tableContentView) {
+ else
+#endif
+ if(aTableView == tableContentView) {
// If table data come from a view
if([tablesListInstance tableType] == SPTableTypeView) {
@@ -4078,7 +4206,6 @@
isFirstChangeInView = YES;
-
[addButton setEnabled:([tablesListInstance tableType] == SPTableTypeTable)];
// If we are editing a row, attempt to save that row - if saving failed, reselect the edit row.
@@ -4200,13 +4327,16 @@
{
if ([tableDocumentInstance isWorking]) return NO;
+#ifndef SP_REFACTOR
if(aTableView == filterTableView) {
if(filterTableIsSwapped && [[aTableColumn identifier] integerValue] == 0)
return NO;
else
return YES;
}
- else if ( aTableView == tableContentView ) {
+ else
+#endif
+ if ( aTableView == tableContentView ) {
// Ensure that row is editable since it could contain "(not loaded)" columns together with
// issue that the table has no primary key
@@ -4244,7 +4374,11 @@
}
// Open the sheet if the multipleLineEditingButton is enabled or the column was a blob or a text.
- if (([multipleLineEditingButton state] == NSOnState || isBlob) && ![[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"enum"]) {
+ if ((
+#ifndef SP_REFACTOR
+ [multipleLineEditingButton state] == NSOnState ||
+#endif
+ isBlob) && ![[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"enum"]) {
// A table is per definitionem editable
isFieldEditable = YES;
@@ -4348,10 +4482,13 @@
*/
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
if(aTableView == filterTableView)
return YES;
- else if(aTableView == tableContentView)
+ else
+#endif
+ if(aTableView == tableContentView)
return tableRowsSelectable;
else
return YES;
@@ -4472,7 +4609,9 @@
tableRowsSelectable = NO;
[paginationPreviousButton setEnabled:NO];
[paginationNextButton setEnabled:NO];
+#ifndef SP_REFACTOR
[paginationButton setEnabled:NO];
+#endif
}
/**
@@ -4493,12 +4632,14 @@
[self updatePaginationState];
[reloadButton setEnabled:YES];
}
+
if ([tableContentView numberOfSelectedRows] > 0) {
if([tablesListInstance tableType] == SPTableTypeTable) {
[removeButton setEnabled:YES];
[copyButton setEnabled:YES];
}
}
+
[filterButton setEnabled:[fieldField isEnabled]];
tableRowsSelectable = YES;
}
@@ -4508,6 +4649,7 @@
- (void)controlTextDidChange:(NSNotification *)notification
{
+#ifndef SP_REFACTOR
if ([notification object] == filterTableView) {
NSString *str = [[[[notification userInfo] objectForKey:@"NSFieldEditor"] textStorage] string];
@@ -4518,6 +4660,7 @@
[self updateFilterTableClause:str];
}
+#endif
}
/**
* If user selected a table cell which is a blob field and tried to edit it
@@ -4574,7 +4717,11 @@
// Check if current edited field is a blob
if ((fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column) headerCell] stringValue]] objectForKey:@"typegrouping"])
- && ![fieldType isEqualToString:@"enum"] && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"] || [multipleLineEditingButton state] == NSOnState))
+ && ![fieldType isEqualToString:@"enum"] && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]
+#ifndef SP_REFACTOR
+ || [multipleLineEditingButton state] == NSOnState
+#endif
+ ))
{
[tableContentView setFieldEditorSelectedRange:[aFieldEditor selectedRange]];
@@ -4584,10 +4731,6 @@
// Call the field editor sheet
[self tableView:tableContentView shouldEditTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], column) row:row];
- // send current event to field editor sheet
- if([NSApp currentEvent])
- [NSApp sendEvent:[NSApp currentEvent]];
-
return NO;
}
@@ -4696,6 +4839,7 @@
*/
- (void)updateFilterTableClause:(id)currentValue
{
+#ifndef SP_REFACTOR
NSMutableString *clause = [NSMutableString string];
NSInteger numberOfRows = [self numberOfRowsInTableView:filterTableView];
NSInteger numberOfCols = [[filterTableView tableColumns] count];
@@ -4833,6 +4977,7 @@
// If live search is set perform filtering
if([filterTableLiveSearchCheckbox state] == NSOnState)
[self filterTable:filterTableFilterButton];
+#endif
}
/**
@@ -4868,17 +5013,6 @@
return [tableContentView fieldEditorSelectedRange];
}
-#ifdef SP_REFACTOR /* glue */
-- (void)setDatabaseDocument:(SPDatabaseDocument*)doc
-{
- tableDocumentInstance = doc;
-}
-
-- (void)setTableListInstance:(SPTablesList*)list
-{
- tablesListInstance = list;
-}
-#endif
#pragma mark -
@@ -4901,9 +5035,11 @@
pthread_mutex_destroy(&tableValuesLock);
[dataColumns release];
[oldRow release];
+#ifndef SP_REFACTOR
[filterTableData release];
if (lastEditedFilterTableValue) [lastEditedFilterTableValue release];
if (filterTableDefaultOperator) [filterTableDefaultOperator release];
+#endif
if (selectedTable) [selectedTable release];
if (contentFilters) [contentFilters release];
if (numberOfDefaultFilters) [numberOfDefaultFilters release];
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index 40b665b2..b8657273 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -27,7 +27,11 @@
@class SPDatabaseDocument, SPTableFieldValidation, SPTableData, SPDatabaseData, SPTablesList, SPIndexesController, SPTableView;
+#ifndef SP_REFACTOR
@interface SPTableStructure : NSObject
+#else
+@interface SPTableStructure : NSObject <NSTableViewDelegate, NSTableViewDataSource>
+#endif
{
IBOutlet SPTablesList* tablesListInstance;
IBOutlet SPTableData* tableDataInstance;
@@ -39,26 +43,32 @@
IBOutlet SPIndexesController* indexesController;
IBOutlet SPDatabaseData* databaseDataInstance;
+#ifndef SP_REFACTOR /* ivars */
IBOutlet id keySheet;
IBOutlet id resetAutoIncrementSheet;
IBOutlet id resetAutoIncrementValue;
IBOutlet id resetAutoIncrementLine;
- IBOutlet SPTableView *tableSourceView;
+#endif
+ IBOutlet SPTableView* tableSourceView;
IBOutlet id addFieldButton;
IBOutlet id copyFieldButton;
IBOutlet id removeFieldButton;
IBOutlet id reloadFieldsButton;
+#ifndef SP_REFACTOR /* ivars */
IBOutlet id chooseKeyButton;
IBOutlet id structureGrabber;
IBOutlet id editTableButton;
IBOutlet id addIndexButton;
IBOutlet id removeIndexButton;
IBOutlet id refreshIndexesButton;
- IBOutlet SPTableView *indexesTableView;
+#endif
+ IBOutlet SPTableView* indexesTableView;
+#ifndef SP_REFACTOR /* ivars */
IBOutlet NSSplitView *tablesIndexesSplitView;
IBOutlet NSButton *indexesShowButton;
IBOutlet id viewColumnsMenu;
+#endif
IBOutlet NSPopUpButtonCell *encodingPopupCell;
MCPConnection *mySQLConnection;
@@ -82,6 +92,15 @@
BOOL isEditingRow, isEditingNewRow, isSavingRow, alertSheetOpened;
}
+#ifdef SP_REFACTOR
+@property (assign) SPIndexesController* indexesController;
+@property (assign) id indexesTableView;
+@property (assign) id addFieldButton;
+@property (assign) id copyFieldButton;
+@property (assign) id removeFieldButton;
+@property (assign) id reloadFieldsButton;
+#endif
+
// Table loading
- (void)loadTable:(NSString *)aTable;
- (IBAction)reloadTable:(id)sender;
@@ -91,6 +110,9 @@
- (void)setDatabaseDocument:(SPDatabaseDocument*)doc;
- (void)setTableListInstance:(SPTablesList*)list;
- (void)setTableDataInstance:(SPTableData*)data;
+- (void)setDatabaseDataInstance:(SPDatabaseData*)data;
+- (void)setTableSourceView:(SPTableView*)tv;
+- (void)setEncodingPopupCell:(NSPopUpButtonCell*)cell;
#endif
- (void)showErrorSheetWith:(NSDictionary *)errorDictionary;
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index ebbb9f7e..618b37b4 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -45,6 +45,15 @@
@implementation SPTableStructure
+#ifdef SP_REFACTOR
+@synthesize indexesController;
+@synthesize indexesTableView;
+@synthesize addFieldButton;
+@synthesize copyFieldButton;
+@synthesize removeFieldButton;
+@synthesize reloadFieldsButton;
+#endif
+
#pragma mark -
#pragma mark Initialization
@@ -171,9 +180,11 @@
[prefs addObserver:indexesController forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
#endif
+#ifndef SP_REFACTOR
// Init the view column submenu according to saved hidden status;
// menu items are identified by their tag number which represents the initial column index
for (NSMenuItem *item in [viewColumnsMenu itemArray]) [item setState:NSOnState]; // Set all items to NSOnState
+#endif
#ifndef SP_REFACTOR /* patch */
for (NSTableColumn *col in [tableSourceView tableColumns])
@@ -190,6 +201,7 @@
}
}
#else
+/*
for (NSTableColumn *col in [tableSourceView tableColumns])
{
if ([col isHidden]) {
@@ -203,6 +215,7 @@
[[viewColumnsMenu itemAtIndex:[viewColumnsMenu indexOfItemWithTag:12]] setState:NSOffState];
}
}
+*/
#endif
[tableSourceView reloadData];
@@ -428,9 +441,11 @@
[addFieldButton setEnabled:NO];
[copyFieldButton setEnabled:NO];
[removeFieldButton setEnabled:NO];
+#ifndef SP_REFACTOR
[addIndexButton setEnabled:NO];
[removeIndexButton setEnabled:NO];
[editTableButton setEnabled:NO];
+#endif
// If no table is selected, refresh the table/index display to blank and return
if (!selectedTable) {
@@ -457,14 +472,18 @@
defaultValues = [[NSDictionary dictionaryWithDictionary:newDefaultValues] retain];
+#ifndef SP_REFACTOR
// Enable the edit table button
[editTableButton setEnabled:enableInteraction];
+#endif
// If a view is selected, disable the buttons; otherwise enable.
BOOL editingEnabled = ([tablesListInstance tableType] == SPTableTypeTable) && enableInteraction;
[addFieldButton setEnabled:editingEnabled];
+#ifndef SP_REFACTOR
[addIndexButton setEnabled:editingEnabled];
+#endif
// Reload the views
[indexesTableView reloadData];
@@ -699,6 +718,7 @@
*/
- (IBAction)resetAutoIncrement:(id)sender
{
+#ifndef SP_REFACTOR
if ([sender tag] == 1) {
[resetAutoIncrementLine setHidden:YES];
@@ -718,6 +738,7 @@
else if ([sender tag] == 2) {
[self setAutoIncrementTo:@"1"];
}
+#endif
}
/**
@@ -725,12 +746,14 @@
*/
- (void)resetAutoincrementSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
+#ifndef SP_REFACTOR
// Order out current sheet to suppress overlapping of sheets
[theSheet orderOut:nil];
if (returnCode == NSAlertDefaultReturn) {
[self setAutoIncrementTo:[[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
+#endif
}
/**
@@ -786,7 +809,9 @@
- (IBAction)unhideIndexesView:(id)sender
{
+#ifndef SP_REFACTOR
[tablesIndexesSplitView setPosition:[tablesIndexesSplitView frame].size.height-130 ofDividerAtIndex:0];
+#endif
}
@@ -1197,9 +1222,11 @@
[addFieldButton setEnabled:NO];
[copyFieldButton setEnabled:NO];
[removeFieldButton setEnabled:NO];
+#ifndef SP_REFACTOR
[addIndexButton setEnabled:NO];
[removeIndexButton setEnabled:NO];
[editTableButton setEnabled:NO];
+#endif
[tablesListInstance updateTables:self];
return NO;
}
@@ -1224,6 +1251,7 @@
}
#ifdef SP_REFACTOR /* glue */
+
- (void)setDatabaseDocument:(SPDatabaseDocument*)doc
{
tableDocumentInstance = doc;
@@ -1239,6 +1267,21 @@
tableDataInstance = data;
}
+- (void)setDatabaseDataInstance:(SPDatabaseData*)data
+{
+ databaseDataInstance = data;
+}
+
+- (void)setTableSourceView:(SPTableView*)tv
+{
+ tableSourceView = tv;
+}
+
+- (void)setEncodingPopupCell:(NSPopUpButtonCell*)cell
+{
+ encodingPopupCell = cell;
+}
+
#endif
/**
@@ -1294,6 +1337,7 @@
*/
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+#ifndef SP_REFACTOR
// Order out current sheet to suppress overlapping of sheets
if ([sheet respondsToSelector:@selector(orderOut:)])
@@ -1324,6 +1368,7 @@
isCurrentExtraAutoIncrement = NO;
}
}
+#endif
}
/**
@@ -1533,12 +1578,16 @@
[removeFieldButton setEnabled:NO];
[copyFieldButton setEnabled:NO];
[reloadFieldsButton setEnabled:NO];
+#ifndef SP_REFACTOR
[editTableButton setEnabled:NO];
+#endif
[indexesTableView setEnabled:NO];
+#ifndef SP_REFACTOR
[addIndexButton setEnabled:NO];
[removeIndexButton setEnabled:NO];
[refreshIndexesButton setEnabled:NO];
+#endif
}
/**
@@ -1563,14 +1612,18 @@
}
[reloadFieldsButton setEnabled:YES];
+#ifndef SP_REFACTOR
[editTableButton setEnabled:YES];
+#endif
[indexesTableView setEnabled:YES];
[indexesTableView displayIfNeeded];
+#ifndef SP_REFACTOR
[addIndexButton setEnabled:editingEnabled];
[removeIndexButton setEnabled:(editingEnabled && ([indexesTableView numberOfSelectedRows] > 0))];
[refreshIndexesButton setEnabled:YES];
+#endif
}
#pragma mark -
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index 4e04ca05..912be276 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -127,12 +127,14 @@
// Asks the user to add an index to query if AUTO_INCREMENT is set and field isn't indexed
if ((![currentRow objectForKey:@"Key"] || [[currentRow objectForKey:@"Key"] isEqualToString:@""])) {
+#ifndef SP_REFACTOR
[chooseKeyButton selectItemWithTag:SPPrimaryKeyMenuTag];
[NSApp beginSheet:keySheet
modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:@"autoincrementindex" ];
+#endif
}
} else {
autoIncrementIndex = nil;
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 5054798c..db470d31 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -872,9 +872,9 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
[[tableSubMenu itemAtIndex:8] setHidden:NO];
[[tableSubMenu itemAtIndex:9] setHidden:NO];
[[tableSubMenu itemAtIndex:10] setHidden:NO];
+#endif
return;
-#endif
}
// If a new selection has been provided, store variables and update the interface to match
@@ -1333,6 +1333,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
return YES;
}
+#endif
#pragma mark -
#pragma mark Data validation
@@ -1398,6 +1399,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
return isValid;
}
+#ifndef SP_REFACTOR
#pragma mark -
#pragma mark Datasource methods
diff --git a/Source/SPTextView.h b/Source/SPTextView.h
index 3309ed1d..dc0557f2 100644
--- a/Source/SPTextView.h
+++ b/Source/SPTextView.h
@@ -111,6 +111,12 @@
@property(assign) BOOL completionIsOpen;
@property(assign) BOOL completionWasReinvokedAutomatically;
+#ifdef SP_REFACTOR
+@property (assign) SPDatabaseDocument *tableDocumentInstance;
+@property (assign) SPTablesList *tablesListInstance;
+@property (assign) SPCustomQuery *customQueryInstance;
+#endif
+
#ifndef SP_REFACTOR
- (IBAction)showMySQLHelpForCurrentWord:(id)sender;
#endif
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index cb0e4d9e..b08db401 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -102,6 +102,12 @@ static inline NSPoint SPPointOnLine(NSPoint a, NSPoint b, CGFloat t) { return NS
@synthesize completionIsOpen;
@synthesize completionWasReinvokedAutomatically;
+#ifdef SP_REFACTOR
+@synthesize tableDocumentInstance;
+@synthesize tablesListInstance;
+@synthesize customQueryInstance;
+#endif
+
/**
* Sort function (mainly used to sort the words in the textView)
*/
@@ -1953,10 +1959,10 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self insertText:snip];
// If autopair is enabled check whether snip begins with ( and ends with ), if so mark ) as pair-linked
+ if (
#ifndef SP_REFACTOR
- if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] &&
+ [prefs boolForKey:SPCustomQueryAutoPairCharacters] &&
#else
- if (
#endif
(([snip hasPrefix:@"("] && [snip hasSuffix:@")"])
|| ([snip hasPrefix:@"`"] && [snip hasSuffix:@"`"])
@@ -2170,8 +2176,10 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Check for {SHIFT}TAB to try to insert query favorite via TAB trigger if SPTextView belongs to SPCustomQuery
// and TAB as soft indention
if ([theEvent keyCode] == 48 && [self isEditable] && [[self delegate] isKindOfClass:[SPCustomQuery class]]){
+#ifndef SP_REFACTOR
NSRange targetRange = [self getRangeForCurrentWord];
NSString *tabTrigger = [[self string] substringWithRange:targetRange];
+#endif
// Is TAB trigger active change selection according to {SHIFT}TAB
if(snippetControlCounter > -1){
@@ -2214,6 +2222,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
+#ifndef SP_REFACTOR
// Check if tab trigger is defined; if so insert it, otherwise pass through event
if(snippetControlCounter < 0 && [tabTrigger length] && [tableDocumentInstance fileURL]) {
NSArray *snippets = [[SPQueryController sharedQueryController] queryFavoritesForFileURL:[tableDocumentInstance fileURL] andTabTrigger:tabTrigger includeGlobals:YES];
@@ -2225,7 +2234,6 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Check for TAB as indention for current line, i.e. left of the caret there are only white spaces
// but only if Soft Indent is set
-#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQuerySoftIndent] && [self isCaretAtIndentPositionIgnoreLineStart:YES]) {
if([self shiftSelectionRight]) return;
}
@@ -3412,7 +3420,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
// Check size and NSFileType
+#ifndef SP_REFACTOR
NSDictionary *attr = [[NSFileManager defaultManager] fileAttributesAtPath:filepath traverseLink:YES];
+#else
+ NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:nil];
+#endif
if(attr)
{
NSNumber *filesize = [attr objectForKey:NSFileSize];
0 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734