Small fixes.
This commit is contained in:
1 parent
75e5b85cfc
commit
ff5ac492a0
9 files changed
+114
-113
No files matched your search
@@ -51,8 +51,8 @@
|
||||
[self.sourceLabel setStringValue:[self.item.URL path]];
|
||||
[self.destinationLabel setStringValue:[self.item.destURL path]];
|
||||
|
||||
NSMutableString *actions = [[NSMutableString alloc] init];
|
||||
for (id<SBQueueActionProtocol> action in self.item.actionsArray) {
|
||||
NSMutableString *actions = [[[NSMutableString alloc] init] autorelease];
|
||||
for (id<SBQueueActionProtocol> action in self.item.actions) {
|
||||
[actions appendString:[NSString stringWithFormat:@"%@\n", [action description]]];
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
}
|
||||
|
||||
NSSize frameSize = self.view.frame.size;
|
||||
frameSize.height += [self.item.actionsArray count] ? self.actionsLabel.frame.size.height * ([self.item.actionsArray count] - 1) : 0;
|
||||
frameSize.height += [self.item.actions count] ? self.actionsLabel.frame.size.height * ([self.item.actions count] - 1) : 0;
|
||||
[self.view setFrameSize:frameSize];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
NSMutableDictionary *_options;
|
||||
|
||||
NSURL *_destination;
|
||||
BOOL _customDestination;
|
||||
}
|
||||
|
||||
- (instancetype)initWithOptions:(NSMutableDictionary *)options;
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
- (IBAction)chooseDestination:(id)sender;
|
||||
- (IBAction)destination:(id)sender;
|
||||
|
||||
@property (nonatomic, retain) NSURL *destination;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SBOptionsViewController
|
||||
|
||||
@synthesize options = _options;
|
||||
@synthesize destination = _destination;
|
||||
|
||||
- (instancetype)initWithOptions:(NSMutableDictionary *)options {
|
||||
self = [self init];
|
||||
@@ -46,32 +49,93 @@
|
||||
[self prepareSetsPopup];
|
||||
}
|
||||
|
||||
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
|
||||
SEL action = [anItem action];
|
||||
|
||||
if (action == @selector(chooseDestination:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(destination:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(applySet:))
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)prepareDestPopup {
|
||||
NSMenuItem *folderItem = nil;
|
||||
|
||||
if ([self.options valueForKey:@"SBQueueDestination"]) {
|
||||
_destination = [[self.options valueForKey:@"SBQueueDestination"] retain];
|
||||
self.destination = [self.options valueForKey:@"SBQueueDestination"];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[_destination path] isDirectory:nil])
|
||||
_destination = nil;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.destination path] isDirectory:nil])
|
||||
self.destination = nil;
|
||||
}
|
||||
|
||||
if (!_destination) {
|
||||
if (!self.destination) {
|
||||
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSMoviesDirectory,
|
||||
NSUserDomainMask,
|
||||
YES);
|
||||
if ([allPaths count])
|
||||
_destination = [[NSURL fileURLWithPath:[allPaths lastObject]] retain];;
|
||||
if ([allPaths count]) {
|
||||
self.destination = [NSURL fileURLWithPath:[allPaths lastObject]];
|
||||
}
|
||||
}
|
||||
|
||||
folderItem = [self prepareDestPopupItem:_destination];
|
||||
folderItem = [self prepareDestPopupItem:self.destination];
|
||||
|
||||
[[_destButton menu] insertItem:[NSMenuItem separatorItem] atIndex:0];
|
||||
[[_destButton menu] insertItem:folderItem atIndex:0];
|
||||
|
||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestinationSelected"] boolValue]) {
|
||||
if ([self.options valueForKey:@"SBQueueDestination"]) {
|
||||
[_destButton selectItem:folderItem];
|
||||
_customDestination = YES;
|
||||
} else {
|
||||
[_destButton selectItemWithTag:10];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)chooseDestination:(id)sender {
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = NO;
|
||||
panel.canChooseFiles = NO;
|
||||
panel.canChooseDirectories = YES;
|
||||
panel.canCreateDirectories = YES;
|
||||
|
||||
[panel setPrompt:@"Select"];
|
||||
[panel beginSheetModalForWindow:nil completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
NSMenuItem *folderItem = [self prepareDestPopupItem:[panel URL]];
|
||||
|
||||
[[_destButton menu] removeItemAtIndex:0];
|
||||
[[_destButton menu] insertItem:folderItem atIndex:0];
|
||||
|
||||
[_destButton selectItem:folderItem];
|
||||
|
||||
[self.options setValue:[panel URL] forKey:@"SBQueueDestination"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"];
|
||||
}
|
||||
else
|
||||
[_destButton selectItemAtIndex:2];
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)prepareDestPopupItem:(NSURL*) dest {
|
||||
NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:[dest lastPathComponent] action:@selector(destination:) keyEquivalent:@""];
|
||||
|
||||
NSImage *menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]];
|
||||
[menuItemIcon setSize:NSMakeSize(16, 16)];
|
||||
|
||||
[folderItem setImage:menuItemIcon];
|
||||
|
||||
return [folderItem autorelease];
|
||||
}
|
||||
|
||||
- (IBAction)destination:(id)sender {
|
||||
if ([sender tag] == 10) {
|
||||
[self.options removeObjectForKey:@"SBQueueDestination"];
|
||||
} else {
|
||||
[self.options setObject:self.destination forKey:@"SBQueueDestination"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,75 +183,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
|
||||
SEL action = [anItem action];
|
||||
|
||||
if (action == @selector(chooseDestination:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(destination:))
|
||||
return YES;
|
||||
|
||||
if (action == @selector(applySet:))
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (IBAction)chooseDestination:(id)sender {
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
panel.allowsMultipleSelection = NO;
|
||||
panel.canChooseFiles = NO;
|
||||
panel.canChooseDirectories = YES;
|
||||
panel.canCreateDirectories = YES;
|
||||
|
||||
[panel setPrompt:@"Select"];
|
||||
[panel beginSheetModalForWindow:nil completionHandler:^(NSInteger result) {
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
_destination = [[panel URL] retain];
|
||||
|
||||
NSMenuItem *folderItem = [self prepareDestPopupItem:[panel URL]];
|
||||
|
||||
[[_destButton menu] removeItemAtIndex:0];
|
||||
[[_destButton menu] insertItem:folderItem atIndex:0];
|
||||
|
||||
[_destButton selectItem:folderItem];
|
||||
_customDestination = YES;
|
||||
|
||||
[self.options setValue:[panel URL] forKey:@"SBQueueDestination"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"];
|
||||
}
|
||||
else
|
||||
[_destButton selectItemAtIndex:2];
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMenuItem *)prepareDestPopupItem:(NSURL*) dest {
|
||||
NSMenuItem *folderItem = [[NSMenuItem alloc] initWithTitle:[dest lastPathComponent] action:@selector(destination:) keyEquivalent:@""];
|
||||
[folderItem setTag:10];
|
||||
|
||||
NSImage *menuItemIcon = [[NSWorkspace sharedWorkspace] iconForFile:[dest path]];
|
||||
[menuItemIcon setSize:NSMakeSize(16, 16)];
|
||||
|
||||
[folderItem setImage:menuItemIcon];
|
||||
|
||||
return [folderItem autorelease];
|
||||
}
|
||||
|
||||
- (IBAction)destination:(id)sender {
|
||||
if ([sender tag] == 10) {
|
||||
_customDestination = YES;
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"];
|
||||
} else {
|
||||
_customDestination = NO;
|
||||
[[NSUserDefaults standardUserDefaults] setValue:nil forKey:@"SBQueueDestinationSelected"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[_options release];
|
||||
[_destination release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -264,10 +264,10 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
self.popover.contentViewController = nil;
|
||||
self.popover = nil;
|
||||
}
|
||||
if (self.itemPopover) {
|
||||
/*if (self.itemPopover) {
|
||||
self.itemPopover.contentViewController = nil;
|
||||
self.itemPopover = nil;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
#pragma mark - UI methods
|
||||
@@ -276,7 +276,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
NSUInteger count = [self.queue readyCount];
|
||||
|
||||
if (count)
|
||||
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%d", count]];
|
||||
[[NSApp dockTile] setBadgeLabel:[NSString stringWithFormat:@"%lu", (unsigned long)count]];
|
||||
else
|
||||
[[NSApp dockTile] setBadgeLabel:nil];
|
||||
}
|
||||
@@ -325,7 +325,7 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
|
||||
if (!self.popover.isShown) {
|
||||
NSButton *targetButton = (NSButton *)sender;
|
||||
[self.popover showRelativeToRect:[targetButton bounds] ofView:sender preferredEdge:NSMaxXEdge];
|
||||
[self.popover showRelativeToRect:[targetButton bounds] ofView:sender preferredEdge:NSMaxYEdge];
|
||||
} else {
|
||||
[self.popover close];
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef enum SBQueueItemStatus : NSInteger {
|
||||
@property (nonatomic, readonly) NSURL *URL;
|
||||
@property (nonatomic, copy) NSURL *destURL;
|
||||
|
||||
@property (nonatomic, readonly) NSArray *actionsArray;
|
||||
@property (nonatomic, readonly) NSMutableArray *actions;
|
||||
|
||||
@property (nonatomic, readwrite) SBQueueItemStatus status;
|
||||
|
||||
|
||||
@@ -113,10 +113,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)actionsArray {
|
||||
return [self.actions copy];
|
||||
}
|
||||
|
||||
- (void)addAction:(id<SBQueueActionProtocol>)action {
|
||||
[self.actions addObject:action];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user