- (void)selectionDidChange
{
- [self applyPreset:fPresetsView.selectedPreset];
+ if (fPresetsView.selectedPreset != self.currentPreset || self.edited)
+ {
+ [self applyPreset:fPresetsView.selectedPreset];
+ }
}
#pragma mark - Presets
- (IBAction)selectDefaultPreset:(id)sender
{
[self applyPreset:presetManager.defaultPreset];
- [fPresetsView setSelection:_currentPreset];
+ fPresetsView.selectedPreset = presetManager.defaultPreset;
}
- (IBAction)insertCategory:(id)sender
HBPreset *preset = [sender representedObject];
[self applyPreset:preset];
- [fPresetsView setSelection:preset];
+ fPresetsView.selectedPreset = preset;
}
@end
- (IBAction)exportPreset:(id)sender;
- (IBAction)importPreset:(id)sender;
-- (void)deselect;
-- (void)setSelection:(HBPreset *)preset;
-
- (IBAction)insertCategory:(id)sender;
-@property (nonatomic, readonly) HBPreset *selectedPreset;
-@property (nonatomic, readonly) NSUInteger indexOfSelectedItem;
+@property (nonatomic, readwrite) HBPreset *selectedPreset;
@property (nonatomic, readwrite, getter=isEnabled) BOOL enabled;
@property (nonatomic, readwrite) BOOL showHeader;
// drag and drop pasteboard type
#define kHandBrakePresetPBoardType @"handBrakePresetPBoardType"
+// KVO Context
+static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
+
@interface HBPresetCellView : NSTableCellView
@end
@interface HBPresetsViewController () <NSOutlineViewDelegate>
@property (nonatomic, strong) HBPresetsManager *presets;
+@property (nonatomic, readwrite) HBPreset *selectedPresetInternal;
@property (nonatomic, unsafe_unretained) IBOutlet NSTreeController *treeController;
@property (nonatomic, strong) IBOutlet NSTextField *headerLabel;
*/
@property (nonatomic, strong) NSMutableArray *expandedNodes;
-@property (unsafe_unretained) IBOutlet NSOutlineView *outlineView;
+@property (nonatomic, unsafe_unretained) IBOutlet NSOutlineView *outlineView;
+
@end
if (self)
{
_presets = presetManager;
+ _selectedPresetInternal = presetManager.defaultPreset;
_expandedNodes = [[NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults]
objectForKey:@"HBPreviewViewExpandedStatus"]] mutableCopy];
}
// Re-expand the items
[self expandNodes:[self.treeController.arrangedObjects childNodes]];
- [self.treeController setSelectionIndexPath:[self.presets indexPathOfPreset:self.presets.defaultPreset]];
+ [self.treeController setSelectionIndexPath:[self.presets indexPathOfPreset:self.selectedPreset]];
// Update header state
self.showHeader = _showHeader;
+
+ [self.treeController addObserver:self forKeyPath:@"selectedObjects" options:NSKeyValueObservingOptionNew context:HBPresetsViewControllerContext];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if (context == HBPresetsViewControllerContext)
+ {
+ HBPreset *selectedNode = [[self.treeController selectedObjects] firstObject];
+ if (selectedNode && selectedNode.isLeaf && selectedNode != self.selectedPresetInternal)
+ {
+ self.selectedPresetInternal = selectedNode;
+ [self.delegate selectionDidChange];
+ }
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
}
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem
}
}
-
return YES;
}
- (IBAction)setDefault:(id)sender
{
HBPreset *selectedNode = [[self.treeController selectedObjects] firstObject];
- if ([[selectedNode valueForKey:@"isLeaf"] boolValue])
+ if (selectedNode.isLeaf)
{
self.presets.defaultPreset = selectedNode;
}
}
-- (void)deselect
+- (void)setSelectedPreset:(HBPreset *)selectedPreset
{
- [self.treeController setSelectionIndexPath:nil];
+ _selectedPresetInternal = selectedPreset;
+ [self setSelection:selectedPreset];
+}
+
+- (HBPreset *)selectedPreset
+{
+ return _selectedPresetInternal;
}
- (void)setSelection:(HBPreset *)preset
}
}
-- (HBPreset *)selectedPreset
-{
- HBPreset *selectedNode = [[self.treeController selectedObjects] firstObject];
- if ([[selectedNode valueForKey:@"isLeaf"] boolValue])
- {
- return selectedNode;
- }
- else
- {
- return self.presets.defaultPreset;
- }
-}
-
- (IBAction)updateBuiltInPresets:(id)sender
{
[self.presets generateBuiltInPresets];