aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/NSNotificationAdditions.h9
-rw-r--r--Source/NSNotificationAdditions.m60
-rw-r--r--Source/SPBundleCommandTextView.m10
-rw-r--r--Source/SPBundleHTMLOutputController.m5
-rw-r--r--Source/SPConnectionController.h43
-rw-r--r--Source/SPConstants.m6
-rw-r--r--Source/SPContentFilterManager.h8
-rw-r--r--Source/SPContentFilterManager.m16
-rw-r--r--Source/SPCopyTable.h7
-rw-r--r--Source/SPCopyTable.m61
-rw-r--r--Source/SPCustomQuery.h20
-rw-r--r--Source/SPCustomQuery.m126
-rw-r--r--Source/SPDatabaseDocument.h80
-rw-r--r--Source/SPDatabaseDocument.m255
-rw-r--r--Source/SPDatabaseViewController.h4
-rw-r--r--Source/SPDatabaseViewController.m53
-rw-r--r--Source/SPEditSheetTextView.m6
-rw-r--r--Source/SPFieldEditorController.h4
-rw-r--r--Source/SPFieldEditorController.m36
-rw-r--r--Source/SPFieldMapperController.h6
-rw-r--r--Source/SPFieldMapperController.m34
-rw-r--r--Source/SPIndexesController.h2
-rw-r--r--Source/SPIndexesController.m22
-rw-r--r--Source/SPNarrowDownCompletion.h8
-rw-r--r--Source/SPNarrowDownCompletion.m14
-rw-r--r--Source/SPNavigatorController.h11
-rw-r--r--Source/SPNavigatorController.m18
-rw-r--r--Source/SPQueryController.h2
-rw-r--r--Source/SPQueryController.m54
-rw-r--r--Source/SPQueryFavoriteManager.h8
-rw-r--r--Source/SPQueryFavoriteManager.m20
-rw-r--r--Source/SPSQLParser.m10
-rw-r--r--Source/SPServerSupport.m2
-rw-r--r--Source/SPStringAdditions.h2
-rw-r--r--Source/SPStringAdditions.m2
-rw-r--r--Source/SPTableContent.h16
-rw-r--r--Source/SPTableContent.m247
-rw-r--r--Source/SPTableData.h12
-rw-r--r--Source/SPTableData.m13
-rw-r--r--Source/SPTableStructure.h21
-rw-r--r--Source/SPTableStructure.m93
-rw-r--r--Source/SPTableStructureDelegate.m2
-rw-r--r--Source/SPTableView.h5
-rw-r--r--Source/SPTableView.m45
-rw-r--r--Source/SPTablesList.h43
-rw-r--r--Source/SPTablesList.m158
-rw-r--r--Source/SPTextView.h18
-rw-r--r--Source/SPTextView.m146
-rw-r--r--Source/SPTextViewAdditions.h3
-rw-r--r--Source/SPTextViewAdditions.m15
50 files changed, 1645 insertions, 216 deletions
diff --git a/Source/NSNotificationAdditions.h b/Source/NSNotificationAdditions.h
index d1903da5..8722ed4f 100644
--- a/Source/NSNotificationAdditions.h
+++ b/Source/NSNotificationAdditions.h
@@ -25,11 +25,20 @@
@interface NSNotificationCenter (NSNotificationCenterAdditions)
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThread:(NSNotification *)notification;
- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait;
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object;
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo;
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait;
+#else
+- (void)sequelProPostNotificationOnMainThread:(NSNotification *)notification;
+- (void)sequelProPostNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait;
+
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object;
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo;
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait;
+#endif
@end
diff --git a/Source/NSNotificationAdditions.m b/Source/NSNotificationAdditions.m
index ae949347..8b64c1f2 100644
--- a/Source/NSNotificationAdditions.m
+++ b/Source/NSNotificationAdditions.m
@@ -27,42 +27,84 @@
#import "pthread.h"
@interface NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI)
+#ifndef SP_REFACTOR
+ (void)_postNotification:(NSNotification *)notification;
+ (void)_postNotificationName:(NSDictionary *)info;
+ (void)_postNotificationForwarder:(NSDictionary *)info;
+#else
++ (void)_sequelProPostNotification:(NSNotification *)notification;
++ (void)_sequelProPostNotificationName:(NSDictionary *)info;
++ (void)_sequelProPostNotificationForwarder:(NSDictionary *)info;
+#endif
@end
@implementation NSNotificationCenter (NSNotificationCenterAdditions)
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThread:(NSNotification *)notification
+#else
+- (void)sequelProPostNotificationOnMainThread:(NSNotification *)notification
+#endif
{
if (pthread_main_np()) return [self postNotification:notification];
+#ifndef SP_REFACTOR
[self postNotificationOnMainThread:notification waitUntilDone:NO];
+#else
+ [self sequelProPostNotificationOnMainThread:notification waitUntilDone:NO];
+#endif
}
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)shouldWaitUntilDone
+#else
+- (void)sequelProPostNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)shouldWaitUntilDone
+#endif
{
if (pthread_main_np()) return [self postNotification:notification];
-
+
+#ifndef SP_REFACTOR
[self performSelectorOnMainThread:@selector(_postNotification:) withObject:notification waitUntilDone:shouldWaitUntilDone];
+#else
+ [self performSelectorOnMainThread:@selector(_sequelProPostNotification:) withObject:notification waitUntilDone:shouldWaitUntilDone];
+#endif
}
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object
+#else
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object
+#endif
{
if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:nil];
+#ifndef SP_REFACTOR
[self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
+#else
+ [self sequelProPostNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO];
+#endif
}
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo
+#else
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo
+#endif
{
if(pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo];
+#ifndef SP_REFACTOR
[self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO];
+#else
+ [self sequelProPostNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO];
+#endif
}
+#ifndef SP_REFACTOR
- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)shouldWaitUntilDone
+#else
+- (void)sequelProPostNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)shouldWaitUntilDone
+#endif
{
if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo];
@@ -72,7 +114,11 @@
if (object) [info setObject:object forKey:@"object"];
if (userInfo) [info setObject:userInfo forKey:@"userInfo"];
+#ifndef SP_REFACTOR
[[self class] performSelectorOnMainThread:@selector(_postNotificationName:) withObject:info waitUntilDone:shouldWaitUntilDone];
+#else
+ [[self class] performSelectorOnMainThread:@selector(_sequelProPostNotificationName:) withObject:info waitUntilDone:shouldWaitUntilDone];
+#endif
[info release];
}
@@ -81,12 +127,20 @@
@implementation NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI)
+#ifndef SP_REFACTOR
+ (void)_postNotification:(NSNotification *)notification
+#else
++ (void)_sequelProPostNotification:(NSNotification *)notification
+#endif
{
[[self defaultCenter] postNotification:notification];
}
+#ifndef SP_REFACTOR
+ (void)_postNotificationName:(NSDictionary *)info
+#else
++ (void)_sequelProPostNotificationName:(NSDictionary *)info
+#endif
{
NSString *name = [info objectForKey:@"name"];
@@ -97,7 +151,11 @@
[[self defaultCenter] postNotificationName:name object:object userInfo:userInfo];
}
+#ifndef SP_REFACTOR
+ (void)_postNotificationForwarder:(NSDictionary *)info
+#else
++ (void)_sequelProPostNotificationForwarder:(NSDictionary *)info
+#endif
{
NSString *name = [info objectForKey:@"name"];
diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m
index 59bebadc..6f91676c 100644
--- a/Source/SPBundleCommandTextView.m
+++ b/Source/SPBundleCommandTextView.m
@@ -488,7 +488,13 @@
[self saveChangedFontInUserDefaults];
return;
}
- if([charactersIgnMod isEqualToString:@"["]) // decrease text size by 1; ⌘- and numpad -
+ if([charactersIgnMod isEqualToString:@"0"]) // return text to standard size; ⌘0
+ {
+ [self makeTextStandardSize];
+ [self saveChangedFontInUserDefaults];
+ return;
+ }
+ if([charactersIgnMod isEqualToString:@"["]) // shift left
{
[self shiftSelectionLeft];
return;
@@ -498,7 +504,7 @@
[self shiftSelectionRight];
return;
}
- if([charactersIgnMod isEqualToString:@"/"]) // shift right
+ if([charactersIgnMod isEqualToString:@"/"]) // comment out text
{
[self commentOut];
return;
diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m
index 1995cfcb..e49cce11 100644
--- a/Source/SPBundleHTMLOutputController.m
+++ b/Source/SPBundleHTMLOutputController.m
@@ -145,6 +145,11 @@
[webView makeTextSmaller:nil];
return;
}
+ if([charactersIgnMod isEqualToString:@"0"]) // return the text size to the default size
+ {
+ [webView makeTextStandardSize:nil];
+ return;
+ }
if([theEvent keyCode] == 123) // goBack
{
if([webView canGoBack])
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index a5b79d80..2fa28019 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -24,17 +24,24 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <MCPKit/MCPKit.h>
-
#import "SPConnectionControllerDelegateProtocol.h"
+#ifndef SP_REFACTOR /* headers */
+#endif
+
@class SPDatabaseDocument,
SPFavoritesController,
- SPKeychain,
SPSSHTunnel,
SPTreeNode,
- SPFavoriteNode,
- SPFavoritesOutlineView,
- BWAnchoredButtonBar;
+ SPFavoritesOutlineView
+#ifndef SP_REFACTOR /* class decl */
+ ,SPKeychain,
+ BWAnchoredButtonBar,
+ SPFavoriteNode
+#endif
+;
+
+#ifndef SP_REFACTOR /* class decl */
@interface NSObject (BWAnchoredButtonBar)
@@ -52,11 +59,24 @@
MCPConnection *mySQLConnection;
+#ifndef SP_REFACTOR /* ivars */
NSView *databaseConnectionSuperview;
NSSplitView *databaseConnectionView;
-
+ SPKeychain *keychain;
+ NSUserDefaults *prefs;
+ NSMutableArray *favorites;
+#endif
+ SPSSHTunnel *sshTunnel;
+ MCPConnection *mySQLConnection;
+#ifndef SP_REFACTOR /* ivars */
+ BOOL automaticFavoriteSelection;
+#endif
+ BOOL cancellingConnection;
+ BOOL isConnecting;
+#ifndef SP_REFACTOR /* ivars */
// Standard details
NSInteger previousType;
+#endif
NSInteger type;
NSString *name;
NSString *host;
@@ -85,6 +105,7 @@
NSString *connectionKeychainID;
NSString *connectionKeychainItemName;
+#ifndef SP_REFACTOR /* ivars */
NSString *connectionKeychainItemAccount;
NSString *connectionSSHKeychainItemName;
NSString *connectionSSHKeychainItemAccount;
@@ -143,10 +164,13 @@
BOOL isConnecting;
BOOL cancellingConnection;
BOOL reverseFavoritesSort;
+#endif
+
BOOL mySQLConnectionCancelled;
BOOL automaticFavoriteSelection;
BOOL favoriteNameFieldWasTouched;
+#ifndef SP_REFACTOR /* ivars */
NSImage *folderImage;
NSUserDefaults *prefs;
@@ -154,9 +178,10 @@
SPFavoriteNode *currentFavorite;
SPFavoritesController *favoritesController;
SPFavoritesSortItem previousSortItem, currentSortItem;
+#endif
}
-@property (readwrite, assign) id <SPConnectionControllerDelegateProtocol> delegate;
+@property (readwrite, assign) id <SPConnectionControllerDelegateProtocol, NSObject> delegate;
@property (readwrite, assign) NSInteger type;
@property (readwrite, retain) NSString *name;
@property (readwrite, retain) NSString *host;
@@ -178,11 +203,13 @@
@property (readwrite, assign) NSInteger 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;
@@ -190,6 +217,7 @@
// Connection processes
- (IBAction)initiateConnection:(id)sender;
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)cancelMySQLConnection:(id)sender;
// Interface interaction
@@ -220,4 +248,5 @@
- (IBAction)importFavorites:(id)sender;
- (IBAction)exportFavorites:(id)sender;
+#endif
@end
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 6e8f8b2d..31ac3806 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -78,9 +78,15 @@ NSString *SPLoadBlobsAsNeeded = @"LoadBlobsAsNeeded";
NSString *SPTableRowCountQueryLevel = @"TableRowCountQueryLevel";
NSString *SPTableRowCountCheapSizeBoundary = @"TableRowCountCheapLookupSizeBoundary";
NSString *SPNewFieldsAllowNulls = @"NewFieldsAllowNulls";
+#ifndef SP_REFACTOR
NSString *SPLimitResults = @"LimitResults";
NSString *SPLimitResultsValue = @"LimitResultsValue";
NSString *SPNullValue = @"NullValue";
+#else
+NSString *SPLimitResults = @"SPLimitResults";
+NSString *SPLimitResultsValue = @"SPLimitResultsValue";
+NSString *SPNullValue = @"SPNullValue";
+#endif
NSString *SPGlobalResultTableFont = @"GlobalResultTableFont";
NSString *SPFilterTableDefaultOperator = @"FilterTableDefaultOperator";
NSString *SPFilterTableDefaultOperatorLastItems = @"FilterTableDefaultOperatorLastItems";
diff --git a/Source/SPContentFilterManager.h b/Source/SPContentFilterManager.h
index ec2c1ef6..ec23afe6 100644
--- a/Source/SPContentFilterManager.h
+++ b/Source/SPContentFilterManager.h
@@ -31,9 +31,15 @@
@end
-@interface SPContentFilterManager : NSWindowController
+#ifndef SP_REFACTOR /* ivars */
+@interface SPContentFilterManager : NSWindowController
+#else
+@interface SPContentFilterManager : NSWindowController <NSOpenSavePanelDelegate>
+#endif
{
+#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
+#endif
SPDatabaseDocument *tableDocumentInstance;
NSURL *delegatesFileURL;
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index 97c0b5d6..7b24d6e1 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -29,7 +29,9 @@
#import "SPQueryController.h"
#import "SPTableContent.h"
#import "SPConnectionController.h"
+#ifndef SP_REFACTOR /* headers */
#import <BWToolkitFramework/BWToolkitFramework.h>
+#endif
#define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]")
#define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]")
@@ -45,7 +47,9 @@
{
if ((self = [super initWithWindowNibName:@"ContentFilterManager"])) {
+#ifndef SP_REFACTOR
prefs = [NSUserDefaults standardUserDefaults];
+#endif
contentFilters = [[NSMutableArray alloc] init];
@@ -84,6 +88,7 @@
@"", @"ConjunctionLabel",
nil]];
+#ifndef SP_REFACTOR /* prefs access */
// Build data source for global content filter (as mutable copy! otherwise each
// change will be stored in the prefs at once)
if([[prefs objectForKey:SPContentFilters] objectForKey:filterType]) {
@@ -94,6 +99,7 @@
[contentFilters addObject:f];
}
}
+#endif
// Build doc-based filters
[contentFilters addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@@ -135,8 +141,10 @@
// Set column header
[[[contentFilterTableView tableColumnWithIdentifier:@"MenuLabel"] headerCell] setStringValue:[NSString stringWithFormat:NSLocalizedString(@"‘%@’ Fields Content Filters", @"table column header. Read: 'Showing all content filters for fields of type %@' (ContentFilterManager)"), filterType]];
+#ifndef SP_REFACTOR /* split view delegate */
// Set the button delegate
[splitViewButtonBar setSplitViewDelegate:self];
+#endif
}
#pragma mark -
@@ -359,6 +367,7 @@
[[SPQueryController sharedQueryController] replaceContentFilterByArray:
[self contentFilterForFileURL:delegatesFileURL] ofType:filterType forFileURL:delegatesFileURL];
+#ifndef SP_REFACTOR
// Update global preferences' list
id cf = [[prefs objectForKey:SPContentFilters] mutableCopy];
[cf setObject:[self contentFilterForFileURL:nil] forKey:filterType];
@@ -370,6 +379,7 @@
if([[doc valueForKeyPath:@"tableContentInstance"] respondsToSelector:@selector(setCompareTypes:)])
[[doc valueForKeyPath:@"tableContentInstance"] setCompareTypes:nil];
+#endif
}
@@ -833,7 +843,7 @@
mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:SP_FILE_PARSER_ERROR_TITLE_STRING]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:SP_FILE_PARSER_ERROR_TITLE_STRING]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
@@ -861,7 +871,7 @@
[contentFilterTableView reloadData];
[spf release];
} else {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:SP_FILE_PARSER_ERROR_TITLE_STRING]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:SP_FILE_PARSER_ERROR_TITLE_STRING]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
@@ -913,7 +923,7 @@
errorDescription:&err];
if(err != nil) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting content filter data", @"Content filters could not be converted to plist upon export - message title (ContentFilterManager)")]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while converting content filter data", @"Content filters could not be converted to plist upon export - message title (ContentFilterManager)")]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
diff --git a/Source/SPCopyTable.h b/Source/SPCopyTable.h
index 4723dbc9..87c4ec8c 100644
--- a/Source/SPCopyTable.h
+++ b/Source/SPCopyTable.h
@@ -28,6 +28,7 @@
#define SP_MAX_CELL_WIDTH 400
@class SPDataStorage;
+@class SPTableContent;
/*!
@class copyTable
@@ -39,7 +40,7 @@
*/
@interface SPCopyTable : SPTableView
{
- id tableInstance; // the table content view instance
+ SPTableContent* tableInstance; // the table content view instance
id mySQLConnection; // current MySQL connection
NSArray* columnDefinitions; // array of NSDictionary containing info about columns
NSString* selectedTable; // the name of the current selected table
@@ -84,6 +85,7 @@
*/
- (NSUInteger)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
+#ifndef SP_REFACTOR /* method decls */
/*!
@method rowsAsTabStringWithHeaders:onlySelectedRows:
@abstract getter of the selected rows or all of the table for copy
@@ -105,6 +107,7 @@
@result The above described string, or nil if nothing selected
*/
- (NSString *)rowsAsCsvStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOOL)onlySelected blobHandling:(NSInteger)withBlobHandling;
+#endif
/*
* Generate a string in form of INSERT INTO <table> VALUES () of
@@ -172,6 +175,8 @@
- (void)selectTableRows:(NSArray*)rowIndices;
+- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command;
+
@end
extern NSInteger MENU_EDIT_COPY;
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index b44ba920..e1b7e773 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -23,7 +23,9 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#import <MCPKit/MCPKit.h>
+#ifndef SP_REFACTOR /* headers */
#import "MCPGeometryData.h"
+#endif
#import "SPCopyTable.h"
#import "SPTableContent.h"
@@ -67,8 +69,8 @@ NSInteger kBlobAsImageFile = 4;
return ([[self delegate] isKindOfClass:[SPCustomQuery class]]
|| ([[self delegate] isKindOfClass:[SPTableContent class]]
- && [[self delegate] valueForKeyPath:@"tablesListInstance"]
- && [[[self delegate] valueForKeyPath:@"tablesListInstance"] tableType] == SPTableTypeView));
+ && [(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"]
+ && [(SPTablesList*)([(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"]) tableType] == SPTableTypeView));
}
@@ -90,6 +92,7 @@ NSInteger kBlobAsImageFile = 4;
*/
- (void) copy:(id)sender
{
+#ifndef SP_REFACTOR /* copy table rows */
NSString *tmp = nil;
if([sender tag] == MENU_EDIT_COPY_AS_SQL) {
@@ -119,12 +122,14 @@ NSInteger kBlobAsImageFile = 4;
[pb setString:tmp forType:NSTabularTextPboardType];
}
}
+#endif
}
/**
* Get selected rows a string of newline separated lines of tab separated fields
* the value in each field is from the objects description method
*/
+#ifndef SP_REFACTOR /* get rows as string */
- (NSString *) rowsAsTabStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOOL)onlySelected blobHandling:(NSInteger)withBlobHandling
{
if (onlySelected && [self numberOfSelectedRows] == 0) return nil;
@@ -397,6 +402,7 @@ NSInteger kBlobAsImageFile = 4;
return result;
}
+#endif
/*
* Return selected rows as SQL INSERT INTO `foo` VALUES (baz) string.
@@ -478,7 +484,7 @@ NSInteger kBlobAsImageFile = 4;
if ([cellData isSPNotLoaded] && [[self delegate] isKindOfClass:spTableContentClass]) {
// Abort if no table name given, not table content, or if there are no indices on this table
- if (!selectedTable || ![[self delegate] isKindOfClass:spTableContentClass] || ![[tableInstance argumentForRow:rowIndex] length]) {
+ if (!selectedTable || ![[self delegate] isKindOfClass:spTableContentClass] || ![(NSString*)[tableInstance argumentForRow:rowIndex] length]) {
NSBeep();
free(columnMappings);
free(columnTypes);
@@ -753,7 +759,11 @@ NSInteger kBlobAsImageFile = 4;
NSUInteger cellWidth, maxCellWidth, i;
NSRange linebreakRange;
double rowStep;
+#ifndef SP_REFACTOR /* patch */
NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]];
+#else
+ NSFont *tableFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+#endif
NSUInteger columnIndex = [[columnDefinition objectForKey:@"datacolumnindex"] unsignedIntegerValue];
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:tableFont forKey:NSFontAttributeName];
Class mcpGeometryData = [MCPGeometryData class];
@@ -836,6 +846,7 @@ NSInteger kBlobAsImageFile = 4;
{
NSMenu *menu = [self menu];
+#ifndef SP_REFACTOR /* menuForEvent: */
if(![[self delegate] isKindOfClass:[SPCustomQuery class]] && ![[self delegate] isKindOfClass:[SPTableContent class]]) return menu;
@@ -903,7 +914,7 @@ NSInteger kBlobAsImageFile = 4;
[bundleSubMenuItem release];
}
-
+#endif
return menu;
}
@@ -914,7 +925,11 @@ NSInteger kBlobAsImageFile = 4;
if(!rowIndices || ![rowIndices count]) return;
NSMutableIndexSet *selection = [NSMutableIndexSet indexSet];
+#ifndef SP_REFACTOR
NSInteger rows = [[self delegate] numberOfRowsInTableView:self];
+#else
+ NSInteger rows = [(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self];
+#endif
NSInteger i;
if(rows > 0) {
for(NSString* idx in rowIndices) {
@@ -934,6 +949,7 @@ NSInteger kBlobAsImageFile = 4;
*/
- (BOOL) validateMenuItem:(NSMenuItem*)anItem
{
+#ifndef SP_REFACTOR /* validateMenuItem: */
NSInteger menuItemTag = [anItem tag];
if ([anItem action] == @selector(performFindPanelAction:)) {
@@ -959,7 +975,7 @@ NSInteger kBlobAsImageFile = 4;
if (menuItemTag == MENU_EDIT_COPY_AS_SQL) {
return (columnDefinitions != nil && [self numberOfSelectedRows] > 0);
}
-
+#endif
return NO;
}
@@ -984,7 +1000,7 @@ NSInteger kBlobAsImageFile = 4;
// Save the current line if it's the last field in the table
if ( [self numberOfColumns] - 1 == column ) {
if([[self delegate] respondsToSelector:@selector(saveRowToTable)])
- [[self delegate] saveRowToTable];
+ [(SPTableContent*)[self delegate] saveRowToTable];
[[self window] makeFirstResponder:self];
} else {
// Select the next field for editing
@@ -1002,7 +1018,7 @@ NSInteger kBlobAsImageFile = 4;
// Save the current line if it's the last field in the table
if ( column < 1 ) {
if([[self delegate] respondsToSelector:@selector(saveRowToTable)])
- [[self delegate] saveRowToTable];
+ [(SPTableContent*)([self delegate]) saveRowToTable];
[[self window] makeFirstResponder:self];
} else {
// Select the previous field for editing
@@ -1021,7 +1037,7 @@ NSInteger kBlobAsImageFile = 4;
[[control window] makeFirstResponder:control];
if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)])
- [[self delegate] saveRowToTable];
+ [(SPTableContent*)[self delegate] saveRowToTable];
return YES;
}
@@ -1035,14 +1051,22 @@ NSInteger kBlobAsImageFile = 4;
return NO;
NSInteger newRow = row+1;
+#ifndef SP_REFACTOR
if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; //check if we're already at the end of the list
+#else
+ if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; //check if we're already at the end of the list
+#endif
[[control window] makeFirstResponder:control];
if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)])
- [[self delegate] saveRowToTable];
+ [(SPTableContent*)([self delegate]) saveRowToTable];
+#ifndef SP_REFACTOR
if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; //check again. saveRowToTable could reload the table and change the number of rows
- if (tableStorage && column >= (NSInteger)[tableStorage columnCount]) return YES; //the column count could change too
+#else
+ if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; //check again. saveRowToTable could reload the table and change the number of rows
+#endif
+ if (tableStorage && (NSUInteger)column>=[tableStorage columnCount]) return YES; //the column count could change too
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO];
[self editColumn:column row:newRow withEvent:nil select:YES];
@@ -1062,10 +1086,14 @@ NSInteger kBlobAsImageFile = 4;
[[control window] makeFirstResponder:control];
if([[self delegate] isKindOfClass:[SPTableContent class]] && ![self isCellEditingMode] && [[self delegate] respondsToSelector:@selector(saveRowToTable)])
- [[self delegate] saveRowToTable];
+ [(SPTableContent*)([self delegate]) saveRowToTable];
+#ifndef SP_REFACTOR
if (newRow>=[[self delegate] numberOfRowsInTableView:self]) return YES; // saveRowToTable could reload the table and change the number of rows
- if (tableStorage && column >= (NSInteger)[tableStorage columnCount]) return YES; //the column count could change too
+#else
+ if (newRow>=[(id<NSTableViewDataSource>)[self delegate] numberOfRowsInTableView:self]) return YES; // saveRowToTable could reload the table and change the number of rows
+#endif
+ if (tableStorage && (NSUInteger)column>=[tableStorage columnCount]) return YES; //the column count could change too
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO];
[self editColumn:column row:newRow withEvent:nil select:YES];
@@ -1089,7 +1117,7 @@ NSInteger kBlobAsImageFile = 4;
// Check if ESCAPE is hit and use it to cancel row editing if supported
if ([theEvent keyCode] == 53 && [[self delegate] respondsToSelector:@selector(cancelRowEditing)])
{
- if ([[self delegate] cancelRowEditing]) return;
+ if ([[self delegate] performSelector:@selector(cancelRowEditing)]) return;
}
else if ([theEvent keyCode] == 48 && ([[self delegate] isKindOfClass:[SPCustomQuery class]]
@@ -1104,7 +1132,7 @@ NSInteger kBlobAsImageFile = 4;
- (void)performFindPanelAction:(id)sender
{
if([sender tag] == 1 && [[self delegate] isKindOfClass:[SPTableContent class]]) {
- [[self delegate] showFilterTable:self];
+ [(SPTableContent*)[self delegate] showFilterTable:self];
}
}
@@ -1113,6 +1141,7 @@ NSInteger kBlobAsImageFile = 4;
- (IBAction)executeBundleItemForDataTable:(id)sender
{
+#ifndef SP_REFACTOR /* executeBundleItemForDataTable: */
NSInteger idx = [sender tag] - 1000000;
NSString *infoPath = nil;
NSArray *bundleItems = [[NSApp delegate] bundleItemsForScope:SPBundleScopeDataTable];
@@ -1389,7 +1418,7 @@ NSInteger kBlobAsImageFile = 4;
if (cmdData) [cmdData release];
}
-
+#endif
}
#pragma mark -
@@ -1407,7 +1436,9 @@ NSInteger kBlobAsImageFile = 4;
- (void) dealloc
{
if (columnDefinitions) [columnDefinitions release];
+#ifndef SP_REFACTOR
[prefs release];
+#endif
[super dealloc];
}
diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h
index 68969a01..8a1ad793 100644
--- a/Source/SPCustomQuery.h
+++ b/Source/SPCustomQuery.h
@@ -46,9 +46,17 @@
#define SP_HISTORY_SAVE_MENUITEM_TAG 300001
#define SP_HISTORY_CLEAR_MENUITEM_TAG 300002
+#ifndef SP_REFACTOR
@class SPCopyTable, SPQueryFavoriteManager, SPDataStorage, BWSplitView, SPFieldEditorController;
+#else
+@class SPCopyTable, SPQueryFavoriteManager, SPDataStorage, NSSplitView, SPFieldEditorController;
+#endif
+#ifndef SP_REFACTOR
@interface SPCustomQuery : NSObject
+#else
+@interface SPCustomQuery : NSObject <NSTableViewDataSource, NSWindowDelegate, NSTableViewDelegate>
+#endif
{
IBOutlet id tableDocumentInstance;
IBOutlet id tablesListInstance;
@@ -101,15 +109,21 @@
IBOutlet NSMenuItem *previousHistoryMenuItem;
IBOutlet NSMenuItem *nextHistoryMenuItem;
+#ifndef SP_REFACTOR
IBOutlet NSWindow *helpWebViewWindow;
IBOutlet WebView *helpWebView;
IBOutlet NSSearchField *helpSearchField;
IBOutlet NSSearchFieldCell *helpSearchFieldCell;
IBOutlet NSSegmentedControl *helpNavigator;
IBOutlet NSSegmentedControl *helpTargetSelector;
+#endif
IBOutlet NSButton *queryInfoButton;
+#ifndef SP_REFACTOR
IBOutlet BWSplitView *queryInfoPaneSplitView;
+#else
+ IBOutlet NSSplitView *queryInfoPaneSplitView;
+#endif
SPFieldEditorController *fieldEditor;
@@ -129,9 +143,11 @@
NSUInteger queryStartPosition;
+#ifndef SP_REFACTOR
NSUInteger helpTarget;
WebHistory *helpHistory;
NSString *helpHTMLTemplate;
+#endif
SPDataStorage *resultData;
pthread_mutex_t resultDataLock;
@@ -181,6 +197,7 @@
- (IBAction)chooseQueryHistory:(id)sender;
- (IBAction)closeSheet:(id)sender;
- (IBAction)gearMenuItemSelected:(id)sender;
+#ifndef SP_REFACTOR
- (IBAction)showHelpForCurrentWord:(id)sender;
- (IBAction)showHelpForSearchString:(id)sender;
- (IBAction)helpSegmentDispatcher:(id)sender;
@@ -190,6 +207,7 @@
- (IBAction)helpSelectHelpTargetMySQL:(id)sender;
- (IBAction)helpSelectHelpTargetPage:(id)sender;
- (IBAction)helpSelectHelpTargetWeb:(id)sender;
+#endif
- (IBAction)filterQueryFavorites:(id)sender;
- (IBAction)filterQueryHistory:(id)sender;
- (IBAction)saveQueryHistory:(id)sender;
@@ -226,6 +244,7 @@
- (void) clearResultViewDetailsToRestore;
- (void) autosizeColumns;
+#ifndef SP_REFACTOR
// MySQL Help
- (void)showAutoHelpForCurrentWord:(id)sender;
- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)searchString calledByAutoHelp:(BOOL)autoHelp;
@@ -233,6 +252,7 @@
- (void)helpTargetValidation;
- (void)openMySQLonlineDocumentationWithString:(NSString *)searchString;
- (NSWindow *)helpWebViewWindow;
+#endif
- (void)setMySQLversion:(NSString *)theVersion;
// Task interaction
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 2c9e890e..a67ec5f3 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -25,7 +25,9 @@
#import "SPCustomQuery.h"
#import "SPSQLParser.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPGrowlController.h"
+#endif
#import "SPDataCellFormatter.h"
#import "SPDatabaseDocument.h"
#import "SPTablesList.h"
@@ -43,7 +45,9 @@
#import "SPAppController.h"
#import "SPBundleHTMLOutputController.h"
+#ifndef SP_REFACTOR /* headers */
#import <BWToolkitFramework/BWToolkitFramework.h>
+#endif
@implementation SPCustomQuery
@@ -212,7 +216,9 @@
return;
}
+#ifndef SP_REFACTOR /* ui manip for query favorites */
if ([tableDocumentInstance isUntitled]) [saveQueryFavoriteGlobal setState:NSOnState];
+#endif
[NSApp beginSheet:queryFavoritesSheet
modalForWindow:[tableDocumentInstance parentWindow]
modalDelegate:self
@@ -230,7 +236,9 @@
return;
}
+#ifndef SP_REFACTOR /* ui manip for query favorites */
if ([tableDocumentInstance isUntitled]) [saveQueryFavoriteGlobal setState:NSOnState];
+#endif
[NSApp beginSheet:queryFavoritesSheet
modalForWindow:[tableDocumentInstance parentWindow]
modalDelegate:self
@@ -240,7 +248,9 @@
else if ([queryFavoritesButton indexOfSelectedItem] == 3) {
// init query favorites controller
+#ifndef SP_REFACTOR
[prefs synchronize];
+#endif
if(favoritesManager) [favoritesManager release];
favoritesManager = [[SPQueryFavoriteManager alloc] initWithDelegate:self];
@@ -253,7 +263,11 @@
}
else if ([queryFavoritesButton indexOfSelectedItem] > 5) {
// Choose favorite
+#ifndef SP_REFACTOR
BOOL replaceContent = [prefs boolForKey:SPQueryFavoriteReplacesContent];
+#else
+ BOOL replaceContent = YES;
+#endif
if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask))
replaceContent = !replaceContent;
@@ -274,12 +288,18 @@
- (IBAction)chooseQueryHistory:(id)sender
{
+#ifndef SP_REFACTOR
[prefs synchronize];
+#endif
// Choose history item
if ([queryHistoryButton indexOfSelectedItem] > 6) {
+#ifndef SP_REFACTOR
BOOL replaceContent = [prefs boolForKey:SPQueryHistoryReplacesContent];
+#else
+ BOOL replaceContent = YES;
+#endif
[textView breakUndoCoalescing];
if([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask|NSControlKeyMask|NSAlternateKeyMask|NSCommandKeyMask))
replaceContent = !replaceContent;
@@ -382,8 +402,10 @@
// "Indent new lines" toggle
if (sender == autoindentMenuItem) {
BOOL enableAutoindent = !([autoindentMenuItem state] == NSOffState);
+#ifndef SP_REFACTOR /* prefs access */
[prefs setBool:enableAutoindent forKey:SPCustomQueryAutoIndent];
[prefs synchronize];
+#endif
[autoindentMenuItem setState:enableAutoindent?NSOnState:NSOffState];
[textView setAutoindent:enableAutoindent];
}
@@ -391,12 +413,15 @@
// "Auto-pair characters" toggle
if (sender == autopairMenuItem) {
BOOL enableAutopair = !([autopairMenuItem state] == NSOffState);
+#ifndef SP_REFACTOR /* prefs access */
[prefs setBool:enableAutopair forKey:SPCustomQueryAutoPairCharacters];
[prefs synchronize];
+#endif
[autopairMenuItem setState:enableAutopair?NSOnState:NSOffState];
[textView setAutopair:enableAutopair];
}
+#ifndef SP_REFACTOR /* prefs access */
// "Auto-help" toggle
if (sender == autohelpMenuItem) {
BOOL enableAutohelp = !([autohelpMenuItem state] == NSOffState);
@@ -405,12 +430,15 @@
[autohelpMenuItem setState:enableAutohelp?NSOnState:NSOffState];
[textView setAutohelp:enableAutohelp];
}
+#endif
// "Auto-uppercase keywords" toggle
if (sender == autouppercaseKeywordsMenuItem) {
BOOL enableAutouppercaseKeywords = !([autouppercaseKeywordsMenuItem state] == NSOffState);
+#ifndef SP_REFACTOR /* prefs access */
[prefs setBool:enableAutouppercaseKeywords forKey:SPCustomQueryAutoUppercaseKeywords];
[prefs synchronize];
+#endif
[autouppercaseKeywordsMenuItem setState:enableAutouppercaseKeywords?NSOnState:NSOffState];
[textView setAutouppercaseKeywords:enableAutouppercaseKeywords];
}
@@ -418,6 +446,7 @@
- (IBAction)saveQueryHistory:(id)sender
{
+#ifndef SP_REFACTOR
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setRequiredFileType:SPFileExtensionSQL];
@@ -432,6 +461,7 @@
[encodingPopUp setEnabled:YES];
[panel beginSheetForDirectory:nil file:@"history" modalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:@"saveHistory"];
+#endif
}
- (IBAction)copyQueryHistory:(id)sender
@@ -450,10 +480,14 @@
NSString *infoString;
+#ifndef SP_REFACTOR /* if ([tableDocumentInstance isUntitled]) */
if ([tableDocumentInstance isUntitled])
+#endif
infoString = NSLocalizedString(@"Are you sure you want to clear the global history list? This action cannot be undone.", @"clear global history list informative message");
+#ifndef SP_REFACTOR /* if ([tableDocumentInstance isUntitled]) */
else
infoString = [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to clear the history list for “%@”? This action cannot be undone.", @"clear history list for “%@” informative message"), [tableDocumentInstance displayName]];
+#endif
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Clear History?", @"clear history message")
defaultButton:NSLocalizedString(@"Clear", @"clear button")
@@ -545,13 +579,21 @@
// BOOL queriesSeparatedByDelimiter = NO;
NSCharacterSet *whitespaceAndNewlineSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
+#ifndef SP_REFACTOR /* [tableDocumentInstance setQueryMode:] */
[tableDocumentInstance setQueryMode:SPCustomQueryQueryMode];
+#endif
// Notify listeners that a query has started
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#endif
+#ifndef SP_REFACTOR /* growl */
// Start the notification timer to allow notifications to be shown even if frontmost for long queries
[[SPGrowlController sharedGrowlController] setVisibilityForNotificationName:@"Query Finished"];
+#endif
// Reset the current table view as necessary to avoid redraw and reload issues.
// Restore the view position to the top left to be within the results for all datasets.
@@ -804,20 +846,28 @@
// Restore automatic query retries
[mySQLConnection setAllowQueryRetries:YES];
+#ifndef SP_REFACTOR /* [tableDocumentInstance setQueryMode:] */
[tableDocumentInstance setQueryMode:SPInterfaceQueryMode];
+#endif
// If no results were returned, redraw the empty table and post notifications before returning.
if ( !resultDataCount ) {
[customQueryView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
// Notify any listeners that the query has completed
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
+#ifndef SP_REFACTOR /* growl */
// Perform the Growl notification for query completion
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Query Finished"
description:[NSString stringWithFormat:NSLocalizedString(@"%@",@"description for query finished growl notification"), [errorText string]]
document:tableDocumentInstance
notificationName:@"Query Finished"];
+#endif
// Set up the callback if present
if ([taskArguments objectForKey:@"callback"]) {
@@ -842,13 +892,19 @@
}
//query finished
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
+#ifndef SP_REFACTOR /* growl */
// Query finished Growl notification
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Query Finished"
description:[NSString stringWithFormat:NSLocalizedString(@"%@",@"description for query finished growl notification"), [errorText string]]
document:tableDocumentInstance
notificationName:@"Query Finished"];
+#endif
// Set up the callback if present
if ([taskArguments objectForKey:@"callback"]) {
@@ -1297,6 +1353,7 @@
[errorText setString:NSLocalizedString(@"There were no errors.", @"text shown when query was successfull")];
}
+#ifndef SP_REFACTOR /* show/hide errror view */
// Show or hide the error area if necessary
if ([errorsString length] && [queryInfoPaneSplitView collapsibleSubviewCollapsed]) {
[queryInfoButton setState:NSOnState];
@@ -1305,6 +1362,7 @@
[queryInfoButton setState:NSOffState];
[self toggleQueryInfoPaneCollapse:queryInfoButton];
}
+#endif
}
#pragma mark -
@@ -1429,16 +1487,25 @@
// Set up the interface
[customQueryView setVerticalMotionCanBeginDrag:NO];
+#ifndef SP_REFACTOR
[autoindentMenuItem setState:([prefs boolForKey:SPCustomQueryAutoIndent]?NSOnState:NSOffState)];
[autopairMenuItem setState:([prefs boolForKey:SPCustomQueryAutoPairCharacters]?NSOnState:NSOffState)];
[autohelpMenuItem setState:([prefs boolForKey:SPCustomQueryUpdateAutoHelp]?NSOnState:NSOffState)];
[autouppercaseKeywordsMenuItem setState:([prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]?NSOnState:NSOffState)];
+#else
+ [autoindentMenuItem setState:(YES?NSOnState:NSOffState)];
+ [autopairMenuItem setState:(YES?NSOnState:NSOffState)];
+ [autohelpMenuItem setState:(YES?NSOnState:NSOffState)];
+ [autouppercaseKeywordsMenuItem setState:(YES?NSOnState:NSOffState)];
+#endif
if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] )
[self performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:YES];
// Populate query favorites
+#ifndef SP_REFACTOR
[self queryFavoritesHaveBeenUpdated:nil];
+#endif
// Disable runSelectionMenuItem in the gear menu
[runSelectionMenuItem setEnabled:NO];
@@ -1487,7 +1554,11 @@
}
// Update font size on the table
+#ifndef SP_REFACTOR
NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]];
+#else
+ NSFont *tableFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+#endif
[customQueryView setRowHeight:2.0f+NSSizeToCGSize([[NSString stringWithString:@"{ǞṶḹÜ∑zgyf"] sizeWithAttributes:[NSDictionary dictionaryWithObject:tableFont forKey:NSFontAttributeName]]).height];
// If there are no table columns to add, return
@@ -1525,6 +1596,7 @@
[[theCol headerCell] setStringValue:[columnDefinition objectForKey:@"name"]];
[theCol setHeaderToolTip:[NSString stringWithFormat:@"%@ – %@%@", [columnDefinition objectForKey:@"name"], [columnDefinition objectForKey:@"type"], ([columnDefinition objectForKey:@"char_length"]) ? [NSString stringWithFormat:@"(%@)", [columnDefinition objectForKey:@"char_length"]] : @""]];
+#ifndef SP_REFACTOR
// Set the width of this column to saved value if exists and maps to a real column
if ([columnDefinition objectForKey:@"org_name"] && [(NSString *)[columnDefinition objectForKey:@"org_name"] length]) {
NSNumber *colWidth = [[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]]] objectForKey:[columnDefinition objectForKey:@"org_table"]] objectForKey:[columnDefinition objectForKey:@"org_name"]];
@@ -1532,6 +1604,7 @@
[theCol setWidth:[colWidth floatValue]];
}
}
+#endif
[customQueryView addTableColumn:theCol];
[theCol release];
@@ -1619,8 +1692,10 @@
[customQueryView setDelegate:nil];
for (NSDictionary *columnDefinition in cqColumnDefinition) {
+#ifndef SP_REFACTOR
// Skip columns with saved widths
if ([[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance tableName]] objectForKey:[columnDefinition objectForKey:@"name"]]) continue;
+#endif
// Otherwise set the column width
NSTableColumn *aTableColumn = [customQueryView tableColumnWithIdentifier:[columnDefinition objectForKey:@"datacolumnindex"]];
@@ -1972,24 +2047,30 @@
// This shouldn't happen – for safety reasons
if ( ![mySQLConnection affectedRows] ) {
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
SPBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db"));
} else {
NSBeep();
}
+#endif
return;
}
// On success reload table data by executing the last query if reloading is enabled
+#ifndef SP_REFACTOR
if ([prefs boolForKey:SPReloadAfterEditingRow]) {
reloadingExistingResult = YES;
[self storeCurrentResultViewForRestoration];
[self performQueries:[NSArray arrayWithObject:lastExecutedQuery] withCallback:NULL];
} else {
+#endif
// otherwise, just update the data in the data storage
SPDataStorageReplaceObjectAtRowAndColumn(resultData, rowIndex, [[aTableColumn identifier] intValue], anObject);
+#ifndef SP_REFACTOR
}
+#endif
} else {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"Updating field content failed. Couldn't identify field origin unambiguously (%ld match%@). It's very likely that while editing this field of table `%@` was changed.", @"message of panel when error while updating field to db after enabling it"),
@@ -2407,6 +2488,7 @@
// Check our notification object is our table content view
if ([aNotification object] != customQueryView) return;
+#ifndef SP_REFACTOR /* triggered commands */
NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionTableRowChanged];
for(NSString* cmdPath in triggeredCommands) {
NSArray *data = [cmdPath componentsSeparatedByString:@"|"];
@@ -2443,7 +2525,7 @@
}
}
}
-
+#endif
}
/**
@@ -2468,11 +2550,15 @@
NSString *col = [columnDefinition objectForKey:@"org_name"];
// Retrieve or instantiate the tableColumnWidths object
+#ifndef SP_REFACTOR
if ([prefs objectForKey:SPTableColumnWidths] != nil) {
tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:SPTableColumnWidths]];
} else {
+#endif
tableColumnWidths = [NSMutableDictionary dictionary];
+#ifndef SP_REFACTOR
}
+#endif
// Edit or create database object
if ([tableColumnWidths objectForKey:host_db] == nil) {
@@ -2490,7 +2576,9 @@
// Save the column size
[[[tableColumnWidths objectForKey:host_db] objectForKey:table] setObject:[NSNumber numberWithDouble:[(NSTableColumn *)[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:col];
+#ifndef SP_REFACTOR
[prefs setObject:tableColumnWidths forKey:SPTableColumnWidths];
+#endif
}
/**
@@ -2505,6 +2593,7 @@
NSUInteger targetWidth = [customQueryView autodetectWidthForColumnDefinition:columnDefinition maxRows:500];
// Clear any saved widths for the column
+#ifndef SP_REFACTOR
NSString *dbKey = [NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]];
NSString *tableKey = [tablesListInstance tableName];
NSMutableDictionary *savedWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:SPTableColumnWidths]];
@@ -2524,6 +2613,7 @@
}
[prefs setObject:[NSDictionary dictionaryWithDictionary:savedWidths] forKey:SPTableColumnWidths];
}
+#endif
// Return the width, while the delegate is empty to prevent column resize notifications
[customQueryView setDelegate:nil];
@@ -2671,6 +2761,8 @@
#pragma mark -
#pragma mark SplitView delegate methods
+#ifndef SP_REFACTOR /* splitview delegate methods */
+
/*
* Tells the splitView that it can collapse views
*/
@@ -2705,6 +2797,8 @@
return (splitView == queryInfoPaneSplitView ? NSZeroRect : proposedEffectiveRect);
}
+#endif
+
#pragma mark -
#pragma mark MySQL Help
@@ -2718,6 +2812,7 @@
}
+#ifndef SP_REFACTOR
/*
* Return the Help window.
*/
@@ -2912,6 +3007,7 @@
helpTarget = [helpTargetSelector selectedSegment];
[self helpTargetValidation];
}
+#endif
- (IBAction)showCompletionList:(id)sender
{
@@ -2928,6 +3024,8 @@
break;
}
}
+
+#ifndef SP_REFACTOR
/*
* Show the data for "HELP 'currentWord' invoked by autohelp"
*/
@@ -3236,6 +3334,8 @@
return YES;
}
+#endif
+
#pragma mark -
#pragma mark Query favorites manager delegate methods
@@ -3304,6 +3404,7 @@
[headerMenuItem setIndentationLevel:0];
[menu addItem:headerMenuItem];
[headerMenuItem release];
+#ifndef SP_REFACTOR
for (NSDictionary *favorite in [prefs objectForKey:SPQueryFavorites]) {
if (![favorite isKindOfClass:[NSDictionary class]] || ![favorite objectForKey:@"name"]) continue;
NSMutableParagraphStyle *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
@@ -3320,6 +3421,7 @@
[menu addItem:item];
[item release];
}
+#endif
}
#pragma mark -
@@ -3332,9 +3434,11 @@
{
isWorking = YES;
+#ifndef SP_REFACTOR /* check selected view */
// Only proceed if this view is selected.
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarCustomQuery])
return;
+#endif
tableRowsSelectable = NO;
[runSelectionButton setEnabled:NO];
@@ -3350,9 +3454,11 @@
{
isWorking = NO;
+#ifndef SP_REFACTOR /* check active tab */
// Only proceed if this view is selected.
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarCustomQuery])
return;
+#endif
if (selectionButtonCanBeEnabled) {
[runSelectionButton setEnabled:YES];
@@ -3435,6 +3541,7 @@
if ([contextInfo isEqualToString:@"addAllToNewQueryFavorite"] || [contextInfo isEqualToString:@"addSelectionToNewQueryFavorite"]) {
if (returnCode == NSOKButton) {
+#ifndef SP_REFACTOR
// Add the new query favorite directly the user's preferences here instead of asking the manager to do it
// as it may not have been fully initialized yet.
@@ -3472,6 +3579,7 @@
[saveQueryFavoriteGlobal setState:NSOffState];
[self queryFavoritesHaveBeenUpdated:nil];
+#endif
}
}
@@ -3485,8 +3593,10 @@
if (returnCode == NSOKButton) {
NSError *error = nil;
+#ifndef SP_REFACTOR
[prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding];
[prefs synchronize];
+#endif
[[self buildHistoryString] writeToFile:[panel filename]
atomically:YES
@@ -3524,13 +3634,17 @@
}
// Control Clear History menu item title according to isUntitled
else if ( [menuItem tag] == SP_HISTORY_CLEAR_MENUITEM_TAG ) {
+#ifndef SP_REFACTOR /* if ( [tableDocumentInstance isUntitled] ) */
if ( [tableDocumentInstance isUntitled] ) {
+#endif
[menuItem setTitle:NSLocalizedString(@"Clear Global History", @"clear global history menu item title")];
[menuItem setToolTip:NSLocalizedString(@"Clear the global history list", @"clear the global history list tooltip message")];
+#ifndef SP_REFACTOR /* if ( [tableDocumentInstance isUntitled] ) */
} else {
[menuItem setTitle:[NSString stringWithFormat:NSLocalizedString(@"Clear History for “%@”", @"clear history for “%@” menu title"), [tableDocumentInstance displayName]]];
[menuItem setToolTip:NSLocalizedString(@"Clear the document-based history list", @"clear the document-based history list tooltip message")];
}
+#endif
}
// Check for History items
else if ( [menuItem tag] >= SP_HISTORY_COPY_MENUITEM_TAG && [menuItem tag] <= SP_HISTORY_CLEAR_MENUITEM_TAG ) {
@@ -3601,6 +3715,7 @@
selectionIndexToRestore = nil;
selectionViewportToRestore = NSZeroRect;
+#ifndef SP_REFACTOR
// init helpHTMLTemplate
NSError *error;
@@ -3618,6 +3733,7 @@
// init search history
[helpWebView setMaintainsBackForwardList:YES];
[[helpWebView backForwardList] setCapacity:20];
+#endif
// init tableView's data source
resultDataCount = 0;
@@ -3834,8 +3950,10 @@
[queryFavoritesSaveAsMenuItem setTag:SP_SAVE_SELECTION_FAVORTITE_MENUITEM_TAG];
[queryFavoritesSaveAllMenuItem setTag:SP_SAVE_ALL_FAVORTITE_MENUITEM_TAG];
+#ifndef SP_REFACTOR
// Set the structure and index view's vertical gridlines if required
[customQueryView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+#endif
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -3847,7 +3965,9 @@
name:SPDocumentTaskEndNotification
object:tableDocumentInstance];
+#ifndef SP_REFACTOR
[prefs addObserver:self forKeyPath:SPGlobalResultTableFont options:NSKeyValueObservingOptionNew context:NULL];
+#endif
// Collapse the query information pane
if ([queryInfoPaneSplitView collapsibleSubview]) {
@@ -3870,7 +3990,9 @@
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
+#ifndef SP_REFACTOR
[prefs removeObserver:self forKeyPath:SPGlobalResultTableFont];
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:customQueryView];
[self clearQueryLoadTimer];
@@ -3880,7 +4002,9 @@
if(fieldEditor) [fieldEditor release], fieldEditor = nil;
+#ifndef SP_REFACTOR
if (helpHTMLTemplate) [helpHTMLTemplate release];
+#endif
if (mySQLversion) [mySQLversion release];
if (sortField) [sortField release];
if (cqColumnDefinition) [cqColumnDefinition release];
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index 485b224b..d70a7a40 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -26,14 +26,15 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <MCPKit/MCPKit.h>
+#ifndef SP_REFACTOR /* headers */
#import <WebKit/WebKit.h>
+#endif
-@class SPConnectionController,
- SPProcessListController,
- SPServerVariablesController,
- SPUserManager,
- SPWindowController,
- SPServerSupport;
+@class SPConnectionController,
+#ifndef SP_REFACTOR /* class forward decls */
+SPProcessListController, SPServerVariablesController, SPUserManager, SPWindowController,
+#endif
+SPTablesList, SPTableStructure, SPTableContent, SPTableData, SPServerSupport;
#import "SPConnectionControllerDelegateProtocol.h"
@@ -42,15 +43,19 @@
*/
@interface SPDatabaseDocument : NSObject <SPConnectionControllerDelegateProtocol>
{
+#ifdef SP_REFACTOR /* patch */
+ id delegate;
+#endif
+
// IBOutlets
- IBOutlet id tablesListInstance;
- IBOutlet id tableSourceInstance;
- IBOutlet id tableContentInstance;
+ SPTablesList* tablesListInstance;
+ SPTableStructure* tableSourceInstance;
+ SPTableContent* tableContentInstance;
IBOutlet id tableRelationsInstance;
IBOutlet id tableTriggersInstance;
IBOutlet id customQueryInstance;
IBOutlet id tableDumpInstance;
- IBOutlet id tableDataInstance;
+ SPTableData* tableDataInstance;
IBOutlet id extendedTableInfoInstance;
IBOutlet id databaseDataInstance;
IBOutlet id spHistoryControllerInstance;
@@ -60,7 +65,9 @@
IBOutlet id statusTableView;
IBOutlet id statusTableCopyChecksum;
+#ifndef SP_REFACTOR /* ivars */
SPUserManager *userManagerInstance;
+#endif
SPServerSupport *serverSupport;
IBOutlet NSSearchField *listFilterField;
@@ -137,13 +144,15 @@
// Controllers
SPConnectionController *connectionController;
+#ifndef SP_REFACTOR /* ivars */
SPProcessListController *processListController;
SPServerVariablesController *serverVariablesController;
-
+#endif
MCPConnection *mySQLConnection;
+#ifndef SP_REFACTOR /* ivars */
NSInteger currentTabIndex;
-
+#endif
NSString *selectedTableName;
SPTableType selectedTableType;
@@ -154,14 +163,18 @@
NSString *selectedDatabase;
NSString *mySQLVersion;
+#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
NSMutableArray *nibObjectsToRelease;
+#endif
NSMenu *selectEncodingMenu;
BOOL _supportsEncoding;
BOOL _isConnected;
NSInteger _isWorkingLevel;
+#ifndef SP_REFACTOR /* ivars */
BOOL _mainNibLoaded;
+#endif
BOOL databaseListIsSelectable;
NSInteger _queryMode;
BOOL _isSavedInBundle;
@@ -182,7 +195,9 @@
NSToolbar *mainToolbar;
NSToolbarItem *chooseDatabaseToolbarItem;
+#ifndef SP_REFACTOR /* ivars */
WebView *printWebView;
+#endif
NSMutableArray *allDatabases;
NSMutableArray *allSystemDatabases;
@@ -198,6 +213,7 @@
NSString *keyChainID;
+#ifndef SP_REFACTOR /* ivars */
NSThread *printThread;
id statusValues;
@@ -206,32 +222,51 @@
// Properties
SPWindowController *parentWindowController;
+#endif
NSWindow *parentWindow;
+#ifndef SP_REFACTOR /* ivars */
NSTabViewItem *parentTabViewItem;
+#endif
BOOL isProcessing;
+#ifndef SP_REFACTOR /* ivars */
NSString *processID;
+#endif
}
+#ifdef SP_REFACTOR /* ivars */
+@property (readwrite, assign) id delegate;
+@property (readonly) NSMutableArray* allDatabases;
+#endif
+
+#ifndef SP_REFACTOR /* ivars */
@property (readwrite, assign) SPWindowController *parentWindowController;
@property (readwrite, assign) NSTabViewItem *parentTabViewItem;
+#endif
@property (readwrite, assign) BOOL isProcessing;
+#ifndef SP_REFACTOR /* ivars */
@property (readwrite, retain) NSString *processID;
+#endif
@property (readonly) SPServerSupport *serverSupport;
+#ifndef SP_REFACTOR /* method decls */
- (BOOL)isUntitled;
- (BOOL)couldCommitCurrentViewActions;
- (void)initQueryEditorWithString:(NSString *)query;
// Connection callback and methods
+#endif
- (void)setConnection:(MCPConnection *)theConnection;
- (MCPConnection *)getConnection;
- (void)setKeychainID:(NSString *)theID;
// Database methods
- (IBAction)setDatabases:(id)sender;
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)chooseDatabase:(id)sender;
+#endif
- (void)selectDatabase:(NSString *)aDatabase item:(NSString *)anItem;
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)addDatabase:(id)sender;
- (IBAction)removeDatabase:(id)sender;
- (IBAction)refreshTables:(id)sender;
@@ -241,6 +276,7 @@
- (IBAction)showServerVariables:(id)sender;
- (IBAction)showServerProcesses:(id)sender;
- (IBAction)openCurrentConnectionInNewWindow:(id)sender;
+#endif
- (NSArray *)allDatabaseNames;
- (NSArray *)allSystemDatabaseNames;
- (NSDictionary *)getDbStructure;
@@ -269,6 +305,7 @@
- (void)updateEncodingMenuWithSelectedEncoding:(NSNumber *)encodingTag;
- (NSNumber *)encodingTagFromMySQLEncoding:(NSString *)mysqlEncoding;
- (NSString *)mysqlEncodingFromEncodingTag:(NSNumber *)encodingTag;
+#ifndef SP_REFACTOR /* method decls */
// Table methods
- (IBAction)showCreateTableSyntax:(id)sender;
@@ -296,7 +333,9 @@
- (void)flushPrivileges:(id)sender;
- (void)closeConnection;
- (NSWindow *)getCreateTableSyntaxWindow;
+#endif
- (void)refreshCurrentDatabase;
+#ifndef SP_REFACTOR /* method decls */
- (void)saveConnectionPanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (IBAction)validateSaveConnectionAccessory:(id)sender;
- (BOOL)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences contextInfo:(NSDictionary*)contextInfo;
@@ -312,6 +351,7 @@
- (void)showConsole:(id)sender;
- (IBAction)showNavigator:(id)sender;
- (IBAction)toggleNavigator:(id)sender;
+#endif
// Accessor methods
- (NSString *)host;
@@ -326,6 +366,7 @@
- (BOOL)isSaveInBundle;
- (NSURL *)fileURL;
- (NSString *)displayName;
+#ifndef SP_REFACTOR /* method decls */
// Notification center methods
- (void)willPerformQuery:(NSNotification *)notification;
@@ -361,11 +402,14 @@
- (void)didBecomeActiveTabInWindow;
- (void)tabDidBecomeKey;
- (void)tabDidResize;
+#endif
+
- (void)setIsProcessing:(BOOL)value;
- (BOOL)isProcessing;
- (void)setParentWindow:(NSWindow *)aWindow;
- (NSWindow *)parentWindow;
+#ifndef SP_REFACTOR /* method decls */
// Scripting
- (void)handleSchemeCommand:(NSDictionary*)commandDict;
- (void)registerActivity:(NSDictionary*)commandDict;
@@ -379,5 +423,17 @@
- (BOOL)setState:(NSDictionary *)stateDetails;
- (void)setStateFromConnectionFile:(NSString *)path;
- (void)restoreSession;
+#endif
+
+#ifdef SP_REFACTOR /* method decls */
+- (SPConnectionController*)createConnectionController;
+- (void)connect;
+- (NSArray*)allTableNames;
+- (SPTablesList*)tablesListInstance;
+- (SPTableData*)tableDataInstance;
+- (void)setTableSourceInstance:(SPTableStructure*)source;
+- (void)setTableContentInstance:(SPTableContent*)content;
+- (void)setTableDataInstance:(SPTableData*)data;
+#endif
@end
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index fce0bd3f..8c05daa0 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -26,8 +26,13 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPDatabaseDocument.h"
+#import "SPConnectionController.h"
+
#import "SPTablesList.h"
#import "SPTableStructure.h"
+#ifndef SP_REFACTOR /* headers */
+#import "SPFileHandle.h"
+#import "SPKeychain.h"
#import "SPTableContent.h"
#import "SPCustomQuery.h"
#import "SPDataImport.h"
@@ -35,13 +40,15 @@
#import "SPGrowlController.h"
#import "SPExportController.h"
#import "SPQueryController.h"
+#import "SPWindowController.h"
+#endif
#import "SPNavigatorController.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPSQLParser.h"
#import "SPTableData.h"
#import "SPDatabaseData.h"
#import "SPAppController.h"
#import "SPExtendedTableInfo.h"
-#import "SPConnectionController.h"
#import "SPHistoryController.h"
#import "SPPreferenceController.h"
#import "SPUserManager.h"
@@ -54,38 +61,58 @@
#import "SPDatabaseCopy.h"
#import "SPTableCopy.h"
#import "SPDatabaseRename.h"
+#endif
#import "SPServerSupport.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPTooltip.h"
+#endif
#import "SPDatabaseViewController.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPBundleHTMLOutputController.h"
#import "SPConnectionDelegate.h"
-#import "SPWindowController.h"
-#import "SPFileHandle.h"
-#import "SPConnectionHandler.h"
+#endif
+
+#ifdef SP_REFACTOR /* headers */
+#import "SPAlertSheets.h"
+#import "NSNotificationAdditions.h"
+#endif
@interface SPDatabaseDocument (PrivateAPI)
+#ifndef SP_REFACTOR /* method decls */
- (void)_addDatabase;
- (void)_copyDatabase;
- (void)_renameDatabase;
- (void)_removeDatabase;
+#endif
- (void)_selectDatabaseAndItem:(NSDictionary *)selectionDetails;
@end
@implementation SPDatabaseDocument
+#ifndef SP_REFACTOR /* ivars */
@synthesize parentWindowController;
@synthesize parentTabViewItem;
+#endif
@synthesize isProcessing;
@synthesize serverSupport;
+#ifndef SP_REFACTOR /* ivars */
@synthesize processID;
+#endif
+
+#ifdef SP_REFACTOR /* ivars */
+@synthesize allDatabases;
+@synthesize delegate;
+#endif
- (id)init
{
if ((self = [super init])) {
+#ifndef SP_REFACTOR /* init ivars */
_mainNibLoaded = NO;
+#endif
_isConnected = NO;
_isWorkingLevel = 0;
_isSavedInBundle = NO;
@@ -109,14 +136,18 @@
mySQLVersion = nil;
allDatabases = nil;
allSystemDatabases = nil;
+#ifndef SP_REFACTOR /* init ivars */
mainToolbar = nil;
parentWindow = nil;
+#endif
isProcessing = NO;
+#ifndef SP_REFACTOR /* init ivars */
printWebView = [[WebView alloc] init];
[printWebView setFrameLoadDelegate:self];
prefs = [NSUserDefaults standardUserDefaults];
+#endif
queryEditorInitString = nil;
spfFileURL = nil;
@@ -138,6 +169,7 @@
taskCancellationCallbackSelector = NULL;
keyChainID = nil;
+#ifndef SP_REFACTOR /* init ivars */
statusValues = nil;
printThread = nil;
nibObjectsToRelease = [[NSMutableArray alloc] init];
@@ -149,11 +181,47 @@
[nibLoader instantiateNibWithOwner:self topLevelObjects:&dbViewTopLevelObjects];
[nibLoader release];
[nibObjectsToRelease addObjectsFromArray:dbViewTopLevelObjects];
+#endif
}
return self;
}
+#ifdef SP_REFACTOR /* glue */
+- (SPConnectionController*)createConnectionController
+{
+ // Set up the connection controller
+ connectionController = [[SPConnectionController alloc] initWithDocument:self];
+
+ // Set the connection controller's delegate
+ [connectionController setDelegate:self];
+ return connectionController;
+}
+
+- (void)setTableSourceInstance:(SPTableStructure*)source
+{
+ tableSourceInstance = source;
+}
+
+- (void)setTableContentInstance:(SPTableContent*)content
+{
+ tableContentInstance = content;
+}
+
+- (void)setTableDataInstance:(SPTableData*)data
+{
+ tableDataInstance = data;
+}
+
+- (SPTableData*)tableDataInstance
+{
+ return tableDataInstance;
+}
+
+#endif
+
+#ifndef SP_REFACTOR /* awakeFromNib */
+
- (void)awakeFromNib
{
if (_mainNibLoaded) return;
@@ -255,7 +323,9 @@
[contentViewSplitter setDelegate:self];
}
+#endif
+#ifndef SP_REFACTOR /* password sheet and history navigation */
/**
* Set the return code for entering the encryption passowrd sheet
*/
@@ -290,6 +360,7 @@
break;
}
}
+#endif
#pragma mark -
#pragma mark Connection callback and methods
@@ -304,12 +375,14 @@
serverSupport = [[SPServerSupport alloc] initWithMajorVersion:[mySQLConnection serverMajorVersion]
minor:[mySQLConnection serverMinorVersion]
release:[mySQLConnection serverReleaseVersion]];
-
+
+#ifndef SP_REFACTOR
// Set the fileURL and init the preferences (query favs, filters, and history) if available for that URL
[self setFileURL:[[SPQueryController sharedQueryController] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences]];
// ...but hide the icon while the document is temporary
if ([self isUntitled]) [[parentWindow standardWindowButton:NSWindowDocumentIconButton] setImage:nil];
+#endif
// Get the mysql version
mySQLVersion = [[NSString alloc] initWithString:[mySQLConnection serverVersionString]];
@@ -318,7 +391,9 @@
if ([connectionController database] && ![[connectionController database] isEqualToString:@""]) {
if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
selectedDatabase = [[NSString alloc] initWithString:[connectionController database]];
+#ifndef SP_REFACTOR /* [spHistoryControllerInstance updateHistoryEntries] */
[spHistoryControllerInstance updateHistoryEntries];
+#endif
}
// Ensure the connection encoding is set to utf8 for database/table name retrieval
@@ -331,19 +406,28 @@
[databaseDataInstance setConnection:mySQLConnection];
+#ifndef SP_REFACTOR /* setServerSupport: */
// Pass the support class to the data instance
[databaseDataInstance setServerSupport:serverSupport];
-
+#endif
+
+#ifdef SP_REFACTOR /* glue */
+ tablesListInstance = [[SPTablesList alloc] init];
+ [tablesListInstance setDatabaseDocument:self];
+#endif
+
// Set the connection on the tables list instance - this updates the table list while the connection
// is still UTF8
[tablesListInstance setConnection:mySQLConnection];
+#ifndef SP_REFACTOR /* set connection encoding from prefs */
// Set the connection encoding if necessary
NSNumber *encodingType = [prefs objectForKey:SPDefaultEncoding];
if ([encodingType intValue] != SPEncodingAutodetect) {
[self setConnectionEncoding:[self mysqlEncodingFromEncodingTag:encodingType] reloadingViews:NO];
}
+#endif
// For each of the main controllers, assign the current connection
[tableSourceInstance setConnection:mySQLConnection];
@@ -356,6 +440,7 @@
[tableDataInstance setConnection:mySQLConnection];
[extendedTableInfoInstance setConnection:mySQLConnection];
+#ifndef SP_REFACTOR /* update custom query editor */
// Set the custom query editor's MySQL version
[customQueryInstance setMySQLversion:mySQLVersion];
@@ -435,6 +520,11 @@
}
(void)[self databaseEncoding];
+#endif
+#ifdef SP_REFACTOR /* glue */
+ if ( delegate && [delegate respondsToSelector:@selector(databaseDocumentDidConnect:)] )
+ [delegate performSelector:@selector(databaseDocumentDidConnect:) withObject:self];
+#endif
}
/**
@@ -463,6 +553,8 @@
*/
- (IBAction)setDatabases:(id)sender;
{
+#ifndef SP_REFACTOR /* ui manipulation */
+
if (!chooseDatabaseButton) return;
[chooseDatabaseButton removeAllItems];
@@ -472,6 +564,7 @@
[[chooseDatabaseButton menu] addItemWithTitle:NSLocalizedString(@"Add Database...", @"menu item to add db") action:@selector(addDatabase:) keyEquivalent:@""];
[[chooseDatabaseButton menu] addItemWithTitle:NSLocalizedString(@"Refresh Databases", @"menu item to refresh databases") action:@selector(setDatabases:) keyEquivalent:@""];
[[chooseDatabaseButton menu] addItem:[NSMenuItem separatorItem]];
+#endif
MCPResult *queryResult = [mySQLConnection listDBs];
@@ -498,6 +591,7 @@
}
}
+#ifndef SP_REFACTOR /* ui manipulation */
// Add system databases
for (NSString *db in allSystemDatabases)
{
@@ -516,8 +610,11 @@
}
(![self database]) ? [chooseDatabaseButton selectItemAtIndex:0] : [chooseDatabaseButton selectItemWithTitle:[self database]];
+#endif
}
+#ifndef SP_REFACTOR /* chooseDatabase: */
+
/**
* Selects the database choosen by the user, using a child task if necessary,
* and displaying errors in an alert sheet on failure.
@@ -542,12 +639,14 @@
// Select the database
[self selectDatabase:[chooseDatabaseButton titleOfSelectedItem] item:[self table]];
}
+#endif
/**
* Select the specified database and, optionally, table.
*/
- (void)selectDatabase:(NSString *)aDatabase item:(NSString *)anItem
{
+#ifndef SP_REFACTOR /* update navigator controller */
// Do not update the navigator since nothing is changed
[[SPNavigatorController sharedNavigatorController] setIgnoreUpdate:NO];
@@ -561,6 +660,7 @@
}
[[SPNavigatorController sharedNavigatorController] selectPath:schemaPath];
}
+#endif
// Start a task
[self startTaskWithDescription:[NSString stringWithFormat:NSLocalizedString(@"Loading database '%@'...", @"Loading database task string"), [chooseDatabaseButton titleOfSelectedItem]]];
@@ -576,6 +676,7 @@
}
}
+#ifndef SP_REFACTOR /* operations on whole databases */
/**
* opens the add-db sheet and creates the new db
*/
@@ -730,6 +831,7 @@
[processListController displayProcessListWindow];
}
+#endif
/**
* Returns an array of all available database names
@@ -747,6 +849,7 @@
return allSystemDatabases;
}
+#ifndef SP_REFACTOR /* sheetDidEnd: */
/**
* Alert sheet method. Invoked when an alert sheet is dismissed.
*
@@ -819,6 +922,7 @@
nil, nil, parentWindow, self, nil, nil,
[error objectAtIndex:1]);
}
+#endif
/**
* Reset the current selected database name
@@ -828,7 +932,11 @@
NSString *dbName = nil;
// Notify listeners that a query has started
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self];
+#endif
MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"];
if (![mySQLConnection queryErrored]) {
@@ -843,23 +951,33 @@
if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
selectedDatabase = [[NSString alloc] initWithString:dbName];
[chooseDatabaseButton selectItemWithTitle:selectedDatabase];
+#ifndef SP_REFACTOR /* [self updateWindowTitle:self] */
[self updateWindowTitle:self];
+#endif
}
} else {
if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
[chooseDatabaseButton selectItemAtIndex:0];
+#ifndef SP_REFACTOR /* [self updateWindowTitle:self] */
[self updateWindowTitle:self];
+#endif
}
}
//query finished
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self];
+#endif
}
+#ifndef SP_REFACTOR /* navigatorSchemaPathExistsForDatabase: */
- (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname
{
return [[SPNavigatorController sharedNavigatorController] schemaPathExistsForConnection:[self connectionID] andDatabase:dbname];
}
+#endif
- (NSDictionary*)getDbStructure
{
@@ -871,6 +989,8 @@
return [[SPNavigatorController sharedNavigatorController] allSchemaKeysForConnection:[self connectionID]];
}
+#ifndef SP_REFACTOR /* console and navigator methods */
+
#pragma mark -
#pragma mark Console methods
@@ -951,6 +1071,7 @@
[[[SPNavigatorController sharedNavigatorController] window] makeKeyAndOrderFront:self];
}
}
+#endif
#pragma mark -
#pragma mark Task progress and notification methods
@@ -1425,6 +1546,7 @@
#pragma mark -
#pragma mark Table Methods
+#ifndef SP_REFACTOR /* whole table operations */
/**
* Copies if sender == self or displays or the CREATE TABLE syntax of the selected table(s) to the user .
@@ -2187,6 +2309,8 @@
[newTableDocument setStateFromConnectionFile:[[self fileURL] path]];
}
+#endif
+
/**
* Ask the connection controller to initiate connection, if it hasn't
* already. Used to support automatic connections on window open,
@@ -2202,13 +2326,16 @@
[mySQLConnection disconnect];
_isConnected = NO;
+#ifndef SP_REFACTOR /* growl */
// Disconnected Growl notification
[[SPGrowlController sharedGrowlController] notifyWithTitle:@"Disconnected"
description:[NSString stringWithFormat:NSLocalizedString(@"Disconnected from %@",@"description for disconnected growl notification"), [parentTabViewItem label]]
document:self
notificationName:@"Disconnected"];
+#endif
}
+#ifndef SP_REFACTOR /* observeValueForKeyPath: */
/**
* This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
*/
@@ -2218,6 +2345,7 @@
[mySQLConnection setDelegateQueryLogging:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]];
}
}
+#endif
/**
* Is current document Untitled?
@@ -2339,8 +2467,10 @@
tabTitle = [NSMutableString string];
+#ifndef SP_REFACTOR /* Add the MySQL version to the window title */
// Add the MySQL version to the window title if enabled in prefs
if ([prefs boolForKey:SPDisplayServerVersionInWindowTitle]) [tabTitle appendFormat:@"(MySQL %@)\n", [self mySQLVersion]];
+#endif
[tabTitle appendString:[self name]];
if ([self database]) {
@@ -2420,6 +2550,7 @@
[queryProgressBar stopAnimation:self];
}
+#ifndef SP_REFACTOR /* applicationWillTerminate: */
/**
* Invoked when the application will terminate
*/
@@ -3271,7 +3402,7 @@
if ([connectionController selectedFavorite]) return;
// Request the connection controller to add its details to favorites
- [connectionController addFavoriteUsingCurrentDetails:self];
+ [connectionController addFavorite:self];
}
/**
@@ -3839,6 +3970,7 @@
// If the task interface is visible, and this tab is frontmost, re-center the task child window
if (_isWorkingLevel && [parentWindowController selectedTableDocument] == self) [self centerTaskWindow];
}
+#endif
/**
* Set the parent window
@@ -3847,7 +3979,9 @@
{
// If the window is being set for the first time - connection controller is visible - update focus
if (!parentWindow && !mySQLConnection) {
- [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesOutlineView"]];
+#ifndef SP_REFACTOR
+ [aWindow makeFirstResponder:[connectionController valueForKey:@"favoritesTable"]];
+#endif
[connectionController performSelector:@selector(updateFavoriteSelection:) withObject:self afterDelay:0.0];
}
@@ -3864,6 +3998,7 @@
return parentWindow;
}
+#ifndef SP_REFACTOR
#pragma mark -
#pragma mark NSDocument compatibility
@@ -3881,6 +4016,7 @@
[parentWindow setRepresentedURL:nil];
}
}
+#endif
/**
* Retrieve the NSURL for the .spf file for this connection instance (if any)
@@ -3890,6 +4026,7 @@
return [[spfFileURL copy] autorelease];
}
+#ifndef SP_REFACTOR /* writeSafelyToURL: */
/**
* Invoked if user chose "Save" from 'Do you want save changes you made...' sheet
* which is called automatically if [self isDocumentEdited] == YES and user wanted to close an Untitled doc.
@@ -3916,6 +4053,7 @@
|| [[[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] objectForKey:@"string"] count])
);
}
+#endif
/**
* The window title for this document.
@@ -3929,7 +4067,7 @@
}
return [[[self fileURL] path] lastPathComponent];
}
-
+#ifndef SP_REFACTOR /* state saving and setting */
#pragma mark -
#pragma mark State saving and setting
@@ -4115,6 +4253,7 @@
{
NSDictionary *connection = nil;
NSInteger connectionType = -1;
+ SPKeychain *keychain = nil;
// If this document already has a connection, don't proceed.
if (mySQLConnection) return NO;
@@ -4123,15 +4262,17 @@
connection = [NSDictionary dictionaryWithDictionary:[stateDetails objectForKey:@"connection"]];
if (!connection) return NO;
+ if ([connection objectForKey:@"kcid"]) keychain = [[SPKeychain alloc] init];
+
[self updateWindowTitle:self];
// Deselect all favorites on the connection controller
- [[connectionController valueForKeyPath:@"favoritesOutlineView"] deselectAll:connectionController];
+ [[connectionController valueForKeyPath:@"favoritesTable"] deselectAll:connectionController];
// Suppress the possibility to choose an other connection from the favorites
// if a connection should initialized by SPF file. Otherwise it could happen
// that the SPF file runs out of sync.
- [[connectionController valueForKeyPath:@"favoritesOutlineView"] setEnabled:NO];
+ [[connectionController valueForKeyPath:@"favoritesTable"] setEnabled:NO];
// Ensure the connection controller is set to a blank slate
[connectionController setName:@""];
@@ -4153,7 +4294,11 @@
[connectionController setSshPort:@""];
[connectionController setDatabase:@""];
[connectionController setPassword:nil];
+ [connectionController setConnectionKeychainItemName:nil];
+ [connectionController setConnectionKeychainItemAccount:nil];
[connectionController setSshPassword:nil];
+ [connectionController setConnectionSSHKeychainItemName:nil];
+ [connectionController setConnectionSSHKeychainItemAccount:nil];
// Set the correct connection type
if ([connection objectForKey:@"type"]) {
@@ -4197,8 +4342,11 @@
[connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]];
// Set the keychain details if available
- if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length])
+ if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
[self setKeychainID:[connection objectForKey:@"kcid"]];
+ [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keyChainID]]];
+ [connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]];
+ }
// Set password - if not in SPF file try to get it via the KeyChain
if ([connection objectForKey:@"password"])
@@ -4229,6 +4377,10 @@
if ([connection objectForKey:@"ssh_password"])
[connectionController setSshPassword:[connection objectForKey:@"ssh_password"]];
else {
+ if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
+ [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]]];
+ [connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]];
+ }
NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
if(sshpw)
[connectionController setSshPassword:sshpw];
@@ -4258,6 +4410,8 @@
[connectionController initiateConnection:self];
}
+ if (keychain) [keychain release];
+
return YES;
}
@@ -4535,6 +4689,7 @@
[self endTask];
[taskPool drain];
}
+#endif
#pragma mark -
#pragma mark Connection controller delegate methods
@@ -4544,12 +4699,14 @@
*/
- (void)connectionControllerInitiatingConnection:(id)controller
{
+#ifndef SP_REFACTOR /* ui manipulation */
// Update the window title to indicate that we are trying to establish a connection
[parentTabViewItem setLabel:NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")];
if ([parentWindowController selectedTableDocument] == self) {
[parentWindow setTitle:NSLocalizedString(@"Connecting…", @"window title string indicating that sp is connecting")];
}
+#endif
}
/**
@@ -4557,10 +4714,15 @@
*/
- (void)connectionControllerConnectAttemptFailed:(id)controller
{
+#ifndef SP_REFACTOR /* updateWindowTitle: */
// Reset the window title
[self updateWindowTitle:self];
+#endif
}
+
+#ifndef SP_REFACTOR /* scheme scripting methods */
+
#pragma mark -
#pragma mark Scheme scripting methods
@@ -5061,7 +5223,11 @@
- (void)registerActivity:(NSDictionary*)commandDict
{
[runningActivitiesArray addObject:commandDict];
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self];
+#endif
if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count])
[self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0];
@@ -5093,7 +5259,11 @@
[self setActivityPaneHidden:[NSNumber numberWithInteger:1]];
}
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self];
+#endif
}
@@ -5166,6 +5336,7 @@
return (NSDictionary*)env;
}
+#endif
#pragma mark -
#pragma mark Text field delegate methods
@@ -5194,6 +5365,7 @@
#pragma mark -
#pragma mark General sheet delegate methods
+#ifndef SP_REFACTOR /* window:willPositionSheet:usingRect: */
- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect {
@@ -5217,10 +5389,11 @@
rect.origin.y -= [[parentWindowController valueForKey:@"tabBar"] frame].size.height - 1;
return rect;
}
+#endif
#pragma mark -
#pragma mark SplitView delegate methods
-
+#ifndef SP_REFACTOR /* SplitView delegate methods */
/**
* tells the splitView that it can collapse views
*/
@@ -5348,6 +5521,9 @@
_isSavedInBundle = savedInBundle;
}
+#endif
+
+
#pragma mark -
/**
@@ -5355,7 +5531,7 @@
*/
- (void)dealloc
{
-
+#ifndef SP_REFACTOR /* Unregister observers */
// Unregister observers
[prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines];
[prefs removeObserver:tableSourceInstance forKeyPath:SPDisplayTableViewVerticalGridlines];
@@ -5371,23 +5547,30 @@
if (processListController) [prefs removeObserver:processListController forKeyPath:SPDisplayTableViewVerticalGridlines];
if (serverVariablesController) [prefs removeObserver:serverVariablesController forKeyPath:SPDisplayTableViewVerticalGridlines];
+#endif
[[NSNotificationCenter defaultCenter] removeObserver:self];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
+#ifndef SP_REFACTOR /* release nib objects */
for (id retainedObject in nibObjectsToRelease) [retainedObject release];
[nibObjectsToRelease release];
+#endif
[allDatabases release];
[allSystemDatabases release];
+#ifndef SP_REFACTOR /* dealloc ivars */
[printWebView release];
+#endif
[taskProgressWindow close];
if (selectedTableName) [selectedTableName release];
if (connectionController) [connectionController release];
+#ifndef SP_REFACTOR /* dealloc ivars */
if (processListController) [processListController release];
if (serverVariablesController) [serverVariablesController release];
+#endif
if (mySQLConnection) [mySQLConnection release];
if (selectedDatabase) [selectedDatabase release];
if (mySQLVersion) [mySQLVersion release];
@@ -5403,16 +5586,30 @@
if (titleAccessoryView) [titleAccessoryView release];
if (taskProgressWindow) [taskProgressWindow release];
if (serverSupport) [serverSupport release];
+#ifndef SP_REFACTOR /* dealloc ivars */
if (processID) [processID release];
+#endif
if (runningActivitiesArray) [runningActivitiesArray release];
[super dealloc];
}
+- (NSArray*)allTableNames
+{
+ return [tablesListInstance allTableNames];
+}
+
+- (SPTablesList*)tablesListInstance
+{
+ return tablesListInstance;
+}
+
@end
@implementation SPDatabaseDocument (PrivateAPI)
+#ifndef SP_REFACTOR /* whole database operations */
+
- (void)_copyDatabase
{
if ([[databaseCopyNameField stringValue] isEqualToString:@""]) {
@@ -5562,6 +5759,8 @@
[self updateWindowTitle:self];
}
+#endif
+
/**
* Select the specified database and, optionally, table.
*/
@@ -5569,6 +5768,7 @@
{
NSAutoreleasePool *taskPool = [[NSAutoreleasePool alloc] init];
NSString *targetDatabaseName = [selectionDetails objectForKey:@"database"];
+#ifndef SP_REFACTOR /* update history controller */
NSString *targetItemName = [selectionDetails objectForKey:@"item"];
// Save existing scroll position and details, and ensure no duplicate entries are created as table list changes
@@ -5577,12 +5777,17 @@
[spHistoryControllerInstance updateHistoryEntries];
[spHistoryControllerInstance setModifyingState:YES];
}
+#endif
if (![targetDatabaseName isEqualToString:selectedDatabase]) {
// Attempt to select the specified database, and abort on failure
+#ifndef SP_REFACTOR /* patch */
if ([chooseDatabaseButton indexOfItemWithTitle:targetDatabaseName] == NSNotFound
|| ![mySQLConnection selectDB:targetDatabaseName])
+#else
+ if ( ![mySQLConnection selectDB:targetDatabaseName] )
+#endif
{
// End the task first to ensure the database dropdown can be reselected
@@ -5600,21 +5805,30 @@
return;
}
+#ifndef SP_REFACTOR /* chooseDatabaseButton selectItemWithTitle: */
[[chooseDatabaseButton onMainThread] selectItemWithTitle:targetDatabaseName];
+#endif
if (selectedDatabase) [selectedDatabase release], selectedDatabase = nil;
+#ifndef SP_REFACTOR /* patch */
selectedDatabase = [[NSString alloc] initWithString:[chooseDatabaseButton titleOfSelectedItem]];
+#else
+ selectedDatabase = [[NSString alloc] initWithString:targetDatabaseName];
+#endif
+#ifndef SP_REFACTOR /* clear SPTablesList selection */
// If the item has changed, clear the item selection for cleaner loading
if (![targetItemName isEqualToString:[self table]]) {
[[tablesListInstance onMainThread] setTableListSelectability:YES];
[[[tablesListInstance valueForKey:@"tablesListView"] onMainThread] deselectAll:self];
[[tablesListInstance onMainThread] setTableListSelectability:NO];
}
+#endif
// Set the connection of SPTablesList and TablesDump to reload tables in db
[tablesListInstance setConnection:mySQLConnection];
[tableDumpInstance setConnection:mySQLConnection];
+#ifndef SP_REFACTOR /* update history controller and ui manip */
// Update the window title
[self updateWindowTitle:self];
@@ -5630,8 +5844,10 @@
[[parentWindow onMainThread] makeFirstResponder:listFilterField];
else
[[parentWindow onMainThread] makeFirstResponder:[tablesListInstance valueForKeyPath:@"tablesListView"]];
+#endif
}
+#ifndef SP_REFACTOR /* update selected table in SPTablesList */
// If a the table has changed, update the selection
if (![targetItemName isEqualToString:[self table]]) {
if (targetItemName) {
@@ -5642,8 +5858,9 @@
[[tablesListInstance onMainThread] setTableListSelectability:NO];
}
}
-
+#endif
[self endTask];
+#ifndef SP_REFACTOR /* triggered commands */
NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionDatabaseChanged];
for(NSString* cmdPath in triggeredCommands) {
@@ -5681,8 +5898,14 @@
}
}
}
+#endif
- [taskPool drain];
+#ifdef SP_REFACTOR /* glue */
+ if ( delegate && [delegate respondsToSelector:@selector(databaseDidChange:)] )
+ [delegate performSelectorOnMainThread:@selector(databaseDidChange:) withObject:self waitUntilDone:NO];
+#endif
+ [taskPool drain];
}
+
@end
diff --git a/Source/SPDatabaseViewController.h b/Source/SPDatabaseViewController.h
index 682d6f74..f84d81cd 100644
--- a/Source/SPDatabaseViewController.h
+++ b/Source/SPDatabaseViewController.h
@@ -35,6 +35,7 @@
- (BOOL)contentLoaded;
- (BOOL)statusLoaded;
+#ifndef SP_REFACTOR /* method decls */
// Tab view control
- (IBAction)viewStructure:(id)sender;
- (IBAction)viewContent:(id)sender;
@@ -42,6 +43,7 @@
- (IBAction)viewStatus:(id)sender;
- (IBAction)viewRelations:(id)sender;
- (IBAction)viewTriggers:(id)sender;
+#endif
- (void)setStructureRequiresReload:(BOOL)reload;
- (void)setContentRequiresReload:(BOOL)reload;
- (void)setStatusRequiresReload:(BOOL)reload;
@@ -49,6 +51,8 @@
// Table control
- (void)loadTable:(NSString *)aTable ofType:(NSInteger)aTableType;
+#ifndef SP_REFACTOR /* method decls */
- (NSView *)databaseView;
+#endif
@end
diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m
index 3b6cfc1f..171ff8f6 100644
--- a/Source/SPDatabaseViewController.m
+++ b/Source/SPDatabaseViewController.m
@@ -32,6 +32,9 @@
#import "SPTableData.h"
#import "SPTablesList.h"
#import "SPTableTriggers.h"
+#ifdef SP_REFACTOR /* headers */
+#import "SPTableStructure.h"
+#endif
@interface SPDatabaseDocument (SPDatabaseViewControllerPrivateAPI)
@@ -46,6 +49,7 @@
#pragma mark -
#pragma mark Getters
+#ifndef SP_REFACTOR /* getters */
/**
* Returns the master database view, containing the tables list and views for
* table setup and contents.
@@ -54,6 +58,7 @@
{
return parentView;
}
+#endif
/**
* Returns the name of the currently selected table/view/procedure/function.
@@ -95,6 +100,7 @@
return statusLoaded;
}
+#ifndef SP_REFACTOR /* toolbar ibactions */
#pragma mark -
#pragma mark Tab view control and delegate methods
@@ -204,6 +210,7 @@
[prefs setInteger:SPTriggersViewMode forKey:SPLastViewMode];
}
+#endif
/**
* Mark the structure tab for refresh when it's next switched to,
@@ -224,7 +231,11 @@
*/
- (void)setContentRequiresReload:(BOOL)reload
{
- if (reload && selectedTableName && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewContent) {
+ if (reload && selectedTableName
+#ifndef SP_REFACTOR /* check which tab is selected */
+ && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewContent
+#endif
+ ) {
[tableContentInstance loadTable:selectedTableName];
} else {
contentLoaded = !reload;
@@ -237,14 +248,18 @@
*/
- (void)setStatusRequiresReload:(BOOL)reload
{
- if (reload && selectedTableName && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewStatus) {
+ if (reload && selectedTableName
+#ifndef SP_REFACTOR /* check which tab is selected */
+ && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewStatus
+#endif
+ ) {
[[extendedTableInfoInstance onMainThread] loadTable:selectedTableName];
} else {
statusLoaded = !reload;
}
}
-
+#ifndef SP_REFACTOR /* !!! respond to tab change */
/**
* Triggers a task to update the newly selected tab view, ensuring
* the data is fully loaded and up-to-date.
@@ -258,6 +273,7 @@
[self _loadTabTask:tabViewItem];
}
}
+#endif
#pragma mark -
#pragma mark Table control
@@ -286,21 +302,29 @@
[[tablesListInstance onMainThread] setSelectionState:nil];
[tableSourceInstance loadTable:nil];
[tableContentInstance loadTable:nil];
+#ifndef SP_REFACTOR /* [extendedTableInfoInstance loadTable:] */
[[extendedTableInfoInstance onMainThread] loadTable:nil];
[[tableTriggersInstance onMainThread] resetInterface];
+#endif
structureLoaded = NO;
contentLoaded = NO;
statusLoaded = NO;
triggersLoaded = NO;
+#ifndef SP_REFACTOR
// Update the window title
[self updateWindowTitle:self];
// Add a history entry
[spHistoryControllerInstance updateHistoryEntries];
+#endif
// Notify listeners of the table change
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
+#endif
return;
}
@@ -370,6 +394,7 @@
contentLoaded = YES;
}
break;
+#ifndef SP_REFACTOR /* case SPTableViewStatus: case SPTableViewTriggers: */
case SPTableViewStatus:
if (!statusLoaded) {
[[extendedTableInfoInstance onMainThread] loadTable:selectedTableName];
@@ -382,6 +407,7 @@
triggersLoaded = YES;
}
break;
+#endif
}
[self endTask];
@@ -397,8 +423,10 @@
NSAutoreleasePool *loadPool = [[NSAutoreleasePool alloc] init];
NSString *tableEncoding = nil;
+#ifndef SP_REFACTOR /* Update the window title */
// Update the window title
[self updateWindowTitle:self];
+#endif
// Reset table information caches and mark that all loaded views require their data reloading
[tableDataInstance resetAllData];
@@ -439,24 +467,35 @@
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
// Notify listeners of the table change now that the state is fully set up.
- [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
+#ifndef SP_REFACTOR
+ [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPTableChangedNotification object:self];
+#endif
+#ifndef SP_REFACTOR /* [spHistoryControllerInstance restoreViewStates] */
// Restore view states as appropriate
[spHistoryControllerInstance restoreViewStates];
+#endif
// Load the currently selected view if looking at a table or view
if (tableEncoding && (selectedTableType == SPTableTypeView || selectedTableType == SPTableTypeTable))
{
+#ifndef SP_REFACTOR /* load everything */
NSInteger selectedTabViewIndex = [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]];
switch (selectedTabViewIndex) {
case SPTableViewStructure:
+#endif
[tableSourceInstance loadTable:selectedTableName];
structureLoaded = YES;
+#ifndef SP_REFACTOR /* load everything */
break;
case SPTableViewContent:
+#endif
[tableContentInstance loadTable:selectedTableName];
contentLoaded = YES;
+#ifndef SP_REFACTOR /* load everything */
break;
case SPTableViewStatus:
[[extendedTableInfoInstance onMainThread] loadTable:selectedTableName];
@@ -467,6 +506,7 @@
triggersLoaded = YES;
break;
}
+#endif
}
// Clear any views which haven't been loaded as they weren't visible. Note
@@ -477,6 +517,7 @@
if (!statusLoaded) [[extendedTableInfoInstance onMainThread] loadTable:nil];
if (!triggersLoaded) [[tableTriggersInstance onMainThread] resetInterface];
+#ifndef SP_REFACTOR /* show Create Table syntax */
// Update the "Show Create Syntax" window if it's already opened
// according to the selected table/view/proc/func
if([[[self onMainThread] getCreateTableSyntaxWindow] isVisible])
@@ -484,10 +525,11 @@
// Add a history entry
[spHistoryControllerInstance updateHistoryEntries];
-
+#endif
// Empty the loading pool and exit the thread
[self endTask];
+#ifndef SP_REFACTOR /* triggered commands */
NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionTableChanged];
for(NSString* cmdPath in triggeredCommands) {
NSArray *data = [cmdPath componentsSeparatedByString:@"|"];
@@ -524,6 +566,7 @@
}
}
}
+#endif
[loadPool drain];
diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m
index 7a4fb37c..b028c177 100644
--- a/Source/SPEditSheetTextView.m
+++ b/Source/SPEditSheetTextView.m
@@ -125,6 +125,12 @@
[self saveChangedFontInUserDefaults];
return;
}
+ if([charactersIgnMod isEqualToString:@"0"]) // return the text size to the default size; ⌘0
+ {
+ [self makeTextStandardSize];
+ [self saveChangedFontInUserDefaults];
+ return;
+ }
}
// Allow undo grouping if user typed a ' ' (for word level undo)
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index 1f3b6ea8..b629acbf 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -32,7 +32,11 @@
* This class offers a sheet for editing different kind of data such as text, blobs (including images) as
* editSheet and bit fields as bitSheet.
*/
+#ifndef SP_REFACTOR
@interface SPFieldEditorController : NSWindowController
+#else
+@interface SPFieldEditorController : NSWindowController <NSComboBoxDataSource>
+#endif
{
IBOutlet id editSheetProgressBar;
IBOutlet id editSheetSegmentControl;
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index 73fafe39..52a90fcd 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -4,7 +4,7 @@
// SPFieldEditorController.m
// sequel-pro
//
-// Created by Hans-Jörg Bibiko on July 16, 2009
+// Created by Hans-Jörg Bibiko on July 16, 2009
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -31,6 +31,8 @@
#import "SPGeometryDataView.h"
#import "SPCopyTable.h"
#include <objc/objc-runtime.h>
+#import "SPCustomQuery.h"
+#import "SPTableContent.h"
@interface SPFieldEditorController (SPFieldEditorControllerDelegate)
@@ -110,6 +112,7 @@
[qlTypesItems addObject:type];
}
}
+#ifndef SP_REFACTOR
// Load user-defined QL types
if([prefs objectForKey:SPQuickLookTypes]) {
for(id type in [prefs objectForKey:SPQuickLookTypes]) {
@@ -122,6 +125,7 @@
[qlTypesItems addObject:type];
}
}
+#endif
qlTypes = [[NSDictionary dictionaryWithObject:qlTypesItems forKey:SPQuickLookTypes] retain];
[qlTypesItems release];
@@ -239,14 +243,28 @@
usedSheet = editSheet;
// If required, use monospaced fonts
+#ifndef SP_REFACTOR
if (![prefs objectForKey:SPFieldEditorSheetFont]) {
- [editTextView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+#endif
+ [editTextView setFont:
+#ifndef SP_REFACTOR
+ ([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] :
+#endif
+ [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+#ifndef SP_REFACTOR
}
else {
[editTextView setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:@"FieldEditorSheetFont"]]];
}
+#endif
- [editTextView setContinuousSpellCheckingEnabled:[prefs boolForKey:SPBlobTextEditorSpellCheckingEnabled]];
+ [editTextView setContinuousSpellCheckingEnabled:
+#ifndef SP_REFACTOR
+ [prefs boolForKey:SPBlobTextEditorSpellCheckingEnabled]
+#else
+ NO
+#endif
+ ];
[hexTextView setFont:[NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]]];
@@ -532,8 +550,10 @@
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
{
+#ifndef SP_REFACTOR
// Remember spell cheecker status
[prefs setBool:[editTextView isContinuousSpellCheckingEnabled] forKey:SPBlobTextEditorSpellCheckingEnabled];
+#endif
}
/**
@@ -551,7 +571,7 @@
// and suppress closing the sheet
if(sender == editSheetOkButton) {
if (maxTextLength > 0 && [[editTextView textStorage] length] > maxTextLength && ![[[editTextView textStorage] string] isEqualToString:[prefs objectForKey:SPNullValue]]) {
- [editTextView setSelectedRange:NSMakeRange((NSUInteger)maxTextLength, [[editTextView textStorage] length] - (NSUInteger)maxTextLength)];
+ [editTextView setSelectedRange:NSMakeRange(maxTextLength, [[editTextView textStorage] length] - maxTextLength)];
[editTextView scrollRangeToVisible:NSMakeRange([editTextView selectedRange].location,0)];
[SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Text is too long. Maximum text length is set to %llu.", @"Text is too long. Maximum text length is set to %llu."), maxTextLength]];
return;
@@ -580,7 +600,15 @@
if(callerInstance) {
id returnData = ( editSheetReturnCode && _isEditable ) ? (_isGeometry) ? [editTextView string] : sheetEditData : nil;
+
+#ifdef SP_REFACTOR /* patch */
+ if ( [callerInstance isKindOfClass:[SPCustomQuery class]] )
+ [(SPCustomQuery*)callerInstance processFieldEditorResult:returnData contextInfo:contextInfo];
+ else if ( [callerInstance isKindOfClass:[SPTableContent class]] )
+ [(SPTableContent*)callerInstance processFieldEditorResult:returnData contextInfo:contextInfo];
+#else
[callerInstance processFieldEditorResult:returnData contextInfo:contextInfo];
+#endif
}
}
diff --git a/Source/SPFieldMapperController.h b/Source/SPFieldMapperController.h
index 69e9fac4..860eef81 100644
--- a/Source/SPFieldMapperController.h
+++ b/Source/SPFieldMapperController.h
@@ -26,7 +26,11 @@
@class SPTextView, SPTableView, SPTablesList;
-@interface SPFieldMapperController : NSWindowController
+#ifndef SP_REFACTOR
+@interface SPFieldMapperController : NSWindowController
+#else
+@interface SPFieldMapperController : NSWindowController <NSTokenFieldCellDelegate>
+#endif
{
IBOutlet SPTableView *fieldMapperTableView;
IBOutlet id fieldMapperTableScrollView;
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index f6633172..ae76f8e2 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -94,11 +94,12 @@ static NSString *SPTableViewSqlColumnID = @"sql";
tablesListInstance = [theDelegate valueForKeyPath:@"tablesListInstance"];
databaseDataInstance = [tablesListInstance valueForKeyPath:@"databaseDataInstance"];
+#ifndef SP_REFACTOR /* init ivars */
if(![prefs objectForKey:SPLastImportIntoNewTableType])
[prefs setObject:@"Default" forKey:SPLastImportIntoNewTableType];
if(![prefs objectForKey:SPLastImportIntoNewTableEncoding])
[prefs setObject:@"Default" forKey:SPLastImportIntoNewTableEncoding];
-
+#endif
}
return self;
@@ -387,8 +388,10 @@ static NSString *SPTableViewSqlColumnID = @"sql";
{
// Only save selection if the user selected 'OK'
if ([sender tag]) {
+#ifndef SP_REFACTOR
[prefs setObject:[newTableInfoEnginePopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableType];
[prefs setObject:[newTableInfoEncodingPopup titleOfSelectedItem] forKey:SPLastImportIntoNewTableEncoding];
+#endif
}
[NSApp endSheet:[sender window] returnCode:[sender tag]];
@@ -453,13 +456,15 @@ static NSString *SPTableViewSqlColumnID = @"sql";
}
[createString appendString:@")"];
+#ifndef SP_REFACTOR
if(![[prefs objectForKey:SPLastImportIntoNewTableType] isEqualToString:@"Default"])
[createString appendFormat:@" ENGINE=%@", [prefs objectForKey:SPLastImportIntoNewTableType]];
if(![[prefs objectForKey:SPLastImportIntoNewTableEncoding] isEqualToString:@"Default"]) {
NSString *encodingName = [[prefs objectForKey:SPLastImportIntoNewTableEncoding] stringByMatching:@"\\((.*)\\)" capture:1L];
if (!encodingName) encodingName = @"utf8";
- [createString appendFormat:[NSString stringWithFormat:@" DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]]];
+ [createString appendString:[NSString stringWithFormat:@" DEFAULT CHARACTER SET %@", [encodingName backtickQuotedString]]];
}
+#endif
[mySQLConnection queryString:createString];
@@ -728,9 +733,11 @@ static NSString *SPTableViewSqlColumnID = @"sql";
}
[fieldMapperTableView reloadData];
+#ifndef SP_REFACTOR
// Remember last field alignment if not "custom order"
if([[alignByPopup selectedItem] tag] != 3)
[prefs setInteger:[[alignByPopup selectedItem] tag] forKey:SPCSVFieldImportMappingAlignment];
+#endif
}
/*
@@ -834,8 +841,8 @@ static NSString *SPTableViewSqlColumnID = @"sql";
columnCounter = 0;
for(id col in row) {
if(col && col != [NSNull null]) {
- if([col isKindOfClass:[NSString class]] && maxLengthOfSourceColumns[columnCounter] < (NSInteger)[col length]) {
- maxLengthOfSourceColumns[columnCounter] = [col length];
+ if([col isKindOfClass:[NSString class]] && maxLengthOfSourceColumns[columnCounter] < (NSInteger)[(NSString*)col length]) {
+ maxLengthOfSourceColumns[columnCounter] = [(NSString*)col length];
}
if(typeOfSourceColumns[columnCounter] == 1) {
if(![[[NSNumber numberWithLongLong:[col longLongValue]] stringValue] isEqualToString:col])
@@ -1034,7 +1041,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[newTableInfoEnginePopup addItemWithTitle:[engine objectForKey:@"Engine"]];
}
+#ifndef SP_REFACTOR
[newTableInfoEnginePopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableType]];
+#endif
// Populate the table encoding popup button with a default menu item
[newTableInfoEncodingPopup removeAllItems];
@@ -1065,7 +1074,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[newTableInfoEncodingPopup insertItemWithTitle:utf8MenuItemTitle atIndex:2];
}
+#ifndef SP_REFACTOR
[newTableInfoEncodingPopup selectItemWithTitle:[prefs objectForKey:SPLastImportIntoNewTableEncoding]];
+#endif
}
[NSApp beginSheet:newTableInfoWindow
@@ -1092,10 +1103,12 @@ static NSString *SPTableViewSqlColumnID = @"sql";
while([insertPullDownButton numberOfItems] > (([[self selectedImportMethod] isEqualToString:@"UPDATE"]) ? 6 : 5))
[insertPullDownButton removeItemAtIndex:[insertPullDownButton numberOfItems]-1];
+#ifndef SP_REFACTOR
// Add recent global value menu
if([prefs objectForKey:SPGlobalValueHistory] && [[prefs objectForKey:SPGlobalValueHistory] isKindOfClass:[NSArray class]] && [[prefs objectForKey:SPGlobalValueHistory] count])
for(id item in [prefs objectForKey:SPGlobalValueHistory])
[recentGlobalValueMenu addItemWithTitle:item action:@selector(insertRecentGlobalValue:) keyEquivalent:@""];
+#endif
// Add column placeholder
NSInteger i = 0;
@@ -1107,7 +1120,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
} else if ([item isSPNotLoaded]) {
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. <%@>", i, @"DEFAULT"]];
} else {
- if([item length] > 20)
+ if([(NSString*)item length] > 20)
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. %@…", i, [item substringToIndex:20]]];
else
[insertPullDownButton addItemWithTitle:[NSString stringWithFormat:@"%i. %@", i, item]];
@@ -1309,6 +1322,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
- (void)resizeWindowByHeightDelta:(NSInteger)delta
{
+#ifndef SP_REFACTOR /* resizeWindowByHeightDelta: */
NSUInteger tableMask = [fieldMapperTableScrollView autoresizingMask];
NSUInteger headerSwitchMask = [importFieldNamesHeaderSwitch autoresizingMask];
NSUInteger alignPopupMask = [alignByPopup autoresizingMask];
@@ -1362,7 +1376,7 @@ static NSString *SPTableViewSqlColumnID = @"sql";
[advancedUpdateView setAutoresizingMask:updateViewMask];
[advancedInsertView setAutoresizingMask:insertViewMask];
[advancedBox setAutoresizingMask:NSViewNotSizable|NSViewWidthSizable|NSViewMaxYMargin|NSViewMaxXMargin|NSViewMinXMargin];
-
+#endif
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
@@ -1535,11 +1549,13 @@ static NSString *SPTableViewSqlColumnID = @"sql";
NSInteger alignment = 0;
+#ifndef SP_REFACTOR
if([prefs integerForKey:SPCSVFieldImportMappingAlignment]
&& [prefs integerForKey:SPCSVFieldImportMappingAlignment] >= 0
&& [prefs integerForKey:SPCSVFieldImportMappingAlignment] < 4) {
alignment = [prefs integerForKey:SPCSVFieldImportMappingAlignment];
}
+#endif
// Set matching names only if csv file has an header
if(importFieldNamesHeader && alignment == 2)
@@ -1642,7 +1658,9 @@ static NSString *SPTableViewSqlColumnID = @"sql";
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
+#ifndef SP_REFACTOR
[aCell setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+#endif
}
- (void)tableView:(NSTableView*)aTableView didClickTableColumn:(NSTableColumn *)aTableColumn
@@ -1940,15 +1958,19 @@ static NSString *SPTableViewSqlColumnID = @"sql";
// Store anObject as recent global value if it's new
NSMutableArray *recents = [NSMutableArray array];
+#ifndef SP_REFACTOR
if([prefs objectForKey:SPGlobalValueHistory] && [[prefs objectForKey:SPGlobalValueHistory] isKindOfClass:[NSArray class]] && [[prefs objectForKey:SPGlobalValueHistory] count])
[recents setArray:[prefs objectForKey:SPGlobalValueHistory]];
+#endif
if([recents containsObject:anObject])
[recents removeObject:anObject];
[recents insertObject:anObject atIndex:0];
while([recents count] > 20)
[recents removeObjectAtIndex:[recents count]-1];
+#ifndef SP_REFACTOR
if([recents count])
[prefs setObject:recents forKey:SPGlobalValueHistory];
+#endif
// Re-init recent menu
[recentGlobalValueMenu compatibleRemoveAllItems];
diff --git a/Source/SPIndexesController.h b/Source/SPIndexesController.h
index 02dade6c..c56ff4eb 100644
--- a/Source/SPIndexesController.h
+++ b/Source/SPIndexesController.h
@@ -62,7 +62,9 @@
NSMutableArray *fields, *indexes, *indexedFields, *supportsLength, *requiresLength;
+#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
+#endif
MCPConnection *connection;
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index 12aa58e1..9c0c03a6 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -28,9 +28,11 @@
#import "SPServerSupport.h"
#import "SPTableContent.h"
#import "SPTableData.h"
-#import "SPTablesList.h"
#import <MCPKit/MCPKit.h>
+#import "SPDatabaseDocument.h"
+#import "SPTablesList.h"
#import "SPDatabaseViewController.h"
+#import "SPTableStructure.h"
// Constants
static const NSString *SPNewIndexIndexName = @"IndexName";
@@ -70,7 +72,9 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
indexes = [[NSMutableArray alloc] init];
indexedFields = [[NSMutableArray alloc] init];
+#ifndef SP_REFACTOR /* init ivars */
prefs = [NSUserDefaults standardUserDefaults];
+#endif
showAdvancedView = NO;
@@ -97,11 +101,15 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
*/
- (void)awakeFromNib
{
+#ifndef SP_REFACTOR /* patch */
// Set the index tables view's vertical gridlines if required
[indexesTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
// Set the strutcture and index view's font
BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
+#else
+ BOOL useMonospacedFont = NO;
+#endif
for (NSTableColumn *indexColumn in [indexesTableView tableColumns])
{
@@ -113,7 +121,9 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[[fieldColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
+#ifndef SP_REFACTOR /* patch */
[prefs addObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines options:NSKeyValueObservingOptionNew context:NULL];
+#endif
}
#pragma mark -
@@ -846,7 +856,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[errorDictionary setObject:NSLocalizedString(@"Unable to delete relation", @"error deleting relation message") forKey:@"title"];
[errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to delete the relation '%@'.\n\nMySQL said: %@", @"error deleting relation informative message"), constraintName, [connection getLastErrorMessage]] forKey:@"message"];
- [[tableStructure onMainThread] showErrorSheetWith:errorDictionary];
+ [(SPTableStructure*)[tableStructure onMainThread] showErrorSheetWith:errorDictionary];
}
}
@@ -865,7 +875,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[errorDictionary setObject:NSLocalizedString(@"Unable to delete index", @"error deleting index message") forKey:@"title"];
[errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to delete the index.\n\nMySQL said: %@", @"error deleting index informative message"), [connection getLastErrorMessage]] forKey:@"message"];
- [[tableStructure onMainThread] showErrorSheetWith:errorDictionary];
+ [(SPTableStructure*)[tableStructure onMainThread] showErrorSheetWith:errorDictionary];
}
else {
[tableData resetAllData];
@@ -895,7 +905,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
NSUInteger advancedViewMask = [indexAdvancedOptionsView autoresizingMask];
NSUInteger typeLabelMask = [indexTypeLabel autoresizingMask];
NSUInteger nameLabelMask = [indexNameLabel autoresizingMask];
- NSUInteger buttonBarMask = [anchoredButtonBar autoresizingMask];
+ NSUInteger buttonBarMask = [(NSView*)anchoredButtonBar autoresizingMask];
NSRect frame = [[self window] frame];
@@ -914,7 +924,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexAdvancedOptionsView setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexTypeLabel setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
[indexNameLabel setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
- [anchoredButtonBar setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
+ [(NSView*)anchoredButtonBar setAutoresizingMask:NSViewNotSizable | NSViewMinYMargin];
NSInteger newMinHeight = (windowMinHeigth - heightOffset + delta < windowMinHeigth) ? windowMinHeigth : windowMinHeigth - heightOffset + delta;
@@ -938,7 +948,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexAdvancedOptionsView setAutoresizingMask:advancedViewMask];
[indexTypeLabel setAutoresizingMask:typeLabelMask];
[indexNameLabel setAutoresizingMask:nameLabelMask];
- [anchoredButtonBar setAutoresizingMask:buttonBarMask];
+ [(NSView*)anchoredButtonBar setAutoresizingMask:buttonBarMask];
}
#pragma mark -
diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h
index 08393d4d..44118380 100644
--- a/Source/SPNarrowDownCompletion.h
+++ b/Source/SPNarrowDownCompletion.h
@@ -26,7 +26,11 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-@interface SPNarrowDownCompletion : NSWindow
+#ifndef SP_REFACTOR
+@interface SPNarrowDownCompletion : NSWindow
+#else
+@interface SPNarrowDownCompletion : NSWindow <NSTableViewDelegate, NSTableViewDataSource, NSTokenFieldCellDelegate>
+#endif
{
NSArray* suggestions;
NSMutableString* mutablePrefix;
@@ -70,7 +74,9 @@
NSMutableCharacterSet* textualInputCharacters;
+#ifndef SP_REFACTOR
NSUserDefaults *prefs;
+#endif
}
- (id)initWithItems:(NSArray*)someSuggestions alreadyTyped:(NSString*)aUserString staticPrefix:(NSString*)aStaticPrefix
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index b1101704..04627e2d 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -92,7 +92,7 @@
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
}
[self scrollRowToVisible:row];
- [[self delegate] insertAutocompletePlaceholder];
+ [(SPNarrowDownCompletion*)[self delegate] insertAutocompletePlaceholder];
return YES;
}
}
@@ -124,9 +124,15 @@
staticPrefix = nil;
suggestions = nil;
autocompletePlaceholderWasInserted = NO;
+#ifndef SP_REFACTOR
prefs = [NSUserDefaults standardUserDefaults];
+#endif
+#ifndef SP_REFACTOR
tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:SPCustomQueryEditorFont]];
+#else
+ tableFont = [NSFont userFixedPitchFontOfSize:10.0];
+#endif
[self setupInterface];
syncArrowImages = [[NSArray alloc] initWithObjects:
@@ -270,7 +276,7 @@
if(!dictMode) {
NSUInteger maxLength = 0;
for(id w in someSuggestions) {
- NSUInteger len = [[w objectForKey:@"display"] length];
+ NSUInteger len = [(NSString*)[w objectForKey:@"display"] length];
if(len>maxLength) maxLength = len;
}
NSMutableString *dummy = [NSMutableString string];
@@ -1054,12 +1060,14 @@
if(backtickMode && !triggerMode)
[theView performSelector:@selector(moveRight:)];
// If it's a function or procedure append () and if a argument list can be retieved insert them as snippets
+#ifndef SP_REFACTOR
else if([prefs boolForKey:SPCustomQueryFunctionCompletionInsertsArguments] && ([[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"func"] || [[[filtered objectAtIndex:[theTableView selectedRow]] objectForKey:@"image"] hasPrefix:@"proc"]) && ![aString hasSuffix:@")"]) {
NSString *functionArgumentSnippet = [NSString stringWithFormat:@"(%@)", [[SPQueryController sharedQueryController] argumentSnippetForFunction:aString]];
[theView insertAsSnippet:functionArgumentSnippet atRange:[theView selectedRange]];
if([functionArgumentSnippet length] == 2)
[theView performSelector:@selector(moveLeft:)];
}
+#endif
}
- (void)completeAndInsertSnippet
@@ -1079,7 +1087,7 @@
NSString* candidateMatch = [selectedItem objectForKey:@"match"] ?: [selectedItem objectForKey:@"display"];
if([selectedItem objectForKey:@"isRef"]
&& ([[NSApp currentEvent] modifierFlags] & (NSShiftKeyMask))
- && [[selectedItem objectForKey:@"path"] length] && theAliasName == nil) {
+ && [(NSString*)[selectedItem objectForKey:@"path"] length] && theAliasName == nil) {
NSString *path = [[[selectedItem objectForKey:@"path"] componentsSeparatedByString:SPUniqueSchemaDelimiter] componentsJoinedByPeriodAndBacktickQuotedAndIgnoreFirst];
// Check if path's db name is the current selected db name
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h
index cdac2706..20b3a796 100644
--- a/Source/SPNavigatorController.h
+++ b/Source/SPNavigatorController.h
@@ -26,6 +26,7 @@
@interface SPNavigatorController : NSWindowController
{
+#ifndef SP_REFACTOR /* ivars */
IBOutlet id outlineSchema2;
IBOutlet id navigatorWindow;
IBOutlet id infoTable;
@@ -36,7 +37,7 @@
IBOutlet id schema12SplitView;
NSUserDefaults *prefs;
-
+#endif
NSMutableDictionary *schemaData;
NSMutableDictionary *schemaDataFiltered;
NSMutableDictionary *allSchemaKeys;
@@ -44,7 +45,7 @@
NSMutableArray *updatingConnections;
NSMutableDictionary *expandStatus2;
NSMutableDictionary *cachedSortedKeys;
-
+#ifndef SP_REFACTOR /* ivars */
NSString *selectedKey2;
NSRect selectionViewPort2;
BOOL ignoreUpdate;
@@ -60,11 +61,12 @@
NSImage *fieldIcon;
Class NSDictionaryClass;
-
+#endif
}
+ (SPNavigatorController *)sharedNavigatorController;
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)outlineViewAction:(id)sender;
- (IBAction)reloadAllStructures:(id)sender;
- (IBAction)filterTree:(id)sender;
@@ -74,11 +76,13 @@
- (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(NSInteger)type;
- (void)updateNavigator:(NSNotification *)aNotification;
+#endif
- (NSDictionary *)dbStructureForConnection:(NSString*)connectionID;
- (NSArray *)allSchemaKeysForConnection:(NSString*)connectionID;
- (NSArray *)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID ignoreFields:(BOOL)ignoreFields;
+#ifndef SP_REFACTOR /* method decls */
- (BOOL)isUpdatingConnection:(NSString*)connectionID;
- (BOOL)isUpdating;
@@ -91,5 +95,6 @@
- (BOOL)schemaPathExistsForConnection:(NSString*)connectionID andDatabase:(NSString*)dbname;
- (void)removeDatabase:(NSString*)db_id forConnectionID:(NSString*)connectionID;
+#endif
@end
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 36dddf39..be24948b 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -23,6 +23,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPNavigatorController.h"
+#ifndef SP_REFACTOR /* headers */
#import "RegexKitLite.h"
#import "SPNavigatorOutlineView.h"
#import "ImageAndTextCell.h"
@@ -34,18 +35,23 @@
#import "SPDatabaseViewController.h"
#import <objc/message.h>
+#endif
static SPNavigatorController *sharedNavigatorController = nil;
+#ifndef SP_REFACTOR /* pasteboard types */
#define DragFromNavigatorPboardType @"SPDragFromNavigatorPboardType"
#define DragTableDataFromNavigatorPboardType @"SPDragTableDataFromNavigatorPboardType"
+#endif
@implementation SPNavigatorController
+#ifndef SP_REFACTOR /* unused sort func */
static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* context)
{
return (NSComparisonResult)objc_msgSend(s1, @selector(localizedCompare:), s2);
}
+#endif
/**
@@ -80,13 +86,14 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
cachedSortedKeys = [[NSMutableDictionary alloc] init];
infoArray = [[NSMutableArray alloc] init];
updatingConnections = [[NSMutableArray alloc] init];
+#ifndef SP_REFACTOR
selectedKey2 = @"";
ignoreUpdate = NO;
isFiltered = NO;
isFiltering = NO;
[syncButton setState:NSOffState];
NSDictionaryClass = [NSDictionary class];
-
+#endif
}
return self;
@@ -103,6 +110,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
if(updatingConnections) [updatingConnections release];
if(expandStatus2) [expandStatus2 release];
if(cachedSortedKeys) [cachedSortedKeys release];
+#ifndef SP_REFACTOR /* dealloc ivars */
[connectionIcon release];
[databaseIcon release];
[tableIcon release];
@@ -110,6 +118,10 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
[procedureIcon release];
[functionIcon release];
[fieldIcon release];
+#endif
+#ifdef SP_REFACTOR /* patch */
+ [super dealloc];
+#endif
}
/**
* The following base protocol methods are implemented to ensure the singleton status of this class.
@@ -125,6 +137,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
- (void)release { }
+#ifndef SP_REFACTOR
/**
* Set the window's auto save name and initialise display
*/
@@ -487,6 +500,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
[[schemaData objectForKey:connectionID] removeObjectForKey:db_id];
[outlineSchema2 reloadData];
}
+#endif
- (NSDictionary *)dbStructureForConnection:(NSString*)connectionID
{
@@ -550,6 +564,7 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
return [NSArray arrayWithObjects:[NSNumber numberWithInt:0], @"", nil];
}
+#ifndef SP_REFACTOR
- (BOOL)isUpdatingConnection:(NSString*)connectionID
{
@@ -1253,4 +1268,5 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
}
return @"";
}
+#endif
@end
diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h
index 6f1d835d..c80da762 100644
--- a/Source/SPQueryController.h
+++ b/Source/SPQueryController.h
@@ -53,7 +53,9 @@
NSArray *completionFunctionList;
NSDictionary *functionArgumentSnippets;
+#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
+#endif
NSDateFormatter *dateFormatter;
pthread_mutex_t consoleLock;
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index 346be3d6..475b96bc 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -32,7 +32,6 @@
#define MESSAGE_TRUNCATE_CHARACTER_LENGTH 256
// Table view column identifier constants
-static NSString *SPTableViewMessageColumnID = @"message";
static NSString *SPTableViewDateColumnID = @"messageDate";
static NSString *SPTableViewConnectionColumnID = @"messageConnection";
@@ -158,20 +157,41 @@ static SPQueryController *sharedQueryController = nil;
*/
- (void)awakeFromNib
{
+#ifndef SP_REFACTOR /* init ivars */
prefs = [NSUserDefaults standardUserDefaults];
+#endif
[self setWindowFrameAutosaveName:@"QueryConsole"];
// Show/hide table columns
- [[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] setHidden:![prefs boolForKey:SPConsoleShowTimestamps]];
- [[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] setHidden:![prefs boolForKey:SPConsoleShowConnections]];
-
+ [[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
+ ];
+
+#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];
@@ -181,11 +201,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])
{
@@ -540,16 +566,20 @@ 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
@@ -652,9 +682,11 @@ static SPQueryController *sharedQueryController = nil;
[[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];
+#endif
}
- (void)addFavorite:(NSDictionary *)favorite forFileURL:(NSURL *)fileURL
@@ -665,7 +697,11 @@ static SPQueryController *sharedQueryController = nil;
- (void)addHistory:(NSString *)history forFileURL:(NSURL *)fileURL
{
- NSInteger maxHistoryItems = [[prefs objectForKey:SPCustomQueryMaxHistoryItems] integerValue];
+#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]]) {
@@ -675,7 +711,7 @@ static SPQueryController *sharedQueryController = nil;
[uniquifier addItemsWithTitles:[historyContainer objectForKey:[fileURL absoluteString]]];
[uniquifier insertItemWithTitle:history atIndex:0];
- while ( [uniquifier numberOfItems] > maxHistoryItems )
+ while ( (NSUInteger)[uniquifier numberOfItems] > maxHistoryItems )
[uniquifier removeItemAtIndex:[uniquifier numberOfItems]-1];
[self replaceHistoryByArray:[uniquifier itemTitles] forFileURL:fileURL];
@@ -685,17 +721,19 @@ 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];
[uniquifier addItemsWithTitles:[prefs objectForKey:SPQueryHistory]];
[uniquifier insertItemWithTitle:history atIndex:0];
- while ( [uniquifier numberOfItems] > maxHistoryItems )
+ while ( (NSUInteger)[uniquifier numberOfItems] > maxHistoryItems )
[uniquifier removeItemAtIndex:[uniquifier numberOfItems]-1];
[prefs setObject:[uniquifier itemTitles] forKey:SPQueryHistory];
[uniquifier release];
+#endif
}
}
@@ -773,6 +811,7 @@ static SPQueryController *sharedQueryController = nil;
[result addObject:fav];
}
+#ifndef SP_REFACTOR
if(includeGlobals && [prefs objectForKey:SPQueryFavorites]) {
for(id fav in [prefs objectForKey:SPQueryFavorites]) {
if([fav objectForKey:@"tabtrigger"] && [[fav objectForKey:@"tabtrigger"] isEqualToString:tabTrigger]) {
@@ -781,6 +820,7 @@ static SPQueryController *sharedQueryController = nil;
}
}
}
+#endif
return [result autorelease];
}
diff --git a/Source/SPQueryFavoriteManager.h b/Source/SPQueryFavoriteManager.h
index 6698ae61..0ebdc837 100644
--- a/Source/SPQueryFavoriteManager.h
+++ b/Source/SPQueryFavoriteManager.h
@@ -31,9 +31,15 @@
@end
-@interface SPQueryFavoriteManager : NSWindowController
+#ifndef SP_REFACTOR
+@interface SPQueryFavoriteManager : NSWindowController
+#else
+@interface SPQueryFavoriteManager : NSWindowController <NSOpenSavePanelDelegate>
+#endif
{
+#ifndef SP_REFACTOR /* ivars */
NSUserDefaults *prefs;
+#endif
NSURL *delegatesFileURL;
SPDatabaseDocument *tableDocumentInstance;
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index 9316c5ec..7fe5797f 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -30,7 +30,9 @@
#import "SPConnectionController.h"
#import "RegexKitLite.h"
#import "SPTextView.h"
+#ifndef SP_REFACTOR
#import <BWToolkitFramework/BWAnchoredButtonBar.h>
+#endif
#define SP_MULTIPLE_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[multiple selection]", @"[multiple selection]")
#define SP_NO_SELECTION_PLACEHOLDER_STRING NSLocalizedString(@"[no selection]", @"[no selection]")
@@ -50,7 +52,9 @@
{
if ((self = [super initWithWindowNibName:@"QueryFavoriteManager"])) {
+#ifndef SP_REFACTOR
prefs = [NSUserDefaults standardUserDefaults];
+#endif
favorites = [[NSMutableArray alloc] init];
@@ -95,12 +99,14 @@
@"", @"query",
nil]];
+#ifndef SP_REFACTOR
// Build data source for global queryFavorites (as mutable copy! otherwise each
// change will be stored in the prefs at once)
if([prefs objectForKey:SPQueryFavorites]) {
for(id fav in [prefs objectForKey:SPQueryFavorites])
[favorites addObject:[[fav mutableCopy] autorelease]];
}
+#endif
[favorites addObject:[NSDictionary dictionaryWithObjectsAndKeys:
[[[delegatesFileURL absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] lastPathComponent], @"name",
@@ -131,8 +137,10 @@
// Set Remove button state
[removeButton setEnabled:([favoritesTableView numberOfSelectedRows] > 0)];
+#ifndef SP_REFACTOR /* split view delegate */
// Set the button bar delegate
[splitViewButtonBar setSplitViewDelegate:self];
+#endif
}
#pragma mark -
@@ -297,7 +305,9 @@
[panel setCanSelectHiddenExtension:YES];
[panel setCanCreateDirectories:YES];
+#ifndef SP_REFACTOR
[panel setAccessoryView:[SPEncodingPopupAccessory encodingAccessory:[prefs integerForKey:SPLastSQLFileEncoding] includeDefaultEntry:NO encodingPopUp:&encodingPopUp]];
+#endif
[encodingPopUp setEnabled:YES];
@@ -379,8 +389,10 @@
[[SPQueryController sharedQueryController] replaceFavoritesByArray:
[self queryFavoritesForFileURL:delegatesFileURL] forFileURL:delegatesFileURL];
+#ifndef SP_REFACTOR
// Update global preferences' list
[prefs setObject:[self queryFavoritesForFileURL:nil] forKey:SPQueryFavorites];
+#endif
// Inform all opened documents to update the query favorites list
for(id doc in [[NSApp delegate] orderedDocuments])
@@ -756,7 +768,7 @@
mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
@@ -784,7 +796,7 @@
[favoritesTableView reloadData];
[spf release];
} else {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while reading data file", @"error while reading data file")]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
@@ -810,8 +822,10 @@
if (returnCode == NSOKButton) {
NSError *error = nil;
+#ifndef SP_REFACTOR
[prefs setInteger:[[encodingPopUp selectedItem] tag] forKey:SPLastSQLFileEncoding];
[prefs synchronize];
+#endif
[[favoriteQueryTextView string] writeToFile:[panel filename] atomically:YES encoding:[[encodingPopUp selectedItem] tag] error:&error];
@@ -846,7 +860,7 @@
errorDescription:&err];
if(err != nil) {
- NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting query favorite data", @"error while converting query favorite data")]
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithString:NSLocalizedString(@"Error while converting query favorite data", @"error while converting query favorite data")]
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
otherButton:nil
diff --git a/Source/SPSQLParser.m b/Source/SPSQLParser.m
index 6485fc85..6da67396 100644
--- a/Source/SPSQLParser.m
+++ b/Source/SPSQLParser.m
@@ -280,12 +280,14 @@ TO_BUFFER_STATE to_scan_string (const char *);
}
}
- if ([carriageReturnPositions count]) {
+ // If any CRs were found, iterate over them backwards, converting to LFs by replacing or subtracting as appropriate
+ NSUInteger carriageReturnCount = [carriageReturnPositions count];
+ if (carriageReturnCount) {
NSMutableString *normalisedString = [NSMutableString stringWithString:queryString];
BOOL isCRLF;
NSUInteger CRLocation;
- for (NSNumber *position in carriageReturnPositions) {
- CRLocation = [position unsignedIntegerValue];
+ while ( carriageReturnCount-- ) {
+ CRLocation = [[carriageReturnPositions objectAtIndex:carriageReturnCount] unsignedIntegerValue];
// Check whether it's a CRLF or just a CR
isCRLF = NO;
@@ -778,7 +780,7 @@ TO_BUFFER_STATE to_scan_string (const char *);
if (delimiter) [delimiter release];
delimiter = [[NSString alloc] initWithString:[delimiterCommandParts objectAtIndex:2]];
delimiterLengthMinusOne = [delimiter length] - 1;
- parsedToPosition = currentStringIndex + [[delimiterCommandParts objectAtIndex:1] length];
+ parsedToPosition = currentStringIndex + [(NSString*)[delimiterCommandParts objectAtIndex:1] length];
// Drop back to standard non-delimiter mode if the delimiter has ended
if ([delimiter isEqualToString:[NSString stringWithFormat:@"%C", character]]) {
diff --git a/Source/SPServerSupport.m b/Source/SPServerSupport.m
index 1aebc0d4..15c3555f 100644
--- a/Source/SPServerSupport.m
+++ b/Source/SPServerSupport.m
@@ -214,7 +214,7 @@
NSString *varName = [NSString stringWithUTF8String:ivar_getName(vars[j])];
if ([varName hasPrefix:@"supports"]) {
- [description appendFormat:@"\t%@ = %@\n", varName, ((BOOL)object_getIvar(self, vars[j])) ? @"YES" : @"NO"];
+ [description appendFormat:@"\t%@ = %@\n", varName, (object_getIvar(self, vars[j])) ? @"YES" : @"NO"];
}
}
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h
index 72967780..a45fbe0b 100644
--- a/Source/SPStringAdditions.h
+++ b/Source/SPStringAdditions.h
@@ -77,7 +77,9 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS
- (CGFloat)levenshteinDistanceWithWord:(NSString *)stringB;
+#ifndef SP_REFACTOR /* run self as bash commands */
- (NSString *)runBashCommandWithEnvironment:(NSDictionary*)shellEnvironment atCurrentDirectoryPath:(NSString*)path callerInstance:(id)caller contextInfo:(NSDictionary*)contextInfo error:(NSError**)theError;
- (NSString *)runBashCommandWithEnvironment:(NSDictionary*)shellEnvironment atCurrentDirectoryPath:(NSString*)path error:(NSError**)theError;
+#endif
@end
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index 79546f9a..31dbbfc6 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -452,6 +452,7 @@
}
+#ifndef SP_REFACTOR /* run self as bash commands */
/**
* Run self as BASH command(s) and return the result.
* This task can be interrupted by pressing ⌘.
@@ -739,6 +740,7 @@
{
return [self runBashCommandWithEnvironment:shellEnvironment atCurrentDirectoryPath:path callerInstance:nil contextInfo:nil error:theError];
}
+#endif
/**
* Returns the minimum of a, b and c.
diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h
index 6c0f2ab7..2b125acd 100644
--- a/Source/SPTableContent.h
+++ b/Source/SPTableContent.h
@@ -29,11 +29,17 @@
@class SPDatabaseDocument, SPCopyTable, SPTextAndLinkCell, SPHistoryController, SPTableInfo, SPDataStorage, SPTextView, SPFieldEditorController;
-@interface SPTableContent : NSObject
+@class SPTableData, SPDatabaseDocument, SPTablesList;
+
+#ifndef SP_REFACTOR
+@interface SPTableContent : NSObject
+#else
+@interface SPTableContent : NSObject <NSTableViewDelegate, NSTableViewDataSource>
+#endif
{
IBOutlet SPDatabaseDocument *tableDocumentInstance;
IBOutlet id tablesListInstance;
- IBOutlet id tableDataInstance;
+ IBOutlet SPTableData* tableDataInstance;
IBOutlet id tableSourceInstance;
IBOutlet SPTableInfo *tableInfoInstance;
@@ -241,4 +247,10 @@
- (void)updateFilterTableClause:(id)currentValue;
- (NSString*)escapeFilterTableDefaultOperator:(NSString*)anOperator;
+#ifdef SP_REFACTOR /* glue */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)doc;
+- (void)setTableListInstance:(SPTablesList*)list;
+- (void)setConnection:(MCPConnection *)theConnection;
+#endif
+
@end
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 9cf2e72f..c9b8c145 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -49,6 +49,7 @@
#import "SPDatabaseViewController.h"
#import "SPAppController.h"
#import "SPBundleHTMLOutputController.h"
+#import "SPCustomQuery.h"
@interface SPTableContent (Private)
- (BOOL)cancelRowEditing;
@@ -157,8 +158,10 @@
if (_mainNibLoaded) return;
_mainNibLoaded = YES;
+#ifndef SP_REFACTOR /* ui manipulation */
// Set the table content view's vertical gridlines if required
[tableContentView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+#endif
// Load the pagination view, keeping references to the top-level objects for later release
NSArray *paginationViewTopLevelObjects = nil;
@@ -186,7 +189,11 @@
[filterTableDistinctMenuItem setState:(filterTableDistinct) ? NSOnState : NSOffState];
[filterTableNegateCheckbox setState:(filterTableNegate) ? NSOnState : NSOffState];
[filterTableLiveSearchCheckbox setState:NSOffState];
+#ifndef SP_REFACTOR /* patch */
filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:[prefs objectForKey:SPFilterTableDefaultOperator]] retain];
+#else
+ filterTableDefaultOperator = [[self escapeFilterTableDefaultOperator:nil] retain];
+#endif
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -230,7 +237,11 @@
}
// Post a notification that a query will be performed
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#endif
// Set up the table details for the new table, and trigger an interface update
NSDictionary *tableDetails = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -252,7 +263,7 @@
// Scroll the viewport to the saved location
selectionViewportToRestore.size = [tableContentView visibleRect].size;
- [[tableContentView onMainThread] scrollRectToVisible:selectionViewportToRestore];
+ [(SPCopyTable*)[tableContentView onMainThread] scrollRectToVisible:selectionViewportToRestore];
}
// Restore selection indexes if appropriate
@@ -270,7 +281,11 @@
[[tableContentView onMainThread] setNeedsDisplay:YES];
// Post the notification that the query is finished
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
// Clear any details to restore now that they have been restored
[self clearDetailsToRestore];
@@ -285,11 +300,19 @@
{
NSString *newTableName;
NSInteger i;
- NSNumber *colWidth, *sortColumnNumberToRestore = nil;
+ NSNumber
+#ifndef SP_REFACTOR
+ *colWidth,
+#endif
+ *sortColumnNumberToRestore = nil;
NSArray *columnNames;
NSDictionary *columnDefinition;
NSTableColumn *theCol, *filterCol;
- BOOL enableInteraction = ![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableContent] || ![tableDocumentInstance isWorking];
+ BOOL enableInteraction =
+#ifndef SP_REFACTOR /* checking toolbar state */
+ ![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableContent] ||
+#endif
+ ![tableDocumentInstance isWorking];
if (!tableDetails) {
@@ -443,7 +466,11 @@
}
NSString *nullValue = [prefs objectForKey:SPNullValue];
+#ifndef SP_REFACTOR /* get font from prefs */
NSFont *tableFont = [NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPGlobalResultTableFont]];
+#else
+ NSFont *tableFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+#endif
[tableContentView setRowHeight:2.0f+NSSizeToCGSize([[NSString stringWithString:@"{ǞṶḹÜ∑zgyf"] sizeWithAttributes:[NSDictionary dictionaryWithObject:tableFont forKey:NSFontAttributeName]]).height];
// Add the new columns to the table and filterTable
@@ -530,11 +557,13 @@
// Assign the data cell
[theCol setDataCell:dataCell];
+#ifndef SP_REFACTOR /* prefs access */
// Set the width of this column to saved value if exists
colWidth = [[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance tableName]] objectForKey:[columnDefinition objectForKey:@"name"]];
if ( colWidth ) {
[theCol setWidth:[colWidth floatValue]];
}
+#endif
// Set the column to be reselected for sorting if appropriate
if (sortColumnToRestore && [sortColumnToRestore isEqualToString:[columnDefinition objectForKey:@"name"]])
@@ -610,7 +639,8 @@
}
// Restore page number if limiting is set
- if ([prefs boolForKey:SPLimitResults]) contentPage = pageToRestore;
+ if ([prefs boolForKey:SPLimitResults])
+ contentPage = pageToRestore;
// Restore first responder
[[tableDocumentInstance parentWindow] makeFirstResponder:currentFirstResponder];
@@ -667,7 +697,11 @@
[countText setStringValue:NSLocalizedString(@"Loading table data...", @"Loading table data string")];
// Notify any listeners that a query has started
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#endif
// Start construction of the query string
queryString = [NSMutableString stringWithFormat:@"SELECT %@%@ FROM %@", (activeFilter == 1 && [self tableFilterString] && filterTableDistinct) ? @"DISTINCT " : @"", [self fieldListForQuery], [selectedTable backtickQuotedString]];
@@ -689,13 +723,13 @@
}
// Check to see if a limit needs to be applied
- if ([prefs boolForKey:SPLimitResults]) {
-
+ if ([prefs boolForKey:SPLimitResults])
+ {
// Ensure the page supplied is within the appropriate limits
if (contentPage <= 0)
contentPage = 1;
else if (contentPage > 1 && (NSInteger)(contentPage - 1) * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows)
- contentPage = ceilf((CGFloat)maxNumRows / [prefs floatForKey:SPLimitResultsValue]);
+ contentPage = ceil((CGFloat)maxNumRows / [prefs floatForKey:SPLimitResultsValue]);
// If the result set is from a late page, take a copy of the string to allow resetting limit
// if no results are found
@@ -756,9 +790,7 @@
// End cancellation ability
[tableDocumentInstance disableTaskCancellation];
- if ([prefs boolForKey:SPLimitResults]
- && (contentPage > 1
- || (NSInteger)tableRowsCount == [prefs integerForKey:SPLimitResultsValue]))
+ if ([prefs boolForKey:SPLimitResults] && (contentPage > 1 || (NSInteger)tableRowsCount == [prefs integerForKey:SPLimitResultsValue]))
{
isLimited = YES;
} else {
@@ -780,7 +812,11 @@
// Notify listenters that the query has finished
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
if ([mySQLConnection queryErrored] && ![mySQLConnection queryCancelled]) {
if(activeFilter == 0) {
@@ -822,8 +858,14 @@
NSAutoreleasePool *dataLoadingPool;
NSProgressIndicator *dataLoadingIndicator = [tableDocumentInstance valueForKey:@"queryProgressBar"];
- BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:SPLoadBlobsAsNeeded];
-
+ BOOL prefsLoadBlobsAsNeeded =
+#ifndef SP_REFACTOR
+ [prefs boolForKey:SPLoadBlobsAsNeeded]
+#else
+ NO
+#endif
+ ;
+
// Build up an array of which columns are blobs for faster iteration
for ( i = 0; i < dataColumnsCount ; i++ ) {
columnBlobStatuses[i] = [tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]];
@@ -1461,19 +1503,19 @@
paginationViewFrame.size.height = paginationViewHeight;
[paginationButton setState:NSOnState];
[paginationButton setImage:[NSImage imageNamed:@"button_action"]];
- [[tableDocumentInstance parentWindow] makeFirstResponder:paginationPageField];
+ [[paginationPageField window] makeFirstResponder:paginationPageField];
} else {
if (paginationViewFrame.size.height == 0) return;
paginationViewFrame.size.height = 0;
[paginationButton setState:NSOffState];
[paginationButton setImage:[NSImage imageNamed:@"button_pagination"]];
- if ([[tableDocumentInstance parentWindow] firstResponder] == paginationPageField
- || ([[[tableDocumentInstance parentWindow] firstResponder] respondsToSelector:@selector(superview)]
- && [(id)[[tableDocumentInstance parentWindow] firstResponder] superview]
- && [[(id)[[tableDocumentInstance parentWindow] firstResponder] superview] respondsToSelector:@selector(superview)]
- && [[(id)[[tableDocumentInstance parentWindow] firstResponder] superview] superview] == paginationPageField))
+ if ([[paginationPageField window] firstResponder] == paginationPageField
+ || ([[[paginationPageField window] firstResponder] respondsToSelector:@selector(superview)]
+ && [(id)[[paginationPageField window] firstResponder] superview]
+ && [[(id)[[paginationPageField window] firstResponder] superview] respondsToSelector:@selector(superview)]
+ && [[(id)[[paginationPageField window] firstResponder] superview] superview] == paginationPageField))
{
- [[tableDocumentInstance parentWindow] makeFirstResponder:nil];
+ [[paginationPageField window] makeFirstResponder:nil];
}
}
@@ -1667,6 +1709,7 @@
//copy row
tempRow = [tableValues rowContentsAtIndex:[tableContentView selectedRow]];
+#ifndef SP_REFACTOR
//if we don't show blobs, read data for this duplicate column from db
if ([prefs boolForKey:SPLoadBlobsAsNeeded]) {
// Abort if there are no indices on this table - argumentForRow will display an error.
@@ -1677,6 +1720,7 @@
queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@", [selectedTable backtickQuotedString], [self argumentForRow:[tableContentView selectedRow]]]];
dbDataRow = [queryResult fetchRowAsArray];
}
+#endif
//set autoincrement fields to NULL
queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [selectedTable backtickQuotedString]]];
@@ -1686,7 +1730,13 @@
row = [queryResult fetchRowAsDictionary];
if ( [[row objectForKey:@"Extra"] isEqualToString:@"auto_increment"] ) {
[tempRow replaceObjectAtIndex:i withObject:[NSNull null]];
- } else if ( [tableDataInstance columnIsBlobOrText:[row objectForKey:@"Field"]] && [prefs boolForKey:SPLoadBlobsAsNeeded] && dbDataRow) {
+ } else if ( [tableDataInstance columnIsBlobOrText:[row objectForKey:@"Field"]] &&
+#ifndef SP_REFACTOR
+ [prefs boolForKey:SPLoadBlobsAsNeeded]
+#else
+ NO
+#endif
+ && dbDataRow) {
[tempRow replaceObjectAtIndex:i withObject:[dbDataRow objectAtIndex:i]];
}
}
@@ -1748,7 +1798,9 @@
// If table has PRIMARY KEY ask for resetting the auto increment after deletion if given
if(![[tableDataInstance statusValueForKey:@"Auto_increment"] isKindOfClass:[NSNull class]]) {
[alert setShowsSuppressionButton:YES];
+#ifndef SP_REFACTOR
[[alert suppressionButton] setState:([prefs boolForKey:SPResetAutoIncrementAfterDeletionOfAllRows]) ? NSOnState : NSOffState];
+#endif
[[[alert suppressionButton] cell] setControlSize:NSSmallControlSize];
[[[alert suppressionButton] cell] setFont:[NSFont systemFontOfSize:11]];
[[alert suppressionButton] setTitle:NSLocalizedString(@"Reset AUTO_INCREMENT after deletion?", @"reset auto_increment after deletion of all rows message")];
@@ -1778,13 +1830,18 @@
NSString *wherePart;
NSInteger i, errors;
BOOL consoleUpdateStatus;
- BOOL reloadAfterRemovingRow = [prefs boolForKey:SPReloadAfterRemovingRow];
-
+ BOOL reloadAfterRemovingRow =
+#ifndef SP_REFACTOR
+ [prefs boolForKey:SPReloadAfterRemovingRow]
+#else
+ NO
+#endif
+ ;
// Order out current sheet to suppress overlapping of sheets
[[alert window] orderOut:nil];
- if ([contextInfo isEqualToString:@"removeallrows"]) {
- if (returnCode == NSAlertDefaultReturn) {
+ if ( [(NSString*)contextInfo isEqualToString:@"removeallrows"] ) {
+ if ( returnCode == NSAlertDefaultReturn ) {
// Check if the user is currently editing a row, and revert to ensure a somewhat
// consistent state if deletion fails.
@@ -1800,9 +1857,13 @@
// Reset auto increment if suppression button was ticked
if([[alert suppressionButton] state] == NSOnState) {
[tableSourceInstance setAutoIncrementTo:@"1"];
+#ifndef SP_REFACTOR
[prefs setBool:YES forKey:SPResetAutoIncrementAfterDeletionOfAllRows];
+#endif
} else {
+#ifndef SP_REFACTOR
[prefs setBool:NO forKey:SPResetAutoIncrementAfterDeletionOfAllRows];
+#endif
}
[self reloadTable:self];
@@ -1816,9 +1877,8 @@
afterDelay:0.3];
}
}
- }
- else if ([contextInfo isEqualToString:@"removerow"]) {
- if (returnCode == NSAlertDefaultReturn) {
+ } else if ( [(NSString*)contextInfo isEqualToString:@"removerow"] ) {
+ if ( returnCode == NSAlertDefaultReturn ) {
[selectedRows addIndexes:[tableContentView selectedRowIndexes]];
//check if the user is currently editing a row
@@ -2343,6 +2403,7 @@
}
}
+#ifndef SP_REFACTOR /* content filters */
// Load global user-defined content filters
if([prefs objectForKey:SPContentFilters]
&& [contentFilters objectForKey:compareType]
@@ -2350,6 +2411,7 @@
{
[[contentFilters objectForKey:compareType] addObjectsFromArray:[[prefs objectForKey:SPContentFilters] objectForKey:compareType]];
}
+#endif
// Load doc-based user-defined content filters
if([[SPQueryController sharedQueryController] contentFilterForFileURL:[tableDocumentInstance fileURL]]) {
@@ -2417,7 +2479,9 @@
[compareField selectItemWithTag:lastSelectedContentFilterIndex];
// init query favorites controller
+#ifndef SP_REFACTOR
[prefs synchronize];
+#endif
if(contentFilterManager) [contentFilterManager release];
contentFilterManager = [[SPContentFilterManager alloc] initWithDelegate:self forFilterType:compareType];
@@ -2516,7 +2580,11 @@
[rowValuesToSave addObject:fieldValue];
}
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#endif
NSMutableString *queryString;
// Use INSERT syntax when creating new rows
@@ -2542,16 +2610,22 @@
// Run the query
[mySQLConnection queryString:queryString];
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
// If no rows have been changed, show error if appropriate.
if ( ![mySQLConnection affectedRows] && ![mySQLConnection queryErrored] ) {
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
SPBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db"));
} else {
NSBeep();
}
+#endif
// If creating a new row, remove the row; otherwise revert the row contents
if (isEditingNewRow) {
@@ -2574,30 +2648,35 @@
// New row created successfully
if ( isEditingNewRow ) {
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPReloadAfterAddingRow] ) {
[[tableDocumentInstance parentWindow] endEditingFor:nil];
previousTableRowsCount = tableRowsCount;
[self loadTableValues];
} else {
-
+#endif
// Set the insertId for fields with auto_increment
for ( i = 0; i < [dataColumns count] ; i++ ) {
if ([[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"autoincrement"] integerValue]) {
[tableValues replaceObjectInRow:currentlyEditingRow column:i withObject:[[NSNumber numberWithUnsignedLongLong:[mySQLConnection insertId]] description]];
}
}
+#ifndef SP_REFACTOR
}
+#endif
isEditingNewRow = NO;
// Existing row edited successfully
} else {
// Reload table if set to - otherwise no action required.
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPReloadAfterEditingRow] ) {
[[tableDocumentInstance parentWindow] endEditingFor:nil];
previousTableRowsCount = tableRowsCount;
[self loadTableValues];
}
+#endif
}
currentlyEditingRow = -1;
@@ -2622,7 +2701,7 @@
// Edit row selected - reselect the row, and start editing.
if ( returnCode == NSAlertDefaultReturn ) {
[tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
- [tableContentView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[[tableDocumentInstance parentWindow] windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
+ [tableContentView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[[tableContentView window] windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
// Discard changes selected
} else {
@@ -2647,9 +2726,9 @@
// Save any edits which have been made but not saved to the table yet;
// but not for any NSSearchFields which could cause a crash for undo, redo.
- if([[[tableDocumentInstance parentWindow] firstResponder] respondsToSelector:@selector(delegate)]
- && ![[(id)[[tableDocumentInstance parentWindow] firstResponder] delegate] isKindOfClass:[NSSearchField class]])
- [[tableDocumentInstance parentWindow] endEditingFor:nil];
+ if([[[tableContentView window] firstResponder] respondsToSelector:@selector(delegate)]
+ && ![[(id)[[tableContentView window] firstResponder] delegate] isKindOfClass:[NSSearchField class]])
+ [[tableContentView window] endEditingFor:nil];
// If no rows are currently being edited, or a save is in progress, return success at once.
if (!isEditingRow || isSavingRow) return YES;
@@ -2674,7 +2753,7 @@
- (BOOL)cancelRowEditing
{
- [[tableDocumentInstance parentWindow] makeFirstResponder:tableContentView];
+ [[tableContentView window] makeFirstResponder:tableContentView];
if (!isEditingRow) return NO;
if (isEditingNewRow) {
@@ -2688,7 +2767,7 @@
isEditingRow = NO;
currentlyEditingRow = -1;
[tableContentView reloadData];
- [[tableDocumentInstance parentWindow] makeFirstResponder:tableContentView];
+ [[tableContentView window] makeFirstResponder:tableContentView];
return YES;
}
@@ -2747,6 +2826,7 @@
// When the option to not show blob or text options is set, we have a problem - we don't have
// the right values to use in the WHERE statement. Throw an error if this is the case.
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPLoadBlobsAsNeeded] && [self tableContainsBlobOrTextColumns] ) {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"You can't hide blob and text fields when working with tables without index.", @"message of panel when trying to edit tables without index and with hidden blob/text fields"));
@@ -2754,6 +2834,7 @@
[tableContentView deselectAll:self];
return @"";
}
+#endif
}
// Walk through the keys list constructing the argument list
@@ -2826,6 +2907,7 @@
*/
- (NSString *)fieldListForQuery
{
+#ifndef SP_REFACTOR
if (([prefs boolForKey:SPLoadBlobsAsNeeded]) && [dataColumns count]) {
NSMutableArray *fields = [NSMutableArray arrayWithCapacity:[dataColumns count]];
@@ -2844,11 +2926,9 @@
return (tableHasBlobs) ? [fields componentsJoinedByString:@", "] : @"*";
}
- else {
-
+#endif
return @"*";
- }
}
/**
@@ -2953,12 +3033,18 @@
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)
@@ -2969,7 +3055,9 @@
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];
}
@@ -3010,8 +3098,7 @@
}
if ([data isKindOfClass:[NSString class]]
- && [data isEqualToString:[prefs objectForKey:SPNullValue]]
- && [[NSArrayObjectAtIndex(dataColumns, column) objectForKey:@"null"] boolValue])
+ && [data isEqualToString:[prefs objectForKey:SPNullValue]] && [[NSArrayObjectAtIndex(dataColumns, column) objectForKey:@"null"] boolValue])
{
data = [[NSNull null] retain];
}
@@ -3032,7 +3119,7 @@
fieldEditor = nil;
}
- [[tableDocumentInstance parentWindow] makeFirstResponder:tableContentView];
+ [[tableContentView window] makeFirstResponder:tableContentView];
if(row > -1 && editedColumn > -1)
[tableContentView editColumn:editedColumn row:row withEvent:nil select:YES];
@@ -3075,13 +3162,15 @@
[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];
- [[tableDocumentInstance parentWindow] makeFirstResponder:filterTableView];
+ [[filterTableView window] makeFirstResponder:filterTableView];
}
/**
@@ -3121,6 +3210,7 @@
[filterTableWindow makeFirstResponder:filterTableView];
// Load history
+#ifndef SP_REFACTOR
if([prefs objectForKey:SPFilterTableDefaultOperatorLastItems]) {
NSMutableArray *lastItems = [NSMutableArray array];
NSString *defaultItem = @"LIKE '%@%'";
@@ -3133,6 +3223,7 @@
}
[filterTableSetDefaultOperatorValue setStringValue:[prefs objectForKey:SPFilterTableDefaultOperator]];
+#endif
[NSApp beginSheet:filterTableSetDefaultOperatorSheet
modalForWindow:filterTableWindow
@@ -3395,7 +3486,9 @@
[tableDataInstance setStatusValue:[NSString stringWithFormat:@"%ld", (long)maxNumRows] forKey:@"Rows"];
[tableDataInstance setStatusValue:@"y" forKey:@"RowsCountAccurate"];
[[tableInfoInstance onMainThread] tableChanged:nil];
+#ifndef SP_REFACTOR
[[[tableDocumentInstance valueForKey:@"extendedTableInfoInstance"] onMainThread] loadTable:selectedTable];
+#endif
// Otherwise, if the table status value is accurate, use it
} else if ([[tableDataInstance statusValueForKey:@"RowsCountAccurate"] boolValue]) {
@@ -3404,10 +3497,23 @@
checkStatusCount = YES;
// Choose whether to display an estimate, or to fetch the correct row count, based on prefs
- } else if ([[prefs objectForKey:SPTableRowCountQueryLevel] integerValue] == SPRowCountFetchAlways
+ } else if (
+#ifndef SP_REFACTOR
+ [[prefs objectForKey:SPTableRowCountQueryLevel] integerValue] == SPRowCountFetchAlways
|| ([[prefs objectForKey:SPTableRowCountQueryLevel] integerValue] == SPRowCountFetchIfCheap
- && [tableDataInstance statusValueForKey:@"Data_length"]
- && [[prefs objectForKey:SPTableRowCountCheapSizeBoundary] integerValue] > [[tableDataInstance statusValueForKey:@"Data_length"] integerValue]))
+ &&
+#endif
+ [tableDataInstance statusValueForKey:@"Data_length"]
+ &&
+#ifndef SP_REFACTOR
+ [[prefs objectForKey:SPTableRowCountCheapSizeBoundary] integerValue]
+#else
+ 5242880
+#endif
+ > [[tableDataInstance statusValueForKey:@"Data_length"] integerValue])
+#ifndef SP_REFACTOR
+ )
+#endif
{
maxNumRows = [self fetchNumberOfRows];
maxNumRowsIsEstimate = NO;
@@ -3426,10 +3532,12 @@
// Check whether the estimated count requires updating, ie if the retrieved count exceeds it
if (checkStatusCount) {
NSInteger foundMaxRows;
- if ([prefs boolForKey:SPLimitResults]) {
+ if ([prefs boolForKey:SPLimitResults])
+ {
foundMaxRows = ((contentPage - 1) * [prefs integerForKey:SPLimitResultsValue]) + tableRowsCount;
if (foundMaxRows > maxNumRows) {
- if ((NSInteger)tableRowsCount == [prefs integerForKey:SPLimitResultsValue]) {
+ if ((NSInteger)tableRowsCount == [prefs integerForKey:SPLimitResultsValue])
+ {
maxNumRows = foundMaxRows + 1;
maxNumRowsIsEstimate = YES;
} else {
@@ -3470,8 +3578,10 @@
[tableContentView setDelegate:nil];
for (NSDictionary *columnDefinition in dataColumns) {
+#ifndef SP_REFACTOR
// Skip columns with saved widths
if ([[[[prefs objectForKey:SPTableColumnWidths] objectForKey:[NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]]] objectForKey:[tablesListInstance tableName]] objectForKey:[columnDefinition objectForKey:@"name"]]) continue;
+#endif
// Otherwise set the column width
NSTableColumn *aTableColumn = [tableContentView tableColumnWithIdentifier:[columnDefinition objectForKey:@"datacolumnindex"]];
@@ -3480,6 +3590,7 @@
}
[tableContentView setDelegate:self];
}
+#ifndef SP_REFACTOR
#pragma mark -
#pragma mark TableView delegate methods
@@ -3565,6 +3676,7 @@
return nil;
}
+#endif
- (NSInteger)numberOfRowsInTableView:(SPCopyTable *)aTableView
{
@@ -3791,12 +3903,14 @@
// This shouldn't happen – for safety reasons
if ( ![mySQLConnection affectedRows] ) {
+#ifndef SP_REFACTOR
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
SPBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db"));
} else {
NSBeep();
}
+#endif
[tableDocumentInstance endTask];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
return;
@@ -3979,6 +4093,7 @@
[self updateCountText];
+#ifndef SP_REFACTOR /* triggered commands */
NSArray *triggeredCommands = [[NSApp delegate] bundleCommandsForTrigger:SPBundleTriggerActionTableRowChanged];
for(NSString* cmdPath in triggeredCommands) {
NSArray *data = [cmdPath componentsSeparatedByString:@"|"];
@@ -4015,7 +4130,7 @@
}
}
}
-
+#endif
}
/**
@@ -4036,11 +4151,15 @@
NSString *table = [tablesListInstance tableName];
// get tableColumnWidths object
+#ifndef SP_REFACTOR
if ( [prefs objectForKey:SPTableColumnWidths] != nil ) {
tableColumnWidths = [NSMutableDictionary dictionaryWithDictionary:[prefs objectForKey:SPTableColumnWidths]];
} else {
+#endif
tableColumnWidths = [NSMutableDictionary dictionary];
+#ifndef SP_REFACTOR
}
+#endif
// get database object
if ( [tableColumnWidths objectForKey:database] == nil ) {
[tableColumnWidths setObject:[NSMutableDictionary dictionary] forKey:database];
@@ -4057,7 +4176,9 @@
}
// save column size
[[[tableColumnWidths objectForKey:database] objectForKey:table] setObject:[NSNumber numberWithDouble:[(NSTableColumn *)[[aNotification userInfo] objectForKey:@"NSTableColumn"] width]] forKey:[[[[aNotification userInfo] objectForKey:@"NSTableColumn"] headerCell] stringValue]];
+#ifndef SP_REFACTOR
[prefs setObject:tableColumnWidths forKey:SPTableColumnWidths];
+#endif
}
/**
@@ -4238,6 +4359,7 @@
// Get the column width
NSUInteger targetWidth = [tableContentView autodetectWidthForColumnDefinition:columnDefinition maxRows:500];
+#ifndef SP_REFACTOR
// Clear any saved widths for the column
NSString *dbKey = [NSString stringWithFormat:@"%@@%@", [tableDocumentInstance database], [tableDocumentInstance host]];
NSString *tableKey = [tablesListInstance tableName];
@@ -4258,6 +4380,7 @@
}
[prefs setObject:[NSDictionary dictionaryWithDictionary:savedWidths] forKey:SPTableColumnWidths];
}
+#endif
// Return the width, while the delegate is empty to prevent column resize notifications
[tableContentView setDelegate:nil];
@@ -4265,6 +4388,7 @@
return targetWidth;
}
+#ifndef SP_REFACTOR /* SplitView delegate methods */
#pragma mark -
#pragma mark SplitView delegate methods
@@ -4310,6 +4434,7 @@
[leftView setFrame:leftFrame];
[rightView setFrame:rightFrame];
}
+#endif
#pragma mark -
@@ -4322,9 +4447,11 @@
{
isWorking = YES;
+#ifndef SP_REFACTOR /* Only proceed if this view is selected */
// Only proceed if this view is selected.
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableContent])
return;
+#endif
[addButton setEnabled:NO];
[removeButton setEnabled:NO];
@@ -4344,9 +4471,11 @@
{
isWorking = NO;
+#ifndef SP_REFACTOR /* Only proceed if this view is selected */
// Only proceed if this view is selected.
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableContent])
return;
+#endif
if ( ![[[tableDataInstance statusValues] objectForKey:@"Rows"] isNSNull] && selectedTable && [selectedTable length] && [tableDataInstance tableEncoding]) {
[addButton setEnabled:([tablesListInstance tableType] == SPTableTypeTable)];
@@ -4460,7 +4589,11 @@
{
// Check firstly if SPCopyTable can handle command
+#ifndef SP_REFACTOR
if([control control:control textView:textView doCommandBySelector:(SEL)command])
+#else
+ if([(id<NSControlTextEditingDelegate>)control control:control textView:textView doCommandBySelector:(SEL)command])
+#endif
return YES;
// Trap the escape key
@@ -4482,6 +4615,7 @@
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
+#ifndef SP_REFACTOR /* observe pref changes */
// Display table veiew vertical gridlines preference changed
if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
[tableContentView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
@@ -4493,6 +4627,7 @@
[tableContentView setFont:tableFont];
[tableContentView reloadData];
}
+#endif
}
/**
@@ -4690,13 +4825,13 @@
NSUInteger numOfArgs = [[filter objectForKey:@"NumberOfArguments"] integerValue];
switch(numOfArgs) {
case 2:
- [[tableDocumentInstance parentWindow] makeFirstResponder:firstBetweenField];
+ [[firstBetweenField window] makeFirstResponder:firstBetweenField];
break;
case 1:
- [[tableDocumentInstance parentWindow] makeFirstResponder:argumentField];
+ [[argumentField window] makeFirstResponder:argumentField];
break;
default:
- [[tableDocumentInstance parentWindow] makeFirstResponder:compareField];
+ [[compareField window] makeFirstResponder:compareField];
}
}
}
@@ -4711,6 +4846,18 @@
return [tableContentView fieldEditorSelectedRange];
}
+#ifdef SP_REFACTOR /* glue */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)doc
+{
+ tableDocumentInstance = doc;
+}
+
+- (void)setTableListInstance:(SPTablesList*)list
+{
+ tablesListInstance = list;
+}
+#endif
+
#pragma mark -
/**
diff --git a/Source/SPTableData.h b/Source/SPTableData.h
index 1c3fa8f0..b4042527 100644
--- a/Source/SPTableData.h
+++ b/Source/SPTableData.h
@@ -25,10 +25,13 @@
#import <MCPKit/MCPKit.h>
+@class SPDatabaseDocument;
+@class SPTablesList;
+
@interface SPTableData : NSObject
{
- IBOutlet id tableDocumentInstance;
- IBOutlet id tableListInstance;
+ IBOutlet SPDatabaseDocument* tableDocumentInstance;
+ IBOutlet SPTablesList* tableListInstance;
NSMutableArray *columns;
NSMutableArray *columnNames;
@@ -74,4 +77,9 @@
- (NSDictionary *) parseFieldDefinitionStringParts:(NSArray *)definitionParts;
- (NSArray *) primaryKeyColumnNames;
+#ifdef SP_REFACTOR /* glue */
+- (void)setTableDocumentInstance:(SPDatabaseDocument*)doc;
+- (void)setTableListInstance:(SPTablesList*)list;
+#endif
+
@end
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index b69ce816..de253e57 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -1374,4 +1374,17 @@
pthread_mutex_unlock(&dataProcessingLock);
}
+#ifdef SP_REFACTOR /* glue */
+
+- (void)setTableDocumentInstance:(SPDatabaseDocument*)doc
+{
+ tableDocumentInstance = doc;
+}
+
+- (void)setTableListInstance:(SPTablesList*)list
+{
+ tableListInstance = list;
+}
+#endif
+
@end \ No newline at end of file
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index a08ddd15..81905410 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -25,17 +25,19 @@
#import <MCPKit/MCPKit.h>
-@class SPDatabaseDocument, SPTableFieldValidation;
+@class SPDatabaseDocument, SPTableFieldValidation, SPTableData, SPDatabaseData, SPTablesList, SPIndexesController;
@interface SPTableStructure : NSObject
{
- IBOutlet id tablesListInstance;
- IBOutlet id tableDataInstance;
- IBOutlet SPDatabaseDocument *tableDocumentInstance;
+ IBOutlet SPTablesList* tablesListInstance;
+ IBOutlet SPTableData* tableDataInstance;
+ IBOutlet SPDatabaseDocument* tableDocumentInstance;
+#ifndef SP_REFACTOR /* ivars */
IBOutlet id tableInfoInstance;
IBOutlet id extendedTableInfoInstance;
- IBOutlet id indexesController;
- IBOutlet id databaseDataInstance;
+#endif
+ IBOutlet SPIndexesController* indexesController;
+ IBOutlet SPDatabaseData* databaseDataInstance;
IBOutlet id keySheet;
IBOutlet id resetAutoIncrementSheet;
@@ -85,6 +87,13 @@
- (IBAction)reloadTable:(id)sender;
- (void)setTableDetails:(NSDictionary *)tableDetails;
+#ifdef SP_REFACTOR /* method decls */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)doc;
+- (void)setTableListInstance:(SPTablesList*)list;
+- (void)setTableDataInstance:(SPTableData*)data;
+#endif
+- (void)showErrorSheetWith:(NSDictionary *)errorDictionary;
+
// Edit methods
- (IBAction)addField:(id)sender;
- (IBAction)copyField:(id)sender;
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index aab62af8..1af8bc62 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -79,12 +79,15 @@
*/
- (void)awakeFromNib
{
+#ifndef SP_REFACTOR /* ui manipulation */
// Set the structure and index view's vertical gridlines if required
[tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
-
+#endif
+#ifndef SP_REFACTOR /* set font from prefs */
// Set the strutcture and index view's font
[tableSourceView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[indexesTableView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+#endif
extraFieldSuggestions = [[NSArray arrayWithObjects:
@"None",
@@ -159,12 +162,15 @@
name:SPDocumentTaskEndNotification
object:tableDocumentInstance];
+#ifndef SP_REFACTOR /* add prefs observer */
[prefs addObserver:indexesController forKeyPath:SPUseMonospacedFonts options:NSKeyValueObservingOptionNew context:NULL];
+#endif
// 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
-
+
+#ifndef SP_REFACTOR /* patch */
for (NSTableColumn *col in [tableSourceView tableColumns])
{
if ([col isHidden]) {
@@ -178,6 +184,21 @@
[[viewColumnsMenu itemWithTag:12] setState:NSOffState];
}
}
+#else
+ for (NSTableColumn *col in [tableSourceView tableColumns])
+ {
+ if ([col isHidden]) {
+ if ([[col identifier] isEqualToString:@"Key"])
+ [[viewColumnsMenu itemAtIndex:[viewColumnsMenu indexOfItemWithTag:7]] setState:NSOffState];
+ else if ([[col identifier] isEqualToString:@"encoding"])
+ [[viewColumnsMenu itemAtIndex:[viewColumnsMenu indexOfItemWithTag:10]] setState:NSOffState];
+ else if ([[col identifier] isEqualToString:@"collation"])
+ [[viewColumnsMenu itemAtIndex:[viewColumnsMenu indexOfItemWithTag:11]] setState:NSOffState];
+ else if ([[col identifier] isEqualToString:@"comment"])
+ [[viewColumnsMenu itemAtIndex:[viewColumnsMenu indexOfItemWithTag:12]] setState:NSOffState];
+ }
+ }
+#endif
[tableSourceView reloadData];
}
@@ -213,7 +234,11 @@
// If an error occurred, reset the interface and abort
if ([mySQLConnection queryErrored]) {
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
[[self onMainThread] setTableDetails:nil];
if ([mySQLConnection isConnected]) {
@@ -341,7 +366,11 @@
autoIncrementIndex = nil;
// Send the query finished/work complete notification
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
[theTableFields release];
}
@@ -373,7 +402,12 @@
{
NSString *newTableName = [tableDetails objectForKey:@"name"];
NSMutableDictionary *newDefaultValues;
- BOOL enableInteraction = ![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure] || ![tableDocumentInstance isWorking];
+
+ BOOL enableInteraction =
+#ifndef SP_REFACTOR /* patch */
+ ![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure] ||
+#endif
+ ![tableDocumentInstance isWorking];
// Update the selected table name
if (selectedTable) [selectedTable release], selectedTable = nil;
@@ -445,10 +479,17 @@
NSInteger insertIndex = ([tableSourceView numberOfSelectedRows] == 0 ? [tableSourceView numberOfRows] : [tableSourceView selectedRow] + 1);
+#ifndef SP_REFACTOR /* prefs access */
[tableFields insertObject:[NSMutableDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"INT", @"", @"0", @"0", @"0", ([prefs boolForKey:SPNewFieldsAllowNulls]) ? @"1" : @"0", @"", [prefs stringForKey:SPNullValue], @"None", @"", [NSNumber numberWithInt:0], [NSNumber numberWithInt:0], nil]
forKeys:[NSArray arrayWithObjects:@"name", @"type", @"length", @"unsigned", @"zerofill", @"binary", @"null", @"Key", @"default", @"Extra", @"comment", @"encoding", @"collation", nil]]
atIndex:insertIndex];
+#else
+ [tableFields insertObject:[NSMutableDictionary
+ dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"INT", @"", @"0", @"0", @"0", @"1", @"", @"NULL", @"None", @"", [NSNumber numberWithInt:0], [NSNumber numberWithInt:0], nil]
+ forKeys:[NSArray arrayWithObjects:@"name", @"type", @"length", @"unsigned", @"zerofill", @"binary", @"null", @"Key", @"default", @"Extra", @"comment", @"encoding", @"collation", nil]]
+ atIndex:insertIndex];
+#endif
[tableSourceView reloadData];
[tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:insertIndex] byExtendingSelection:NO];
@@ -769,8 +810,10 @@
if (valueAsString == nil || ![valueAsString length]) {
// reload data and bail
[tableDataInstance resetAllData];
+#ifndef SP_REFACTOR
[extendedTableInfoInstance loadTable:selTable];
[tableInfoInstance tableChanged:nil];
+#endif
return;
}
@@ -793,10 +836,14 @@
[tableDataInstance resetStatusData];
if([[tableDocumentInstance valueForKeyPath:@"tableTabView"] indexOfTabViewItem:[[tableDocumentInstance valueForKeyPath:@"tableTabView"] selectedTabViewItem]] == 3) {
[tableDataInstance resetAllData];
+#ifndef SP_REFACTOR
[extendedTableInfoInstance loadTable:selTable];
+#endif
}
+#ifndef SP_REFACTOR
[tableInfoInstance tableChanged:nil];
+#endif
}
/**
@@ -808,14 +855,14 @@
NSMutableArray *tempResult = [NSMutableArray arrayWithCapacity:numOfRows];
NSMutableDictionary *tempRow;
NSArray *keys;
- NSUInteger i;
+ NSInteger i;
id prefsNullValue = [prefs objectForKey:SPNullValue];
// Ensure table information is returned as strings to avoid problems with some server versions
[theResult setReturnDataAsStrings:YES];
if (numOfRows) [theResult dataSeek:0];
- for ( i = 0 ; i < numOfRows ; i++ ) {
+ for ( i = 0 ; i < (NSInteger)numOfRows ; i++ ) {
tempRow = [NSMutableDictionary dictionaryWithDictionary:[theResult fetchRowAsDictionary]];
// Replace NSNull instances with the NULL string from preferences
@@ -862,7 +909,11 @@
isSavingRow = YES;
// Save any edits which have been made but not saved to the table yet.
+#ifndef SP_REFACTOR /* patch */
[[tableDocumentInstance parentWindow] endEditingFor:nil];
+#else
+ [[tableSourceView window] endEditingFor:nil];
+#endif
// Attempt to save the row, and return YES if the save succeeded.
if ([self addRowToDB]) {
@@ -880,7 +931,7 @@
* returns YES if row written to db, otherwies NO
* returns YES if no row is beeing edited and nothing has to be written to db
*/
-- (BOOL)addRowToDB;
+- (BOOL)addRowToDB
{
if ((!isEditingRow) || (currentlyEditingRow == -1)) return YES;
@@ -931,7 +982,8 @@
[queryString appendString:@"\n NULL"];
}
// If a NULL value has been specified, and NULL is allowed, specify DEFAULT NULL
- if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) {
+ if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]])
+ {
if ([[theRow objectForKey:@"null"] integerValue] == 1) {
[queryString appendString:@"\n DEFAULT NULL "];
}
@@ -1003,7 +1055,8 @@
if (![theRowExtra isEqualToString:@"AUTO_INCREMENT"]) {
// If a NULL value has been specified, and NULL is allowed, specify DEFAULT NULL
- if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) {
+ if ([[theRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]])
+ {
if ([[theRow objectForKey:@"null"] integerValue] == 1) {
[queryString appendString:@"\n DEFAULT NULL"];
}
@@ -1161,6 +1214,24 @@
}
}
+#ifdef SP_REFACTOR /* glue */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)doc
+{
+ tableDocumentInstance = doc;
+}
+
+- (void)setTableListInstance:(SPTablesList*)list
+{
+ tablesListInstance = list;
+}
+
+- (void)setTableDataInstance:(SPTableData*)data
+{
+ tableDataInstance = data;
+}
+
+#endif
+
/**
* A method to show an error sheet after a short delay, so that it can
* be called from within an endSheet selector. This should be called on
@@ -1280,6 +1351,7 @@
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
+#ifndef SP_REFACTOR /* observe prefs change */
// Display table veiew vertical gridlines preference changed
if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
[tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
@@ -1295,6 +1367,7 @@
[tableSourceView reloadData];
[indexesTableView reloadData];
}
+#endif
}
#pragma mark -
@@ -1441,8 +1514,10 @@
*/
- (void)startDocumentTaskForTab:(NSNotification *)aNotification
{
+#ifndef SP_REFACTOR /* check toolbar mode */
// Only proceed if this view is selected.
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return;
+#endif
[tableSourceView setEnabled:NO];
[addFieldButton setEnabled:NO];
@@ -1462,8 +1537,10 @@
*/
- (void)endDocumentTaskForTab:(NSNotification *)aNotification
{
+#ifndef SP_REFACTOR /* check toolbar mode */
// Only re-enable elements if the current tab is the structure view
if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return;
+#endif
BOOL editingEnabled = ([tablesListInstance tableType] == SPTableTypeTable);
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index 0cabda4c..e7f9d3be 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -541,6 +541,7 @@
#pragma mark -
#pragma mark Split view delegate methods
+#ifndef SP_REFACTOR /* Split view delegate methods */
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview
{
@@ -576,6 +577,7 @@
}
}
}
+#endif
#pragma mark -
#pragma mark Combo box delegate methods
diff --git a/Source/SPTableView.h b/Source/SPTableView.h
index 6914723d..e39df82f 100644
--- a/Source/SPTableView.h
+++ b/Source/SPTableView.h
@@ -23,5 +23,10 @@
// More info at <http://code.google.com/p/sequel-pro/>
@interface SPTableView : NSTableView
+{
+ BOOL tabEditingDisabled;
+}
+
+@property (readwrite, assign) BOOL tabEditingDisabled;
@end
diff --git a/Source/SPTableView.m b/Source/SPTableView.m
index 226bfe6c..d678fef3 100644
--- a/Source/SPTableView.m
+++ b/Source/SPTableView.m
@@ -36,12 +36,15 @@
@implementation SPTableView
+@synthesize tabEditingDisabled;
+
/**
* Right-click at row will select that row before ordering out the contextual menu
* if not more than one row is selected.
*/
- (NSMenu *)menuForEvent:(NSEvent *)event
{
+#ifndef SP_REFACTOR /* menuForEvent: */
// Try to retrieve a reference to the table document (assuming this is frontmost tab)
SPDatabaseDocument *parentTableDocument = nil;
@@ -65,24 +68,24 @@
// Check for SPTablesList if right-click on header, then suppress context menu
if ([[[[self delegate] class] description] isEqualToString:@"SPTablesList"]) {
- if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"tableTypes"], row) integerValue] == -1)
+ if ([NSArrayObjectAtIndex([(NSObject*)[self delegate] valueForKeyPath:@"tableTypes"], row) integerValue] == -1)
return nil;
}
if ([[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]) {
- if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"favorites"], row) objectForKey:@"headerOfFileURL"])
+ if ([NSArrayObjectAtIndex([(NSObject*)[self delegate] valueForKeyPath:SPFavorites], row) objectForKey:@"headerOfFileURL"])
return nil;
}
if ([[[[self delegate] class] description] isEqualToString:@"SPContentFilterManager"]) {
- if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"contentFilters"], row) objectForKey:@"headerOfFileURL"])
+ if ([NSArrayObjectAtIndex([(NSObject*)[self delegate] valueForKeyPath:@"contentFilters"], row) objectForKey:@"headerOfFileURL"])
return nil;
}
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
[[self window] makeFirstResponder:self];
}
-
+#endif
return [self menu];
}
@@ -91,23 +94,36 @@
return YES;
}
+/**
+ * On becomeFirstResponder, if editing is disabled, override the super and just
+ * display instead; this prevents the selected cell from automatically editing
+ * if the table is backtabbed to.
+ */
+- (BOOL)becomeFirstResponder {
+ if (tabEditingDisabled) {
+ [self display];
+ return YES;
+ }
+ return [super becomeFirstResponder];
+}
+
- (void)keyDown:(NSEvent *)theEvent
{
// Check if ENTER or RETURN is hit and edit the column.
if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) {
if ([[[[self delegate] class] description] isEqualToString:@"SPFieldMapperController"]) {
- if ([[self delegate] isGlobalValueSheetOpen]) {
- [[self delegate] closeGlobalValuesSheet:nil];
+ if ([(SPFieldMapperController*)[self delegate] isGlobalValueSheetOpen]) {
+ [(SPFieldMapperController*)[self delegate] closeGlobalValuesSheet:nil];
return;
}
// ENTER or RETURN closes the SPFieldMapperController sheet
// by sending an object with the tag 1 if no table cell is edited
- if ([[self delegate] canBeClosed]) {
+ if ([(SPFieldMapperController*)[self delegate] canBeClosed]) {
NSButton *b = [[[NSButton alloc] init] autorelease];
[b setTag:1];
- [[self delegate] closeSheet:b];
+ [(SPFieldMapperController*)[self delegate] closeSheet:b];
return;
}
@@ -131,9 +147,20 @@
return;
}
}
+
// Check if ESCAPE is hit and use it to cancel row editing if supported
else if ([theEvent keyCode] == 53 && [[self delegate] respondsToSelector:@selector(cancelRowEditing)]) {
- if ([[self delegate] cancelRowEditing]) return;
+ if ([[self delegate] performSelector:@selector(cancelRowEditing)]) return;
+ }
+
+ // If the Tab key is used, but tab editing is disabled, change focus rather than entering edit mode.
+ else if (tabEditingDisabled && [[theEvent characters] length] && [[theEvent characters] characterAtIndex:0] == NSTabCharacter) {
+ if (([theEvent modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) {
+ [[self window] selectKeyViewFollowingView:self];
+ } else {
+ [[self window] selectKeyViewPrecedingView:self];
+ }
+ return;
}
[super keyDown:theEvent];
diff --git a/Source/SPTablesList.h b/Source/SPTablesList.h
index d4623f40..914295a5 100644
--- a/Source/SPTablesList.h
+++ b/Source/SPTablesList.h
@@ -25,7 +25,8 @@
#import <MCPKit/MCPKit.h>
-@class SPHistoryController;
+@class SPHistoryController, SPTableView;
+@class SPDatabaseDocument;
@interface NSObject (NSSplitView)
@@ -38,7 +39,8 @@
@interface SPTablesList : NSObject
{
- IBOutlet id tableDocumentInstance;
+ SPDatabaseDocument* tableDocumentInstance;
+#ifndef SP_REFACTOR /* ivars */
IBOutlet id tableSourceInstance;
IBOutlet id tableContentInstance;
IBOutlet id customQueryInstance;
@@ -51,7 +53,7 @@
IBOutlet SPHistoryController *spHistoryControllerInstance;
IBOutlet id copyTableSheet;
- IBOutlet id tablesListView;
+ IBOutlet SPTableView *tablesListView;
IBOutlet id copyTableButton;
IBOutlet id copyTableNameField;
IBOutlet id copyTableMessageField;
@@ -79,9 +81,11 @@
IBOutlet NSMenuItem *separatorTableMenuItem;
IBOutlet NSMenuItem *showCreateSyntaxMenuItem;
IBOutlet NSMenuItem *separatorTableMenuItem2;
+#endif
MCPConnection *mySQLConnection;
+#ifndef SP_REFACTOR /* ivars */
// Table list context menu items
IBOutlet NSMenuItem *removeTableContextMenuItem;
IBOutlet NSMenuItem *duplicateTableContextMenuItem;
@@ -91,25 +95,34 @@
IBOutlet NSMenuItem *separatorTableContextMenuItem;
IBOutlet NSMenuItem *showCreateSyntaxContextMenuItem;
IBOutlet NSMenuItem *separatorTableContextMenuItem2;
+#endif
NSMutableArray *tables;
+#ifndef SP_REFACTOR /* ivars */
NSMutableArray *filteredTables;
+#endif
NSMutableArray *tableTypes;
+#ifndef SP_REFACTOR /* ivars */
NSMutableArray *filteredTableTypes;
- SPTableType selectedTableType;
+#endif
+ NSInteger selectedTableType;
NSString *selectedTableName;
+#ifndef SP_REFACTOR /* ivars */
BOOL isTableListFiltered;
BOOL tableListIsSelectable;
+#endif
BOOL tableListContainsViews;
-
+#ifndef SP_REFACTOR /* ivars */
BOOL alertSheetOpened;
NSFont *smallSystemFont;
-
+#endif
}
// IBAction methods
- (IBAction)updateTables:(id)sender;
+
+#ifndef SP_REFACTOR /* method decls */
- (IBAction)addTable:(id)sender;
- (IBAction)closeSheet:(id)sender;
- (IBAction)removeTable:(id)sender;
@@ -118,13 +131,11 @@
- (IBAction)truncateTable:(id)sender;
- (IBAction)openTableInNewTab:(id)sender;
- (IBAction)togglePaneCollapse:(id)sender;
-
-// Alert sheet callbacks
-- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
-
+#endif
// Additional methods
- (void)setConnection:(MCPConnection *)theConnection;
- (void)setSelectionState:(NSDictionary *)selectionDetails;
+#ifndef SP_REFACTOR /* method decls */
- (void)selectTableAtIndex:(NSNumber *)row;
- (void)makeTableListFilterHaveFocus;
@@ -132,6 +143,7 @@
- (NSArray *)selectedTableNames;
- (NSArray *)selectedTableItems;
- (NSArray *)selectedTableTypes;
+#endif
- (NSString *)tableName;
- (SPTableType)tableType;
- (NSArray *)tables;
@@ -147,12 +159,9 @@
// Setters
- (BOOL)selectItemWithName:(NSString *)theName;
+#ifndef SP_REFACTOR /* method decls */
- (BOOL)selectItemsWithNames:(NSArray *)theNames;
-// Data validation
-- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType;
-- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType ignoringSelectedTable:(BOOL)ignoreSelectedTable;
-
// Table list filter interaction
- (void) showFilter;
- (void) hideFilter;
@@ -163,5 +172,11 @@
- (void) startDocumentTaskForTab:(NSNotification *)aNotification;
- (void) endDocumentTaskForTab:(NSNotification *)aNotification;
- (void) setTableListSelectability:(BOOL)isSelectable;
+#endif
+- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType;
+- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType ignoringSelectedTable:(BOOL)ignoreSelectedTable;
+#ifdef SP_REFACTOR /* method decls */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)val;
+#endif
@end
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 9c1a1d0c..5ccb9bae 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -24,13 +24,21 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPTablesList.h"
+#ifndef SP_REFACTOR /* headers */
+#import "SPConnectionController.h"
+#endif
#import "SPDatabaseDocument.h"
-#import "SPDatabaseViewController.h"
#import "SPTableStructure.h"
+#import "SPDatabaseViewController.h"
+
+#ifndef SP_REFACTOR /* headers */
#import "SPTableContent.h"
+#endif
#import "SPTableData.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPTableInfo.h"
#import "SPDataImport.h"
+#import "SPTableView.h"
#import "ImageAndTextCell.h"
#import "RegexKitLite.h"
#import "SPDatabaseData.h"
@@ -50,6 +58,7 @@
- (void)renameTableOfType:(SPTableType)tableType from:(NSString *)oldTableName to:(NSString *)newTableName;
@end
+#endif
@implementation SPTablesList
@@ -66,10 +75,13 @@
NSUInteger i;
NSString *previousSelectedTable = nil;
NSString *previousFilterString = nil;
+#ifndef SP_REFACTOR /* table list filtering */
BOOL previousTableListIsSelectable = tableListIsSelectable;
+#endif
BOOL changeEncoding = ![[mySQLConnection encoding] isEqualToString:@"utf8"];
if (selectedTableName) previousSelectedTable = [[NSString alloc] initWithString:selectedTableName];
+#ifndef SP_REFACTOR /* table list filtering */
if (isTableListFiltered) {
previousFilterString = [[NSString alloc] initWithString:[listFilterField stringValue]];
if (filteredTables) [filteredTables release];
@@ -84,13 +96,18 @@
tableListIsSelectable = YES;
[[tablesListView onMainThread] deselectAll:self];
tableListIsSelectable = previousTableListIsSelectable;
+#endif
[tables removeAllObjects];
[tableTypes removeAllObjects];
if ([tableDocumentInstance database]) {
// Notify listeners that a query has started
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+#endif
// Use UTF8 for identifier-based queries
if (changeEncoding) {
@@ -131,6 +148,7 @@
// Reorder the tables in alphabetical order
[tables sortArrayUsingSelector:@selector(localizedCompare:) withPairedMutableArrays:tableTypes, nil];
+#ifndef SP_REFACTOR /* table procedures and functions */
/* Grab the procedures and functions
*
* Using information_schema gives us more info (for information window perhaps?) but breaks
@@ -170,7 +188,7 @@
}
}
}
- /*
+#endif /*
BOOL addedPFHeader = FALSE;
NSString *pQuery = [NSString stringWithFormat:@"SHOW PROCEDURE STATUS WHERE db = '%@'",[tableDocumentInstance database]];
theResult = [mySQLConnection queryString:pQuery];
@@ -226,7 +244,11 @@
if (changeEncoding) [mySQLConnection restoreStoredEncoding];
// Notify listeners that the query has finished
+#ifndef SP_REFACTOR
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#else
+ [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+#endif
}
// Add the table headers even if no tables were found
@@ -239,7 +261,9 @@
[tableTypes insertObject:[NSNumber numberWithInteger:SPTableTypeNone] atIndex:0];
+#ifndef SP_REFACTOR /* ui manipulation */
[[tablesListView onMainThread] reloadData];
+#endif
// if the previous selected table still exists, select it
// but not if the update was called from SPTableData since it calls that method
@@ -247,9 +271,11 @@
// or if the table name contains characters which are not supported by the current set encoding
if ( ![sender isKindOfClass:[SPTableData class]] && previousSelectedTable != nil && [tables indexOfObject:previousSelectedTable] < [tables count]) {
NSInteger itemToReselect = [tables indexOfObject:previousSelectedTable];
+#ifndef SP_REFACTOR /* ui manipulation */
tableListIsSelectable = YES;
[[tablesListView onMainThread] selectRowIndexes:[NSIndexSet indexSetWithIndex:itemToReselect] byExtendingSelection:NO];
tableListIsSelectable = previousTableListIsSelectable;
+#endif
if (selectedTableName) [selectedTableName release];
selectedTableName = [[NSString alloc] initWithString:[tables objectAtIndex:itemToReselect]];
selectedTableType = (SPTableType)[[tableTypes objectAtIndex:itemToReselect] integerValue];
@@ -260,6 +286,7 @@
selectedTableType = SPTableTypeNone;
}
+#ifndef SP_REFACTOR /* table list filtering */
// Determine whether or not to preserve the existing filter, and whether to
// show or hide the list filter based on the number of tables
if ([tables count] > 20) {
@@ -276,6 +303,7 @@
if ([tableDocumentInstance database]) {
[[[listFilterField cell] onMainThread] setPlaceholderString:NSLocalizedString(@"Filter", @"filter label")];
}
+#endif
if (previousSelectedTable) [previousSelectedTable release];
if (previousFilterString) [previousFilterString release];
@@ -288,6 +316,7 @@
// User press refresh button ergo force update
[NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", [NSNumber numberWithBool:YES], @"cancelQuerying", nil]];
}
+#ifndef SP_REFACTOR /* whole table operations */
/**
* Adds a new table to the tables-array (no changes in mysql-db)
@@ -657,6 +686,8 @@
#pragma mark -
#pragma mark Additional methods
+#endif
+
/**
* Sets the connection (received from SPDatabaseDocument) and makes things that have to be done only once
*/
@@ -666,6 +697,8 @@
[self updateTables:self];
}
+#ifndef SP_REFACTOR /* ui validation */
+
/**
* Performs interface validation for various controls.
*/
@@ -701,6 +734,7 @@
[copyTableButton performClick:object];
}
}
+#endif
/**
* Updates application state to match the current selection, including
@@ -714,17 +748,23 @@
{
// First handle empty or multiple selections
if (!selectionDetails || ![selectionDetails objectForKey:@"name"]) {
+#ifndef SP_REFACTOR /* ui manipulation */
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
-
+#endif
// Update the selected table name and type
if (selectedTableName) [selectedTableName release];
+#ifndef SP_REFACTOR /* ui manipulation */
if ([indexes count]) {
selectedTableName = [[NSString alloc] initWithString:@""];
}
else {
+#endif
selectedTableName = nil;
+#ifndef SP_REFACTOR /* ui manipulation */
}
+#endif
+#ifndef SP_REFACTOR /* ui manipulation */
// Set gear menu items Remove/Duplicate table/view according to the table types
// if at least one item is selected
@@ -825,6 +865,7 @@
[[tableSubMenu itemAtIndex:10] setHidden:NO];
return;
+#endif
}
// If a new selection has been provided, store variables and update the interface to match
@@ -836,6 +877,7 @@
selectedTableName = [[NSString alloc] initWithString:selectedItemName];
selectedTableType = selectedItemType;
+#ifndef SP_REFACTOR /* ui manipulation */
// Remove the "current selection" item for filtered lists if appropriate
if (isTableListFiltered && [tablesListView selectedRow] < (NSInteger)[filteredTables count] - 2 && [filteredTables count] > 2
&& [[filteredTableTypes objectAtIndex:[filteredTableTypes count]-2] integerValue] == SPTableTypeNone
@@ -1006,8 +1048,11 @@
[showCreateSyntaxContextMenuItem setHidden:NO];
[showCreateSyntaxContextMenuItem setTitle:NSLocalizedString(@"Show Create Function Syntax...", @"show create func syntax menu item")];
}
+#endif
}
+#ifndef SP_REFACTOR /* getters */
+
#pragma mark -
#pragma mark Getter methods
@@ -1054,6 +1099,7 @@
}
return selTables;
}
+#endif
/**
* Returns the currently selected table or nil if no table or mulitple tables are selected
@@ -1202,6 +1248,7 @@
// If no match found, return failure
if (itemIndex == NSNotFound) return NO;
+#ifndef SP_REFACTOR /* table list filtering */
if (!isTableListFiltered) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO];
} else {
@@ -1210,19 +1257,26 @@
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:filteredIndex] byExtendingSelection:NO];
} else {
[tablesListView deselectAll:nil];
+#endif
if (selectedTableName) [selectedTableName release];
selectedTableName = [[NSString alloc] initWithString:[tables objectAtIndex:itemIndex]];
- selectedTableType = (SPTableType)[[tableTypes objectAtIndex:itemIndex] integerValue];
+ selectedTableType = [[tableTypes objectAtIndex:itemIndex] integerValue];
+#ifndef SP_REFACTOR /* table list filtering */
[self updateFilter:self];
+#endif
[tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
+#ifndef SP_REFACTOR /* table list filtering */
}
}
[[tablesListView onMainThread] scrollRowToVisible:[tablesListView selectedRow]];
+#endif
return YES;
}
+#ifndef SP_REFACTOR /* tableView datasource/delegate */
+
/**
* Try to select items using the provided names in theNames; returns YES if at least
* one item could be seleceted, otherwise NO.
@@ -1360,6 +1414,9 @@
return ![tableDocumentInstance isWorking];
}
+
+#ifndef SP_REFACTOR
+
/**
* Renames a table (in tables-array and mysql-db).
*/
@@ -1419,6 +1476,7 @@
// Query the structure of all databases in the background (mainly for completion)
[NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
}
+#endif
#pragma mark -
#pragma mark TableView delegate methods
@@ -1428,15 +1486,16 @@
*/
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
{
+
+ // When enter/return is used, save the row.
if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) {
- //save current line
[[control window] makeFirstResponder:control];
return TRUE;
+ // When the escape key is used, abort the rename.
} else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] ||
[textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) {
- //abort editing
[control abortEditing];
[[NSApp mainWindow] makeFirstResponder:tablesListView];
@@ -1847,6 +1906,7 @@
{
return (splitView == tableListSplitView ? NSZeroRect : proposedEffectiveRect);
}
+#endif
#pragma mark -
@@ -1859,21 +1919,28 @@
{
if ((self = [super init])) {
tables = [[NSMutableArray alloc] init];
+#ifndef SP_REFACTOR
filteredTables = tables;
+#endif
tableTypes = [[NSMutableArray alloc] init];
+#ifndef SP_REFACTOR
filteredTableTypes = tableTypes;
isTableListFiltered = NO;
tableListIsSelectable = YES;
+#endif
tableListContainsViews = NO;
selectedTableType = SPTableTypeNone;
selectedTableName = nil;
[tables addObject:NSLocalizedString(@"TABLES",@"header for table list")];
+#ifndef SP_REFACTOR /* font */
smallSystemFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+#endif
}
return self;
}
+#ifndef SP_REFACTOR /* awakeFromNib */
/**
* Standard awakeFromNib method for interface loading.
*/
@@ -1903,6 +1970,9 @@
[tableListFilterSplitView setCollapsibleSubviewCollapsed:YES];
}
+ // Disable tab edit behaviour in the tables list
+ [tablesListView setTabEditingDisabled:YES];
+
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(startDocumentTaskForTab:)
@@ -1917,6 +1987,7 @@
[tablesListView registerForDraggedTypes:[NSArray arrayWithObjects:@"SPDragTableDataFromNavigatorPboardType", nil]];
}
+#endif
/**
* Standard dealloc method.
@@ -1927,13 +1998,24 @@
[tables release];
[tableTypes release];
+#ifndef SP_REFACTOR
if (isTableListFiltered && filteredTables) [filteredTables release];
if (isTableListFiltered && filteredTableTypes) [filteredTableTypes release];
+#endif
if (selectedTableName) [selectedTableName release];
[super dealloc];
}
+
+#ifdef SP_REFACTOR /* glue */
+- (void)setDatabaseDocument:(SPDatabaseDocument*)val
+{
+ tableDocumentInstance = val;
+}
+#endif
+
+#ifndef SP_REFACTOR /* operations performed on whole tables */
@end
@implementation SPTablesList (PrivateAPI)
@@ -2148,7 +2230,9 @@
[self updateFilter:self];
[tablesListView scrollRowToVisible:[tablesListView selectedRow]];
+ // Select the newly created table and switch to the table structure view for easier setup
[tableDocumentInstance loadTable:selectedTableName ofType:selectedTableType];
+ [tableDocumentInstance viewStructure:self];
// Query the structure of all databases in the background (mainly for completion)
[NSThread detachNewThreadSelector:@selector(queryDbStructureWithUserInfo:) toTarget:mySQLConnection withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"forceUpdate", nil]];
@@ -2438,5 +2522,67 @@
[NSException raise:@"Object of unknown type" format:NSLocalizedString(@"An error occured while renaming. '%@' is of an unknown type.", @"rename error - don't know what type the renamed thing is"), oldTableName];
}
+#endif
+
+/**
+ * Check tableName for length and if the tableName doesn't match
+ * against current database table/view names (case-insensitive).
+ */
+- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType
+{
+ return [self isTableNameValid:tableName forType:tableType ignoringSelectedTable:NO];
+}
+
+/**
+ * Check tableName for length and if the tableName doesn't match
+ * against current database table/view names (case-insensitive).
+ */
+- (BOOL)isTableNameValid:(NSString *)tableName forType:(SPTableType)tableType ignoringSelectedTable:(BOOL)ignoreSelectedTable
+{
+ BOOL isValid = YES;
+
+ // delete trailing whitespaces since 'foo ' or ' ' are not valid table names
+ NSString *fieldStr = [tableName stringByMatching:@"(.*?)\\s*$" capture:1];
+ NSString *lowercaseFieldStr = [fieldStr lowercaseString];
+
+ // If table name has trailing whitespaces return 'no valid'
+ if([fieldStr length] != [tableName length]) return NO;
+
+ // empty table names are invalid
+ if([fieldStr length] == 0) return NO;
+
+
+ NSArray *similarTables;
+ switch (tableType) {
+ case SPTableTypeView:
+ case SPTableTypeTable:
+ similarTables = [self allTableAndViewNames];
+ break;
+ case SPTableTypeProc:
+ similarTables = [self allProcedureNames];
+ break;
+ case SPTableTypeFunc:
+ similarTables = [self allFunctionNames];
+ break;
+ default:
+ // if some other table type is given, just return yes
+ // better a mysql error than not being able to change something at all
+ return YES;
+ }
+
+ for(id table in similarTables) {
+ //compare case insensitive here
+ if([lowercaseFieldStr isEqualToString:[table lowercaseString]]) {
+ if (ignoreSelectedTable) {
+ // if table is the selectedTable, ignore it
+ // we must compare CASE SENSITIVE here!
+ if ([table isEqualToString:selectedTableName]) continue;
+ }
+ isValid = NO;
+ break;
+ }
+ }
+ return isValid;
+}
@end
diff --git a/Source/SPTextView.h b/Source/SPTextView.h
index 3954c941..bc4a3eb8 100644
--- a/Source/SPTextView.h
+++ b/Source/SPTextView.h
@@ -32,7 +32,11 @@
@class SPNarrowDownCompletion, SPDatabaseDocument, SPTablesList, SPCustomQuery;
-@interface SPTextView : NSTextView
+#ifndef SP_REFACTOR
+@interface SPTextView : NSTextView
+#else
+@interface SPTextView : NSTextView <NSTextStorageDelegate>
+#endif
{
IBOutlet SPDatabaseDocument *tableDocumentInstance;
IBOutlet SPTablesList *tablesListInstance;
@@ -43,18 +47,24 @@
BOOL autoindentIgnoresEnter;
BOOL autouppercaseKeywordsEnabled;
BOOL delBackwardsWasPressed;
+#ifndef SP_REFACTOR
BOOL autohelpEnabled;
+#endif
NoodleLineNumberView *lineNumberView;
BOOL startListeningToBoundChanges;
BOOL textBufferSizeIncreased;
+#ifndef SP_REFACTOR
NSString *showMySQLHelpFor;
+#endif
IBOutlet NSScrollView *scrollView;
SPNarrowDownCompletion *completionPopup;
+#ifndef SP_REFACTOR
NSUserDefaults *prefs;
+#endif
MCPConnection *mySQLConnection;
NSInteger mySQLmajorVersion;
@@ -102,7 +112,9 @@
@property(assign) BOOL completionIsOpen;
@property(assign) BOOL completionWasReinvokedAutomatically;
+#ifndef SP_REFACTOR
- (IBAction)showMySQLHelpForCurrentWord:(id)sender;
+#endif
- (BOOL) isNextCharMarkedBy:(id)attribute withValue:(id)aValue;
- (BOOL) areAdjacentCharsLinked;
@@ -119,12 +131,16 @@
- (BOOL) autopair;
- (void) setAutouppercaseKeywords:(BOOL)enableAutouppercaseKeywords;
- (BOOL) autouppercaseKeywords;
+#ifndef SP_REFACTOR
- (void) setAutohelp:(BOOL)enableAutohelp;
- (BOOL) autohelp;
+#endif
- (void) setTabStops;
- (void) selectLineNumber:(NSUInteger)lineNumber ignoreLeadingNewLines:(BOOL)ignLeadingNewLines;
- (NSUInteger) getLineNumberForCharacterIndex:(NSUInteger)anIndex;
+#ifndef SP_REFACTOR
- (void) autoHelp;
+#endif
- (void) doSyntaxHighlighting;
- (NSBezierPath*)roundedBezierPathAroundRange:(NSRange)aRange;
- (void) setConnection:(MCPConnection *)theConnection withVersion:(NSInteger)majorVersion;
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 4fef6ee3..fa01709e 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -112,9 +112,10 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
- (void) awakeFromNib
{
-
+#ifndef SP_REFACTOR /* init ivars */
prefs = [[NSUserDefaults standardUserDefaults] retain];
[self setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]];
+#endif
// Set self as delegate for the textView's textStorage to enable syntax highlighting,
[[self textStorage] setDelegate:self];
@@ -124,7 +125,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
autopairEnabled = YES;
autoindentIgnoresEnter = NO;
autouppercaseKeywordsEnabled = NO;
+#ifndef SP_REFACTOR
autohelpEnabled = NO;
+#endif
delBackwardsWasPressed = NO;
startListeningToBoundChanges = NO;
textBufferSizeIncreased = NO;
@@ -142,11 +145,20 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[scrollView setRulersVisible:YES];
[self setAllowsDocumentBackgroundColorChange:YES];
[self setContinuousSpellCheckingEnabled:NO];
+#ifndef SP_REFACTOR
[self setAutoindent:[prefs boolForKey:SPCustomQueryAutoIndent]];
+#else
+ [self setAutoindent:YES];
+#endif
[self setAutoindentIgnoresEnter:YES];
+#ifndef SP_REFACTOR
[self setAutopair:[prefs boolForKey:SPCustomQueryAutoPairCharacters]];
[self setAutohelp:[prefs boolForKey:SPCustomQueryUpdateAutoHelp]];
[self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]];
+#else
+ [self setAutopair:YES];
+ [self setAutouppercaseKeywords:YES];
+#endif
[self setCompletionWasReinvokedAutomatically:NO];
// Re-define tab stops for a better editing
@@ -159,6 +171,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[scrollView setPostsBoundsChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChangeNotification:) name:NSViewBoundsDidChangeNotification object:[scrollView contentView]];
+#ifndef SP_REFACTOR
[self setQueryHiliteColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorHighlightQueryColor]]];
[self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorBackgroundColor]]];
[self setCommentColor:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorCommentColor]]];
@@ -189,7 +202,22 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[prefs addObserver:self forKeyPath:SPCustomQueryEditorTextColor options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords options:NSKeyValueObservingOptionNew context:NULL];
+#else
+ [self setQueryHiliteColor:[NSColor whiteColor]];
+ [self setQueryEditorBackgroundColor:[NSColor whiteColor]];
+ [self setCommentColor:[NSColor darkGrayColor]];
+ [self setQuoteColor:[NSColor blueColor]];
+ [self setKeywordColor:[NSColor redColor]];
+ [self setBacktickColor:[NSColor purpleColor]];
+ [self setNumericColor:[NSColor blueColor]];
+ [self setVariableColor:[NSColor yellowColor]];
+ [self setOtherTextColor:[NSColor blackColor]];
+ [self setTextColor:otherTextColor];
+ [self setInsertionPointColor:[NSColor blackColor]];
+ [self setShouldHiliteQuery:YES];
+ [self setSelectedTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSBackgroundColorAttributeName, nil]];
+#endif
}
- (void) setConnection:(MCPConnection *)theConnection withVersion:(NSInteger)majorVersion
@@ -203,6 +231,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
+#ifndef SP_REFACTOR
if ([keyPath isEqualToString:SPCustomQueryEditorBackgroundColor]) {
[self setQueryEditorBackgroundColor:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
[self setNeedsDisplay:YES];
@@ -255,6 +284,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
} else if ([keyPath isEqualToString:SPCustomQueryAutoUppercaseKeywords]) {
[self setAutouppercaseKeywords:[prefs boolForKey:SPCustomQueryAutoUppercaseKeywords]];
}
+#endif
}
/**
@@ -375,7 +405,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if(!aDbName) {
// Try to suggest only items which are uniquely valid for the parsed string
- NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID] ignoreFields:YES];
+ NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[(NSObject*)[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID] ignoreFields:YES];
NSInteger uniqueSchemaKind = [[uniqueSchema objectAtIndex:0] intValue];
// If no db name but table name check if table name is a valid name in the current selected db
@@ -535,7 +565,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if(completionIsOpen || !self || ![self delegate]) return;
// Cancel autocompletion trigger
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -577,7 +609,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
// Cancel autocompletion trigger
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -770,7 +804,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
// Cancel autocompletion trigger again if user typed something in while parsing
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -982,7 +1018,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// If Extended Table Info tab is active delegate the print call to the SPPrintController
// if the user doesn't select anything in self
if([[[[self delegate] class] description] isEqualToString:@"SPExtendedTableInfo"] && ![self selectedRange].length) {
- [[[self delegate] valueForKeyPath:@"tableDocumentInstance"] printDocument:sender];
+ [[(NSObject*)[self delegate] valueForKeyPath:@"tableDocumentInstance"] printDocument:sender];
return;
}
@@ -1020,6 +1056,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.01];
}
+#ifndef SP_REFACTOR
/**
* Search for the current selection or current word in the MySQL Help
*/
@@ -1027,6 +1064,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
[customQueryInstance showHelpForCurrentWord:self];
}
+#endif
/**
* If the textview has a selection, wrap it with the supplied prefix and suffix strings;
@@ -1051,7 +1089,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self setSelectedRange:innerSelectionRange];
// If autopair is enabled mark last autopair character as autopair-linked
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoPairCharacters])
+#endif
[[self textStorage] addAttribute:kAPlinked value:kAPval range:NSMakeRange(NSMaxRange(innerSelectionRange), 1)];
return YES;
@@ -1133,6 +1173,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if (selectedRange.location == NSNotFound || ![self isEditable]) return NO;
NSString *indentString = @"\t";
+#ifndef SP_REFACTOR
if ([prefs boolForKey:SPCustomQuerySoftIndent]) {
NSUInteger numberOfSpaces = [prefs integerForKey:SPCustomQuerySoftIndentWidth];
if(numberOfSpaces < 1) numberOfSpaces = 1;
@@ -1142,6 +1183,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[spaces appendString:@" "];
indentString = [NSString stringWithString:spaces];
}
+#endif
// Indent the currently selected line if the caret is within a single line
if (selectedRange.length == 0) {
@@ -1222,6 +1264,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Check for soft indention
NSUInteger indentStringLength = 1;
+#ifndef SP_REFACTOR
if ([prefs boolForKey:SPCustomQuerySoftIndent]) {
NSUInteger numberOfSpaces = [prefs integerForKey:SPCustomQuerySoftIndentWidth];
if(numberOfSpaces < 1) numberOfSpaces = 1;
@@ -1234,8 +1277,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if(numberOfLeadingWhiteSpaces == NSNotFound) numberOfLeadingWhiteSpaces = 0;
replaceRange = NSMakeRange(currentLineRange.location, numberOfLeadingWhiteSpaces);
} else {
+#endif
replaceRange = NSMakeRange(currentLineRange.location, indentStringLength);
+#ifndef SP_REFACTOR
}
+#endif
// Register the undent for undo
[self shouldChangeTextInRange:replaceRange replacementString:@""];
@@ -1258,6 +1304,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Check for soft or hard indention
NSString *indentString = @"\t";
NSUInteger indentStringLength = 1;
+#ifndef SP_REFACTOR
if ([prefs boolForKey:SPCustomQuerySoftIndent]) {
indentStringLength = [prefs integerForKey:SPCustomQuerySoftIndentWidth];
if(indentStringLength < 1) indentStringLength = 1;
@@ -1267,6 +1314,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[spaces appendString:@" "];
indentString = [NSString stringWithString:spaces];
}
+#endif
// Check if blockRange starts with SPACE or TAB
// (this also catches the first line of the entire text buffer or
@@ -1321,7 +1369,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
// Cancel auto-completion timer
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -1362,7 +1412,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// }
// }
// } else {
- arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allTableAndViewNames]];
+ arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allTableAndViewNames]];
if(arr == nil) {
arr = [NSArray array];
}
@@ -1371,13 +1421,13 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// }
}
else if([kind isEqualToString:@"$SP_ASLIST_ALL_DATABASES"]) {
- arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allDatabaseNames]];
+ arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allDatabaseNames]];
if(arr == nil) {
arr = [NSArray array];
}
for(id w in arr)
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", @"database-small", @"image", @"", @"isRef", nil]];
- arr = [NSArray arrayWithArray:[[[self delegate] valueForKeyPath:@"tablesListInstance"] allSystemDatabaseNames]];
+ arr = [NSArray arrayWithArray:[[(NSObject*)[self delegate] valueForKeyPath:@"tablesListInstance"] allSystemDatabaseNames]];
if(arr == nil) {
arr = [NSArray array];
}
@@ -1733,6 +1783,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if (tablesListInstance && [tablesListInstance selectedDatabase])
currentDb = [tablesListInstance selectedDatabase];
+#ifndef SP_REFACTOR
while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLES"]) {
r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLES"];
if(r.length) {
@@ -1744,6 +1795,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
[theHintString flushCachedRegexData];
}
+#endif
while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"]) {
r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"];
@@ -1772,6 +1824,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[theHintString replaceOccurrencesOfRegex:@"\\\\(\\$\\(|\\}|\\$SP_)" withString:@"$1"];
[theHintString flushCachedRegexData];
+#ifndef SP_REFACTOR
// If inside the snippet hint $(…) is defined run … as BASH command
// and replace $(…) by the return string of that command. Please note
// only one $(…) statement is allowed within one ${…} snippet environment.
@@ -1794,6 +1847,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
}
[theHintString flushCachedRegexData];
+#endif
[snip replaceCharactersInRange:snipRange withString:theHintString];
[snip flushCachedRegexData];
@@ -1899,11 +1953,15 @@ 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 ([prefs boolForKey:SPCustomQueryAutoPairCharacters]
- && (([snip hasPrefix:@"("] && [snip hasSuffix:@")"])
- || ([snip hasPrefix:@"`"] && [snip hasSuffix:@"`"])
- || ([snip hasPrefix:@"'"] && [snip hasSuffix:@"'"])
- || ([snip hasPrefix:@"\""] && [snip hasSuffix:@"\""])))
+#ifndef SP_REFACTOR
+ if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] &&
+#else
+ if (
+#endif
+ (([snip hasPrefix:@"("] && [snip hasSuffix:@")"])
+ || ([snip hasPrefix:@"`"] && [snip hasSuffix:@"`"])
+ || ([snip hasPrefix:@"'"] && [snip hasSuffix:@"'"])
+ || ([snip hasPrefix:@"\""] && [snip hasSuffix:@"\""])))
{
[[self textStorage] addAttribute:kAPlinked value:kAPval range:NSMakeRange([self selectedRange].location - 1, 1)];
}
@@ -2019,23 +2077,28 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
// Cancel autoHelp timer
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryUpdateAutoHelp])
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(autoHelp)
object:nil];
+#endif
// Cancel auto-completion timer
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
[super mouseDown:theEvent];
+#ifndef SP_REFACTOR
// Start autoHelp timer
if([prefs boolForKey:SPCustomQueryUpdateAutoHelp])
[self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[prefs valueForKey:SPCustomQueryAutoHelpDelay] doubleValue]];
-
+#endif
}
/**
@@ -2043,6 +2106,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
*/
- (void) keyDown:(NSEvent *)theEvent
{
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryUpdateAutoHelp]) {// restart autoHelp timer
[NSObject cancelPreviousPerformRequestsWithTarget:self
@@ -2051,9 +2115,12 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self performSelector:@selector(autoHelp) withObject:nil
afterDelay:[[prefs valueForKey:SPCustomQueryAutoHelpDelay] doubleValue]];
}
+#endif
// Cancel auto-completion timer
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -2081,7 +2148,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self setCompletionWasReinvokedAutomatically:NO];
completionWasRefreshed = NO;
// Cancel autocompletion trigger
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -2156,11 +2225,14 @@ 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;
}
+#endif
}
+#ifndef SP_REFACTOR
// Note: switch(insertedCharacter) {} does not work instead use charactersIgnoringModifiers
if([charactersIgnMod isEqualToString:@"h"]) // ^H show MySQL Help
if(curFlags==(NSControlKeyMask))
@@ -2168,6 +2240,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self showMySQLHelpForCurrentWord:self];
return;
}
+#endif
if([charactersIgnMod isEqualToString:@"y"]) // ^Y select current query
if(curFlags==(NSControlKeyMask))
{
@@ -2188,14 +2261,20 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if([charactersIgnMod isEqualToString:@"0"]) { // reset font to default
BOOL editableStatus = [self isEditable];
[self setEditable:YES];
+#ifndef SP_REFACTOR
[self setFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]];
+#endif
[self setEditable:editableStatus];
return;
}
}
// Only process for character autopairing if autopairing is enabled and a single character is being added.
+#ifndef SP_REFACTOR
if ([prefs boolForKey:SPCustomQueryAutoPairCharacters] && characters && [characters length] == 1) {
+#else
+ if (characters && [characters length] == 1) {
+#endif
delBackwardsWasPressed = NO;
@@ -2400,7 +2479,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
// Remove soft indent if active and left from caret are only white spaces
+#ifndef SP_REFACTOR
else if ([prefs boolForKey:SPCustomQuerySoftIndent] && [self isCaretAtIndentPositionIgnoreLineStart:NO])
+#else
+ else if ([self isCaretAtIndentPositionIgnoreLineStart:NO])
+#endif
{
[self shiftSelectionLeft];
return;
@@ -2422,7 +2505,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Handle newlines, adding any indentation found on the current line to the new line - ignoring the enter key if appropriate
if (aSelector == @selector(insertNewline:)
+#ifndef SP_REFACTOR
&& [prefs boolForKey:SPCustomQueryAutoIndent]
+#endif
&& (!autoindentIgnoresEnter || [[NSApp currentEvent] keyCode] != 0x4C))
{
NSString *textViewString = [[self textStorage] string];
@@ -2460,6 +2545,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
}
// Remove soft indent if active and left from caret are only white spaces
+#ifndef SP_REFACTOR
if (aSelector == @selector(deleteForward:)
&& ![self selectedRange].length
&& [prefs boolForKey:SPCustomQuerySoftIndent]
@@ -2469,6 +2555,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self shiftSelectionLeft];
return;
}
+#endif
[super doCommandBySelector:aSelector];
}
@@ -2522,6 +2609,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
return autopairEnabled;
}
+#ifndef SP_REFACTOR
/**
* Set whether MySQL Help should be automatically invoked while typing.
*/
@@ -2537,6 +2625,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
{
return autohelpEnabled;
}
+#endif
/**
* Set whether SQL keywords should be automatically uppercased.
@@ -2562,7 +2651,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
- (void)autoHelp
{
+#ifndef SP_REFACTOR
if(![prefs boolForKey:SPCustomQueryUpdateAutoHelp] || ![[self string] length]) return;
+#else
+ if(![[self string] length]) return;
+#endif
// If selection show Help for it
if([self selectedRange].length)
@@ -2784,7 +2877,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
- (void) setTabStops
{
+#ifndef SP_REFACTOR
NSFont *tvFont = [self font];
+#else
+ NSFont* tvFont = [NSFont userFixedPitchFontOfSize:10.0];
+#endif
NSInteger i;
NSTextTab *aTab;
NSMutableArray *myArrayOfTabs;
@@ -2793,7 +2890,11 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
BOOL oldEditableStatus = [self isEditable];
[self setEditable:YES];
+#ifndef SP_REFACTOR
NSInteger tabStopWidth = [prefs integerForKey:SPCustomQueryEditorTabStopWidth];
+#else
+ NSInteger tabStopWidth = 4;
+#endif
if(tabStopWidth < 1) tabStopWidth = 1;
float tabWidth = NSSizeToCGSize([[NSString stringWithString:@" "] sizeWithAttributes:[NSDictionary dictionaryWithObject:tvFont forKey:NSFontAttributeName]]).width;
@@ -2960,11 +3061,13 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
*/
- (NSMenu *)menuForEvent:(NSEvent *)event
{
+#ifndef SP_REFACTOR
// Set title of the menu item
if([self selectedRange].length)
showMySQLHelpFor = NSLocalizedString(@"MySQL Help for Selection", @"MySQL Help for Selection");
else
showMySQLHelpFor = NSLocalizedString(@"MySQL Help for Word", @"MySQL Help for Word");
+#endif
// Add the menu items for
// - MySQL Help for Word/Selection
@@ -2973,6 +3076,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// if it doesn't yet exist
NSMenu *menu = [[self class] defaultMenu];
+#ifndef SP_REFACTOR
if ([[[self class] defaultMenu] itemWithTag:SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG] == nil)
{
[menu insertItem:[NSMenuItem separatorItem] atIndex:3];
@@ -2984,6 +3088,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
} else {
[[menu itemWithTag:SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG] setTitle:showMySQLHelpFor];
}
+#endif
if ([[[self class] defaultMenu] itemWithTag:SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG] == nil)
{
NSMenuItem *copyAsRTFMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Copy as RTF", @"Copy as RTF") action:@selector(copyAsRTF) keyEquivalent:@""];
@@ -3010,6 +3115,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[[menu itemAtIndex:6] setHidden:YES];
}
+#ifndef SP_REFACTOR
[[NSApp delegate] reloadBundles:self];
// Remove 'Bundles' sub menu and separator
@@ -3074,6 +3180,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[bundleSubMenuItem release];
}
+#endif
return menu;
@@ -3147,7 +3254,9 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
if (textStore!=[self textStorage]) return;
// Cancel autocompletion trigger
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryAutoComplete])
+#endif
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(doAutoCompletion)
object:nil];
@@ -3155,13 +3264,20 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
NSInteger editedMask = [textStore editedMask];
// Start autohelp only if the user really changed the text (not e.g. for setting a background color)
+#ifndef SP_REFACTOR
if([prefs boolForKey:SPCustomQueryUpdateAutoHelp] && editedMask != 1) {
[self performSelector:@selector(autoHelp) withObject:nil afterDelay:[[prefs valueForKey:SPCustomQueryAutoHelpDelay] doubleValue]];
}
+#endif
// Start autocompletion if enabled
+#ifndef SP_REFACTOR
if([[NSApp keyWindow] firstResponder] == self && [prefs boolForKey:SPCustomQueryAutoComplete] && !completionIsOpen && editedMask != 1 && [textStore changeInLength] == 1)
[self performSelector:@selector(doAutoCompletion) withObject:nil afterDelay:[[prefs valueForKey:SPCustomQueryAutoCompleteDelay] doubleValue]];
+#else
+ if([[NSApp keyWindow] firstResponder] == self && !completionIsOpen && editedMask != 1 && [textStore changeInLength] == 1)
+ [self performSelector:@selector(doAutoCompletion) withObject:nil afterDelay:1.5];
+#endif
// Cancel calling doSyntaxHighlighting for large text
if([[self string] length] > SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING)
@@ -3488,6 +3604,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
- (void)changeFont:(id)sender
{
+#ifndef SP_REFACTOR
if (prefs && [self font] != nil) {
[prefs setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:SPCustomQueryEditorFont];
NSFont *nf = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:SPCustomQueryEditorFont]]];
@@ -3498,6 +3615,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[self setNeedsDisplay:YES];
[prefs setObject:[NSArchiver archivedDataWithRootObject:nf] forKey:SPCustomQueryEditorFont];
}
+#endif
}
#pragma mark -
@@ -3513,6 +3631,7 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
// Remove observers
[[NSNotificationCenter defaultCenter] removeObserver:self];
+#ifndef SP_REFACTOR
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorFont];
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorBackgroundColor];
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorHighlightQueryColor];
@@ -3526,9 +3645,12 @@ NSInteger _alphabeticSort(id string1, id string2, void *reverse)
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorTextColor];
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth];
[prefs removeObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords];
+#endif
if (completionIsOpen) [completionPopup close], completionIsOpen = NO;
+#ifndef SP_REFACTOR
[prefs release];
+#endif
[lineNumberView release];
if(queryHiliteColor) [queryHiliteColor release];
if(queryEditorBackgroundColor) [queryEditorBackgroundColor release];
diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h
index 013d8872..e95b7041 100644
--- a/Source/SPTextViewAdditions.h
+++ b/Source/SPTextViewAdditions.h
@@ -42,9 +42,12 @@
- (IBAction)moveSelectionLineUp:(id)sender;
- (IBAction)moveSelectionLineDown:(id)sender;
+#ifndef SP_REFACTOR
- (IBAction)executeBundleItemForInputField:(id)sender;
+#endif
- (void)makeTextSizeLarger;
- (void)makeTextSizeSmaller;
+- (void)makeTextStandardSize;
@end
diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m
index 0d3b4b8e..b2a2354b 100644
--- a/Source/SPTextViewAdditions.m
+++ b/Source/SPTextViewAdditions.m
@@ -389,7 +389,6 @@
*/
- (IBAction)insertNULLvalue:(id)sender
{
-
id prefs = [NSUserDefaults standardUserDefaults];
if ([self respondsToSelector:@selector(insertText:)]) {
if([prefs stringForKey:SPNullValue] && [[prefs stringForKey:SPNullValue] length])
@@ -482,6 +481,19 @@
[self setEditable:editableStatus];
}
+/**
+ * Increase the textView's font size by 1
+ */
+- (void)makeTextStandardSize
+{
+ NSFont *aFont = [self font];
+ BOOL editableStatus = [self isEditable];
+ [self setEditable:YES];
+ [self setFont:[[NSFontManager sharedFontManager] convertFont:aFont toSize:11.0f]];
+ [self setEditable:editableStatus];
+}
+
+#ifndef SP_REFACTOR
- (IBAction)executeBundleItemForInputField:(id)sender
{
@@ -859,5 +871,6 @@
else if([anEvent deltaZ]<-5.0)
[self makeTextSizeSmaller];
}
+#endif
@end