aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionControllerDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPConnectionControllerDelegate.m')
-rw-r--r--Source/SPConnectionControllerDelegate.m180
1 files changed, 90 insertions, 90 deletions
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index 191a5b32..a6001309 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -31,7 +31,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPConnectionControllerDelegate.h"
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
#import "SPFavoritesController.h"
#import "SPTableTextFieldCell.h"
#import "SPPreferenceController.h"
@@ -42,7 +42,7 @@
#import "SPTreeNode.h"
#endif
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
static NSString *SPDatabaseImage = @"database-small";
static NSString *SPQuickConnectImage = @"quick-connect-icon.pdf";
static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
@@ -73,7 +73,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark SplitView delegate methods
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* When the split view is resized, trigger a resize in the hidden table
@@ -82,8 +82,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (void)splitViewDidResizeSubviews:(NSNotification *)notification
{
if (initComplete) {
- [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0];
- }
+ [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0];
+}
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
@@ -96,13 +96,13 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Outline view delegate methods
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
{
return ([[(SPTreeNode *)item parentNode] parentNode] == nil);
}
-
+
- (void)outlineViewSelectionIsChanging:(NSNotification *)notification
{
if (isEditingConnection) {
@@ -112,15 +112,15 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
-{
+ {
NSInteger selected = [favoritesOutlineView numberOfSelectedRows];
-
+
if (isEditingConnection) {
[self _stopEditingConnection];
[[notification object] setNeedsDisplay:YES];
}
- if (selected == 1) {
+ if (selected == 1) {
[self updateFavoriteSelection:self];
favoriteNameFieldWasAutogenerated = NO;
@@ -145,7 +145,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
SPTreeNode *node = (SPTreeNode *)item;
-
+
// Draw entries with the small system font by default
[(SPTableTextFieldCell *)cell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
@@ -228,7 +228,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
-{
+{
// If this is a top level item, only allow the "Quick Connect" item to be selectable
if (![[item parentNode] parentNode]) {
@@ -265,10 +265,10 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (void)outlineViewItemDidCollapse:(NSNotification *)notification
{
[self _setNodeIsExpanded:NO fromNotification:notification];
-}
-
+ }
+
- (void)outlineViewItemDidExpand:(NSNotification *)notification
-{
+ {
[self _setNodeIsExpanded:YES fromNotification:notification];
}
@@ -277,7 +277,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Outline view drag & drop
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
@@ -308,9 +308,9 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)childIndex
-{
+ {
NSDragOperation result = NSDragOperationNone;
-
+
// Prevent the top level or the quick connect item from being a target
if (!item || item == quickConnectItem) return result;
@@ -332,35 +332,35 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[outlineView setDropItem:item dropChildIndex:childIndex];
result = NSDragOperationMove;
- }
+ }
return result;
-}
-
+ }
+
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)childIndex
-{
- BOOL acceptedDrop = NO;
-
+ {
+ BOOL acceptedDrop = NO;
+
if ((!item) || ([info draggingSource] != outlineView)) return acceptedDrop;
SPTreeNode *node = item ? item : [[[[favoritesRoot childNodes] objectAtIndex:0] childNodes] objectAtIndex:0];
// Cache the selected nodes for selection restoration afterwards
NSArray *preDragSelection = [self selectedFavoriteNodes];
-
- // Disable all automatic sorting
- currentSortItem = -1;
- reverseFavoritesSort = NO;
-
- [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
- [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
-
- // Uncheck sort by menu items
- for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
- {
- [menuItem setState:NSOffState];
- }
-
+
+ // Disable all automatic sorting
+ currentSortItem = -1;
+ reverseFavoritesSort = NO;
+
+ [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
+ [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
+
+ // Uncheck sort by menu items
+ for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
+ {
+ [menuItem setState:NSOffState];
+ }
+
if (![draggedNodes count]) return acceptedDrop;
if ([node isGroup]) {
@@ -382,7 +382,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
NSMutableArray *childNodeArray = [node mutableChildNodes];
for (SPTreeNode *treeNode in draggedNodes)
- {
+ {
// Remove the node from its old location
NSInteger oldIndex = [childNodeArray indexOfObject:treeNode];
NSInteger newIndex = childIndex;
@@ -393,8 +393,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (childIndex > oldIndex) {
newIndex--;
- }
- }
+ }
+ }
else {
[[[treeNode parentNode] mutableChildNodes] removeObject:treeNode];
}
@@ -407,21 +407,21 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[favoritesController saveFavorites];
[self _reloadFavoritesViewData];
-
+
[[NSNotificationCenter defaultCenter] postNotificationName:SPConnectionFavoritesChangedNotification object:self];
-
- [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup];
-
+
+ [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup];
+
// Update the selection to account for rearranged faourites
NSMutableIndexSet *restoredSelection = [NSMutableIndexSet indexSet];
for (SPTreeNode *eachNode in preDragSelection) {
[restoredSelection addIndex:[favoritesOutlineView rowForItem:eachNode]];
}
[favoritesOutlineView selectRowIndexes:restoredSelection byExtendingSelection:NO];
-
- acceptedDrop = YES;
-
- return acceptedDrop;
+
+ acceptedDrop = YES;
+
+ return acceptedDrop;
}
#endif
@@ -429,7 +429,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Textfield delegate methods
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* React to control text changes in the connection interface
@@ -437,7 +437,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
- (void)controlTextDidChange:(NSNotification *)notification
{
id field = [notification object];
-
+
// Ignore changes in the outline view edit fields
if ([field isKindOfClass:[NSOutlineView class]]) {
return;
@@ -450,41 +450,41 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[self controlTextDidEndEditing:notification];
}
}
-
+
[self _startEditingConnection];
-
+
if (favoriteNameFieldWasAutogenerated && (field != standardNameField && field != socketNameField && field != sshNameField)) {
[self setName:[self _generateNameForConnection]];
- }
-}
-
+ }
+ }
+
/**
* React to the end of control text changes in the connection interface.
*/
- (void)controlTextDidEndEditing:(NSNotification *)notification
{
id field = [notification object];
-
+
// Handle updates to the 'name' field of the selected favourite. The favourite name should
// have leading or trailing spaces removed at the end of editing, and if it's left empty,
// should have a default name set.
if (((field == standardNameField) || (field == socketNameField) || (field == sshNameField)) && [self selectedFavoriteNode]) {
-
+
NSString *favoriteName = [self _stripInvalidCharactersFromString:[field stringValue]];
-
+
if (![favoriteName length]) {
favoriteName = [self _generateNameForConnection];
if (favoriteName) {
[self setName:favoriteName];
- }
-
+ }
+
// Enable user@host update in reaction to other UI changes
favoriteNameFieldWasAutogenerated = YES;
} else if (![[field stringValue] isEqualToString:[self _generateNameForConnection]]) {
favoriteNameFieldWasAutogenerated = NO;
[self setName:favoriteName];
- }
}
+}
// When a host field finishes editing, ensure that it hasn't been set to "localhost" to
// ensure that socket connections don't inadvertently occur.
@@ -498,7 +498,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Tab bar delegate methods
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* Trigger a resize action whenever the tab view changes. The connection
@@ -508,22 +508,22 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
* to be sized according to the detail type.
*/
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
-{
+{
NSInteger selectedTabView = [tabView indexOfTabViewItem:tabViewItem];
if (selectedTabView == previousType) return;
-
+
[self resizeTabViewToConnectionType:selectedTabView animating:YES];
// Update the host as appropriate
if ((selectedTabView != SPSocketConnection) && [[self host] isEqualToString:@"localhost"]) {
[self setHost:@""];
}
-
+
previousType = selectedTabView;
-
+
[self _startEditingConnection];
-
+
[self _favoriteTypeDidChange];
}
@@ -532,7 +532,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Scroll view notifications
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* As the scrollview resizes, keep the details centered within it if
@@ -560,7 +560,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
[connectionResizeContainer setFrame:connectionDetailsFrame];
scrollDocumentFrame.size.height = scrollViewFrame.size.height;
[[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame];
- }
+}
}
#endif
@@ -568,18 +568,18 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Menu Validation
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* Menu item validation.
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
-{
+{
SEL action = [menuItem action];
SPTreeNode *node = [self selectedFavoriteNode];
NSInteger selectedRows = [favoritesOutlineView numberOfSelectedRows];
-
+
if (node == quickConnectItem) {
return NO;
}
@@ -598,8 +598,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (action == @selector(reverseSortFavorites:)) {
[menuItem setState:reverseFavoritesSort];
}
- }
-
+}
+
// Remove/rename the selected node
if (action == @selector(removeNode:) || action == @selector(renameNode:)) {
return selectedRows == 1;
@@ -608,18 +608,18 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
// Duplicate and make the selected favorite the default
if (action == @selector(duplicateFavorite:)) {
return ((selectedRows == 1) && (![node isGroup]));
- }
-
+}
+
// Make selected favorite the default
if (action == @selector(makeSelectedFavoriteDefault:)) {
NSInteger favoriteID = [[[self selectedFavorite] objectForKey:SPFavoriteIDKey] integerValue];
-
+
return ((selectedRows == 1) && (![node isGroup]) && (favoriteID != [prefs integerForKey:SPDefaultFavorite]));
- }
-
+}
+
// Favorites export
if (action == @selector(exportFavorites:)) {
-
+
if ([[favoritesRoot allChildLeafs] count] == 0) {
return NO;
}
@@ -628,7 +628,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
}
else if (selectedRows > 1) {
[menuItem setTitle:NSLocalizedString(@"Export Selected...", @"export selected favorites menu item")];
- }
+ }
}
return YES;
@@ -639,26 +639,26 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Favorites import/export delegate methods
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* Called by the favorites exporter when the export completes.
*/
- (void)favoritesExportCompletedWithError:(NSError *)error
-{
+{
if (error) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Favorites export error", @"favorites export error message")
defaultButton:NSLocalizedString(@"OK", @"OK")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"The following error occurred during the export process:\n\n%@", @"favorites export error informative message"), [error localizedDescription]]];
-
+
[alert beginSheetModalForWindow:[dbDocument parentWindow]
modalDelegate:self
didEndSelector:NULL
contextInfo:NULL];
}
-}
+ }
/**
* Called by the favorites importer when the imported data is available.
@@ -673,8 +673,8 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
if (currentSortItem > SPFavoritesSortUnsorted) {
[self _sortFavorites];
- }
-
+}
+
[self _reloadFavoritesViewData];
}
@@ -682,7 +682,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
* Called by the favorites importer when the import completes.
*/
- (void)favoritesImportCompletedWithError:(NSError *)error
-{
+{
if (error) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Favorites import error", @"favorites import error message")
defaultButton:NSLocalizedString(@"OK", @"OK")
@@ -702,7 +702,7 @@ static NSString *SPQuickConnectImageWhite = @"quick-connect-icon-white.pdf";
#pragma mark -
#pragma mark Private API
-#ifndef SP_REFACTOR
+#ifndef SP_CODA
/**
* Sets the expanded state of the node from the supplied outline view notification.