aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPGeneralPreferencePane.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-03-17 19:25:56 +0000
committerstuconnolly <stuart02@gmail.com>2011-03-17 19:25:56 +0000
commitb2a0af91eae18b6490ddeafd2708d256b0d53cb3 (patch)
tree6fffce3be41ecf2f9a902f7bf795eb9471d81382 /Source/SPGeneralPreferencePane.m
parent1632c45fdd9d0b8fe1e0aef3e891e8bd5704df29 (diff)
downloadsequelpro-b2a0af91eae18b6490ddeafd2708d256b0d53cb3.tar.gz
sequelpro-b2a0af91eae18b6490ddeafd2708d256b0d53cb3.tar.bz2
sequelpro-b2a0af91eae18b6490ddeafd2708d256b0d53cb3.zip
Bind the default favorites drop down menu pref to the new favorites data file, with sub-menus representing groups (still a bit buggy).
Diffstat (limited to 'Source/SPGeneralPreferencePane.m')
-rw-r--r--Source/SPGeneralPreferencePane.m68
1 files changed, 61 insertions, 7 deletions
diff --git a/Source/SPGeneralPreferencePane.m b/Source/SPGeneralPreferencePane.m
index 36cbed9f..ecc3172a 100644
--- a/Source/SPGeneralPreferencePane.m
+++ b/Source/SPGeneralPreferencePane.m
@@ -24,6 +24,16 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPGeneralPreferencePane.h"
+#import "SPFavoritesController.h"
+#import "SPTreeNode.h"
+#import "SPFavoriteNode.h"
+#import "SPGroupNode.h"
+
+@interface SPGeneralPreferencePane ()
+
+- (NSMenuItem *)_constructMenuItemForNode:(SPTreeNode *)node;
+
+@end
@implementation SPGeneralPreferencePane
@@ -37,7 +47,7 @@
{
[prefs setBool:([defaultFavoritePopup indexOfSelectedItem] == 0) forKey:SPSelectLastFavoriteUsed];
- [prefs setInteger:[[sender selectedItem] tag] forKey:SPDefaultFavorite];
+ [prefs setInteger:[sender tag] forKey:SPDefaultFavorite];
}
#pragma mark -
@@ -55,15 +65,13 @@
[[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]];
// Add all favorites to the menu
- for (NSDictionary *favorite in [favoritesController arrangedObjects])
+ for (SPTreeNode *node in [[[[[SPFavoritesController sharedFavoritesController] favoritesTree] childNodes] objectAtIndex:0] childNodes])
{
- NSMenuItem *favoriteMenuItem = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:SPFavoriteNameKey] action:NULL keyEquivalent:@""];
-
- [favoriteMenuItem setTag:[[favorite objectForKey:SPFavoriteIDKey] integerValue]];
+ NSMenuItem *menuItem = [self _constructMenuItemForNode:node];
- [[defaultFavoritePopup menu] addItem:favoriteMenuItem];
+ [[defaultFavoritePopup menu] addItem:menuItem];
- [favoriteMenuItem release];
+ [menuItem release];
}
// Select the default favorite from prefs
@@ -76,6 +84,52 @@
}
#pragma mark -
+#pragma mark Private API
+
+/**
+ * Builds a menu item and sub-menu (if required) of the supplied tree node.
+ *
+ * @param node The node to build the menu item for
+ *
+ * @return The menu item
+ */
+- (NSMenuItem *)_constructMenuItemForNode:(SPTreeNode *)node
+{
+ NSMenuItem *menuItem = nil;
+
+ if ([node isGroup]) {
+
+ SPGroupNode *groupNode = (SPGroupNode *)[node representedObject];
+
+ menuItem = [[NSMenuItem alloc] initWithTitle:[groupNode nodeName] action:NULL keyEquivalent:@""];
+
+ NSMenu *subMenu = [[NSMenu alloc] initWithTitle:[groupNode nodeName]];
+
+ for (SPTreeNode *childNode in [node childNodes])
+ {
+ NSMenuItem *innerItem = [self _constructMenuItemForNode:childNode];
+
+ [subMenu addItem:innerItem];
+
+ [innerItem release];
+ }
+
+ [menuItem setSubmenu:subMenu];
+ }
+ else {
+ NSDictionary *favorite = [(SPFavoriteNode *)[node representedObject] nodeFavorite];
+
+ menuItem = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:SPFavoriteNameKey] action:@selector(updateDefaultFavorite:) keyEquivalent:@""];
+
+ [menuItem setTag:[[favorite objectForKey:SPFavoriteIDKey] integerValue]];
+
+ [menuItem setTarget:self];
+ }
+
+ return menuItem;
+}
+
+#pragma mark -
#pragma mark Preference pane protocol methods
- (NSView *)preferencePaneView