Added some bindings magic.

This commit is contained in:
Damiano Galassi committed 2014-03-21 20:22:02 +01:00
1 parent 67c821901a
commit 609af54296
6 files changed
+68 -42

No files matched your search

+1
View File
@@ -20,6 +20,7 @@
NSTextField *_actionsLabel;
NSButton *_editButton;
NSProgressIndicator *_spinner;
id _delegate;
+28 -1
View File
@@ -11,6 +11,8 @@
#import "SBQueueItem.h"
#import "SBQueueController.h"
static void *SBItemViewContex = &SBItemViewContex;
@interface SBItemViewController ()
@property SBQueueItem *item;
@@ -21,6 +23,7 @@
@property (assign) IBOutlet NSTextField *actionsLabel;
@property (assign) IBOutlet NSButton *editButton;
@property (assign) IBOutlet NSProgressIndicator *spinner;
@end
@@ -36,6 +39,7 @@
@synthesize actionsLabel = _actionsLabel;
@synthesize editButton = _editButton;
@synthesize spinner = _spinner;
- (instancetype)initWithItem:(SBQueueItem *)item {
@@ -72,10 +76,28 @@
NSSize frameSize = self.view.frame.size;
frameSize.height += [self.item.actions count] ? self.actionsLabel.frame.size.height * ([self.item.actions count] - 1) : 0;
[self.view setFrameSize:frameSize];
// Observe the item status
[self addObserver:self forKeyPath:@"item.status" options:NSKeyValueObservingOptionInitial context:SBItemViewContex];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == SBItemViewContex) {
// Disable the edit button if the item status
// is different from ready
if ([keyPath isEqualToString:@"item.status"]) {
if (self.item.status != SBQueueItemStatusReady) {
[self.editButton setEnabled:NO];
} else {
[self.editButton setEnabled:YES];
}
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (IBAction)edit:(id)sender {
[sender setEnabled:NO];
[self.spinner setHidden:NO];
if ([self.delegate respondsToSelector:@selector(editItem:)]) {
@@ -85,6 +107,11 @@
- (void)dealloc {
[_item release];
@try {
[self removeObserver:self forKeyPath:@"item.status"];
} @catch (NSException * __unused exception) {}
[super dealloc];
}
+1
View File
@@ -14,6 +14,7 @@
IBOutlet NSPopUpButton *_setsPopup;
NSMutableDictionary *_options;
NSMutableArray *_sets;
NSURL *_destination;
}
+7 -38
View File
@@ -13,7 +13,8 @@
@interface SBOptionsViewController ()
@property NSMutableDictionary *options;
@property (nonatomic) NSMutableDictionary *options;
@property (nonatomic, copy) NSMutableArray *sets;
- (IBAction)chooseDestination:(id)sender;
- (IBAction)destination:(id)sender;
@@ -25,12 +26,15 @@
@implementation SBOptionsViewController
@synthesize options = _options;
@synthesize sets = _sets;
@synthesize destination = _destination;
- (instancetype)initWithOptions:(NSMutableDictionary *)options {
self = [self init];
if (self) {
_options = [options retain];
_sets = [[NSMutableArray alloc] init];
}
return self;
}
@@ -58,9 +62,6 @@
if (action == @selector(destination:))
return YES;
if (action == @selector(applySet:))
return YES;
return NO;
}
@@ -147,45 +148,13 @@
}
- (void)updateSetsMenu:(id)sender {
SBPresetManager *presetManager = [SBPresetManager sharedManager];
NSMenu *setListMenu = [_setsPopup menu];
[setListMenu removeAllItems];
NSMenuItem *newItem = nil;
newItem = [[[NSMenuItem alloc] initWithTitle:@"None" action:@selector(applySet:) keyEquivalent:@""] autorelease];
[newItem setTarget:self];
[newItem setTag:-1];
[setListMenu addItem:newItem];
NSUInteger i = 0;
for (MP42Metadata *set in [presetManager presets]) {
newItem = [[NSMenuItem alloc] initWithTitle:set.presetName action:@selector(applySet:) keyEquivalent:@""];
[newItem setTarget:self];
[newItem setTag:i++];
[setListMenu addItem:newItem];
[newItem release];
}
if ([self.options objectForKey:@"SBQueueSet"]) {
[_setsPopup selectItemWithTitle:[[self.options objectForKey:@"SBQueueSet"] presetName]];
}
}
- (void)applySet:(id)sender {
if ([sender tag] > -1) {
[self.options setObject:[[SBPresetManager sharedManager].presets objectAtIndex:[sender tag]] forKey:@"SBQueueSet"];
} else {
[self.options removeObjectForKey:@"SBQueueSet"];
}
self.sets = [[SBPresetManager sharedManager].presets mutableCopy];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_options release];
[_sets release];
[_destination release];
[super dealloc];