diff options
author | Damiano Galassi <[email protected]> | 2016-05-25 10:20:51 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2016-05-25 10:20:51 +0200 |
commit | f252ae60c2f2222be64125313e02cb92e3fb8412 (patch) | |
tree | dfa610bf6c9fb0b1737f2b664d8a477eadb31cca /macosx | |
parent | e8c37c88b864f515aacda7a1a8fbcda9ed6b8bad (diff) |
MacGui: make a submenu for each preset folder in the Presets menu.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBAppDelegate.m | 82 |
1 files changed, 45 insertions, 37 deletions
diff --git a/macosx/HBAppDelegate.m b/macosx/HBAppDelegate.m index 80b4d5ac4..1cdde8fb6 100644 --- a/macosx/HBAppDelegate.m +++ b/macosx/HBAppDelegate.m @@ -292,7 +292,7 @@ - (void)buildPresetsMenu { // First we remove all the preset menu items - // inserted previosly + // inserted previously NSArray *menuItems = [self.presetsMenu.itemArray copy]; for (NSMenuItem *item in menuItems) { @@ -302,42 +302,50 @@ } } - __block NSUInteger i = 0; - __block BOOL builtInEnded = NO; - [self.presetsManager.root enumerateObjectsUsingBlock:^(HBPreset *obj, NSIndexPath *idx, BOOL *stop) - { - if (idx.length) - { - NSMenuItem *item = [[NSMenuItem alloc] init]; - item.title = obj.name; - item.tag = i++; - - // Set an action only to the actual presets, - // not on the folders. - if (obj.isLeaf) - { - item.action = @selector(selectPresetFromMenu:); - item.representedObject = obj; - } - // Make the default preset font bold. - if ([obj isEqualTo:self.presetsManager.defaultPreset]) - { - NSAttributedString *newTitle = [[NSAttributedString alloc] initWithString:obj.name - attributes:@{NSFontAttributeName: [NSFont boldSystemFontOfSize:14]}]; - [item setAttributedTitle:newTitle]; - } - // Add a separator line after the last builtIn preset - if (obj.isBuiltIn == NO && builtInEnded == NO) - { - [self.presetsMenu addItem:[NSMenuItem separatorItem]]; - builtInEnded = YES; - } - - item.indentationLevel = idx.length - 1; - - [self.presetsMenu addItem:item]; - } - }]; + BOOL builtInSeparatorInserted = NO; + for (HBPreset *preset in self.presetsManager.root.children) + { + if (preset.isBuiltIn == NO && builtInSeparatorInserted == NO) + { + [self.presetsMenu addItem:[NSMenuItem separatorItem]]; + builtInSeparatorInserted = YES; + } + [self.presetsMenu addItem:[self buildMenuItemWithPreset:preset]]; + } +} + +- (NSMenuItem *)buildMenuItemWithPreset:(HBPreset *)preset +{ + NSMenuItem *item = [[NSMenuItem alloc] init]; + item.title = preset.name; + item.toolTip = preset.presetDescription; + item.tag = 2; + + if (preset.isLeaf) + { + item.action = @selector(selectPresetFromMenu:); + item.representedObject = preset; + + // Make the default preset font bold. + if ([preset isEqualTo:self.presetsManager.defaultPreset]) + { + NSAttributedString *newTitle = [[NSAttributedString alloc] initWithString:preset.name + attributes:@{NSFontAttributeName: [NSFont boldSystemFontOfSize:14]}]; + [item setAttributedTitle:newTitle]; + } + } + else + { + NSMenu *menu = [[NSMenu alloc] init]; + for (HBPreset *childPreset in preset.children) + { + [menu addItem:[self buildMenuItemWithPreset:childPreset]]; + } + + item.submenu = menu; + } + + return item; } /** |