diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPAppController.h | 2 | ||||
-rw-r--r-- | Source/SPGeneralPreferencePane.h | 2 | ||||
-rw-r--r-- | Source/SPGeneralPreferencePane.m | 68 | ||||
-rw-r--r-- | Source/SPTreeNode.m | 14 |
4 files changed, 68 insertions, 18 deletions
diff --git a/Source/SPAppController.h b/Source/SPAppController.h index fe80e2d9..5d12be48 100644 --- a/Source/SPAppController.h +++ b/Source/SPAppController.h @@ -30,7 +30,6 @@ @interface SPAppController : NSObject <FRFeedbackReporterDelegate> { - IBOutlet NSWindow* bundleEditorWindow; BOOL isNewFavorite; @@ -55,7 +54,6 @@ NSMutableArray *runningActivitiesArray; NSString *lastBundleBlobFilesDirectory; - } @property (readwrite, retain) NSString *lastBundleBlobFilesDirectory; diff --git a/Source/SPGeneralPreferencePane.h b/Source/SPGeneralPreferencePane.h index ab7ef949..7d14492e 100644 --- a/Source/SPGeneralPreferencePane.h +++ b/Source/SPGeneralPreferencePane.h @@ -35,8 +35,6 @@ @interface SPGeneralPreferencePane : SPPreferencePane <SPPreferencePaneProtocol> { IBOutlet NSPopUpButton *defaultFavoritePopup; - - IBOutlet NSArrayController *favoritesController; } - (IBAction)updateDefaultFavorite:(id)sender; 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 diff --git a/Source/SPTreeNode.m b/Source/SPTreeNode.m index e197d180..d93db01b 100644 --- a/Source/SPTreeNode.m +++ b/Source/SPTreeNode.m @@ -69,7 +69,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; return; } - if (![node isLeaf]) { + if ([node isGroup]) { [node removeObjectFromChildren:object]; } } @@ -88,7 +88,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; { [descendants addObject:node]; - if (![node isLeaf]) { + if ([node isGroup]) { [descendants addObjectsFromArray:[node descendants]]; } } @@ -107,7 +107,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; for (SPTreeNode *node in [self childNodes]) { - if ([node isLeaf]) { + if (![node isGroup]) { [childLeafs addObject:node]; } } @@ -127,7 +127,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; for (SPTreeNode *node in [self childNodes]) { - if ([node isLeaf]) { + if (![node isGroup]) { [childLeafs addObject:node]; } else { @@ -149,7 +149,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; for (SPTreeNode *node in [self childNodes]) { - if (![node isLeaf]) { + if ([node isGroup]) { [groupChildren addObject:node]; } } @@ -177,7 +177,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; break; } - if (![node isLeaf]) { + if ([node isGroup]) { SPTreeNode *innerNode = [self parentFromArray:[node childNodes]]; if (innerNode) { @@ -205,7 +205,7 @@ static NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; if (node == self) return YES; // Check all the sub-nodes - if (![node isLeaf]) { + if ([node isGroup]) { if ([self isDescendantOfOrOneOfNodes:[node childNodes]]) { return YES; } |