summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2017-12-20 22:06:38 +0100
committerDamiano Galassi <[email protected]>2017-12-20 22:06:38 +0100
commitb9b77487aa14741e6662cc1f818cc5fbc1d9f1b5 (patch)
tree2347c149c9804f343246e48faaf9f531d5c9971b
parent3b29457332a0bf43fc923b8f3694661acb92d4f4 (diff)
MacGui: update preset when navigating with the keyboard arrows, fix #452
-rw-r--r--macosx/HBAddPresetController.m2
-rw-r--r--macosx/HBController.m9
-rw-r--r--macosx/HBPresetsViewController.h6
-rw-r--r--macosx/HBPresetsViewController.m55
4 files changed, 44 insertions, 28 deletions
diff --git a/macosx/HBAddPresetController.m b/macosx/HBAddPresetController.m
index 4ff228d01..76ce3facd 100644
--- a/macosx/HBAddPresetController.m
+++ b/macosx/HBAddPresetController.m
@@ -252,7 +252,7 @@ typedef NS_ENUM(NSUInteger, HBAddPresetControllerMode) {
[newPreset cleanUp];
self.preset = [newPreset copy];
- [self.selectedCategory insertObject:self.preset inChildrenAtIndex:0];
+ [self.selectedCategory insertObject:self.preset inChildrenAtIndex:self.selectedCategory.countOfChildren];
[self.window orderOut:nil];
[NSApp endSheet:self.window returnCode:NSModalResponseContinue];
diff --git a/macosx/HBController.m b/macosx/HBController.m
index 95cda984f..575270c71 100644
--- a/macosx/HBController.m
+++ b/macosx/HBController.m
@@ -1363,7 +1363,10 @@
- (void)selectionDidChange
{
- [self applyPreset:fPresetsView.selectedPreset];
+ if (fPresetsView.selectedPreset != self.currentPreset || self.edited)
+ {
+ [self applyPreset:fPresetsView.selectedPreset];
+ }
}
#pragma mark - Presets
@@ -1507,7 +1510,7 @@
- (IBAction)selectDefaultPreset:(id)sender
{
[self applyPreset:presetManager.defaultPreset];
- [fPresetsView setSelection:_currentPreset];
+ fPresetsView.selectedPreset = presetManager.defaultPreset;
}
- (IBAction)insertCategory:(id)sender
@@ -1521,7 +1524,7 @@
HBPreset *preset = [sender representedObject];
[self applyPreset:preset];
- [fPresetsView setSelection:preset];
+ fPresetsView.selectedPreset = preset;
}
@end
diff --git a/macosx/HBPresetsViewController.h b/macosx/HBPresetsViewController.h
index 11390e452..e3cca8cd1 100644
--- a/macosx/HBPresetsViewController.h
+++ b/macosx/HBPresetsViewController.h
@@ -27,13 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
- (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;
diff --git a/macosx/HBPresetsViewController.m b/macosx/HBPresetsViewController.m
index 7763a3a56..b9a975c91 100644
--- a/macosx/HBPresetsViewController.m
+++ b/macosx/HBPresetsViewController.m
@@ -12,6 +12,9 @@
// drag and drop pasteboard type
#define kHandBrakePresetPBoardType @"handBrakePresetPBoardType"
+// KVO Context
+static void *HBPresetsViewControllerContext = &HBPresetsViewControllerContext;
+
@interface HBPresetCellView : NSTableCellView
@end
@@ -44,6 +47,7 @@
@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;
@@ -59,7 +63,8 @@
*/
@property (nonatomic, strong) NSMutableArray *expandedNodes;
-@property (unsafe_unretained) IBOutlet NSOutlineView *outlineView;
+@property (nonatomic, unsafe_unretained) IBOutlet NSOutlineView *outlineView;
+
@end
@@ -71,6 +76,7 @@
if (self)
{
_presets = presetManager;
+ _selectedPresetInternal = presetManager.defaultPreset;
_expandedNodes = [[NSArray arrayWithArray:[[NSUserDefaults standardUserDefaults]
objectForKey:@"HBPreviewViewExpandedStatus"]] mutableCopy];
}
@@ -92,10 +98,29 @@
// 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
@@ -117,7 +142,6 @@
}
}
-
return YES;
}
@@ -272,15 +296,21 @@
- (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
@@ -293,19 +323,6 @@
}
}
-- (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];