From 61fd0974630a9857548829e4599223c99897e045 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sun, 23 Mar 2014 16:58:56 +0100 Subject: [PATCH] Small improvements in the Queue UI. --- Classes/SBItemViewController.h | 7 ++++++ Classes/SBItemViewController.m | 18 +++++++++++----- Classes/SBQueueController.h | 3 +++ Classes/SBQueueController.m | 15 ++++++++++++- Classes/SBQueueItem.h | 3 ++- Classes/SBQueueItem.m | 39 ++++++++++++++++++++++++++++++---- English.lproj/Queue.xib | 2 +- English.lproj/QueueItem.xib | 13 +++++++++--- 8 files changed, 85 insertions(+), 15 deletions(-) diff --git a/Classes/SBItemViewController.h b/Classes/SBItemViewController.h index e392fcc..7ed6e2e 100644 --- a/Classes/SBItemViewController.h +++ b/Classes/SBItemViewController.h @@ -10,6 +10,13 @@ @class SBQueueItem; +@protocol SBItemViewDelegate + +- (void)setPopoverSize:(NSSize)size; +- (void)editItem:(SBQueueItem *)item; + +@end + @interface SBItemViewController : NSViewController { @private SBQueueItem *_item; diff --git a/Classes/SBItemViewController.m b/Classes/SBItemViewController.m index f041e89..2d6cfb8 100644 --- a/Classes/SBItemViewController.m +++ b/Classes/SBItemViewController.m @@ -9,7 +9,6 @@ #import "SBItemViewController.h" #import "SBQueueItem.h" -#import "SBQueueController.h" static void *SBItemViewContex = &SBItemViewContex; @@ -49,10 +48,16 @@ static void *SBItemViewContex = &SBItemViewContex; [super loadView]; // Observe the item status - [self addObserver:self forKeyPath:@"item.status" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:SBItemViewContex]; + [self addObserver:self + forKeyPath:@"item.status" + options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew + context:SBItemViewContex]; // Observe the item actions - [self addObserver:self forKeyPath:@"item.actions" options:NSKeyValueObservingOptionInitial context:SBItemViewContex]; + [self addObserver:self + forKeyPath:@"item.actions" + options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld + context:SBItemViewContex]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { @@ -67,9 +72,12 @@ static void *SBItemViewContex = &SBItemViewContex; [self.editButton setEnabled:YES]; } } else if ([keyPath isEqualToString:@"item.actions"]) { + NSInteger count = [[change objectForKey:NSKeyValueChangeNewKey] count] - [[change objectForKey:NSKeyValueChangeOldKey] count]; NSSize frameSize = self.view.frame.size; - frameSize.height += [self.item.actions count] ? TABLE_ROW_HEIGHT * ([self.item.actions count] - 1) : 0; - [self.view setFrameSize:frameSize]; + frameSize.height += TABLE_ROW_HEIGHT * (count >= 0 ? count - 1 : count); + if ([self.delegate respondsToSelector:@selector(setPopoverSize:)]) { + [self.delegate setPopoverSize:frameSize]; + } } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; diff --git a/Classes/SBQueueController.h b/Classes/SBQueueController.h index dbb58da..f3338f3 100755 --- a/Classes/SBQueueController.h +++ b/Classes/SBQueueController.h @@ -11,6 +11,8 @@ #import "SBQueue.h" @class SBQueueItem; +@class SBOptionsViewController; + @class SBTableView; @class MP42File; @@ -26,6 +28,7 @@ NSPopover *_popover; NSPopover *_itemPopover; + SBOptionsViewController *_windowController; NSMutableDictionary *_options; NSImage *_docImg; diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index 3ac9776..94cde18 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -29,6 +29,7 @@ static void *SBQueueContex = &SBQueueContex; @property (nonatomic, readonly) SBQueue *queue; @property (nonatomic, retain) NSPopover *popover; @property (nonatomic, retain) NSPopover *itemPopover; +@property (nonatomic, retain) SBOptionsViewController *windowController; @property NSMutableDictionary *options; @@ -62,6 +63,7 @@ static void *SBQueueContex = &SBQueueContex; @synthesize queue = _queue; @synthesize popover = _popover; @synthesize itemPopover = _itemPopover; +@synthesize windowController = _windowController; @synthesize options = _options; + (SBQueueController *)sharedManager { @@ -393,15 +395,26 @@ static void *SBQueueContex = &SBQueueContex; } +- (void)setPopoverSize:(NSSize)size { + self.itemPopover.contentSize = size; +} + - (NSWindow *)detachableWindowForPopover:(NSPopover *)popover { if (popover == self.popover) { - _detachedWindow.contentView = [[SBOptionsViewController alloc] initWithOptions:self.options].view; + if (!self.windowController) { + self.windowController = [[[SBOptionsViewController alloc] initWithOptions:self.options] autorelease]; + } + _detachedWindow.contentView = _windowController.view; _detachedWindow.delegate = self; return _detachedWindow; } return nil; } +- (void)windowWillClose:(NSNotification *)notification { + self.windowController = nil; +} + - (void)popoverDidClose:(NSNotification *)notification { NSPopover *closedPopover = [notification object]; if (self.popover == closedPopover) { diff --git a/Classes/SBQueueItem.h b/Classes/SBQueueItem.h index b4b9031..3f69927 100755 --- a/Classes/SBQueueItem.h +++ b/Classes/SBQueueItem.h @@ -43,7 +43,7 @@ typedef enum SBQueueItemStatus : NSInteger { @property (nonatomic, readonly) NSURL *URL; @property (nonatomic, copy) NSURL *destURL; -@property (nonatomic, readonly) NSMutableArray *actions; +@property (nonatomic, readonly) NSArray *actions; @property (nonatomic, readonly) NSDictionary *attributes; @property (nonatomic, assign) id delegate; @@ -54,6 +54,7 @@ typedef enum SBQueueItemStatus : NSInteger { + (instancetype)itemWithMP4:(MP42File *)MP4 url:(NSURL *)URL attributes:(NSDictionary *)dict; - (void)addAction:(id)action; +- (void)removeAction:(id)action; - (BOOL)prepareItem:(NSError **)outError; - (BOOL)processItem:(BOOL)optimize error:(NSError **)outError; diff --git a/Classes/SBQueueItem.m b/Classes/SBQueueItem.m index edc6280..d26ea20 100755 --- a/Classes/SBQueueItem.m +++ b/Classes/SBQueueItem.m @@ -18,7 +18,7 @@ @interface SBQueueItem () @property (nonatomic, readwrite, retain) MP42File *mp4File; -@property (nonatomic, readwrite) NSMutableArray *actions; +@property (nonatomic, readwrite) NSMutableArray *actionsInternal; @property (atomic) BOOL cancelled; @end @@ -28,7 +28,7 @@ @synthesize status = _status; @synthesize attributes = _attributes; -@synthesize actions = _actions; +@synthesize actionsInternal = _actions; @synthesize cancelled = _cancelled; @synthesize URL = _fileURL; @@ -111,6 +111,16 @@ return [[[SBQueueItem alloc] initWithMP4:MP4 url:URL attributes:dict] autorelease]; } ++ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)theKey { + BOOL automatic = NO; + if ([theKey isEqualToString:@"actions"]) { + automatic = NO; + } else { + automatic = [super automaticallyNotifiesObserversForKey:theKey]; + } + return automatic; +} + #pragma mark Public methods - (void)setStatus:(SBQueueItemStatus)itemStatus { @@ -121,7 +131,25 @@ } - (void)addAction:(id)action { - [self.actions addObject:action]; + if (self.status != SBQueueItemStatusWorking) { + [self willChangeValueForKey:@"actions"]; + [self.actionsInternal addObject:action]; + [self didChangeValueForKey:@"actions"]; + } +} + +- (void)removeAction:(id)action { + if (self.status != SBQueueItemStatusWorking) { + [self willChangeValueForKey:@"actions"]; + if ([self.actionsInternal containsObject:action]) { + [self.actionsInternal removeObject:action]; + } + [self didChangeValueForKey:@"actions"]; + } +} + +- (NSArray *)actions { + return [[self.actionsInternal copy] autorelease]; } #pragma mark Item processing @@ -233,7 +261,10 @@ bail: self.mp4File = nil; - [self.actions removeAllObjects]; + + [self willChangeValueForKey:@"actions"]; + [self.actionsInternal removeAllObjects]; + [self didChangeValueForKey:@"actions"]; #ifdef SB_SANDBOX if ([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)]) diff --git a/English.lproj/Queue.xib b/English.lproj/Queue.xib index 8a8558b..1000c20 100755 --- a/English.lproj/Queue.xib +++ b/English.lproj/Queue.xib @@ -208,7 +208,7 @@ - + diff --git a/English.lproj/QueueItem.xib b/English.lproj/QueueItem.xib index e15dc22..5601deb 100644 --- a/English.lproj/QueueItem.xib +++ b/English.lproj/QueueItem.xib @@ -50,6 +50,13 @@ + + + + NSNegateBoolean + + + @@ -100,14 +107,14 @@ - + - + - +