diff options
author | stuconnolly <stuart02@gmail.com> | 2010-11-09 18:19:12 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-11-09 18:19:12 +0000 |
commit | 1af63b378e644ceef6e26918b0a1d693bcc232f8 (patch) | |
tree | 8bbf8a8e07266bbff51d35dca1d89a0c41c97016 | |
parent | d10ca821ae2f3ab62daf92f5e9bde58bf796e36c (diff) | |
download | sequelpro-1af63b378e644ceef6e26918b0a1d693bcc232f8.tar.gz sequelpro-1af63b378e644ceef6e26918b0a1d693bcc232f8.tar.bz2 sequelpro-1af63b378e644ceef6e26918b0a1d693bcc232f8.zip |
First changes towards changing the initial connection view's favorites table list to an outline view in order to support grouping favorites. Future changes include creating a favorites data controller, including migrating favorites storage to their own plist in the app support directory as well as support for grouping favorites.
-rw-r--r-- | Interfaces/English.lproj/ConnectionView.xib | 52 | ||||
-rw-r--r-- | Source/SPConnectionController.h | 10 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 251 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.h | 20 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 212 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegateProtocol.h | 49 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.h | 4 | ||||
-rw-r--r-- | Source/SPFavoriteNode.h | 37 | ||||
-rw-r--r-- | Source/SPFavoriteNode.m | 54 | ||||
-rw-r--r-- | Source/SPOutlineView.h | 2 | ||||
-rw-r--r-- | Source/SPOutlineView.m | 38 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 16 |
12 files changed, 508 insertions, 237 deletions
diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib index 978d87a3..8243fa90 100644 --- a/Interfaces/English.lproj/ConnectionView.xib +++ b/Interfaces/English.lproj/ConnectionView.xib @@ -3,7 +3,7 @@ <data> <int key="IBDocument.SystemTarget">1050</int> <string key="IBDocument.SystemVersion">10F569</string> - <string key="IBDocument.InterfaceBuilderVersion">804</string> + <string key="IBDocument.InterfaceBuilderVersion">823</string> <string key="IBDocument.AppKitVersion">1038.29</string> <string key="IBDocument.HIToolboxVersion">461.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> @@ -15,7 +15,7 @@ </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> - <string>804</string> + <string>823</string> <string>1.2.5</string> </object> </object> @@ -6153,7 +6153,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> - <string>{{126, 318}, {882, 475}}</string> + <string>{{123, 342}, {882, 475}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <integer value="1"/> @@ -6162,10 +6162,10 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>SPTableView</string> + <string>SPOutlineView</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>ImageAndTextCell</string> + <string>SPTableTextFieldCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">InitialTabViewItem</string> @@ -6676,13 +6676,6 @@ <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">NSObject</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> <string key="minorKey">Frameworks/MCPKit/MCPFoundationKit/MCPNull.h</string> </object> </object> @@ -6776,6 +6769,8 @@ <string>doSelectionUpperCase:</string> <string>doTranspose:</string> <string>insertNULLvalue:</string> + <string>moveSelectionLineDown:</string> + <string>moveSelectionLineUp:</string> <string>selectCurrentLine:</string> <string>selectCurrentWord:</string> <string>selectEnclosingBrackets:</string> @@ -6795,6 +6790,8 @@ <string>id</string> <string>id</string> <string>id</string> + <string>id</string> + <string>id</string> </object> </object> <object class="NSMutableDictionary" key="actionInfosByName"> @@ -6811,6 +6808,8 @@ <string>doSelectionUpperCase:</string> <string>doTranspose:</string> <string>insertNULLvalue:</string> + <string>moveSelectionLineDown:</string> + <string>moveSelectionLineUp:</string> <string>selectCurrentLine:</string> <string>selectCurrentWord:</string> <string>selectEnclosingBrackets:</string> @@ -6858,6 +6857,14 @@ <string key="candidateClassName">id</string> </object> <object class="IBActionInfo"> + <string key="name">moveSelectionLineDown:</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBActionInfo"> + <string key="name">moveSelectionLineUp:</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBActionInfo"> <string key="name">selectCurrentLine:</string> <string key="candidateClassName">id</string> </object> @@ -7259,11 +7266,19 @@ <reference key="sourceIdentifier" ref="968459546"/> </object> <object class="IBPartialClassDescription"> - <string key="className">SPTableView</string> - <string key="superclassName">NSTableView</string> + <string key="className">SPOutlineView</string> + <string key="superclassName">NSOutlineView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">Source/SPOutlineView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">SPTableTextFieldCell</string> + <string key="superclassName">ImageAndTextCell</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">Source/SPTableView.h</string> + <string key="minorKey">Source/SPTableTextFieldCell.h</string> </object> </object> </object> @@ -7526,7 +7541,7 @@ </object> <object class="IBPartialClassDescription"> <string key="className">NSObject</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="124846695"> <string key="majorKey">IBFrameworkSource</string> <string key="minorKey">AppKit.framework/Headers/NSOutlineView.h</string> </object> @@ -7819,6 +7834,11 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSOutlineView</string> + <string key="superclassName">NSTableView</string> + <reference key="sourceIdentifier" ref="124846695"/> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSPanel</string> <string key="superclassName">NSWindow</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index 3dd0563e..2a618fad 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -25,9 +25,9 @@ #import <MCPKit/MCPKit.h> -#import "SPConnectionControllerDelegate.h" +#import "SPConnectionControllerDelegateProtocol.h" -@class SPDatabaseDocument, SPKeychain, SPSSHTunnel, BWAnchoredButtonBar; +@class SPDatabaseDocument, SPKeychain, SPSSHTunnel, BWAnchoredButtonBar, SPFavoriteNode; @interface NSObject (BWAnchoredButtonBar) @@ -43,7 +43,7 @@ @interface SPConnectionController : NSObject { - id <SPConnectionControllerDelegate> delegate; + id <SPConnectionControllerDelegateProtocol> delegate; SPDatabaseDocument *tableDocument; NSView *databaseConnectionSuperview; @@ -133,9 +133,11 @@ BOOL mySQLConnectionCancelled; SPFavoritesSortItem previousSortItem, currentSortItem; + + SPFavoriteNode *favoritesRoot; } -@property (readwrite, assign) id <SPConnectionControllerDelegate> delegate; +@property (readwrite, assign) id <SPConnectionControllerDelegateProtocol> delegate; @property (readwrite, assign) NSInteger type; @property (readwrite, retain) NSString *name; @property (readwrite, retain) NSString *host; diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index d356bc89..ce2acd3f 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -32,10 +32,13 @@ #import "SPAlertSheets.h" #import "SPKeychain.h" #import "SPSSHTunnel.h" +#import "SPFavoriteNode.h" +#import "SPTableTextFieldCell.h" @interface SPConnectionController (PrivateAPI) - (void)_sortFavorites; +- (void)_buildFavoritesTree; - (void)_restoreConnectionInterface; - (void)_mySQLConnectionEstablished; - (void)_initiateMySQLConnectionInBackground; @@ -122,6 +125,9 @@ // Load favorites [self updateFavorites]; + // Expand the favorites heading + [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]]; + // Register an observer for changes within the favorites [prefs addObserver:self forKeyPath:SPFavorites options:NSKeyValueObservingOptionNew context:NULL]; @@ -823,7 +829,7 @@ * Sorts the favorites table view based on the selected sort by item. */ - (void)sortFavorites:(id)sender -{ +{ previousSortItem = currentSortItem; currentSortItem = [[sender menu] indexOfItem:sender]; @@ -858,14 +864,21 @@ - (void)updateFavorites { [favoritesTable deselectAll:self]; + if (favorites) [favorites release]; + if ([prefs objectForKey:SPFavorites]) { favorites = [[NSMutableArray alloc] initWithArray:[prefs objectForKey:SPFavorites]]; - } else { + } + else { favorites = [[NSMutableArray alloc] init]; } - [favorites insertObject:[NSDictionary dictionaryWithObject:NSLocalizedString(@"FAVORITES", @"Favorites title at the top of the sidebar") forKey:@"name"] atIndex:0]; + + [self _buildFavoritesTree]; + [favoritesTable reloadData]; + + [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]]; } /** @@ -887,6 +900,7 @@ // Update key-value properties from the selected favourite, using empty strings where not found NSDictionary *fav = [self selectedFavorite]; + [self setType:([fav objectForKey:@"type"] ? [[fav objectForKey:@"type"] integerValue] : SPTCPIPConnection)]; [self setName:([fav objectForKey:@"name"] ? [fav objectForKey:@"name"] : @"")]; [self setHost:([fav objectForKey:@"host"] ? [fav objectForKey:@"host"] : @"")]; @@ -956,10 +970,9 @@ */ - (id)selectedFavorite { - if ([favoritesTable selectedRow] == -1) - return nil; + if ([favoritesTable selectedRow] == -1) return nil; - return [favorites objectAtIndex:[favoritesTable selectedRow]]; + return [favorites objectAtIndex:([favoritesTable selectedRow] - 1)]; } /** @@ -1066,194 +1079,6 @@ } #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 Favorites tableview datasource methods - -/** - * Returns the number of favorites to display - */ -- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView -{ - return [favorites count]; -} - -/** - * Returns the favorite names to be displayed in the table - */ -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex -{ - return [[favorites objectAtIndex:rowIndex] objectForKey:@"name"]; -} - -#pragma mark - -#pragma mark Favorites tableview delegate methods - -/** - * Loads a favorite, if any are selected. - */ -- (void)tableViewSelectionDidChange:(NSNotification *)aNotification -{ - if ([favoritesTable numberOfSelectedRows] == 1) { - [self updateFavoriteSelection:self]; - [addToFavoritesButton setEnabled:NO]; - } else { - [addToFavoritesButton setEnabled:YES]; - } -} - -/** - * Display the title row - */ -- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(NSInteger)rowIndex -{ - return (rowIndex == 0); -} - -/** - * Don't allow the title row to be selected - */ -- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex -{ - return (rowIndex != 0); -} - -/** - * Set the title row to display with extra height - */ -- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row -{ - return (row == 0) ? 25 : 17; -} - -/** - * Control the display of rows within the favorites table - */ -- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex -{ - [(ImageAndTextCell*)aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; - if (rowIndex == 0) { - [(ImageAndTextCell *)aCell setIndentationLevel:0]; - } else { - [(ImageAndTextCell *)aCell setIndentationLevel:1]; - } - if([favoritesTable isEnabled]) - [(ImageAndTextCell *)aCell setTextColor:[NSColor blackColor]]; - else - [(ImageAndTextCell *)aCell setTextColor:[NSColor grayColor]]; -} - - -#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 Menu Validation -(BOOL)validateMenuItem:(NSMenuItem *)menuItem @@ -1316,12 +1141,50 @@ [favorites removeObjectAtIndex:0]; [favorites sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; [favorites insertObject:first atIndex:0]; + + // Rebuild the favorites tree + [self _buildFavoritesTree]; + [favoritesTable reloadData]; + + [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]]; [first release]; } /** + * + */ +- (void)_buildFavoritesTree +{ + if (favoritesRoot) [favoritesRoot release], favoritesRoot = nil; + + favoritesRoot = [[SPFavoriteNode alloc] init]; + + SPFavoriteNode *favoritesNode = [[SPFavoriteNode alloc] init]; + + [favoritesNode setIsGroup:YES]; + [favoritesNode setFavorite:[NSDictionary dictionaryWithObject:NSLocalizedString(@"FAVORITES", @"Favorites title at the top of the sidebar") forKey:@"name"]]; + + + for (NSDictionary *favorite in favorites) + { + SPFavoriteNode *node2 = [[SPFavoriteNode alloc] init]; + + [node2 setFavorite:favorite]; + [node2 setIsGroup:NO]; + + [[favoritesNode children] addObject:node2]; + + [node2 release]; + } + + [[favoritesRoot children] addObject:favoritesNode]; + + [favoritesNode release]; +} + +/** * Restores the connection interface to its original state. */ - (void)_restoreConnectionInterface diff --git a/Source/SPConnectionControllerDelegate.h b/Source/SPConnectionControllerDelegate.h index dc5e8a45..0a7323cb 100644 --- a/Source/SPConnectionControllerDelegate.h +++ b/Source/SPConnectionControllerDelegate.h @@ -24,26 +24,12 @@ // More info at <http://code.google.com/p/sequel-pro/> /** - * @protocol SPConnectionControllerDelegate SPConnectionControllerDelegate.h + * @category SPConnectionControllerDelegate SPConnectionControllerDelegate.h * * @author Stuart Connolly http://stuconnolly.com/ * - * Connection controller delegate protocol. + * Connection controller delegate/data source category. */ -@protocol SPConnectionControllerDelegate - -/** - * Called when the connection controller starts initiating the connection process. - * - * @param controller The calling connection controller - */ -- (void)connectionControllerInitiatingConnection:(id)controller; - -/** - * Called when the connection controller's connection attempt failed. - * - * @param controller The calling connection controller - */ -- (void)connectionControllerConnectAttemptFailed:(id)controller; +@implementation SPConnectionController (SPConnectionControllerDelegate) @end 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 diff --git a/Source/SPConnectionControllerDelegateProtocol.h b/Source/SPConnectionControllerDelegateProtocol.h new file mode 100644 index 00000000..bb1bbfe9 --- /dev/null +++ b/Source/SPConnectionControllerDelegateProtocol.h @@ -0,0 +1,49 @@ +// +// $Id$ +// +// SPConnectionControllerDelegateProtocol.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on October 29, 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/> + +/** + * @protocol SPConnectionControllerDelegateProtocol SPConnectionControllerDelegateProtocol.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * Connection controller delegate protocol. + */ +@protocol SPConnectionControllerDelegateProtocol + +/** + * Called when the connection controller starts initiating the connection process. + * + * @param controller The calling connection controller + */ +- (void)connectionControllerInitiatingConnection:(id)controller; + +/** + * Called when the connection controller's connection attempt failed. + * + * @param controller The calling connection controller + */ +- (void)connectionControllerConnectAttemptFailed:(id)controller; + +@end diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 35681506..31c35f7e 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -35,12 +35,12 @@ SPWindowController, SPServerSupport; -@protocol SPConnectionControllerDelegate; +@protocol SPConnectionControllerDelegateProtocol; /** * The SPDatabaseDocument class controls the primary database view window. */ -@interface SPDatabaseDocument : NSObject <NSUserInterfaceValidations, SPConnectionControllerDelegate> +@interface SPDatabaseDocument : NSObject <NSUserInterfaceValidations, SPConnectionControllerDelegateProtocol> { // IBOutlets IBOutlet id tablesListInstance; diff --git a/Source/SPFavoriteNode.h b/Source/SPFavoriteNode.h new file mode 100644 index 00000000..289958f7 --- /dev/null +++ b/Source/SPFavoriteNode.h @@ -0,0 +1,37 @@ +// +// $Id$ +// +// SPFavoriteNode.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 8, 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/> + +@interface SPFavoriteNode : NSObject +{ + BOOL isGroup; + NSDictionary *favorite; + NSMutableArray *children; +} + +@property (readwrite, assign) BOOL isGroup; +@property (readwrite, retain) NSDictionary *favorite; +@property (readwrite, retain) NSMutableArray *children; + +@end diff --git a/Source/SPFavoriteNode.m b/Source/SPFavoriteNode.m new file mode 100644 index 00000000..3b46ba80 --- /dev/null +++ b/Source/SPFavoriteNode.m @@ -0,0 +1,54 @@ +// +// $Id$ +// +// SPFavoriteNode.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 8, 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 "SPFavoriteNode.h" + +@implementation SPFavoriteNode + +@synthesize isGroup; +@synthesize favorite; +@synthesize children; + +- (id)init +{ + if ((self = [super init])) { + [self setIsGroup:NO]; + + [self setFavorite:nil]; + [self setChildren:[[NSMutableArray alloc] init]]; + } + + return self; +} + +- (void)dealloc +{ + if (favorite) [favorite release], favorite = nil; + if (children) [children release], children = nil; + + [super dealloc]; +} + +@end diff --git a/Source/SPOutlineView.h b/Source/SPOutlineView.h index 680638c9..5211d73f 100644 --- a/Source/SPOutlineView.h +++ b/Source/SPOutlineView.h @@ -1,5 +1,5 @@ // -// $Id: SPUserManager.m 856 2009-06-12 05:31:39Z mltownsend $ +// $Id$ // // SPOutlineView.h // sequel-pro diff --git a/Source/SPOutlineView.m b/Source/SPOutlineView.m index 8eb55630..7ae50072 100644 --- a/Source/SPOutlineView.m +++ b/Source/SPOutlineView.m @@ -1,5 +1,5 @@ // -// $Id: SPUserManager.m 856 2009-06-12 05:31:39Z mltownsend $ +// $Id$ // // SPOutlineView.m // sequel-pro @@ -42,4 +42,40 @@ } } +/** + * Right-click at row will select that row before ordering out the contextual menu + * if not more than one row is selected. + */ +- (NSMenu *)menuForEvent:(NSEvent *)event +{ + // If more than one row is selected only return the default contextual menu + if ([self numberOfSelectedRows] > 1) return [self menu]; + + // Right-click at a row will select that row before ordering out the context menu + NSInteger row = [self rowAtPoint:[self convertPoint:[event locationInWindow] fromView:nil]]; + + if ((row >= 0) && (row < [self numberOfRows])) { + [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; + [[self window] makeFirstResponder:self]; + } + + return [self menu]; +} + +/** + * To prevent right-clicking in a column's 'group' heading, ask the delegate if we support selecting it + * as this normally doesn't apply to left-clicks. If we do support selecting this row, simply pass on the event. + */ +- (void)rightMouseDown:(NSEvent *)event +{ + if ([[self delegate] respondsToSelector:@selector(outlineView:shouldSelectItem:)]) { + if ([[self delegate] outlineView:self shouldSelectItem:[self itemAtRow:[self rowAtPoint:[self convertPoint:[event locationInWindow] fromView:nil]]]]) { + [super rightMouseDown:event]; + } + } + else { + [super rightMouseDown:event]; + } +} + @end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 5940462e..be34cfa9 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -121,6 +121,8 @@ 17D38F701279E23A00672B13 /* SPTableFieldValidation.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D38F6F1279E23A00672B13 /* SPTableFieldValidation.m */; }; 17D390C8127B65AF00672B13 /* SPGeneralPreferencePane.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D390C7127B65AF00672B13 /* SPGeneralPreferencePane.m */; }; 17D390CB127B6BF800672B13 /* SPPreferencesUpgrade.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D390CA127B6BF800672B13 /* SPPreferencesUpgrade.m */; }; + 17D3C22212859E070047709F /* SPFavoriteNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D3C22112859E070047709F /* SPFavoriteNode.m */; }; + 17D3C6041289BF350047709F /* SPConnectionControllerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D3C6031289BF350047709F /* SPConnectionControllerDelegate.m */; }; 17D3DC201281816E002A163A /* SPDatabaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D3DC1F1281816E002A163A /* SPDatabaseViewController.m */; }; 17DC8E75126F4AB600E9AAEC /* MCPConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17DCC5C7115C202700F89A00 /* MCPStringAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */; }; @@ -696,12 +698,16 @@ 17D38EBB12771A1C00672B13 /* SPTableStructureDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableStructureDelegate.m; sourceTree = "<group>"; }; 17D38F6E1279E23A00672B13 /* SPTableFieldValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableFieldValidation.h; sourceTree = "<group>"; }; 17D38F6F1279E23A00672B13 /* SPTableFieldValidation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableFieldValidation.m; sourceTree = "<group>"; }; - 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionControllerDelegate.h; sourceTree = "<group>"; }; + 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionControllerDelegateProtocol.h; sourceTree = "<group>"; }; 17D390A8127B556F00672B13 /* SPPreferencePaneProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPPreferencePaneProtocol.h; sourceTree = "<group>"; }; 17D390C6127B65AF00672B13 /* SPGeneralPreferencePane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPGeneralPreferencePane.h; sourceTree = "<group>"; }; 17D390C7127B65AF00672B13 /* SPGeneralPreferencePane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPGeneralPreferencePane.m; sourceTree = "<group>"; }; 17D390C9127B6BF800672B13 /* SPPreferencesUpgrade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPPreferencesUpgrade.h; sourceTree = "<group>"; }; 17D390CA127B6BF800672B13 /* SPPreferencesUpgrade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPPreferencesUpgrade.m; sourceTree = "<group>"; }; + 17D3C22012859E070047709F /* SPFavoriteNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoriteNode.h; sourceTree = "<group>"; }; + 17D3C22112859E070047709F /* SPFavoriteNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPFavoriteNode.m; sourceTree = "<group>"; }; + 17D3C6021289BF350047709F /* SPConnectionControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionControllerDelegate.h; sourceTree = "<group>"; }; + 17D3C6031289BF350047709F /* SPConnectionControllerDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPConnectionControllerDelegate.m; sourceTree = "<group>"; }; 17D3DC1E1281816E002A163A /* SPDatabaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDatabaseViewController.h; sourceTree = "<group>"; }; 17D3DC1F1281816E002A163A /* SPDatabaseViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDatabaseViewController.m; sourceTree = "<group>"; }; 17DA04EA0FC1A7DA00D66140 /* Unit Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Unit Tests-Info.plist"; path = "Plists/Unit Tests-Info.plist"; sourceTree = "<group>"; }; @@ -1660,9 +1666,13 @@ 17D38FC2127B0C9500672B13 /* Connection View */ = { isa = PBXGroup; children = ( + 17D3C22012859E070047709F /* SPFavoriteNode.h */, + 17D3C22112859E070047709F /* SPFavoriteNode.m */, 5822C9B31000DB2400DCC3D6 /* SPConnectionController.h */, 5822C9B41000DB2400DCC3D6 /* SPConnectionController.m */, - 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegate.h */, + 17D3C6021289BF350047709F /* SPConnectionControllerDelegate.h */, + 17D3C6031289BF350047709F /* SPConnectionControllerDelegate.m */, + 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegateProtocol.h */, ); name = "Connection View"; sourceTree = "<group>"; @@ -3054,6 +3064,8 @@ 1785EB6A127DD79300F468C8 /* SPEditorPreferencePane.m in Sources */, 17FDB04C1280778B00DBBBC2 /* SPFontPreviewTextField.m in Sources */, 17D3DC201281816E002A163A /* SPDatabaseViewController.m in Sources */, + 17D3C22212859E070047709F /* SPFavoriteNode.m in Sources */, + 17D3C6041289BF350047709F /* SPConnectionControllerDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |