Smalls changes. Linked the edit button to its IBAction.
This commit is contained in:
1 parent
ff5ac492a0
commit
151d9c07f8
8 files changed
+161
-114
No files matched your search
@@ -11,7 +11,7 @@
|
||||
@class SBQueueItem;
|
||||
|
||||
@interface SBItemViewController : NSViewController {
|
||||
@private
|
||||
@private
|
||||
SBQueueItem *_item;
|
||||
|
||||
NSTextField *_nameLabel;
|
||||
@@ -19,8 +19,13 @@
|
||||
NSTextField *_destinationLabel;
|
||||
|
||||
NSTextField *_actionsLabel;
|
||||
|
||||
id _delegate;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) SBQueueItem *item;
|
||||
@property (nonatomic, assign, readwrite) id delegate;
|
||||
|
||||
- (instancetype)initWithItem:(SBQueueItem *)item;
|
||||
|
||||
@end
|
||||
@@ -7,7 +7,9 @@
|
||||
//
|
||||
|
||||
#import "SBItemViewController.h"
|
||||
|
||||
#import "SBQueueItem.h"
|
||||
#import "SBQueueController.h"
|
||||
|
||||
@interface SBItemViewController ()
|
||||
|
||||
@@ -24,6 +26,7 @@
|
||||
@implementation SBItemViewController
|
||||
|
||||
@synthesize item = _item;
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
@synthesize nameLabel = _nameLabel;
|
||||
@synthesize sourceLabel = _sourceLabel;
|
||||
@@ -67,6 +70,14 @@
|
||||
[self.view setFrameSize:frameSize];
|
||||
}
|
||||
|
||||
- (IBAction)edit:(id)sender {
|
||||
[sender setEnabled:NO];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(editItem:)]) {
|
||||
[self.delegate performSelector:@selector(editItem:) withObject:self.item];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_item release];
|
||||
[super dealloc];
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface SBOptionsViewController : NSViewController {
|
||||
@private
|
||||
@private
|
||||
IBOutlet NSPopUpButton *_destButton;
|
||||
IBOutlet NSPopUpButton *_setsPopup;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
@end
|
||||
|
||||
@interface SBQueueSetAction : NSObject <SBQueueActionProtocol> {
|
||||
@private
|
||||
MP42Metadata *_set;
|
||||
}
|
||||
- (id)initWithSet:(MP42Metadata *)set;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
@class MP42File;
|
||||
|
||||
@interface SBQueueController : NSWindowController {
|
||||
@private
|
||||
IBOutlet NSButton *_start;
|
||||
IBOutlet NSButton *_open;
|
||||
|
||||
@@ -39,6 +40,7 @@
|
||||
+ (SBQueueController *)sharedManager;
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item;
|
||||
- (void)editItem:(SBQueueItem *)item;
|
||||
|
||||
- (BOOL)saveQueueToDisk;
|
||||
|
||||
|
||||
+136
-112
@@ -24,11 +24,11 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
#define SublerBatchTableViewDataType @"SublerBatchTableViewDataType"
|
||||
#define kOptionsPanelHeight 88
|
||||
|
||||
@interface SBQueueController () <NSPopoverDelegate, NSTableViewDelegate, NSTableViewDataSource, SBTableViewDelegate>
|
||||
@interface SBQueueController () <NSPopoverDelegate, NSWindowDelegate, NSTableViewDelegate, NSTableViewDataSource, SBTableViewDelegate>
|
||||
|
||||
@property (readonly) SBQueue *queue;
|
||||
@property NSPopover *popover;
|
||||
@property NSPopover *itemPopover;
|
||||
@property (nonatomic, readonly) SBQueue *queue;
|
||||
@property (nonatomic, retain) NSPopover *popover;
|
||||
@property (nonatomic, retain) NSPopover *itemPopover;
|
||||
|
||||
@property NSMutableDictionary *options;
|
||||
|
||||
@@ -202,6 +202,8 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Queue methods
|
||||
|
||||
- (SBQueueStatus)status {
|
||||
return self.queue.status;
|
||||
}
|
||||
@@ -211,6 +213,116 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
return [self.queue saveQueueToDisk];
|
||||
}
|
||||
|
||||
- (void)editItem:(SBQueueItem *)item {
|
||||
item.status = SBQueueItemStatusEditing;
|
||||
[self updateUI];
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
if (!item.mp4File)
|
||||
[item prepareItem:NULL];
|
||||
|
||||
MP42File *mp4 = item.mp4File;
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
|
||||
[doc setMp4File:mp4];
|
||||
|
||||
[self.itemPopover close];
|
||||
|
||||
[self removeItems:[NSArray arrayWithObject:item]];
|
||||
[self updateUI];
|
||||
});
|
||||
|
||||
[item release];
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Queue items creation
|
||||
|
||||
- (SBQueueItem *)createItemWithURL:(NSURL *)url {
|
||||
SBQueueItem *item = [SBQueueItem itemWithURL:url];
|
||||
|
||||
if ([[self.options objectForKey:@"SBQueueMetadata"] boolValue]) {
|
||||
[item addAction:[[[SBQueueMetadataAction alloc] init] autorelease]];
|
||||
[item addAction:[[[SBQueueSubtitlesAction alloc] init] autorelease]];
|
||||
}
|
||||
if ([[self.options objectForKey:@"SBQueueOrganize"] boolValue]) {
|
||||
[item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
if ([self.options objectForKey:@"SBQueueSet"]) {
|
||||
[item addAction:[[[SBQueueSetAction alloc] initWithSet:[self.options objectForKey:@"SBQueueSet"]] autorelease]];
|
||||
}
|
||||
|
||||
NSURL *destination = [self.options objectForKey:@"SBQueueDestination"];
|
||||
if (destination) {
|
||||
destination = [[[destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
} else {
|
||||
destination = [[url URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
}
|
||||
|
||||
item.destURL = destination;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes; {
|
||||
NSMutableIndexSet *mutableIndexes = [indexes mutableCopy];
|
||||
if ([indexes count] == [items count]) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
[mutableIndexes removeIndexesInRange:NSMakeRange(0, 1)];
|
||||
}
|
||||
} else if ([indexes count] == 1) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
}
|
||||
} else {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue addItem:item];
|
||||
}
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] removeItems:items];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Add Queue Item"];
|
||||
}
|
||||
if ([undo isUndoing] || [undo isRedoing])
|
||||
[self updateUI];
|
||||
|
||||
if ([[self.options objectForKey:@"SBQueueAutoStart"] boolValue])
|
||||
[self start:self];
|
||||
|
||||
[mutableIndexes release];
|
||||
}
|
||||
|
||||
- (void)removeItems:(NSArray *)items {
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (id item in items) {
|
||||
[indexes addIndex:[self.queue indexOfItem:item]];
|
||||
[self.queue removeItem:item];
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] addItems:items atIndexes:indexes];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Delete Queue Item"];
|
||||
}
|
||||
if ([undo isUndoing] || [undo isRedoing])
|
||||
[self updateUI];
|
||||
|
||||
[indexes release];
|
||||
}
|
||||
|
||||
#pragma mark - NSPopover delegate
|
||||
|
||||
- (void)createPopover {
|
||||
@@ -234,11 +346,16 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
}
|
||||
|
||||
- (void)createItemPopover:(SBQueueItem *)item {
|
||||
if (self.itemPopover) {
|
||||
self.itemPopover = nil;
|
||||
}
|
||||
_itemPopover = [[NSPopover alloc] init];
|
||||
|
||||
// the popover retains us and we retain the popover,
|
||||
// we drop the popover whenever it is closed to avoid a cycle
|
||||
self.itemPopover.contentViewController = [[[SBItemViewController alloc] initWithItem:item] autorelease];
|
||||
SBItemViewController *view = [[[SBItemViewController alloc] initWithItem:item] autorelease];
|
||||
view.delegate = self;
|
||||
self.itemPopover.contentViewController = view;
|
||||
self.itemPopover.appearance = NSPopoverAppearanceMinimal;
|
||||
self.itemPopover.animates = YES;
|
||||
|
||||
@@ -254,20 +371,20 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
- (NSWindow *)detachableWindowForPopover:(NSPopover *)popover {
|
||||
if (popover == self.popover) {
|
||||
_detachedWindow.contentView = [[SBOptionsViewController alloc] initWithOptions:self.options].view;
|
||||
_detachedWindow.delegate = self;
|
||||
return _detachedWindow;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)popoverDidClose:(NSNotification *)notification {
|
||||
if (self.popover) {
|
||||
self.popover.contentViewController = nil;
|
||||
NSPopover *closedPopover = [notification object];
|
||||
if (self.popover == closedPopover) {
|
||||
self.popover = nil;
|
||||
}
|
||||
/*if (self.itemPopover) {
|
||||
self.itemPopover.contentViewController = nil;
|
||||
if (self.itemPopover == closedPopover) {
|
||||
self.itemPopover = nil;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UI methods
|
||||
@@ -328,18 +445,20 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[self.popover showRelativeToRect:[targetButton bounds] ofView:sender preferredEdge:NSMaxYEdge];
|
||||
} else {
|
||||
[self.popover close];
|
||||
self.popover = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)toggleItemsOptions:(id)sender {
|
||||
NSInteger clickedRow = [sender clickedRow];
|
||||
SBQueueItem *item = [self.queue itemAtIndex:clickedRow];
|
||||
|
||||
[self createItemPopover:[self.queue itemAtIndex:clickedRow]];
|
||||
|
||||
if (!self.itemPopover.isShown) {
|
||||
[self.itemPopover showRelativeToRect:[sender frameOfCellAtColumn:2 row:clickedRow] ofView:sender preferredEdge:NSMaxXEdge];
|
||||
} else {
|
||||
if (self.itemPopover.isShown && [(SBItemViewController *)self.itemPopover.contentViewController item] == item) {
|
||||
[self.itemPopover close];
|
||||
self.itemPopover = nil;
|
||||
} else {
|
||||
[self createItemPopover:[self.queue itemAtIndex:clickedRow]];
|
||||
[self.itemPopover showRelativeToRect:[sender frameOfCellAtColumn:2 row:clickedRow] ofView:sender preferredEdge:NSMaxXEdge];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +502,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
SBQueueItemStatus batchStatus = [[self.queue itemAtIndex:rowIndex] status];
|
||||
if (batchStatus == SBQueueItemStatusCompleted)
|
||||
return [NSImage imageNamed:@"EncodeComplete"];
|
||||
else if (batchStatus == SBQueueItemStatusWorking)
|
||||
else if (batchStatus == SBQueueItemStatusWorking || batchStatus == SBQueueItemStatusEditing)
|
||||
return [NSImage imageNamed:@"EncodeWorking"];
|
||||
else if (batchStatus == SBQueueItemStatusFailed)
|
||||
return [NSImage imageNamed:@"EncodeCanceled"];
|
||||
@@ -439,19 +558,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
|
||||
- (IBAction)edit:(id)sender {
|
||||
SBQueueItem *item = [[self.queue itemAtIndex:[_tableView clickedRow]] retain];
|
||||
item.status = SBQueueItemStatusEditing;
|
||||
|
||||
if (!item.mp4File)
|
||||
[item prepareItem:NULL];
|
||||
|
||||
MP42File *mp4 = item.mp4File;
|
||||
|
||||
SBDocument *doc = [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error:NULL];
|
||||
[doc setMp4File:mp4];
|
||||
[item release];
|
||||
|
||||
[self removeItems:[NSArray arrayWithObject:item]];
|
||||
[self updateUI];
|
||||
[self editItem:item];
|
||||
}
|
||||
|
||||
- (IBAction)showInFinder:(id)sender {
|
||||
@@ -597,87 +704,4 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (SBQueueItem *)createItemWithURL:(NSURL *)url {
|
||||
SBQueueItem *item = [SBQueueItem itemWithURL:url];
|
||||
|
||||
if ([[self.options objectForKey:@"SBQueueMetadata"] boolValue]) {
|
||||
[item addAction:[[[SBQueueMetadataAction alloc] init] autorelease]];
|
||||
[item addAction:[[[SBQueueSubtitlesAction alloc] init] autorelease]];
|
||||
}
|
||||
if ([[self.options objectForKey:@"SBQueueOrganize"] boolValue]) {
|
||||
[item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]];
|
||||
}
|
||||
|
||||
if ([self.options objectForKey:@"SBQueueSet"]) {
|
||||
[item addAction:[[[SBQueueSetAction alloc] initWithSet:[self.options objectForKey:@"SBQueueSet"]] autorelease]];
|
||||
}
|
||||
|
||||
|
||||
NSURL *destination = [self.options objectForKey:@"SBQueueDestination"];
|
||||
if (destination) {
|
||||
destination = [[[destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
|
||||
}
|
||||
|
||||
item.destURL = destination;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
- (void)addItem:(SBQueueItem *)item {
|
||||
[self addItems:[NSArray arrayWithObject:item] atIndexes:nil];
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
- (void)addItems:(NSArray *)items atIndexes:(NSIndexSet *)indexes; {
|
||||
NSMutableIndexSet *mutableIndexes = [indexes mutableCopy];
|
||||
if ([indexes count] == [items count]) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
[mutableIndexes removeIndexesInRange:NSMakeRange(0, 1)];
|
||||
}
|
||||
} else if ([indexes count] == 1) {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue insertItem:item atIndex:[mutableIndexes firstIndex]];
|
||||
}
|
||||
} else {
|
||||
for (id item in [items reverseObjectEnumerator]) {
|
||||
[self.queue addItem:item];
|
||||
}
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] removeItems:items];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Add Queue Item"];
|
||||
}
|
||||
if ([undo isUndoing] || [undo isRedoing])
|
||||
[self updateUI];
|
||||
|
||||
if ([[self.options objectForKey:@"SBQueueAutoStart"] boolValue])
|
||||
[self start:self];
|
||||
|
||||
[mutableIndexes release];
|
||||
}
|
||||
|
||||
- (void)removeItems:(NSArray *)items {
|
||||
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
|
||||
|
||||
for (id item in items) {
|
||||
[indexes addIndex:[self.queue indexOfItem:item]];
|
||||
[self.queue removeItem:item];
|
||||
}
|
||||
|
||||
NSUndoManager *undo = [[self window] undoManager];
|
||||
[[undo prepareWithInvocationTarget:self] addItems:items atIndexes:indexes];
|
||||
|
||||
if (![undo isUndoing]) {
|
||||
[undo setActionName:@"Delete Queue Item"];
|
||||
}
|
||||
if ([undo isUndoing] || [undo isRedoing])
|
||||
[self updateUI];
|
||||
|
||||
[indexes release];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -23,6 +23,7 @@ typedef enum SBQueueItemStatus : NSInteger {
|
||||
} SBQueueItemStatus;
|
||||
|
||||
@interface SBQueueItem : NSObject <NSCoding> {
|
||||
@private
|
||||
MP42File *_mp4File;
|
||||
NSURL *_fileURL;
|
||||
NSURL *_destURL;
|
||||
|
||||
@@ -90,6 +90,9 @@
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="edit:" target="-2" id="ZCT-Of-7Vv"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
</customView>
|
||||
|
||||
Reference in new issue
Block a user