From 646cb272a2c9feecc5a839360248621991c1f453 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sun, 25 Oct 2015 07:03:36 +0100 Subject: [PATCH] MacGui: change the title selection sheet to use a view-based table view. --- macosx/English.lproj/HBTitleSelection.xib | 183 ++++++++++++++++------ macosx/HBTitleSelectionController.h | 4 +- macosx/HBTitleSelectionController.m | 88 +++++------ 3 files changed, 177 insertions(+), 98 deletions(-) diff --git a/macosx/English.lproj/HBTitleSelection.xib b/macosx/English.lproj/HBTitleSelection.xib index 4a6040c1c..f0134e6b3 100644 --- a/macosx/English.lproj/HBTitleSelection.xib +++ b/macosx/English.lproj/HBTitleSelection.xib @@ -1,9 +1,9 @@ - + - + @@ -11,6 +11,11 @@ + + + + + @@ -23,6 +28,46 @@ + + + + + + + + + + + + @@ -30,8 +75,8 @@ - - + + @@ -51,6 +96,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -63,6 +133,28 @@ + + + + + + + + + + @@ -76,11 +168,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -88,57 +205,17 @@ - - - - - - - - - - - - - @@ -147,5 +224,15 @@ Gw + + + + + + + + + + diff --git a/macosx/HBTitleSelectionController.h b/macosx/HBTitleSelectionController.h index 226340347..8aa7e33eb 100644 --- a/macosx/HBTitleSelectionController.h +++ b/macosx/HBTitleSelectionController.h @@ -8,6 +8,8 @@ NS_ASSUME_NONNULL_BEGIN +@class HBTitle; + @protocol HBTitleSelectionDelegate - (void)didSelectIndexes:(NSIndexSet *)indexes; @@ -16,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface HBTitleSelectionController : NSWindowController -- (instancetype)initWithTitles:(NSArray *)titles delegate:(id)delegate; +- (instancetype)initWithTitles:(NSArray *)titles delegate:(id)delegate; @end diff --git a/macosx/HBTitleSelectionController.m b/macosx/HBTitleSelectionController.m index 7575eb74a..7e9ea0af0 100644 --- a/macosx/HBTitleSelectionController.m +++ b/macosx/HBTitleSelectionController.m @@ -7,11 +7,37 @@ #import "HBTitleSelectionController.h" #import "HBTitle.h" -@interface HBTitleSelectionController () +@interface HBTitleSelection : NSObject +@property (nonatomic, readonly) HBTitle *title; +@property (nonatomic, readonly) BOOL selected; +@property (nonatomic, readonly, assign) NSUndoManager *undo; +@end + +@implementation HBTitleSelection +- (instancetype)initWithTitle:(HBTitle *)title undo:(NSUndoManager *)undo +{ + if (self = [super init]) + { + _title = title; + _selected = YES; + _undo = undo; + } + return self; +} + +- (void)setSelected:(BOOL)selected +{ + if (selected != _selected) + { + [[self.undo prepareWithInvocationTarget:self] setSelected:_selected]; + } + _selected = selected; +} +@end -@property (nonatomic, readonly) NSArray *titles; -@property (nonatomic, readonly) NSMutableArray *selection; +@interface HBTitleSelectionController () +@property (nonatomic, readwrite) NSArray *titles; @property (nonatomic, readonly, assign) id delegate; @end @@ -23,58 +49,24 @@ self = [super initWithWindowNibName:@"HBTitleSelection"]; if (self) { - _titles = titles; - _selection = [[NSMutableArray alloc] initWithCapacity:titles.count]; _delegate = delegate; - for (NSUInteger i = 0; i < titles.count; i++) + NSMutableArray *array = [[NSMutableArray alloc] init]; + for (HBTitle *title in titles) { - _selection[i] = @YES; + [array addObject:[[HBTitleSelection alloc] initWithTitle:title undo:self.window.undoManager]]; } + self.titles = [array copy]; } return self; } -- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView -{ - return self.titles.count; -} - -- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row +- (IBAction)deselectAll:(id)sender { - HBTitle *title = self.titles[row]; - - if ([tableColumn.identifier isEqualTo:@"index"]) - { - return @(title.index); - } - else if ([tableColumn.identifier isEqualTo:@"title"]) - { - return self.selection[row]; - } - else if ([tableColumn.identifier isEqualTo:@"duration"]) + for (HBTitleSelection *title in self.titles) { - return title.timeCode; - } - - return nil; -} - -- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; -{ - if ([tableColumn.identifier isEqualTo:@"title"]) - { - self.selection[row] = object; - } -} - -- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row -{ - if ([tableColumn.identifier isEqualTo:@"title"]) - { - HBTitle *title = self.titles[row]; - [aCell setTitle:title.name]; + title.selected = NO; } } @@ -82,13 +74,11 @@ { NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; - [self.selection enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - if ([obj boolValue]) + [self.titles enumerateObjectsUsingBlock:^(HBTitleSelection *obj, NSUInteger idx, BOOL *stop) { + if (obj.selected) { - HBTitle *title = self.titles[idx]; - [indexes addIndex:title.index]; + [indexes addIndex:obj.title.index]; } - }]; [self.delegate didSelectIndexes:indexes]; } -- 2.40.0