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; NSTextField *_actionsLabel;
NSButton *_editButton;
NSProgressIndicator *_spinner; NSProgressIndicator *_spinner;
id _delegate; id _delegate;
+28 -1
View File
@@ -11,6 +11,8 @@
#import "SBQueueItem.h" #import "SBQueueItem.h"
#import "SBQueueController.h" #import "SBQueueController.h"
static void *SBItemViewContex = &SBItemViewContex;
@interface SBItemViewController () @interface SBItemViewController ()
@property SBQueueItem *item; @property SBQueueItem *item;
@@ -21,6 +23,7 @@
@property (assign) IBOutlet NSTextField *actionsLabel; @property (assign) IBOutlet NSTextField *actionsLabel;
@property (assign) IBOutlet NSButton *editButton;
@property (assign) IBOutlet NSProgressIndicator *spinner; @property (assign) IBOutlet NSProgressIndicator *spinner;
@end @end
@@ -36,6 +39,7 @@
@synthesize actionsLabel = _actionsLabel; @synthesize actionsLabel = _actionsLabel;
@synthesize editButton = _editButton;
@synthesize spinner = _spinner; @synthesize spinner = _spinner;
- (instancetype)initWithItem:(SBQueueItem *)item { - (instancetype)initWithItem:(SBQueueItem *)item {
@@ -72,10 +76,28 @@
NSSize frameSize = self.view.frame.size; NSSize frameSize = self.view.frame.size;
frameSize.height += [self.item.actions count] ? self.actionsLabel.frame.size.height * ([self.item.actions count] - 1) : 0; frameSize.height += [self.item.actions count] ? self.actionsLabel.frame.size.height * ([self.item.actions count] - 1) : 0;
[self.view setFrameSize:frameSize]; [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 { - (IBAction)edit:(id)sender {
[sender setEnabled:NO];
[self.spinner setHidden:NO]; [self.spinner setHidden:NO];
if ([self.delegate respondsToSelector:@selector(editItem:)]) { if ([self.delegate respondsToSelector:@selector(editItem:)]) {
@@ -85,6 +107,11 @@
- (void)dealloc { - (void)dealloc {
[_item release]; [_item release];
@try {
[self removeObserver:self forKeyPath:@"item.status"];
} @catch (NSException * __unused exception) {}
[super dealloc]; [super dealloc];
} }
+1
View File
@@ -14,6 +14,7 @@
IBOutlet NSPopUpButton *_setsPopup; IBOutlet NSPopUpButton *_setsPopup;
NSMutableDictionary *_options; NSMutableDictionary *_options;
NSMutableArray *_sets;
NSURL *_destination; NSURL *_destination;
} }
+7 -38
View File
@@ -13,7 +13,8 @@
@interface SBOptionsViewController () @interface SBOptionsViewController ()
@property NSMutableDictionary *options; @property (nonatomic) NSMutableDictionary *options;
@property (nonatomic, copy) NSMutableArray *sets;
- (IBAction)chooseDestination:(id)sender; - (IBAction)chooseDestination:(id)sender;
- (IBAction)destination:(id)sender; - (IBAction)destination:(id)sender;
@@ -25,12 +26,15 @@
@implementation SBOptionsViewController @implementation SBOptionsViewController
@synthesize options = _options; @synthesize options = _options;
@synthesize sets = _sets;
@synthesize destination = _destination; @synthesize destination = _destination;
- (instancetype)initWithOptions:(NSMutableDictionary *)options { - (instancetype)initWithOptions:(NSMutableDictionary *)options {
self = [self init]; self = [self init];
if (self) { if (self) {
_options = [options retain]; _options = [options retain];
_sets = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
@@ -58,9 +62,6 @@
if (action == @selector(destination:)) if (action == @selector(destination:))
return YES; return YES;
if (action == @selector(applySet:))
return YES;
return NO; return NO;
} }
@@ -147,45 +148,13 @@
} }
- (void)updateSetsMenu:(id)sender { - (void)updateSetsMenu:(id)sender {
SBPresetManager *presetManager = [SBPresetManager sharedManager]; self.sets = [[SBPresetManager sharedManager].presets mutableCopy];
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"];
}
} }
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[_options release]; [_options release];
[_sets release];
[_destination release]; [_destination release];
[super dealloc]; [super dealloc];
+2 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?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> <dependencies>
<deployment version="1060" defaultVersion="1060" identifier="macosx"/> <deployment version="1060" defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
@@ -9,6 +9,7 @@
<connections> <connections>
<outlet property="actionsLabel" destination="pW0-Ga-LFI" id="8jA-6w-Inv"/> <outlet property="actionsLabel" destination="pW0-Ga-LFI" id="8jA-6w-Inv"/>
<outlet property="destinationLabel" destination="eTa-uz-sjk" id="ivS-cY-3Jt"/> <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="nameLabel" destination="ITP-pW-XrQ" id="o3b-Gi-Mey"/>
<outlet property="sourceLabel" destination="aBh-Is-f6Q" id="xCJ-Zl-gZ6"/> <outlet property="sourceLabel" destination="aBh-Is-f6Q" id="xCJ-Zl-gZ6"/>
<outlet property="spinner" destination="fCV-gk-gLV" id="1Vf-98-EBX"/> <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"?> <?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> <dependencies>
<deployment defaultVersion="1060" identifier="macosx"/> <deployment defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
@@ -8,7 +8,6 @@
<customObject id="-2" userLabel="File's Owner" customClass="SBOptionsViewController"> <customObject id="-2" userLabel="File's Owner" customClass="SBOptionsViewController">
<connections> <connections>
<outlet property="_destButton" destination="86l-GG-SpO" id="bE1-31-17X"/> <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"/> <outlet property="view" destination="UlG-O3-eNc" id="hzl-ex-WZi"/>
</connections> </connections>
</customObject> </customObject>
@@ -145,8 +144,36 @@
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="4en-ZA-qlS"/> <menu key="menu" title="OtherViews" id="4en-ZA-qlS"/>
</popUpButtonCell> </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> </popUpButton>
</subviews> </subviews>
</customView> </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> </objects>
</document> </document>