aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-03-19 18:53:25 +0000
committerstuconnolly <stuart02@gmail.com>2011-03-19 18:53:25 +0000
commit0a6a53a530c6fead2ed807b08838db3d095e6393 (patch)
tree5378e905307c711876120aa6df9b403965b7f536 /Source
parent6d3f21336846d7745e795202c99390832c4220c8 (diff)
downloadsequelpro-0a6a53a530c6fead2ed807b08838db3d095e6393.tar.gz
sequelpro-0a6a53a530c6fead2ed807b08838db3d095e6393.tar.bz2
sequelpro-0a6a53a530c6fead2ed807b08838db3d095e6393.zip
Remove sub-menus from default favorite popup button.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPGeneralPreferencePane.h2
-rw-r--r--Source/SPGeneralPreferencePane.m80
2 files changed, 61 insertions, 21 deletions
diff --git a/Source/SPGeneralPreferencePane.h b/Source/SPGeneralPreferencePane.h
index 7d14492e..c573b84a 100644
--- a/Source/SPGeneralPreferencePane.h
+++ b/Source/SPGeneralPreferencePane.h
@@ -34,6 +34,8 @@
*/
@interface SPGeneralPreferencePane : SPPreferencePane <SPPreferencePaneProtocol>
{
+ NSImage *folderImage;
+
IBOutlet NSPopUpButton *defaultFavoritePopup;
}
diff --git a/Source/SPGeneralPreferencePane.m b/Source/SPGeneralPreferencePane.m
index ecc3172a..d8daa229 100644
--- a/Source/SPGeneralPreferencePane.m
+++ b/Source/SPGeneralPreferencePane.m
@@ -29,22 +29,43 @@
#import "SPFavoriteNode.h"
#import "SPGroupNode.h"
+static NSString *SPDatabaseImage = @"database-small";
+
@interface SPGeneralPreferencePane ()
-- (NSMenuItem *)_constructMenuItemForNode:(SPTreeNode *)node;
+- (NSArray *)_constructMenuItemsForNode:(SPTreeNode *)node atLevel:(NSUInteger)level;
@end
@implementation SPGeneralPreferencePane
#pragma mark -
+#pragma mark Initialisation
+
+- (void)awakeFromNib
+{
+ // Generic folder image for use in the outline view's groups
+ folderImage = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)] retain];
+
+ [folderImage setSize:NSMakeSize(16, 16)];
+}
+
+#pragma mark -
#pragma mark IB action methods
/**
* Updates the default favorite.
*/
- (IBAction)updateDefaultFavorite:(id)sender
-{
+{
+ for (NSMenuItem *item in [defaultFavoritePopup itemArray])
+ {
+ [item setState:NSOffState];
+ }
+
+ [sender setState:NSOnState];
+ [defaultFavoritePopup setTitle:[sender title]];
+
[prefs setBool:([defaultFavoritePopup indexOfSelectedItem] == 0) forKey:SPSelectLastFavoriteUsed];
[prefs setInteger:[sender tag] forKey:SPDefaultFavorite];
@@ -60,18 +81,18 @@
{
[defaultFavoritePopup removeAllItems];
- // Use the last used favorite
[defaultFavoritePopup addItemWithTitle:NSLocalizedString(@"Last Used", @"Last Used entry in favorites menu")];
[[defaultFavoritePopup menu] addItem:[NSMenuItem separatorItem]];
// Add all favorites to the menu
for (SPTreeNode *node in [[[[[SPFavoritesController sharedFavoritesController] favoritesTree] childNodes] objectAtIndex:0] childNodes])
{
- NSMenuItem *menuItem = [self _constructMenuItemForNode:node];
-
- [[defaultFavoritePopup menu] addItem:menuItem];
+ NSArray *items = [self _constructMenuItemsForNode:node atLevel:0];
- [menuItem release];
+ for (NSMenuItem *item in items)
+ {
+ [[defaultFavoritePopup menu] addItem:item];
+ }
}
// Select the default favorite from prefs
@@ -93,40 +114,48 @@
*
* @return The menu item
*/
-- (NSMenuItem *)_constructMenuItemForNode:(SPTreeNode *)node
+- (NSArray *)_constructMenuItemsForNode:(SPTreeNode *)node atLevel:(NSUInteger)level
{
- NSMenuItem *menuItem = nil;
+ NSMutableArray *items = [NSMutableArray array];
if ([node isGroup]) {
+ level++;
+
SPGroupNode *groupNode = (SPGroupNode *)[node representedObject];
- menuItem = [[NSMenuItem alloc] initWithTitle:[groupNode nodeName] action:NULL keyEquivalent:@""];
+ NSMenuItem *groupItem = [[NSMenuItem alloc] initWithTitle:[groupNode nodeName] action:NULL keyEquivalent:@""];
- NSMenu *subMenu = [[NSMenu alloc] initWithTitle:[groupNode nodeName]];
+ [groupItem setEnabled:NO];
+ [groupItem setImage:folderImage];
+
+ [items addObject:groupItem];
+
+ [groupItem release];
for (SPTreeNode *childNode in [node childNodes])
{
- NSMenuItem *innerItem = [self _constructMenuItemForNode:childNode];
-
- [subMenu addItem:innerItem];
-
- [innerItem release];
+ NSArray *innerItems = [self _constructMenuItemsForNode:childNode atLevel:level];
+
+ [items addObjectsFromArray:innerItems];
}
-
- [menuItem setSubmenu:subMenu];
}
else {
NSDictionary *favorite = [(SPFavoriteNode *)[node representedObject] nodeFavorite];
- menuItem = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:SPFavoriteNameKey] action:@selector(updateDefaultFavorite:) keyEquivalent:@""];
+ NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[favorite objectForKey:SPFavoriteNameKey] action:@selector(updateDefaultFavorite:) keyEquivalent:@""];
[menuItem setTag:[[favorite objectForKey:SPFavoriteIDKey] integerValue]];
-
+ [menuItem setImage:[NSImage imageNamed:SPDatabaseImage]];
+ [menuItem setIndentationLevel:level];
[menuItem setTarget:self];
+
+ [items addObject:menuItem];
+
+ [menuItem release];
}
- return menuItem;
+ return items;
}
#pragma mark -
@@ -162,4 +191,13 @@
return NO;
}
+#pragma mark -
+
+- (void)dealloc
+{
+ [folderImage release], folderImage = nil;
+
+ [super dealloc];
+}
+
@end