diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/English.lproj/MainWindow.xib | 43 | ||||
-rw-r--r-- | macosx/HBAppDelegate.m | 71 | ||||
-rw-r--r-- | macosx/HBController.m | 13 | ||||
-rw-r--r-- | macosx/HBPresetsMenuBuilder.h | 23 | ||||
-rw-r--r-- | macosx/HBPresetsMenuBuilder.m | 103 | ||||
-rw-r--r-- | macosx/HandBrake.xcodeproj/project.pbxproj | 6 |
6 files changed, 179 insertions, 80 deletions
diff --git a/macosx/English.lproj/MainWindow.xib b/macosx/English.lproj/MainWindow.xib index d31cfe14c..a22b4b131 100644 --- a/macosx/English.lproj/MainWindow.xib +++ b/macosx/English.lproj/MainWindow.xib @@ -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> @@ -356,21 +357,9 @@ </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"> diff --git a/macosx/HBAppDelegate.m b/macosx/HBAppDelegate.m index 97627194b..32253ed54 100644 --- a/macosx/HBAppDelegate.m +++ b/macosx/HBAppDelegate.m @@ -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; @@ -80,9 +82,12 @@ - (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; @@ -287,68 +292,6 @@ #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 */ - (IBAction)addFactoryPresets:(id)sender diff --git a/macosx/HBController.m b/macosx/HBController.m index 32995f738..42488ccba 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -14,6 +14,7 @@ #import "HBPresetsManager.h" #import "HBPreset.h" #import "HBMutablePreset.h" +#import "HBPresetsMenuBuilder.h" #import "HBSummaryViewController.h" #import "HBPictureViewController.h" @@ -99,6 +100,9 @@ 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; @@ -282,7 +286,14 @@ 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 index 000000000..d7b66aa04 --- /dev/null +++ b/macosx/HBPresetsMenuBuilder.h @@ -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 index 000000000..1bdb9ba2d --- /dev/null +++ b/macosx/HBPresetsMenuBuilder.m @@ -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 diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index be8fc167b..32ac5fcd6 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -186,6 +186,7 @@ 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 */; }; @@ -453,6 +454,8 @@ 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>"; }; @@ -1188,6 +1191,8 @@ 273F209C14ADBE670021BE6D /* HBOutputPanelController.m */, 273F209F14ADBE670021BE6D /* HBPreferencesController.h */, 273F20A014ADBE670021BE6D /* HBPreferencesController.m */, + A939DD891FC8826A00135F2A /* HBPresetsMenuBuilder.h */, + A939DD8A1FC8826A00135F2A /* HBPresetsMenuBuilder.m */, ); name = Controllers; sourceTree = "<group>"; @@ -1571,6 +1576,7 @@ 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 */, |