From 1af63b378e644ceef6e26918b0a1d693bcc232f8 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Tue, 9 Nov 2010 18:19:12 +0000 Subject: 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. --- Source/SPConnectionController.h | 10 +- Source/SPConnectionController.m | 251 ++++++------------------ Source/SPConnectionControllerDelegate.h | 20 +- Source/SPConnectionControllerDelegate.m | 212 ++++++++++++++++++++ Source/SPConnectionControllerDelegateProtocol.h | 49 +++++ Source/SPDatabaseDocument.h | 4 +- Source/SPFavoriteNode.h | 37 ++++ Source/SPFavoriteNode.m | 54 +++++ Source/SPOutlineView.h | 2 +- Source/SPOutlineView.m | 38 +++- 10 files changed, 458 insertions(+), 219 deletions(-) create mode 100644 Source/SPConnectionControllerDelegate.m create mode 100644 Source/SPConnectionControllerDelegateProtocol.h create mode 100644 Source/SPFavoriteNode.h create mode 100644 Source/SPFavoriteNode.m (limited to 'Source') 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 -#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 delegate; + id delegate; SPDatabaseDocument *tableDocument; NSView *databaseConnectionSuperview; @@ -133,9 +133,11 @@ BOOL mySQLConnectionCancelled; SPFavoritesSortItem previousSortItem, currentSortItem; + + SPFavoriteNode *favoritesRoot; } -@property (readwrite, assign) id delegate; +@property (readwrite, assign) id 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)]; } /** @@ -1065,194 +1078,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 )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 )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 @@ -1316,11 +1141,49 @@ [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. */ 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 /** - * @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 + +#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 )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 )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 + +/** + * @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 +@interface SPDatabaseDocument : NSObject { // 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 + +@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 + +#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 -- cgit v1.2.3