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];
+2 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13D17" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1060" defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
@@ -9,6 +9,7 @@
<connections>
<outlet property="actionsLabel" destination="pW0-Ga-LFI" id="8jA-6w-Inv"/>
<outlet property="destinationLabel" destination="eTa-uz-sjk" id="ivS-cY-3Jt"/>
<outlet property="editButton" destination="J0r-57-7ab" id="aR4-lN-fpm"/>
<outlet property="nameLabel" destination="ITP-pW-XrQ" id="o3b-Gi-Mey"/>
<outlet property="sourceLabel" destination="aBh-Is-f6Q" id="xCJ-Zl-gZ6"/>
<outlet property="spinner" destination="fCV-gk-gLV" id="1Vf-98-EBX"/>
+29 -2
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13D17" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
@@ -8,7 +8,6 @@
<customObject id="-2" userLabel="File's Owner" customClass="SBOptionsViewController">
<connections>
<outlet property="_destButton" destination="86l-GG-SpO" id="bE1-31-17X"/>
<outlet property="_setsPopup" destination="DVM-Js-DwK" id="971-id-uEe"/>
<outlet property="view" destination="UlG-O3-eNc" id="hzl-ex-WZi"/>
</connections>
</customObject>
@@ -145,8 +144,36 @@
<font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="4en-ZA-qlS"/>
</popUpButtonCell>
<connections>
<binding destination="vyv-na-Xpo" name="content" keyPath="arrangedObjects" id="HIJ-Fo-c7b">
<dictionary key="options">
<bool key="NSInsertsNullPlaceholder" value="YES"/>
<string key="NSNoSelectionPlaceholder">None</string>
<string key="NSNotApplicablePlaceholder">None</string>
<string key="NSNullPlaceholder">None</string>
</dictionary>
</binding>
<binding destination="vyv-na-Xpo" name="contentValues" keyPath="arrangedObjects.presetName" previousBinding="HIJ-Fo-c7b" id="P6E-1t-NzK">
<dictionary key="options">
<bool key="NSInsertsNullPlaceholder" value="YES"/>
</dictionary>
</binding>
<binding destination="-2" name="selectedObject" keyPath="options.SBQueueSet" previousBinding="P6E-1t-NzK" id="76d-3o-xTk"/>
</connections>
</popUpButton>
</subviews>
</customView>
<arrayController objectClassName="Set" automaticallyPreparesContent="YES" id="vyv-na-Xpo" userLabel="Set Controller">
<declaredKeys>
<string>presetName</string>
</declaredKeys>
<connections>
<binding destination="-2" name="contentArray" keyPath="sets" id="zFp-g2-I2n">
<dictionary key="options">
<bool key="NSValidatesImmediately" value="YES"/>
</dictionary>
</binding>
</connections>
</arrayController>
</objects>
</document>