Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/mergeclasses'
Conflicts:
	Source/SPQueryControllerInitializer.m
	Source/SPQueryDocumentsController.m
	Source/SPQueryFavoriteManager.m
  • Loading branch information
dmoagx committed Jan 20, 2018
2 parents ef21bc5 + b04243d commit d403528
Show file tree
Hide file tree
Showing 136 changed files with 9,910 additions and 13,126 deletions.
2 changes: 1 addition & 1 deletion Source/MGTemplateEngine.m
Expand Up @@ -28,7 +28,7 @@
#define GLOBAL_DELIM_EXPR_END @"expressionEnd"
#define GLOBAL_DELIM_FILTER @"filter"

@interface MGTemplateEngine (PrivateMethods)
@interface MGTemplateEngine ()

- (NSObject *)valueForVariable:(NSString *)var parent:(NSObject **)parent parentKey:(NSString **)parentKey;
- (void)setValue:(NSObject *)newValue forVariable:(NSString *)var forceCurrentStackFrame:(BOOL)inStackFrame;
Expand Down
2 changes: 1 addition & 1 deletion Source/NoodleLineNumberView.m
Expand Up @@ -53,7 +53,7 @@

#pragma mark -

@interface NoodleLineNumberView (Private)
@interface NoodleLineNumberView ()

- (NSArray *)lineIndices;
- (void)invalidateLineIndices;
Expand Down
6 changes: 2 additions & 4 deletions Source/SPActivityTextFieldCell.m
Expand Up @@ -33,7 +33,7 @@

#define FAVORITE_NAME_FONT_SIZE 12.0f

@interface SPActivityTextFieldCell (PrivateAPI)
@interface SPActivityTextFieldCell ()

- (NSAttributedString *)constructSubStringAttributedString;
- (NSAttributedString *)attributedStringForFavoriteName;
Expand Down Expand Up @@ -332,9 +332,7 @@ - (void)dealloc
[super dealloc];
}

@end

@implementation SPActivityTextFieldCell (PrivateAPI)
#pragma mark - Private API

/**
* Constructs the attributed string to be used as the cell's substring.
Expand Down
22 changes: 22 additions & 0 deletions Source/SPAppController.h
Expand Up @@ -37,6 +37,7 @@
@class SPAboutController;
@class SPDatabaseDocument;
@class SPBundleEditorController;
@class SPWindowController;

@interface SPAppController : NSObject <FRFeedbackReporterDelegate, NSApplicationDelegate, NSOpenSavePanelDelegate, NSFileManagerDelegate>
{
Expand Down Expand Up @@ -116,4 +117,25 @@
- (void)addHTMLOutputController:(id)controller;
- (void)removeHTMLOutputController:(id)controller;

#pragma mark - SPAppleScriptSupport

- (NSArray *)orderedDocuments;
- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc;
- (NSArray *)orderedWindows;
- (id)handleQuitScriptCommand:(NSScriptCommand *)command;
- (id)handleOpenScriptCommand:(NSScriptCommand *)command;

#pragma mark - SPWindowManagement

- (IBAction)newWindow:(id)sender;
- (IBAction)newTab:(id)sender;
- (IBAction)duplicateTab:(id)sender;

- (SPWindowController *)newWindow;
- (SPDatabaseDocument *)makeNewConnectionTabOrWindow;
- (SPWindowController *)frontController;

- (NSWindow *)frontDocumentWindow;
- (void)tabDragStarted:(id)sender;

@end
239 changes: 238 additions & 1 deletion Source/SPAppController.m
Expand Up @@ -47,7 +47,6 @@
#import "SPFavoritesController.h"
#import "SPEditorTokens.h"
#import "SPBundleCommandRunner.h"
#import "SPWindowManagement.h"
#import "SPCopyTable.h"
#import "SPSyntaxParser.h"
#import "SPOSInfo.h"
Expand Down Expand Up @@ -2362,6 +2361,244 @@ - (void)_copyDefaultThemes
}
}

#pragma mark - SPAppleScriptSupport

/**
* Is needed to interact with AppleScript for set/get internal SP variables
*/
- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key
{
NSLog(@"Not yet implemented.");

return NO;
}

/**
* AppleScript call to get the available documents.
*/
- (NSArray *)orderedDocuments
{
NSMutableArray *orderedDocuments = [NSMutableArray array];

for (NSWindow *aWindow in [self orderedWindows])
{
if ([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
[orderedDocuments addObjectsFromArray:[[aWindow windowController] documents]];
}
}

return orderedDocuments;
}

/**
* AppleScript support for 'make new document'.
*
* TODO: following tab support this has been disabled - need to discuss reimplmenting vs syntax.
*/
- (void)insertInOrderedDocuments:(SPDatabaseDocument *)doc
{
[self newWindow:self];

// Set autoconnection if appropriate
if ([[NSUserDefaults standardUserDefaults] boolForKey:SPAutoConnectToDefault]) {
[[self frontDocument] connect];
}
}

/**
* AppleScript call to get the available windows.
*/
- (NSArray *)orderedWindows
{
return [NSApp orderedWindows];
}

/**
* AppleScript handler to quit Sequel Pro
*
* This handler is required to allow termination via the Dock or AppleScript event after activating it using AppleScript
*/
- (id)handleQuitScriptCommand:(NSScriptCommand *)command
{
[NSApp terminate:self];

return nil;
}

/**
* AppleScript open handler
*
* This handler is required to catch the 'open' command if no argument was passed which would cause a crash.
*/
- (id)handleOpenScriptCommand:(NSScriptCommand *)command
{
return nil;
}

/**
* AppleScript print handler
*
* This handler prints the active view.
*/
- (id)handlePrintScriptCommand:(NSScriptCommand *)command
{
SPDatabaseDocument *frontDoc = [self frontDocument];

if (frontDoc && ![frontDoc isWorking] && ![[frontDoc connectionID] isEqualToString:@"_"]) {
[frontDoc startPrintDocumentOperation];
}

return nil;
}

#pragma mark - SPWindowManagement

- (IBAction)newWindow:(id)sender
{
[self newWindow];
}

/**
* Create a new window, containing a single tab.
*/
- (SPWindowController *)newWindow
{
static NSPoint cascadeLocation = {.x = 0, .y = 0};

// Create a new window controller, and set up a new connection view within it.
SPWindowController *newWindowController = [[SPWindowController alloc] initWithWindowNibName:@"MainWindow"];
NSWindow *newWindow = [newWindowController window];

// Cascading defaults to on - retrieve the window origin automatically assigned by cascading,
// and convert to a top left point.
NSPoint topLeftPoint = [newWindow frame].origin;
topLeftPoint.y += [newWindow frame].size.height;

// The first window should use autosaving; subsequent windows should cascade.
// So attempt to set the frame autosave name; this will succeed for the very
// first window, and fail for others.
BOOL usedAutosave = [newWindow setFrameAutosaveName:@"DBView"];

if (!usedAutosave) {
[newWindow setFrameUsingName:@"DBView"];
}

// Add the connection view
[newWindowController addNewConnection];

// Cascade according to the statically stored cascade location.
cascadeLocation = [newWindow cascadeTopLeftFromPoint:cascadeLocation];

// Set the window controller as the window's delegate
[newWindow setDelegate:newWindowController];

// Show the window, and perform frontmost tasks again once the window has drawn
[newWindowController showWindow:self];
[[newWindowController selectedTableDocument] didBecomeActiveTabInWindow];

return newWindowController;
}

/**
* Create a new tab in the frontmost window.
*/
- (IBAction)newTab:(id)sender
{
SPWindowController *frontController = [self frontController];

// If no window was found, create a new one
if (!frontController) {
[self newWindow:self];
}
else {
if ([[frontController window] isMiniaturized]) {
[[frontController window] deminiaturize:self];
}

[frontController addNewConnection:self];
}
}

- (SPDatabaseDocument *)makeNewConnectionTabOrWindow
{
SPWindowController *frontController = [self frontController];

SPDatabaseDocument *frontDocument;
// If no window was found or the front most window has no tabs, create a new one
if (!frontController || [[frontController valueForKeyPath:@"tabView"] numberOfTabViewItems] == 1) {
frontController = [self newWindow];
frontDocument = [frontController selectedTableDocument];
}
// Open the spf file in a new tab if the tab bar is visible
else {
if ([[frontController window] isMiniaturized]) [[frontController window] deminiaturize:self];
frontDocument = [frontController addNewConnection];
}

return frontDocument;
}

/**
* Duplicate the current connection tab
*/
- (IBAction)duplicateTab:(id)sender
{
SPDatabaseDocument *theFrontDocument = [self frontDocument];

if (!theFrontDocument) return [self newTab:sender];

// Add a new tab to the window
if ([[self frontDocumentWindow] isMiniaturized]) {
[[self frontDocumentWindow] deminiaturize:self];
}

SPDatabaseDocument *newConnection = [[self frontController] addNewConnection];

// Get the state of the previously-frontmost document
NSDictionary *allStateDetails = @{
@"connection" : @YES,
@"history" : @YES,
@"session" : @YES,
@"query" : @YES,
@"password" : @YES
};

NSMutableDictionary *frontState = [NSMutableDictionary dictionaryWithDictionary:[theFrontDocument stateIncludingDetails:allStateDetails]];

// Ensure it's set to autoconnect
[frontState setObject:@YES forKey:@"auto_connect"];

// Set the connection on the new tab
[newConnection setState:frontState];
}

/**
* Retrieve the frontmost document window; returns nil if not found.
*/
- (NSWindow *)frontDocumentWindow
{
return [[self frontController] window];
}

- (SPWindowController *)frontController
{
for (NSWindow *aWindow in [NSApp orderedWindows]) {
id ctr = [aWindow windowController];
if ([ctr isMemberOfClass:[SPWindowController class]]) {
return ctr;
}
}
return nil;
}

/**
* When tab drags start, bring all the windows in front of other applications.
*/
- (void)tabDragStarted:(id)sender
{
[NSApp arrangeInFront:self];
}

#pragma mark -

- (void)dealloc
Expand Down
41 changes: 0 additions & 41 deletions Source/SPAppleScriptSupport.h

This file was deleted.

0 comments on commit d403528

Please sign in to comment.