Skip to content

Commit d403528

Browse files
committed
Merge remote-tracking branch 'origin/mergeclasses'
Conflicts: Source/SPQueryControllerInitializer.m Source/SPQueryDocumentsController.m Source/SPQueryFavoriteManager.m
2 parents ef21bc5 + b04243d commit d403528

File tree

136 files changed

+9910
-13126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+9910
-13126
lines changed

Source/MGTemplateEngine.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define GLOBAL_DELIM_EXPR_END @"expressionEnd"
2929
#define GLOBAL_DELIM_FILTER @"filter"
3030

31-
@interface MGTemplateEngine (PrivateMethods)
31+
@interface MGTemplateEngine ()
3232

3333
- (NSObject *)valueForVariable:(NSString *)var parent:(NSObject **)parent parentKey:(NSString **)parentKey;
3434
- (void)setValue:(NSObject *)newValue forVariable:(NSString *)var forceCurrentStackFrame:(BOOL)inStackFrame;

Source/NoodleLineNumberView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
#pragma mark -
5555

56-
@interface NoodleLineNumberView (Private)
56+
@interface NoodleLineNumberView ()
5757

5858
- (NSArray *)lineIndices;
5959
- (void)invalidateLineIndices;

Source/SPActivityTextFieldCell.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#define FAVORITE_NAME_FONT_SIZE 12.0f
3535

36-
@interface SPActivityTextFieldCell (PrivateAPI)
36+
@interface SPActivityTextFieldCell ()
3737

3838
- (NSAttributedString *)constructSubStringAttributedString;
3939
- (NSAttributedString *)attributedStringForFavoriteName;
@@ -332,9 +332,7 @@ - (void)dealloc
332332
[super dealloc];
333333
}
334334

335-
@end
336-
337-
@implementation SPActivityTextFieldCell (PrivateAPI)
335+
#pragma mark - Private API
338336

339337
/**
340338
* Constructs the attributed string to be used as the cell's substring.

Source/SPAppController.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@class SPAboutController;
3838
@class SPDatabaseDocument;
3939
@class SPBundleEditorController;
40+
@class SPWindowController;
4041

4142
@interface SPAppController : NSObject <FRFeedbackReporterDelegate, NSApplicationDelegate, NSOpenSavePanelDelegate, NSFileManagerDelegate>
4243
{
@@ -116,4 +117,25 @@
116117
- (void)addHTMLOutputController:(id)controller;
117118
- (void)removeHTMLOutputController:(id)controller;
118119

120+
#pragma mark - SPAppleScriptSupport
121+
122+
- (NSArray *)orderedDocuments;
123+
- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc;
124+
- (NSArray *)orderedWindows;
125+
- (id)handleQuitScriptCommand:(NSScriptCommand *)command;
126+
- (id)handleOpenScriptCommand:(NSScriptCommand *)command;
127+
128+
#pragma mark - SPWindowManagement
129+
130+
- (IBAction)newWindow:(id)sender;
131+
- (IBAction)newTab:(id)sender;
132+
- (IBAction)duplicateTab:(id)sender;
133+
134+
- (SPWindowController *)newWindow;
135+
- (SPDatabaseDocument *)makeNewConnectionTabOrWindow;
136+
- (SPWindowController *)frontController;
137+
138+
- (NSWindow *)frontDocumentWindow;
139+
- (void)tabDragStarted:(id)sender;
140+
119141
@end

Source/SPAppController.m

Lines changed: 238 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#import "SPFavoritesController.h"
4848
#import "SPEditorTokens.h"
4949
#import "SPBundleCommandRunner.h"
50-
#import "SPWindowManagement.h"
5150
#import "SPCopyTable.h"
5251
#import "SPSyntaxParser.h"
5352
#import "SPOSInfo.h"
@@ -2362,6 +2361,244 @@ - (void)_copyDefaultThemes
23622361
}
23632362
}
23642363

2364+
#pragma mark - SPAppleScriptSupport
2365+
2366+
/**
2367+
* Is needed to interact with AppleScript for set/get internal SP variables
2368+
*/
2369+
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
2370+
{
2371+
NSLog(@"Not yet implemented.");
2372+
2373+
return NO;
2374+
}
2375+
2376+
/**
2377+
* AppleScript call to get the available documents.
2378+
*/
2379+
- (NSArray *)orderedDocuments
2380+
{
2381+
NSMutableArray *orderedDocuments = [NSMutableArray array];
2382+
2383+
for (NSWindow *aWindow in [self orderedWindows])
2384+
{
2385+
if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
2386+
[orderedDocuments addObjectsFromArray:[[aWindow windowController] documents]];
2387+
}
2388+
}
2389+
2390+
return orderedDocuments;
2391+
}
2392+
2393+
/**
2394+
* AppleScript support for 'make new document'.
2395+
*
2396+
* TODO: following tab support this has been disabled - need to discuss reimplmenting vs syntax.
2397+
*/
2398+
- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc
2399+
{
2400+
[self newWindow:self];
2401+
2402+
// Set autoconnection if appropriate
2403+
if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
2404+
[[self frontDocument] connect];
2405+
}
2406+
}
2407+
2408+
/**
2409+
* AppleScript call to get the available windows.
2410+
*/
2411+
- (NSArray *)orderedWindows
2412+
{
2413+
return [NSApp orderedWindows];
2414+
}
2415+
2416+
/**
2417+
* AppleScript handler to quit Sequel Pro
2418+
*
2419+
* This handler is required to allow termination via the Dock or AppleScript event after activating it using AppleScript
2420+
*/
2421+
- (id)handleQuitScriptCommand:(NSScriptCommand *)command
2422+
{
2423+
[NSApp terminate:self];
2424+
2425+
return nil;
2426+
}
2427+
2428+
/**
2429+
* AppleScript open handler
2430+
*
2431+
* This handler is required to catch the 'open' command if no argument was passed which would cause a crash.
2432+
*/
2433+
- (id)handleOpenScriptCommand:(NSScriptCommand *)command
2434+
{
2435+
return nil;
2436+
}
2437+
2438+
/**
2439+
* AppleScript print handler
2440+
*
2441+
* This handler prints the active view.
2442+
*/
2443+
- (id)handlePrintScriptCommand:(NSScriptCommand *)command
2444+
{
2445+
SPDatabaseDocument *frontDoc = [self frontDocument];
2446+
2447+
if (frontDoc && ![frontDoc isWorking] && ![[frontDoc connectionID] isEqualToString:@"_"]) {
2448+
[frontDoc startPrintDocumentOperation];
2449+
}
2450+
2451+
return nil;
2452+
}
2453+
2454+
#pragma mark - SPWindowManagement
2455+
2456+
- (IBAction)newWindow:(id)sender
2457+
{
2458+
[self newWindow];
2459+
}
2460+
2461+
/**
2462+
* Create a new window, containing a single tab.
2463+
*/
2464+
- (SPWindowController *)newWindow
2465+
{
2466+
static NSPoint cascadeLocation = {.x = 0, .y = 0};
2467+
2468+
// Create a new window controller, and set up a new connection view within it.
2469+
SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"];
2470+
NSWindow *newWindow = [newWindowController window];
2471+
2472+
// Cascading defaults to on - retrieve the window origin automatically assigned by cascading,
2473+
// and convert to a top left point.
2474+
NSPoint topLeftPoint = [newWindow frame].origin;
2475+
topLeftPoint.y += [newWindow frame].size.height;
2476+
2477+
// The first window should use autosaving; subsequent windows should cascade.
2478+
// So attempt to set the frame autosave name; this will succeed for the very
2479+
// first window, and fail for others.
2480+
BOOL usedAutosave = [newWindow setFrameAutosaveName:@"DBView"];
2481+
2482+
if (!usedAutosave) {
2483+
[newWindow setFrameUsingName:@"DBView"];
2484+
}
2485+
2486+
// Add the connection view
2487+
[newWindowController addNewConnection];
2488+
2489+
// Cascade according to the statically stored cascade location.
2490+
cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation];
2491+
2492+
// Set the window controller as the window's delegate
2493+
[newWindow setDelegate:newWindowController];
2494+
2495+
// Show the window, and perform frontmost tasks again once the window has drawn
2496+
[newWindowController showWindow:self];
2497+
[[newWindowController selectedTableDocument] didBecomeActiveTabInWindow];
2498+
2499+
return newWindowController;
2500+
}
2501+
2502+
/**
2503+
* Create a new tab in the frontmost window.
2504+
*/
2505+
- (IBAction)newTab:(id)sender
2506+
{
2507+
SPWindowController *frontController = [self frontController];
2508+
2509+
// If no window was found, create a new one
2510+
if (!frontController) {
2511+
[self newWindow:self];
2512+
}
2513+
else {
2514+
if ([[frontController window] isMiniaturized]) {
2515+
[[frontController window] deminiaturize:self];
2516+
}
2517+
2518+
[frontController addNewConnection:self];
2519+
}
2520+
}
2521+
2522+
- (SPDatabaseDocument *)makeNewConnectionTabOrWindow
2523+
{
2524+
SPWindowController *frontController = [self frontController];
2525+
2526+
SPDatabaseDocument *frontDocument;
2527+
// If no window was found or the front most window has no tabs, create a new one
2528+
if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
2529+
frontController = [self newWindow];
2530+
frontDocument = [frontController selectedTableDocument];
2531+
}
2532+
// Open the spf file in a new tab if the tab bar is visible
2533+
else {
2534+
if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
2535+
frontDocument = [frontController addNewConnection];
2536+
}
2537+
2538+
return frontDocument;
2539+
}
2540+
2541+
/**
2542+
* Duplicate the current connection tab
2543+
*/
2544+
- (IBAction)duplicateTab:(id)sender
2545+
{
2546+
SPDatabaseDocument *theFrontDocument = [self frontDocument];
2547+
2548+
if (!theFrontDocument) return [self newTab:sender];
2549+
2550+
// Add a new tab to the window
2551+
if ([[self frontDocumentWindow] isMiniaturized]) {
2552+
[[self frontDocumentWindow] deminiaturize:self];
2553+
}
2554+
2555+
SPDatabaseDocument *newConnection = [[self frontController] addNewConnection];
2556+
2557+
// Get the state of the previously-frontmost document
2558+
NSDictionary *allStateDetails = @{
2559+
@"connection" : @YES,
2560+
@"history" : @YES,
2561+
@"session" : @YES,
2562+
@"query" : @YES,
2563+
@"password" : @YES
2564+
};
2565+
2566+
NSMutableDictionary *frontState = [NSMutableDictionary dictionaryWithDictionary:[theFrontDocument stateIncludingDetails:allStateDetails]];
2567+
2568+
// Ensure it's set to autoconnect
2569+
[frontState setObject:@YES forKey:@"auto_connect"];
2570+
2571+
// Set the connection on the new tab
2572+
[newConnection setState:frontState];
2573+
}
2574+
2575+
/**
2576+
* Retrieve the frontmost document window; returns nil if not found.
2577+
*/
2578+
- (NSWindow *)frontDocumentWindow
2579+
{
2580+
return [[self frontController] window];
2581+
}
2582+
2583+
- (SPWindowController *)frontController
2584+
{
2585+
for (NSWindow *aWindow in [NSApp orderedWindows]) {
2586+
id ctr = [aWindow windowController];
2587+
if ([ctr isMemberOfClass:[SPWindowController class]]) {
2588+
return ctr;
2589+
}
2590+
}
2591+
return nil;
2592+
}
2593+
2594+
/**
2595+
* When tab drags start, bring all the windows in front of other applications.
2596+
*/
2597+
- (void)tabDragStarted:(id)sender
2598+
{
2599+
[NSApp arrangeInFront:self];
2600+
}
2601+
23652602
#pragma mark -
23662603

23672604
- (void)dealloc

Source/SPAppleScriptSupport.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)