summaryrefslogtreecommitdiffstats
path: root/macosx/HBAddPresetController.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2017-11-10 13:59:14 +0100
committerDamiano Galassi <[email protected]>2017-11-10 13:59:14 +0100
commit69e4867fd92921d911b1b288bc3c00de9772c356 (patch)
tree24fbc18f3d7320fec745416d8986b93e9c2caeff /macosx/HBAddPresetController.m
parent1f7aeb62b9ac51132fddc260e4193e07f056ed2f (diff)
MacGui: add a popup menu to select the category in the add preset sheet.
Diffstat (limited to 'macosx/HBAddPresetController.m')
-rw-r--r--macosx/HBAddPresetController.m79
1 files changed, 78 insertions, 1 deletions
diff --git a/macosx/HBAddPresetController.m b/macosx/HBAddPresetController.m
index 3cdce5cb0..580673a27 100644
--- a/macosx/HBAddPresetController.m
+++ b/macosx/HBAddPresetController.m
@@ -6,9 +6,14 @@
#import "HBAddPresetController.h"
+#import "HBAddCategoryController.h"
+
#import "HBAudioDefaultsController.h"
#import "HBSubtitlesDefaultsController.h"
+#import "HBPresetsManager.h"
+#import "HBPreset.h"
+
@import HandBrakeKit;
typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
@@ -22,6 +27,8 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
@property (unsafe_unretained) IBOutlet NSTextField *name;
@property (unsafe_unretained) IBOutlet NSTextField *desc;
+@property (unsafe_unretained) IBOutlet NSPopUpButton *categories;
+
@property (unsafe_unretained) IBOutlet NSPopUpButton *picSettingsPopUp;
@property (unsafe_unretained) IBOutlet NSTextField *picWidth;
@property (unsafe_unretained) IBOutlet NSTextField *picHeight;
@@ -30,6 +37,10 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
@property (nonatomic, strong) HBPreset *preset;
@property (nonatomic, strong) HBMutablePreset *mutablePreset;
+@property (nonatomic, strong) HBPreset *selectedCategory;
+
+@property (nonatomic, strong) HBPresetsManager *manager;
+
@property (nonatomic) int width;
@property (nonatomic) int height;
@@ -42,13 +53,14 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
@implementation HBAddPresetController
-- (instancetype)initWithPreset:(HBPreset *)preset customWidth:(int)customWidth customHeight:(int)customHeight defaultToCustom:(BOOL)defaultToCustom
+- (instancetype)initWithPreset:(HBPreset *)preset presetManager:(HBPresetsManager *)manager customWidth:(int)customWidth customHeight:(int)customHeight defaultToCustom:(BOOL)defaultToCustom
{
self = [super initWithWindowNibName:@"AddPreset"];
if (self)
{
NSParameterAssert(preset);
_mutablePreset = [preset mutableCopy];
+ _manager = manager;
_width = customWidth;
_height = customHeight;
_defaultToCustom = defaultToCustom;
@@ -59,6 +71,17 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
- (void)windowDidLoad {
[super windowDidLoad];
+ // Build the categories menu, and select the first
+ [self buildCategoriesMenu];
+ if ([self.categories selectItemWithTag:2] == NO)
+ {
+ HBPreset *category = [[HBPreset alloc] initWithCategoryName:@"My Presets" builtIn:NO];
+ [self.manager addPreset:category];
+ NSMenuItem *item = [self buildMenuItemWithCategory:category];
+ [self.categories.menu insertItem:item atIndex:2];
+ [self.categories selectItemWithTag:2];
+ }
+
// Populate the preset picture settings popup.
// Use [NSMenuItem tag] to store preset values for each option.
@@ -87,6 +110,59 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
[self addPresetPicDropdownChanged:nil];
}
+/**
+ * Adds the presets list to the menu.
+ */
+- (void)buildCategoriesMenu
+{
+ for (HBPreset *preset in self.manager.root.children)
+ {
+ if (preset.isBuiltIn == NO && preset.isLeaf == NO)
+ {
+ [self.categories.menu addItem:[self buildMenuItemWithCategory:preset]];
+ }
+ }
+}
+
+- (NSMenuItem *)buildMenuItemWithCategory:(HBPreset *)preset
+{
+ NSMenuItem *item = [[NSMenuItem alloc] init];
+ item.title = preset.name;
+ item.toolTip = preset.presetDescription;
+ item.tag = 2;
+
+ item.action = @selector(selectCategoryFromMenu:);
+ item.representedObject = preset;
+
+ return item;
+}
+
+- (IBAction)showNewCategoryWindow:(id)sender
+{
+ HBAddCategoryController *addCategoryController = [[HBAddCategoryController alloc] initWithPresetManager:self.manager];
+
+ [NSApp beginSheet:addCategoryController.window modalForWindow:self.window modalDelegate:self didEndSelector:@selector(categorySheetDidEnd:returnCode:contextInfo:) contextInfo:(void *)CFBridgingRetain(addCategoryController)];
+}
+
+- (void)categorySheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ HBAddCategoryController *addCategoryController = (HBAddCategoryController *)CFBridgingRelease(contextInfo);
+
+ if (returnCode == NSModalResponseOK)
+ {
+ NSMenuItem *item = [self buildMenuItemWithCategory:addCategoryController.category];
+ [self.categories.menu insertItem:item atIndex:2];
+ }
+
+ [self.categories selectItemWithTag:2];
+
+}
+
+- (IBAction)selectCategoryFromMenu:(NSMenuItem *)sender
+{
+ self.selectedCategory = sender.representedObject;
+}
+
- (IBAction)addPresetPicDropdownChanged:(id)sender
{
if (self.picSettingsPopUp.selectedItem.tag == HBAddPresetControllerModeCustom)
@@ -175,6 +251,7 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
[newPreset cleanUp];
self.preset = [newPreset copy];
+ [self.selectedCategory insertObject:self.preset inChildrenAtIndex:0];
[self.window orderOut:nil];
[NSApp endSheet:self.window returnCode:NSModalResponseContinue];