diff options
author | Damiano Galassi <[email protected]> | 2015-10-25 07:03:36 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2015-10-25 07:03:36 +0100 |
commit | 646cb272a2c9feecc5a839360248621991c1f453 (patch) | |
tree | 438b4139252281ef544cb5502609206ac9be4f78 /macosx/HBTitleSelectionController.m | |
parent | 4fde4b8fdd7c40401f74b18f668de53d6a04c2dd (diff) |
MacGui: change the title selection sheet to use a view-based table view.
Diffstat (limited to 'macosx/HBTitleSelectionController.m')
-rw-r--r-- | macosx/HBTitleSelectionController.m | 88 |
1 files changed, 39 insertions, 49 deletions
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 () <NSTableViewDataSource, NSTableViewDelegate> +@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 () <NSTableViewDataSource, NSTableViewDelegate> +@property (nonatomic, readwrite) NSArray<HBTitleSelection *> *titles; @property (nonatomic, readonly, assign) id<HBTitleSelectionDelegate> 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<HBTitleSelection *> *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]; } |