Skip to content

Commit

Permalink
MacGui: improve touch bar support, add touch bars to the add titles t…
Browse files Browse the repository at this point in the history
…o queue and add preset sheets.
  • Loading branch information
galad87 committed Oct 16, 2018
1 parent acee000 commit 8150402
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 5 deletions.
48 changes: 48 additions & 0 deletions macosx/HBAddPresetController.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,51 @@ - (IBAction)openUserGuide:(id)sender
}

@end

@interface HBAddPresetController (TouchBar) <NSTouchBarProvider, NSTouchBarDelegate>
@end

@implementation HBAddPresetController (TouchBar)

@dynamic touchBar;

static NSTouchBarItemIdentifier HBTouchBarGroup = @"fr.handbrake.buttonsGroup";
static NSTouchBarItemIdentifier HBTouchBarAdd = @"fr.handbrake.openSource";
static NSTouchBarItemIdentifier HBTouchBarCancel = @"fr.handbrake.addToQueue";

- (NSTouchBar *)makeTouchBar
{
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;

bar.defaultItemIdentifiers = @[HBTouchBarGroup, NSTouchBarItemIdentifierOtherItemsProxy];
bar.principalItemIdentifier = HBTouchBarGroup;

return bar;
}

- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
if ([identifier isEqualTo:HBTouchBarGroup])
{
NSCustomTouchBarItem *cancelItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarAdd];
cancelItem.customizationLabel = NSLocalizedString(@"Cancel", @"Touch bar");
NSButton *cancelButton = [NSButton buttonWithTitle:NSLocalizedString(@"Cancel", @"Touch bar") target:self action:@selector(cancel:)];
[cancelButton.widthAnchor constraintGreaterThanOrEqualToConstant:200].active = YES;
cancelItem.view = cancelButton;

NSCustomTouchBarItem *addItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarCancel];
addItem.customizationLabel = NSLocalizedString(@"Add Preset", @"Touch bar");
NSButton *addButton = [NSButton buttonWithTitle:NSLocalizedString(@"Add Preset", @"Touch bar") target:self action:@selector(add:)];
[addButton.widthAnchor constraintGreaterThanOrEqualToConstant:200].active = YES;
addButton.keyEquivalent = @"\r";
addItem.view = addButton;

NSGroupTouchBarItem *item = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:@[cancelItem, addItem]];
return item;
}

return nil;
}

@end
17 changes: 13 additions & 4 deletions macosx/HBController.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ - (void)windowDidLoad
fPresetsView = [[HBPresetsViewController alloc] initWithPresetManager:presetManager];
fPresetsView.delegate = self;

fPresetsView.showHeader = YES;

// Set up the presets popover
self.presetsPopover = [[NSPopover alloc] init];

Expand Down Expand Up @@ -1544,6 +1542,7 @@ @implementation HBController (TouchBar)

static NSTouchBarItemIdentifier HBTouchBarOpen = @"fr.handbrake.openSource";
static NSTouchBarItemIdentifier HBTouchBarAddToQueue = @"fr.handbrake.addToQueue";
static NSTouchBarItemIdentifier HBTouchBarAddTitlesToQueue = @"fr.handbrake.addTitlesToQueue";
static NSTouchBarItemIdentifier HBTouchBarRip = @"fr.handbrake.rip";
static NSTouchBarItemIdentifier HBTouchBarPause = @"fr.handbrake.pause";
static NSTouchBarItemIdentifier HBTouchBarPreview = @"fr.handbrake.preview";
Expand All @@ -1553,10 +1552,10 @@ - (NSTouchBar *)makeTouchBar
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;

bar.defaultItemIdentifiers = @[HBTouchBarOpen, NSTouchBarItemIdentifierFixedSpaceSmall, HBTouchBarAddToQueue, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarRip, HBTouchBarPause, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarPreview];
bar.defaultItemIdentifiers = @[HBTouchBarOpen, NSTouchBarItemIdentifierFixedSpaceSmall, HBTouchBarAddToQueue, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarRip, HBTouchBarPause, NSTouchBarItemIdentifierFixedSpaceLarge, HBTouchBarPreview, NSTouchBarItemIdentifierOtherItemsProxy];

bar.customizationIdentifier = HBTouchBarMain;
bar.customizationAllowedItemIdentifiers = @[HBTouchBarOpen, HBTouchBarAddToQueue, HBTouchBarRip, HBTouchBarPause, HBTouchBarPreview, NSTouchBarItemIdentifierFixedSpaceSmall, NSTouchBarItemIdentifierFixedSpaceLarge, NSTouchBarItemIdentifierFlexibleSpace];
bar.customizationAllowedItemIdentifiers = @[HBTouchBarOpen, HBTouchBarAddToQueue, HBTouchBarAddTitlesToQueue, HBTouchBarRip, HBTouchBarPause, HBTouchBarPreview, NSTouchBarItemIdentifierFixedSpaceSmall, NSTouchBarItemIdentifierFixedSpaceLarge, NSTouchBarItemIdentifierFlexibleSpace];

return bar;
}
Expand All @@ -1583,6 +1582,16 @@ - (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTou
item.view = button;
return item;
}
else if ([identifier isEqualTo:HBTouchBarAddTitlesToQueue])
{
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
item.customizationLabel = NSLocalizedString(@"Add Titles To Queue", @"Touch bar");

NSButton *button = [NSButton buttonWithTitle:NSLocalizedString(@"Add Titles To Queue", @"Touch bar") target:self action:@selector(addTitlesToQueue:)];

item.view = button;
return item;
}
else if ([identifier isEqualTo:HBTouchBarRip])
{
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
Expand Down
7 changes: 7 additions & 0 deletions macosx/HBCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ typedef void (^HBCoreCompletionHandler)(HBCoreResult result);
* HBCore is an Objective-C interface to the low-level HandBrake library.
* HBCore monitors state changes of libhb. It can also be used
* to implement properties that can be directly bound to elements of the gui.
*
* Instance methods must be called on the same queue as the queue
* passed to initWithLogLevel:queue:
* Convenience inits use the main queue by default.
*
* copyImageAtIndex: can be called on a different queue,
* but the caller must ensure the validity of the title.
*/
@interface HBCore : NSObject

Expand Down
1 change: 1 addition & 0 deletions macosx/HBPresetsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ - (instancetype)initWithPresetManager:(HBPresetsManager *)presetManager
_selectedPresetInternal = presetManager.defaultPreset;
_expandedNodes = [[NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults]
objectForKey:@"HBPreviewViewExpandedStatus"]] mutableCopy];
_showHeader = YES;
}
return self;
}
Expand Down
6 changes: 5 additions & 1 deletion macosx/HBPreviewGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface HBPreviewGenerator ()
@property (nonatomic, readonly) NSCache<NSNumber *, id> *smallPreviewsCache;

@property (nonatomic, readonly) dispatch_semaphore_t sem;
@property (nonatomic, readonly) _Atomic bool invalidated;

@property (nonatomic, strong) HBCore *core;

Expand Down Expand Up @@ -59,6 +60,8 @@ - (instancetype)initWithCore:(HBCore *)core job:(HBJob *)job

- (void)dealloc
{
_invalidated = true;

[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
[self.core cancelEncode];
Expand Down Expand Up @@ -154,7 +157,8 @@ - (NSString *)info
- (void)copySmallImageAtIndex:(NSUInteger)index completionHandler:(void (^)(__nullable CGImageRef result))handler
{
dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER);
if (index >= self.imagesCount)

if (_invalidated || index >= self.imagesCount)
{
handler(NULL);
dispatch_semaphore_signal(_sem);
Expand Down
48 changes: 48 additions & 0 deletions macosx/HBTitleSelectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,51 @@ - (IBAction)cancel:(id)sender
}

@end

@interface HBTitleSelectionController (TouchBar) <NSTouchBarProvider, NSTouchBarDelegate>
@end

@implementation HBTitleSelectionController (TouchBar)

@dynamic touchBar;

static NSTouchBarItemIdentifier HBTouchBarGroup = @"fr.handbrake.buttonsGroup";
static NSTouchBarItemIdentifier HBTouchBarAdd = @"fr.handbrake.openSource";
static NSTouchBarItemIdentifier HBTouchBarCancel = @"fr.handbrake.addToQueue";

- (NSTouchBar *)makeTouchBar
{
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;

bar.defaultItemIdentifiers = @[HBTouchBarGroup];
bar.principalItemIdentifier = HBTouchBarGroup;

return bar;
}

- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
{
if ([identifier isEqualTo:HBTouchBarGroup])
{
NSCustomTouchBarItem *cancelItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarAdd];
cancelItem.customizationLabel = NSLocalizedString(@"Cancel", @"Touch bar");
NSButton *cancelButton = [NSButton buttonWithTitle:NSLocalizedString(@"Cancel", @"Touch bar") target:self action:@selector(cancel:)];
[cancelButton.widthAnchor constraintGreaterThanOrEqualToConstant:200].active = YES;
cancelItem.view = cancelButton;

NSCustomTouchBarItem *addItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:HBTouchBarCancel];
addItem.customizationLabel = NSLocalizedString(@"Add To Queue", @"Touch bar");
NSButton *addButton = [NSButton buttonWithTitle:NSLocalizedString(@"Add To Queue", @"Touch bar") target:self action:@selector(add:)];
[addButton.widthAnchor constraintGreaterThanOrEqualToConstant:200].active = YES;
addButton.keyEquivalent = @"\r";
addItem.view = addButton;

NSGroupTouchBarItem *item = [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:@[cancelItem, addItem]];
return item;
}

return nil;
}

@end

0 comments on commit 8150402

Please sign in to comment.