aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionControllerInitializer.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-05-02 13:12:38 +0000
committerstuconnolly <stuart02@gmail.com>2012-05-02 13:12:38 +0000
commit5d87f0f50fc90c7ed47ff82b35f07b2749262132 (patch)
tree37ab959b7385c8f5aaf2d1465e1f19fbd47247c7 /Source/SPConnectionControllerInitializer.m
parentdea294a90f9bf6017986f9c950991a7fc7c9645e (diff)
parentfe555b6d511a51f3bdfb5c0a2b00a3206993076b (diff)
downloadsequelpro-5d87f0f50fc90c7ed47ff82b35f07b2749262132.tar.gz
sequelpro-5d87f0f50fc90c7ed47ff82b35f07b2749262132.tar.bz2
sequelpro-5d87f0f50fc90c7ed47ff82b35f07b2749262132.zip
Merge outline view branch into trunk.
Adds support for managing and grouping favorites into folders in the connection view and removes the associated favorites management from the preferences window. NOTE: On first launch your connection favorites will be migrated from Sequel Pro's preference file to a new file in ~/Application Support/Sequel Pro/Data. Your old favorites will remain in the preference file until removed in a future version. Outstanding known issues: - Removing a group node with no child favorites presents a warning about also removing the non-existent favorites. - Starting the application with no favorites, creating a group node then selecting, hides the connection details input. Doesn't support emoty selection. - Setting the name of a connection, adding it to the favorites and then swicthing to a different connection type, screws with the favorite name. - The preservation between launches of whether group nodes are collapsed or not is currently not supported.
Diffstat (limited to 'Source/SPConnectionControllerInitializer.m')
-rw-r--r--Source/SPConnectionControllerInitializer.m271
1 files changed, 271 insertions, 0 deletions
diff --git a/Source/SPConnectionControllerInitializer.m b/Source/SPConnectionControllerInitializer.m
new file mode 100644
index 00000000..34f9ca40
--- /dev/null
+++ b/Source/SPConnectionControllerInitializer.m
@@ -0,0 +1,271 @@
+//
+// $Id$
+//
+// SPConnectionControllerInitializer.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on January 22, 2012
+// Copyright (c) 2012 Stuart Connolly. All rights reserved.
+//
+// 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
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPConnectionControllerInitializer.h"
+#import "SPKeychain.h"
+#import "SPFavoritesController.h"
+#import "SPFavoriteNode.h"
+#import "SPDatabaseViewController.h"
+
+static NSString *SPConnectionViewNibName = @"ConnectionView";
+
+@interface SPConnectionController ()
+
+- (void)_reloadFavoritesViewData;
+- (void)_selectNode:(SPTreeNode *)node;
+
+- (SPTreeNode *)_favoriteNodeForFavoriteID:(NSInteger)favoriteID;
+
+@end
+
+@implementation SPConnectionController (SPConnectionControllerInitializer)
+
+/**
+ * Initialise the connection controller, linking it to the parent document and setting up the parent window.
+ */
+- (id)initWithDocument:(SPDatabaseDocument *)document
+{
+ if ((self = [super init])) {
+
+ // Weak reference
+ dbDocument = document;
+
+ databaseConnectionSuperview = [dbDocument databaseView];
+ databaseConnectionView = [dbDocument valueForKey:@"contentViewSplitter"];
+
+ // Keychain references
+ connectionKeychainItemName = nil;
+ connectionKeychainItemAccount = nil;
+ connectionSSHKeychainItemName = nil;
+ connectionSSHKeychainItemAccount = nil;
+
+ isEditing = NO;
+ isConnecting = NO;
+ sshTunnel = nil;
+ mySQLConnection = nil;
+ cancellingConnection = NO;
+ mySQLConnectionCancelled = NO;
+ favoriteNameFieldWasTouched = YES;
+
+ [self loadNib];
+ [self registerForNotifications];
+
+ // Hide the main view and position and display the connection view
+ [databaseConnectionView setHidden:YES];
+ [connectionView setFrame:[databaseConnectionView frame]];
+ [databaseConnectionSuperview addSubview:connectionView];
+ [connectionSplitView setPosition:[[dbDocument valueForKey:@"dbTablesTableView"] frame].size.width ofDividerAtIndex:0];
+ [connectionSplitView setDelegate:self];
+
+ // Generic folder image for use in the outline view's groups
+ folderImage = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)] retain];
+
+ [folderImage setSize:NSMakeSize(16, 16)];
+
+ // Set up a keychain instance and preferences reference, and create the initial favorites list
+ keychain = [[SPKeychain alloc] init];
+ prefs = [[NSUserDefaults standardUserDefaults] retain];
+
+ // Create a reference to the favorites controller, forcing the data to be loaded from disk
+ // and the tree to be constructed.
+ favoritesController = [SPFavoritesController sharedFavoritesController];
+
+ // Tree reference
+ favoritesRoot = [favoritesController favoritesTree];
+
+ // Update the UI
+ [self _reloadFavoritesViewData];
+ [self setUpFavoritesOutlineView];
+ [self setUpSelectedConnectionFavorite];
+
+ // Set sort items
+ currentSortItem = [prefs integerForKey:SPFavoritesSortedBy];
+ reverseFavoritesSort = [prefs boolForKey:SPFavoritesSortedInReverse];
+ }
+
+ return self;
+}
+
+/**
+ * Loads the connection controllers UI nib.
+ */
+- (void)loadNib
+{
+ // Load the connection nib, keeping references to the top-level objects for later release
+ nibObjectsToRelease = [[NSMutableArray alloc] init];
+
+ NSArray *connectionViewTopLevelObjects = nil;
+ NSNib *nibLoader = [[NSNib alloc] initWithNibNamed:SPConnectionViewNibName bundle:[NSBundle mainBundle]];
+
+ [nibLoader instantiateNibWithOwner:self topLevelObjects:&connectionViewTopLevelObjects];
+ [nibObjectsToRelease addObjectsFromArray:connectionViewTopLevelObjects];
+ [nibLoader release];
+}
+
+/**
+ * Registers for various notifications.
+ */
+- (void)registerForNotifications
+{
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(scrollViewFrameChanged:)
+ name:NSViewFrameDidChangeNotification
+ object:nil];
+
+ // Registered to be notified of changes to connection information
+ [self addObserver:self
+ forKeyPath:SPFavoriteNameKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteHostKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteUserKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteDatabaseKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSocketKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoritePortKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteUseSSLKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSHHostKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSHUserKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSHPortKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSHKeyLocationEnabledKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSHKeyLocationKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLKeyFileLocationEnabledKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLKeyFileLocationKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLCertificateFileLocationEnabledKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLCertificateFileLocationKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLCACertFileLocationEnabledKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+
+ [self addObserver:self
+ forKeyPath:SPFavoriteSSLCACertFileLocationKey
+ options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew)
+ context:NULL];
+}
+
+/**
+ * Performs any set up necessary for the favorities outline view.
+ */
+- (void)setUpFavoritesOutlineView
+{
+ // Register double click action for the favorites outline view (double click favorite to connect)
+ [favoritesOutlineView setTarget:self];
+ [favoritesOutlineView setDoubleAction:@selector(nodeDoubleClicked:)];
+
+ // Register drag types for the favorites outline view
+ [favoritesOutlineView registerForDraggedTypes:[NSArray arrayWithObject:SPFavoritesPasteboardDragType]];
+ [favoritesOutlineView setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES];
+
+ // Preserve expanded group nodes
+ [favoritesOutlineView setAutosaveExpandedItems:YES];
+}
+
+/**
+ * Sets up the selected connection favorite according to the user's preferences.
+ */
+- (void)setUpSelectedConnectionFavorite
+{
+ SPTreeNode *favorite = [self _favoriteNodeForFavoriteID:[prefs integerForKey:[prefs boolForKey:SPSelectLastFavoriteUsed] ? SPLastFavoriteID : SPDefaultFavorite]];
+
+ if (favorite) {
+
+ NSNumber *typeNumber = [[[favorite representedObject] nodeFavorite] objectForKey:SPFavoriteTypeKey];
+
+ previousType = typeNumber ? [typeNumber integerValue] : SPTCPIPConnection;
+
+ [self _selectNode:favorite];
+ [self resizeTabViewToConnectionType:[[[[favorite representedObject] nodeFavorite] objectForKey:SPFavoriteTypeKey] integerValue] animating:NO];
+
+ [favoritesOutlineView scrollRowToVisible:[favoritesOutlineView selectedRow]];
+ }
+ else {
+ previousType = SPTCPIPConnection;
+
+ [self resizeTabViewToConnectionType:SPTCPIPConnection animating:NO];
+ }
+}
+
+@end