]> granicus.if.org Git - handbrake/commitdiff
MacGui: add a popup button to select the preset in the main window.
authorDamiano Galassi <damiog@gmail.com>
Fri, 24 Nov 2017 17:01:43 +0000 (18:01 +0100)
committerDamiano Galassi <damiog@gmail.com>
Fri, 24 Nov 2017 17:01:43 +0000 (18:01 +0100)
macosx/English.lproj/MainWindow.xib
macosx/HBAppDelegate.m
macosx/HBController.m
macosx/HBPresetsMenuBuilder.h [new file with mode: 0644]
macosx/HBPresetsMenuBuilder.m [new file with mode: 0644]
macosx/HandBrake.xcodeproj/project.pbxproj

index d31cfe14c55d0f56367d69b7f7e053b168d2cf97..a22b4b131c606ddc9b2409114a00e9823ff7ce3a 100644 (file)
@@ -32,6 +32,7 @@
                 <outlet property="fSubtitlesTab" destination="5194" id="PF0-qx-Iu4"/>
                 <outlet property="fVideoTab" destination="1477" id="hFY-kK-afW"/>
                 <outlet property="openTitleView" destination="lZQ-gl-3wX" id="Wh6-fB-pWi"/>
+                <outlet property="presetsPopup" destination="bWH-Lp-mKY" id="vot-gQ-hLV"/>
                 <outlet property="showQueueToolbarItem" destination="HCx-ku-nF7" id="CC6-Yu-j7N"/>
                 <outlet property="summaryTab" destination="BA0-eg-2Ka" id="wh5-Js-weO"/>
                 <outlet property="window" destination="21" id="qib-ZH-aNm"/>
@@ -54,7 +55,7 @@
                         <tabViewItems>
                             <tabViewItem label="Summary" identifier="" id="BA0-eg-2Ka">
                                 <view key="view" id="BjX-E2-6tb">
-                                    <rect key="frame" x="10" y="25" width="874" height="339"/>
+                                    <rect key="frame" x="10" y="29" width="874" height="335"/>
                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 </view>
                             </tabViewItem>
                         </textFieldCell>
                     </textField>
                     <box verticalHuggingPriority="750" misplaced="YES" boxType="separator" id="1628">
-                        <rect key="frame" x="292" y="476" width="608" height="5"/>
+                        <rect key="frame" x="283" y="476" width="617" height="5"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
                     </box>
-                    <textField toolTip="Selected preset name." verticalHuggingPriority="750" misplaced="YES" allowsCharacterPickerTouchBarItem="YES" id="1882">
-                        <rect key="frame" x="69" y="472" width="217" height="14"/>
-                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                        <textFieldCell key="cell" sendsActionOnEndEditing="YES" id="4924">
-                            <font key="font" metaFont="smallSystemBold"/>
-                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
-                            <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
-                        </textFieldCell>
-                        <connections>
-                            <binding destination="-2" name="value" keyPath="self.job.presetName" id="W9D-4K-e1F"/>
-                        </connections>
-                    </textField>
                     <box verticalHuggingPriority="750" boxType="separator" id="3205">
                         <rect key="frame" x="391" y="537" width="509" height="5"/>
                         <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
@@ -578,6 +567,30 @@ Blu-ray and DVD sources often have multiple titles, the longest of which is typi
                             </subviews>
                         </view>
                     </box>
+                    <popUpButton verticalHuggingPriority="750" misplaced="YES" id="bWH-Lp-mKY">
+                        <rect key="frame" x="68" y="467" width="210" height="22"/>
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                        <popUpButtonCell key="cell" type="push" title="Selected Preset" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" pullsDown="YES" id="4hk-61-M1H">
+                            <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
+                            <font key="font" metaFont="smallSystem"/>
+                            <menu key="menu" id="X2f-Tk-x0c">
+                                <items>
+                                    <menuItem title="Selected Preset" state="on" hidden="YES" id="OYP-3T-FnA">
+                                        <connections>
+                                            <binding destination="-2" name="title" keyPath="self.job.presetName" id="vO4-JB-o7Q"/>
+                                        </connections>
+                                    </menuItem>
+                                </items>
+                            </menu>
+                        </popUpButtonCell>
+                        <connections>
+                            <binding destination="-2" name="enabled" keyPath="self.job" id="1XP-x4-0GV">
+                                <dictionary key="options">
+                                    <string key="NSValueTransformerName">NSIsNotNil</string>
+                                </dictionary>
+                            </binding>
+                        </connections>
+                    </popUpButton>
                 </subviews>
             </view>
             <toolbar key="toolbar" implicitIdentifier="E92CA47A-01F7-432A-A61C-28FE4D58C2CD" explicitIdentifier="HBMainWindowToolbar" displayMode="iconAndLabel" sizeMode="regular" id="7g3-gy-bUl">
@@ -613,7 +626,7 @@ Blu-ray and DVD sources often have multiple titles, the longest of which is typi
                         <popUpButton key="view" misplaced="YES" imageHugsTitle="YES" id="pJJ-0V-TQq">
                             <rect key="frame" x="28" y="14" width="58" height="25"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" heightSizable="YES"/>
-                            <popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="addqueue" alignment="center" lineBreakMode="truncatingTail" state="on" inset="2" pullsDown="YES" id="BAK-n3-eIN">
+                            <popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="center" lineBreakMode="truncatingTail" state="on" inset="2" pullsDown="YES" id="BAK-n3-eIN">
                                 <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                 <font key="font" metaFont="menu"/>
                                 <menu key="menu" id="QCi-1O-Msg">
index 97627194b897b6c01a1020f2350fa17d2917b7e8..32253ed54ca49bf9301c9035cb1d21a0ac9326f9 100644 (file)
@@ -9,6 +9,7 @@
 #import "HBUtilities.h"
 #import "HBPresetsManager.h"
 #import "HBPreset.h"
+#import "HBPresetsMenuBuilder.h"
 
 #import "HBPreferencesController.h"
 #import "HBQueueController.h"
@@ -23,6 +24,7 @@
 @interface HBAppDelegate ()
 
 @property (nonatomic, strong) HBPresetsManager *presetsManager;
+@property (nonatomic, strong) HBPresetsMenuBuilder *presetsMenuBuilder;
 @property (unsafe_unretained) IBOutlet NSMenu *presetsMenu;
 
 @property (nonatomic, strong) HBPreferencesController *preferencesController;
 
 - (void)applicationDidFinishLaunching:(NSNotification *)notification
 {
-    [self buildPresetsMenu];
 
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buildPresetsMenu) name:HBPresetsChangedNotification object:nil];
+    self.presetsMenuBuilder = [[HBPresetsMenuBuilder alloc] initWithMenu:self.presetsMenu
+                                                                  action:@selector(selectPresetFromMenu:)
+                                                                    size:[NSFont systemFontSize]
+                                                          presetsManager:self.presetsManager];
+    [self.presetsMenuBuilder build];
 
     // Get the number of HandBrake instances currently running
     NSUInteger instances = [NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]].count;
 
 #pragma mark - Presets Menu actions
 
-/**
- *  Adds the presets list to the menu.
- */
-- (void)buildPresetsMenu
-{
-    // First we remove all the preset menu items
-    // inserted previously
-    NSArray *menuItems = [self.presetsMenu.itemArray copy];
-    for (NSMenuItem *item in menuItems)
-    {
-        if (item.tag != -1)
-        {
-            [self.presetsMenu removeItem: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;
-}
-
 /**
  * We use this method to recreate new, updated factory presets
  */
index 32995f7382830eac99c8d495265410b8bb728d08..42488ccba5b7e5cf77df1e3b921f5f950e91213f 100644 (file)
@@ -14,6 +14,7 @@
 #import "HBPresetsManager.h"
 #import "HBPreset.h"
 #import "HBMutablePreset.h"
+#import "HBPresetsMenuBuilder.h"
 
 #import "HBSummaryViewController.h"
 #import "HBPictureViewController.h"
     IBOutlet NSDrawer            * fPresetDrawer;
 }
 
+@property (nonatomic, strong) HBPresetsMenuBuilder *presetsMenuBuilder;
+@property (nonatomic, strong) IBOutlet NSPopUpButton *presetsPopup;
+
 @property (nonatomic, strong) HBSummaryViewController *summaryController;
 @property (nonatomic, strong) IBOutlet NSTabViewItem *summaryTab;
 
                                                               forKeyPath:@"values.HBShowAdvancedTab"
                                                                  options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial
                                                                  context:NULL];
-    
+
+
+    self.presetsMenuBuilder = [[HBPresetsMenuBuilder alloc] initWithMenu:self.presetsPopup.menu
+                                                                  action:@selector(selectPresetFromMenu:)
+                                                                    size:[NSFont smallSystemFontSize]
+                                                          presetsManager:presetManager];
+    [self.presetsMenuBuilder build];
+
     [self.window recalculateKeyViewLoop];
 }
 
diff --git a/macosx/HBPresetsMenuBuilder.h b/macosx/HBPresetsMenuBuilder.h
new file mode 100644 (file)
index 0000000..d7b66aa
--- /dev/null
@@ -0,0 +1,23 @@
+//
+//  HBPresetsMenuBuilder.h
+//  HandBrake
+//
+//  Created by Damiano Galassi on 24/11/2017.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@import HandBrakeKit;
+
+@interface HBPresetsMenuBuilder : NSObject
+
+@property (nonatomic, readonly) NSMenu *menu;
+
+- (instancetype)initWithMenu:(NSMenu *)menu action:(SEL)action size:(CGFloat)size presetsManager:(HBPresetsManager *)manager;
+
+/**
+ *  Adds the presets list to the menu.
+ */
+- (void)build;
+
+@end
diff --git a/macosx/HBPresetsMenuBuilder.m b/macosx/HBPresetsMenuBuilder.m
new file mode 100644 (file)
index 0000000..1bdb9ba
--- /dev/null
@@ -0,0 +1,103 @@
+//
+//  HBPresetsMenuBuilder.m
+//  HandBrake
+//
+//  Created by Damiano Galassi on 24/11/2017.
+//
+
+#import "HBPresetsMenuBuilder.h"
+
+@interface HBPresetsMenuBuilder ()
+
+@property (nonatomic, readonly) CGFloat size;
+@property (nonatomic, readonly) HBPresetsManager *manager;
+@property (nonatomic, readonly) SEL action;
+
+@end
+
+@implementation HBPresetsMenuBuilder
+
+- (instancetype)initWithMenu:(NSMenu *)menu action:(SEL)action size:(CGFloat)size presetsManager:(HBPresetsManager *)manager
+{
+    self = [super init];
+    if (self)
+    {
+        _menu = menu;
+        _size = size;
+        _manager = manager;
+        _action = action;
+
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(build) name:HBPresetsChangedNotification object:nil];
+    }
+
+    return self;
+}
+
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+/**
+ *  Adds the presets list to the menu.
+ */
+- (void)build
+{
+    // First we remove all the preset menu items
+    // inserted previously
+    NSArray *menuItems = [self.menu.itemArray copy];
+    for (NSMenuItem *item in menuItems)
+    {
+        if (item.tag == 2)
+        {
+            [self.menu removeItem:item];
+        }
+    }
+
+    BOOL builtInSeparatorInserted = NO;
+    for (HBPreset *preset in self.manager.root.children)
+    {
+        if (preset.isBuiltIn == NO && builtInSeparatorInserted == NO)
+        {
+            [self.menu addItem:[NSMenuItem separatorItem]];
+            builtInSeparatorInserted = YES;
+        }
+        [self.menu 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 = self.action;
+        item.representedObject = preset;
+
+        // Make the default preset font bold.
+        if ([preset isEqualTo:self.manager.defaultPreset])
+        {
+            NSAttributedString *newTitle = [[NSAttributedString alloc] initWithString:preset.name
+                                                                           attributes:@{NSFontAttributeName: [NSFont boldSystemFontOfSize:self.size]}];
+            [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;
+}
+
+@end
index be8fc167bcefd3a8ab6ba4a9f49bc0afd1d93054..32ac5fcd6afc2a1b36df9a844820032420dc0e14 100644 (file)
                A932E26C1988334B0047D13E /* AudioDefaults.xib in Resources */ = {isa = PBXBuildFile; fileRef = A932E26A1988334B0047D13E /* AudioDefaults.xib */; };
                A9350F501CCA7F490089F970 /* HBQTKitPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = A9350F4E1CCA7C3B0089F970 /* HBQTKitPlayer.m */; };
                A937EECB1C6C7C0300EEAE6D /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = A937EECA1C6C7C0300EEAE6D /* dsa_pub.pem */; };
+               A939DD8B1FC8826A00135F2A /* HBPresetsMenuBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = A939DD8A1FC8826A00135F2A /* HBPresetsMenuBuilder.m */; };
                A93B49221DA3AA6900DD70A3 /* HBToolbarBadgedItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A93B49211DA3AA6900DD70A3 /* HBToolbarBadgedItem.m */; };
                A93E0ED31972957000FD67FB /* HBVideoController.m in Sources */ = {isa = PBXBuildFile; fileRef = A93E0ED11972957000FD67FB /* HBVideoController.m */; };
                A93E0ED71972958C00FD67FB /* Video.xib in Resources */ = {isa = PBXBuildFile; fileRef = A93E0ED51972958C00FD67FB /* Video.xib */; };
                A9350F4D1CCA7C3B0089F970 /* HBQTKitPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBQTKitPlayer.h; sourceTree = "<group>"; };
                A9350F4E1CCA7C3B0089F970 /* HBQTKitPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBQTKitPlayer.m; sourceTree = "<group>"; };
                A937EECA1C6C7C0300EEAE6D /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
+               A939DD891FC8826A00135F2A /* HBPresetsMenuBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HBPresetsMenuBuilder.h; sourceTree = "<group>"; };
+               A939DD8A1FC8826A00135F2A /* HBPresetsMenuBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HBPresetsMenuBuilder.m; sourceTree = "<group>"; };
                A93B0DF61C804CF50051A3FA /* NSDictionary+HBAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+HBAdditions.h"; sourceTree = "<group>"; };
                A93B0DF71C804CF50051A3FA /* NSDictionary+HBAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+HBAdditions.m"; sourceTree = "<group>"; };
                A93B49201DA3AA6900DD70A3 /* HBToolbarBadgedItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBToolbarBadgedItem.h; sourceTree = "<group>"; };
                                273F209C14ADBE670021BE6D /* HBOutputPanelController.m */,
                                273F209F14ADBE670021BE6D /* HBPreferencesController.h */,
                                273F20A014ADBE670021BE6D /* HBPreferencesController.m */,
+                               A939DD891FC8826A00135F2A /* HBPresetsMenuBuilder.h */,
+                               A939DD8A1FC8826A00135F2A /* HBPresetsMenuBuilder.m */,
                        );
                        name = Controllers;
                        sourceTree = "<group>";
                                A9706CB71AC1437800BAEAA8 /* HBExceptionAlertController.m in Sources */,
                                A93B49221DA3AA6900DD70A3 /* HBToolbarBadgedItem.m in Sources */,
                                A91AD3401FB5D2FC00AEA822 /* HBAddCategoryController.m in Sources */,
+                               A939DD8B1FC8826A00135F2A /* HBPresetsMenuBuilder.m in Sources */,
                                A92268781A6E555500A8D5C5 /* HBAppDelegate.m in Sources */,
                                A98036CD1CCA91DD007661AA /* HBAVPlayer.m in Sources */,
                                A9BC24C91A69293E007DC41A /* HBAttributedStringAdditions.m in Sources */,