summaryrefslogtreecommitdiffstats
path: root/macosx/HBTitleSelectionController.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-01-25 08:02:47 +0000
committerritsuka <[email protected]>2015-01-25 08:02:47 +0000
commit8e7fdbaed7f2ece531fee19ebc6c3f0f284b795d (patch)
treeb812001465c02d5ff86e8eaa7ae80a80bca885da /macosx/HBTitleSelectionController.m
parentffc93adeaa23923c1c8b401e45cf4b155e4e99eb (diff)
MacGui: add a "Add Titles to Queue…" menu item that let select which titles are added to the queue.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6810 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBTitleSelectionController.m')
-rw-r--r--macosx/HBTitleSelectionController.m112
1 files changed, 112 insertions, 0 deletions
diff --git a/macosx/HBTitleSelectionController.m b/macosx/HBTitleSelectionController.m
new file mode 100644
index 000000000..814c78991
--- /dev/null
+++ b/macosx/HBTitleSelectionController.m
@@ -0,0 +1,112 @@
+/* HBTitleSelectionController.h
+
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License. */
+
+#import "HBTitleSelectionController.h"
+#import "HBTitle.h"
+
+@interface HBTitleSelectionController () <NSTableViewDataSource, NSTableViewDelegate>
+
+@property (nonatomic, readonly) NSArray *titles;
+@property (nonatomic, readonly) NSMutableArray *selection;
+
+@property (nonatomic, readonly) id<HBTitleSelectionDelegate> delegate;
+
+@end
+
+@implementation HBTitleSelectionController
+
+- (instancetype)initWithTitles:(NSArray *)titles delegate:(id<HBTitleSelectionDelegate>)delegate
+{
+ self = [super initWithWindowNibName:@"HBTitleSelection"];
+ if (self)
+ {
+ _titles = [titles retain];
+ _selection = [[NSMutableArray alloc] initWithCapacity:titles.count];
+ _delegate = delegate;
+
+ for (NSUInteger i = 0; i < titles.count; i++)
+ {
+ _selection[i] = @YES;
+ }
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [_titles release];
+ _titles = nil;
+
+ [_selection release];
+ _selection = nil;
+
+ [super dealloc];
+}
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
+{
+ return self.titles.count;
+}
+
+- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+ 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"])
+ {
+ 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];
+ }
+}
+
+- (IBAction)add:(id)sender
+{
+ NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
+
+ [self.selection enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+ if ([obj boolValue])
+ {
+ HBTitle *title = self.titles[idx];
+ [indexes addIndex:title.index];
+ }
+
+ }];
+ [self.delegate didSelectIndexes:indexes];
+}
+
+- (IBAction)cancel:(id)sender
+{
+ [self.delegate didSelectIndexes:[NSIndexSet indexSet]];
+}
+
+@end