aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionControllerDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPConnectionControllerDelegate.m')
-rw-r--r--Source/SPConnectionControllerDelegate.m212
1 files changed, 212 insertions, 0 deletions
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
new file mode 100644
index 00000000..7384d859
--- /dev/null
+++ b/Source/SPConnectionControllerDelegate.m
@@ -0,0 +1,212 @@
+//
+// $Id$
+//
+// SPConnectionControllerDelegate.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on November 9, 2010
+// Copyright (c) 2010 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 "SPConnectionControllerDelegate.h"
+
+@implementation SPConnectionController (SPConnectionControllerDelegate)
+
+/*#pragma mark -
+ #pragma mark TableView drag & drop delegate methods
+
+ - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
+ {
+ NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
+ [pboard declareTypes:[NSArray arrayWithObject:favoritesPBoardType] owner:self];
+ [pboard setData:archivedData forType:favoritesPBoardType];
+ return YES;
+ }
+
+ - (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
+ {
+ if (row == 0) return NSDragOperationNone;
+ if ([info draggingSource] == aTableView)
+ {
+ [aTableView setDropRow:row dropOperation:NSTableViewDropAbove];
+ return NSDragOperationMove;
+ }
+ return NSDragOperationNone;
+ }
+
+ - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
+ {
+ BOOL acceptedDrop = NO;
+
+ if ((row == 0) || ([info draggingSource] != aTableView)) return acceptedDrop;
+
+ // Disable all automatic sorting
+ currentSortItem = -1;
+ reverseFavoritesSort = NO;
+
+ [prefs setInteger:currentSortItem forKey:SPFavoritesSortedBy];
+ [prefs setBool:NO forKey:SPFavoritesSortedInReverse];
+
+ // Remove sort descriptors
+ [favorites sortUsingDescriptors:[NSArray array]];
+
+ // Uncheck sort by menu items
+ for (NSMenuItem *menuItem in [[favoritesSortByMenuItem submenu] itemArray])
+ {
+ [menuItem setState:NSOffState];
+ }
+
+ NSPasteboard* pboard = [info draggingPasteboard];
+ NSData* rowData = [pboard dataForType:favoritesPBoardType];
+ NSIndexSet* rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
+ NSInteger dragRow = [rowIndexes firstIndex];
+ NSInteger defaultConnectionRow = [prefs integerForKey:SPLastFavoriteIndex];
+ if (defaultConnectionRow == dragRow)
+ {
+ [prefs setInteger:row forKey:SPLastFavoriteIndex];
+ }
+ NSMutableDictionary *draggedFavorite = [favorites objectAtIndex:dragRow];
+ [favorites removeObjectAtIndex:dragRow];
+ if (row > dragRow)
+ {
+ row--;
+ }
+ [favorites insertObject:draggedFavorite atIndex:row];
+ [aTableView reloadData];
+
+ // reset the prefs with the new order
+ NSMutableArray *reorderedFavorites = [[NSMutableArray alloc] initWithArray:favorites];
+ [reorderedFavorites removeObjectAtIndex:0];
+ [prefs setObject:reorderedFavorites forKey:SPFavorites];
+
+ [[[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup];
+
+ [reorderedFavorites release];
+
+ [self updateFavorites];
+ [aTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
+
+ acceptedDrop = YES;
+
+ return acceptedDrop;
+ }*/
+
+#pragma mark -
+#pragma mark SplitView delegate methods
+
+/**
+ * When the split view is resized, trigger a resize in the hidden table
+ * width as well, to keep the connection view and connected view in synch.
+ * Use this rather than splitViewDidResizeSubviews: as the latter is not
+ * forwarded by the BWAnchoredButtonBar.
+ */
+- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex
+{
+ [databaseConnectionView setPosition:[[[connectionSplitView subviews] objectAtIndex:0] frame].size.width ofDividerAtIndex:0];
+
+ return proposedPosition;
+}
+
+/**
+ * Return the maximum possible size of the splitview.
+ */
+- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)offset
+{
+ return (proposedMax - 445);
+}
+
+/**
+ * Return the minimum possible size of the splitview.
+ */
+- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)offset
+{
+ return (proposedMin + 80);
+}
+
+#pragma mark -
+#pragma mark Outline view datasource methods
+
+- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
+{
+ SPFavoriteNode *node = (item == nil ? favoritesRoot : (SPFavoriteNode *)item);
+
+ return [[node children] count];
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
+{
+ SPFavoriteNode *node = (item == nil ? favoritesRoot : (SPFavoriteNode *)item);
+
+ return [[node children] objectAtIndex:index];
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
+{
+ return [(SPFavoriteNode *)item isGroup];
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
+{
+ return [[(SPFavoriteNode *)item favorite] objectForKey:@"name"];
+}
+
+#pragma mark -
+#pragma mark Outline view delegate methods
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
+{
+ return [(SPFavoriteNode *)item isGroup];
+}
+
+- (void)outlineViewSelectionDidChange:(NSNotification *)notification
+{
+ if ([favoritesTable numberOfSelectedRows] == 1) {
+ [self updateFavoriteSelection:self];
+
+ [addToFavoritesButton setEnabled:NO];
+ }
+ else {
+ [addToFavoritesButton setEnabled:YES];
+ }
+}
+
+- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
+{
+ [(SPTableTextFieldCell *)cell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+
+ if ([favoritesTable isEnabled]) {
+ [(SPTableTextFieldCell *)cell setTextColor:[NSColor blackColor]];
+ }
+ else {
+ [(SPTableTextFieldCell *)cell setTextColor:[NSColor grayColor]];
+ }
+
+ [(SPTableTextFieldCell *)cell setImage:([(SPFavoriteNode *)item isGroup]) ? nil : [NSImage imageNamed:@"database-small"]];
+}
+
+- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
+{
+ return ([item isGroup]) ? 22 : 17;
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
+{
+ return (![item isGroup]);
+}
+
+@end