From 786042401cf317426ac50b497b390a52b53693f6 Mon Sep 17 00:00:00 2001 From: ritsuka Date: Mon, 2 Feb 2015 11:12:54 +0000 Subject: MacGui: add a "Clear All" and "Clear completed items" menu items to the queue contextual menu. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6860 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/English.lproj/Queue.xib | 31 ++++++++++++++++------- macosx/HBQueueController.m | 56 +++++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 21 deletions(-) (limited to 'macosx') diff --git a/macosx/English.lproj/Queue.xib b/macosx/English.lproj/Queue.xib index 297e3c964..82fc7ee3b 100644 --- a/macosx/English.lproj/Queue.xib +++ b/macosx/English.lproj/Queue.xib @@ -1,5 +1,5 @@ - + @@ -58,9 +58,6 @@ - - - @@ -79,6 +76,7 @@ + @@ -137,7 +135,7 @@ - + @@ -147,19 +145,34 @@ - + - + - + + - + + + + + + + + + + + + + + + diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index 054db0568..46d9bae69 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -172,7 +172,14 @@ return (self.core.state == HBStateWorking || self.core.state == HBStatePaused); } - + + if (action == @selector(editSelectedQueueItem:) || + action == @selector(removeSelectedQueueItem:) || + action == @selector(revealSelectedQueueItem:)) + { + return (self.outlineView.selectedRow != -1 || self.outlineView.clickedRow != -1); + } + return YES; } @@ -370,18 +377,10 @@ - (void)clearEncodedJobs { [self.jobs beginTransaction]; - NSMutableArray *encodedJobs = [NSMutableArray array]; - for (HBJob *job in self.jobs) - { - if (job.state == HBJobStateCompleted || job.state == HBJobStateCanceled) - { - [encodedJobs addObject:job]; - } - } - - [self.jobs removeObjectsInArray:encodedJobs]; + [self removeItemsUsingBlock:^BOOL(HBJob *item) { + return (item.state == HBJobStateCompleted || item.state == HBJobStateCanceled); + }]; [self.jobs commit]; - [self reloadQueue]; } @@ -397,6 +396,19 @@ [self reloadQueue]; } +- (void)removeItemsUsingBlock:(BOOL (^)(HBJob *item))predicate +{ + NSMutableArray *encodedJobs = [NSMutableArray array]; + for (HBJob *job in self.jobs) + { + if (predicate(job)) + { + [encodedJobs addObject:job]; + } + } + [self.jobs removeObjectsInArray:encodedJobs]; +} + /** * this is actually called from the queue controller to modify the queue array and return it back to the queue controller */ @@ -1122,6 +1134,26 @@ } } +- (IBAction)clearAll:(id)sender +{ + [self.jobs beginTransaction]; + [self removeItemsUsingBlock:^BOOL(HBJob *item) { + return (item.state != HBJobStateWorking); + }]; + [self.jobs commit]; + [self reloadQueue]; +} + +- (IBAction)clearCompleted:(id)sender +{ + [self.jobs beginTransaction]; + [self removeItemsUsingBlock:^BOOL(HBJob *item) { + return (item.state == HBJobStateCompleted); + }]; + [self.jobs commit]; + [self reloadQueue]; +} + #pragma mark - #pragma mark NSOutlineView delegate -- cgit v1.2.3