aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-11-11 16:53:24 +0000
committerstuconnolly <stuart02@gmail.com>2010-11-11 16:53:24 +0000
commitb1bc59225d7f190b6db36da4634cc96095f01591 (patch)
tree95cfdcc96dfbb48750d9f0afa79569591d04bea0
parentb8fc79dd357d8dd1cf3177d1a7faef030497a9e0 (diff)
downloadsequelpro-b1bc59225d7f190b6db36da4634cc96095f01591.tar.gz
sequelpro-b1bc59225d7f190b6db36da4634cc96095f01591.tar.bz2
sequelpro-b1bc59225d7f190b6db36da4634cc96095f01591.zip
Refactor the favorite node class and fix auto-selection of the default or last used favorite.
-rw-r--r--Source/SPConnectionController.m35
-rw-r--r--Source/SPConnectionControllerDelegate.m18
-rw-r--r--Source/SPFavoriteNode.h29
-rw-r--r--Source/SPFavoriteNode.m20
-rw-r--r--Source/SPFavoritesPreferencePane.m8
5 files changed, 59 insertions, 51 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index f8e9db18..2300d2e8 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -126,7 +126,7 @@
[self updateFavorites];
// Expand the favorites heading
- [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]];
+ [favoritesTable expandItem:[[favoritesRoot nodeChildren] objectAtIndex:0]];
// Register an observer for changes within the favorites
[prefs addObserver:self forKeyPath:SPFavorites options:NSKeyValueObservingOptionNew context:NULL];
@@ -144,11 +144,11 @@
// Sort the favourites to match prefs and select the appropriate row - if a valid sort option is selected
if (currentSortItem > -1) [self _sortFavorites];
- NSInteger tableRow = ([prefs integerForKey:[prefs boolForKey:SPSelectLastFavoriteUsed] ? SPLastFavoriteIndex : SPDefaultFavorite] + 1);
-
+ NSInteger tableRow = [prefs integerForKey:[prefs boolForKey:SPSelectLastFavoriteUsed] ? SPLastFavoriteIndex : SPDefaultFavorite];
+
if (tableRow < [favorites count]) {
previousType = [[[favorites objectAtIndex:tableRow] objectForKey:@"type"] integerValue];
- [favoritesTable selectRowIndexes:[NSIndexSet indexSetWithIndex:tableRow] byExtendingSelection:NO];
+ [favoritesTable selectRowIndexes:[NSIndexSet indexSetWithIndex:(tableRow + 1)] byExtendingSelection:NO];
[self resizeTabViewToConnectionType:[[[favorites objectAtIndex:tableRow] objectForKey:@"type"] integerValue] animating:NO];
[favoritesTable scrollRowToVisible:[favoritesTable selectedRow]];
}
@@ -878,7 +878,7 @@
[favoritesTable reloadData];
- [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]];
+ [favoritesTable expandItem:[[favoritesRoot nodeChildren] objectAtIndex:0]];
}
/**
@@ -886,7 +886,6 @@
*/
- (void)updateFavoriteSelection:(id)sender
{
-
// If nothing is selected, return without updating the interface
if (![self selectedFavorite]) return;
@@ -1109,21 +1108,18 @@
*/
- (void)_sortFavorites
{
- NSString *sortKey = @"";
+ NSString *sortKey = SPFavoriteNameKey;
switch (currentSortItem)
{
case SPFavoritesSortNameItem:
- sortKey = @"name";
+ sortKey = SPFavoriteNameKey;
break;
case SPFavoritesSortHostItem:
- sortKey = @"host";
+ sortKey = SPFavoriteHostKey;
break;
case SPFavoritesSortTypeItem:
- sortKey = @"type";
- break;
- default:
- sortKey = @"name";
+ sortKey = SPFavoriteTypeKey;
break;
}
@@ -1147,7 +1143,7 @@
[favoritesTable reloadData];
- [favoritesTable expandItem:[[favoritesRoot children] objectAtIndex:0]];
+ [favoritesTable expandItem:[[favoritesRoot nodeChildren] objectAtIndex:0]];
[first release];
}
@@ -1164,22 +1160,21 @@
// Add a dummy item to represent the favorites heading
SPFavoriteNode *favoritesNode = [[SPFavoriteNode alloc] init];
- [favoritesNode setIsGroup:YES];
- [favoritesNode setFavorite:[NSDictionary dictionaryWithObject:NSLocalizedString(@"FAVORITES", @"Favorites title at the top of the sidebar") forKey:@"name"]];
+ [favoritesNode setNodeIsGroup:YES];
+ [favoritesNode setNodeName:NSLocalizedString(@"FAVORITES", @"Favorites title at the top of the sidebar")];
for (NSDictionary *favorite in favorites)
{
SPFavoriteNode *node2 = [[SPFavoriteNode alloc] init];
- [node2 setFavorite:favorite];
- [node2 setIsGroup:NO];
+ [node2 setNodeFavorite:favorite];
- [[favoritesNode children] addObject:node2];
+ [[favoritesNode nodeChildren] addObject:node2];
[node2 release];
}
- [[favoritesRoot children] addObject:favoritesNode];
+ [[favoritesRoot nodeChildren] addObject:favoritesNode];
[favoritesNode release];
}
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m
index dab7465f..8d3b385d 100644
--- a/Source/SPConnectionControllerDelegate.m
+++ b/Source/SPConnectionControllerDelegate.m
@@ -146,24 +146,26 @@
{
SPFavoriteNode *node = (item == nil ? favoritesRoot : (SPFavoriteNode *)item);
- return [[node children] count];
+ return [[node nodeChildren] count];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
SPFavoriteNode *node = (item == nil ? favoritesRoot : (SPFavoriteNode *)item);
- return [[node children] objectAtIndex:index];
+ return NSArrayObjectAtIndex([node nodeChildren], index);
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
- return [(SPFavoriteNode *)item isGroup];
+ return [(SPFavoriteNode *)item nodeIsGroup];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
- return [[(SPFavoriteNode *)item favorite] objectForKey:@"name"];
+ SPFavoriteNode *node = (SPFavoriteNode *)item;
+
+ return ([node nodeIsGroup]) ? [node nodeName] : [[node nodeFavorite] objectForKey:SPFavoriteNameKey];
}
#pragma mark -
@@ -171,7 +173,7 @@
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
{
- return [(SPFavoriteNode *)item isGroup];
+ return [(SPFavoriteNode *)item nodeIsGroup];
}
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
@@ -197,17 +199,17 @@
[(SPTableTextFieldCell *)cell setTextColor:[NSColor grayColor]];
}
- [(SPTableTextFieldCell *)cell setImage:([(SPFavoriteNode *)item isGroup]) ? nil : [NSImage imageNamed:@"database-small"]];
+ [(SPTableTextFieldCell *)cell setImage:([(SPFavoriteNode *)item nodeIsGroup]) ? nil : [NSImage imageNamed:@"database-small"]];
}
- (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
{
- return ([item isGroup]) ? 22 : 17;
+ return ([item nodeIsGroup]) ? 22 : 17;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
{
- return (![item isGroup]);
+ return (![item nodeIsGroup]);
}
@end
diff --git a/Source/SPFavoriteNode.h b/Source/SPFavoriteNode.h
index 0493ae70..d3b25854 100644
--- a/Source/SPFavoriteNode.h
+++ b/Source/SPFavoriteNode.h
@@ -29,28 +29,37 @@
* @author Stuart Connolly http://stuconnolly.com/
*
* This class is designed to be a simple wrapper around a connection favorite to allow us to easily represent
- * them in a tree structure for use in an outline view.
+ * them in a tree structure for use in an outline view. If the node is a group item (i.e. a folder) then it
+ * should have a name as well as zero or more child nodes. Similarly, actual connection favorite nodes, don't
+ * have a name and should have no children.
*/
@interface SPFavoriteNode : NSObject
{
- BOOL isGroup;
- NSDictionary *favorite;
- NSMutableArray *children;
+ BOOL nodeIsGroup;
+ NSString *nodeName;
+
+ NSDictionary *nodeFavorite;
+ NSMutableArray *nodeChildren;
}
/**
- * @property isGroup Indicates whether this node is a group item
+ * @property nodeIsGroup Indicates whether this node is a group item
*/
-@property (readwrite, assign) BOOL isGroup;
+@property (readwrite, assign) BOOL nodeIsGroup;
/**
- * @property favorite The actual favorite dictionary
+ * @property nodeName The node's name if it's a group item
*/
-@property (readwrite, retain) NSDictionary *favorite;
+@property (readwrite, retain) NSString *nodeName;
/**
- * @property children This node's children
+ * @property nodeFavorite The actual favorite dictionary
*/
-@property (readwrite, retain) NSMutableArray *children;
+@property (readwrite, retain) NSDictionary *nodeFavorite;
+
+/**
+ * @property nodeChildren This node's children
+ */
+@property (readwrite, retain) NSMutableArray *nodeChildren;
@end
diff --git a/Source/SPFavoriteNode.m b/Source/SPFavoriteNode.m
index 3b46ba80..51a9d1aa 100644
--- a/Source/SPFavoriteNode.m
+++ b/Source/SPFavoriteNode.m
@@ -27,17 +27,18 @@
@implementation SPFavoriteNode
-@synthesize isGroup;
-@synthesize favorite;
-@synthesize children;
+@synthesize nodeIsGroup;
+@synthesize nodeName;
+@synthesize nodeFavorite;
+@synthesize nodeChildren;
- (id)init
{
if ((self = [super init])) {
- [self setIsGroup:NO];
-
- [self setFavorite:nil];
- [self setChildren:[[NSMutableArray alloc] init]];
+ [self setNodeIsGroup:NO];
+ [self setNodeName:nil];
+ [self setNodeFavorite:nil];
+ [self setNodeChildren:[[NSMutableArray alloc] init]];
}
return self;
@@ -45,8 +46,9 @@
- (void)dealloc
{
- if (favorite) [favorite release], favorite = nil;
- if (children) [children release], children = nil;
+ if (nodeName) [nodeName release], nodeName = nil;
+ if (nodeFavorite) [nodeFavorite release], nodeFavorite = nil;
+ if (nodeChildren) [nodeChildren release], nodeChildren = nil;
[super dealloc];
}
diff --git a/Source/SPFavoritesPreferencePane.m b/Source/SPFavoritesPreferencePane.m
index 07405dd3..7833d923 100644
--- a/Source/SPFavoritesPreferencePane.m
+++ b/Source/SPFavoritesPreferencePane.m
@@ -769,18 +769,18 @@
*/
- (void)_sortFavorites
{
- NSString *sortKey = @"";
+ NSString *sortKey = SPFavoriteNameKey;
switch (currentSortItem)
{
case SPFavoritesSortNameItem:
- sortKey = @"name";
+ sortKey = SPFavoriteNameKey;
break;
case SPFavoritesSortHostItem:
- sortKey = @"host";
+ sortKey = SPFavoriteHostKey;
break;
case SPFavoritesSortTypeItem:
- sortKey = @"type";
+ sortKey = SPFavoriteTypeKey;
break;
}