edit: selector validation and fixed an exception.

This commit is contained in:
Damiano Galassi committed 2014-03-16 22:50:58 +01:00
1 parent ed1e386e90
commit d730f1699f
3 files changed
+29 -9

No files matched your search

+3 -1
View File
@@ -9,7 +9,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <IOKit/pwr_mgt/IOPMLib.h> #import <IOKit/pwr_mgt/IOPMLib.h>
@class SBQueueItem; #import "SBQueueItem.h"
@class MP42File; @class MP42File;
typedef NS_ENUM(NSUInteger, SBQueueStatus) { typedef NS_ENUM(NSUInteger, SBQueueStatus) {
@@ -58,6 +59,7 @@ extern NSString *SBQueueCancelledNotification;
- (SBQueueItem *)itemAtIndex:(NSUInteger)index; - (SBQueueItem *)itemAtIndex:(NSUInteger)index;
- (NSUInteger)indexOfItem:(SBQueueItem *)item; - (NSUInteger)indexOfItem:(SBQueueItem *)item;
- (NSIndexSet *)indexesOfItemsWithStatus:(SBQueueItemStatus)status;
- (NSArray *)itemsAtIndexes:(NSIndexSet *)indexes; - (NSArray *)itemsAtIndexes:(NSIndexSet *)indexes;
- (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index; - (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index;
+13 -1
View File
@@ -7,7 +7,6 @@
// //
#import "SBQueue.h" #import "SBQueue.h"
#import "SBQueueItem.h"
#import "MetadataImporter.h" #import "MetadataImporter.h"
@@ -147,6 +146,18 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
return index; return index;
} }
- (NSIndexSet *)indexesOfItemsWithStatus:(SBQueueItemStatus)status {
NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
dispatch_sync(self.itemsQueue, ^{
[self.items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (((SBQueueItem *)obj).status == status) {
[indexes addIndex:idx];
}
}];
});
return indexes;
}
- (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index { - (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index {
dispatch_sync(self.itemsQueue, ^{ dispatch_sync(self.itemsQueue, ^{
[self.items insertObject:anItem atIndex:index]; [self.items insertObject:anItem atIndex:index];
@@ -314,6 +325,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
#endif #endif
[attributes release]; [attributes release];
return noErr; return noErr;
} }
+13 -7
View File
@@ -93,14 +93,14 @@ static NSString *fileType = @"mp4";
// Register to the queue notifications // Register to the queue notifications
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue]; NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueWorkingNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) { [[NSNotificationCenter defaultCenter] addObserverForName:SBQueueWorkingNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) {
NSDictionary *info = [note userInfo]; NSDictionary *info = [note userInfo];
[_countLabel setStringValue:[info valueForKey:@"ProgressString"]]; [_countLabel setStringValue:[info valueForKey:@"ProgressString"]];
[_progressIndicator setIndeterminate:NO]; [_progressIndicator setIndeterminate:NO];
[_progressIndicator setDoubleValue:[[info valueForKey:@"Progress"] doubleValue]]; [_progressIndicator setDoubleValue:[[info valueForKey:@"Progress"] doubleValue]];
}]; }];
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueCompletedNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) { [[NSNotificationCenter defaultCenter] addObserverForName:SBQueueCompletedNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) {
[_progressIndicator setHidden:YES]; [_progressIndicator setHidden:YES];
[_progressIndicator stopAnimation:self]; [_progressIndicator stopAnimation:self];
[_progressIndicator setDoubleValue:0]; [_progressIndicator setDoubleValue:0];
@@ -112,7 +112,7 @@ static NSString *fileType = @"mp4";
[self updateUI]; [self updateUI];
}]; }];
[[NSNotificationCenter defaultCenter] addObserverForName:SBQueueFailedNotification object:nil queue:mainQueue usingBlock:^(NSNotification *note) { [[NSNotificationCenter defaultCenter] addObserverForName:SBQueueFailedNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) {
NSDictionary *info = [note userInfo]; NSDictionary *info = [note userInfo];
[NSApp presentError:[info valueForKey:@"Error"]]; [NSApp presentError:[info valueForKey:@"Error"]];
}]; }];
@@ -443,7 +443,7 @@ static NSString *fileType = @"mp4";
} }
- (IBAction)removeCompletedItems:(id)sender { - (IBAction)removeCompletedItems:(id)sender {
NSIndexSet *indexes = [self.queue removeCompletedItems]; NSIndexSet *indexes = [self.queue indexesOfItemsWithStatus:SBQueueItemStatusCompleted];
if ([indexes count]) { if ([indexes count]) {
if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) { if ([NSTableView instancesRespondToSelector:@selector(beginUpdates)]) {
@@ -451,6 +451,7 @@ static NSString *fileType = @"mp4";
[_tableView beginUpdates]; [_tableView beginUpdates];
[_tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectFade]; [_tableView removeRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectFade];
[_tableView endUpdates]; [_tableView endUpdates];
[self.queue removeItemsAtIndexes:indexes];
#endif #endif
} else { } else {
[_tableView reloadData]; [_tableView reloadData];
@@ -478,9 +479,14 @@ static NSString *fileType = @"mp4";
} }
} }
if (action == @selector(edit:)) if (action == @selector(edit:)) {
return YES; if ([_tableView clickedRow] != -1) {
SBQueueItem *item = [self.queue itemAtIndex:[_tableView clickedRow]];
if (item.status == SBQueueItemStatusReady)
return YES;
}
}
if (action == @selector(removeCompletedItems:)) if (action == @selector(removeCompletedItems:))
return YES; return YES;