Commit 0b2f47e8 authored by David Fuhrmann's avatar David Fuhrmann

macosx: popup panel: switch from delegate to completion block

Also fixes behaviour for eq profile list
parent 2609901e
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
@interface VLCAudioEffects () @interface VLCAudioEffects ()
{ {
BOOL b_genericAudioProfileInInteraction;
NSInteger i_old_profile_index; NSInteger i_old_profile_index;
} }
- (void)resetProfileSelector; - (void)resetProfileSelector;
...@@ -420,10 +419,31 @@ ...@@ -420,10 +419,31 @@
[_popupPanel setOKButtonLabel:_NS("Remove")]; [_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")]; [_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]]; [_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
[_popupPanel setTarget:self];
b_genericAudioProfileInInteraction = YES;
[_popupPanel runModalForWindow:self.window]; __weak typeof(self) _self = self;
[_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (returnCode != NSOKButton) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
return;
}
/* remove selected profile from settings */
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
[workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
[workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
if (i_old_profile_index >= selectedIndex)
[defaults setInteger:i_old_profile_index - 1 forKey:@"AudioEffectSelectedProfile"];
/* save defaults */
[defaults synchronize];
[_self resetProfileSelector];
}];
} }
#pragma mark - #pragma mark -
...@@ -684,64 +704,37 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf, ...@@ -684,64 +704,37 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
- (IBAction)deletePresetAction:(id)sender - (IBAction)deletePresetAction:(id)sender
{ {
VLCPopupPanelController *panel = [[VLCPopupPanelController alloc] init]; [_popupPanel setTitle:_NS("Remove a preset")];
[panel setTitle:_NS("Remove a preset")]; [_popupPanel setSubTitle:_NS("Select the preset you would like to remove:")];
[panel setSubTitle:_NS("Select the preset you would like to remove:")]; [_popupPanel setOKButtonLabel:_NS("Remove")];
[panel setOKButtonLabel:_NS("Remove")]; [_popupPanel setCancelButtonLabel:_NS("Cancel")];
[panel setCancelButtonLabel:_NS("Cancel")]; [_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
[panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"EQTitles"]];
[panel setTarget:self];
b_genericAudioProfileInInteraction = NO;
[panel runModalForWindow:self.window];
}
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
if (!b_genericAudioProfileInInteraction) {
if (value == NSOKButton) {
/* remove requested profile from the arrays */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
[defaults synchronize];
}
/* update UI */ __weak typeof(self) _self = self;
[self updatePresetSelector]; [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
} else {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if (returnCode != NSOKButton)
if (value != NSOKButton) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"AudioEffectSelectedProfile"]];
return; return;
}
/* remove selected profile from settings */
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfiles"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfiles"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"AudioEffectProfileNames"]];
[workArray removeObjectAtIndex:item];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"AudioEffectProfileNames"];
if (i_old_profile_index >= item) /* remove requested profile from the arrays */
[defaults setInteger:i_old_profile_index - 1 forKey:@"AudioEffectSelectedProfile"]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQValues"]];
/* save defaults */ [workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQValues"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQTitles"]];
[workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQTitles"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQPreampValues"]];
[workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQPreampValues"];
workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"EQNames"]];
[workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"EQNames"];
[defaults synchronize]; [defaults synchronize];
[self resetProfileSelector];
} /* update UI */
[_self updatePresetSelector];
}];
} }
#pragma mark - #pragma mark -
......
...@@ -166,6 +166,4 @@ ...@@ -166,6 +166,4 @@
- (IBAction)streamAnnouncementToggle:(id)sender; - (IBAction)streamAnnouncementToggle:(id)sender;
- (IBAction)sdpFileLocationSelector:(id)sender; - (IBAction)sdpFileLocationSelector:(id)sender;
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
@end @end
...@@ -326,7 +326,6 @@ ...@@ -326,7 +326,6 @@
[self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]]; [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]];
} }
- (IBAction)deleteProfileAction:(id)sender - (IBAction)deleteProfileAction:(id)sender
{ {
/* show panel */ /* show panel */
...@@ -335,9 +334,28 @@ ...@@ -335,9 +334,28 @@
[_popupPanel setOKButtonLabel:_NS("Remove")]; [_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")]; [_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:self.profileNames]; [_popupPanel setPopupButtonContent:self.profileNames];
[_popupPanel setTarget:self];
[_popupPanel runModalForWindow:self.window]; __weak typeof(self) _self = self;
[_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
if (returnCode != NSOKButton)
return;
/* remove requested profile from the arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:_self.profileNames];
[workArray removeObjectAtIndex:selectedIndex];
[_self setProfileNames:[[NSArray alloc] initWithArray:workArray]];
workArray = [[NSMutableArray alloc] initWithArray:_self.profileValueList];
[workArray removeObjectAtIndex:selectedIndex];
[_self setProfileValueList:[[NSArray alloc] initWithArray:workArray]];
/* update UI */
[_self recreateProfilePopup];
/* update internals */
[_self switchProfile:_self];
[_self storeProfilesOnDisk];
}];
} }
- (IBAction)iWantAFile:(id)sender - (IBAction)iWantAFile:(id)sender
...@@ -628,26 +646,6 @@ ...@@ -628,26 +646,6 @@
return NO; return NO;
} }
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
if (value == NSOKButton) {
/* remove requested profile from the arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
[workArray removeObjectAtIndex:item];
[self setProfileNames:[[NSArray alloc] initWithArray:workArray]];
workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
[workArray removeObjectAtIndex:item];
[self setProfileValueList:[[NSArray alloc] initWithArray:workArray]];
/* update UI */
[self recreateProfilePopup];
/* update internals */
[self switchProfile:self];
[self storeProfilesOnDisk];
}
}
# pragma mark - # pragma mark -
# pragma mark Private Functionality # pragma mark Private Functionality
......
...@@ -68,16 +68,21 @@ typedef void(^TextfieldPanelCompletionBlock)(NSInteger returnCode, NSString *res ...@@ -68,16 +68,21 @@ typedef void(^TextfieldPanelCompletionBlock)(NSInteger returnCode, NSString *res
@property (readwrite, assign) NSString *OKButtonLabel; @property (readwrite, assign) NSString *OKButtonLabel;
@property (readwrite, assign) NSString *CancelButtonLabel; @property (readwrite, assign) NSString *CancelButtonLabel;
@property (readwrite, assign) NSArray *popupButtonContent; @property (readwrite, assign) NSArray *popupButtonContent;
@property (readwrite, assign) id target;
@property (readonly) NSUInteger currentItem;
- (void)runModalForWindow:(NSWindow *)window; /**
* Completion handler for popup panel
* \param returnCode Result from panel. Can be NSOKButton or NSCancelButton.
* \param selectedIndex Selected index of the popup in panel.
*/
typedef void(^PopupPanelCompletionBlock)(NSInteger returnCode, NSInteger selectedIndex);
- (IBAction)windowElementAction:(id)sender; /**
* Shows the panel as a modal dialog with window as its owner.
* \param window Parent window for the dialog.
* \param handler Completion block.
*/
- (void)runModalForWindow:(NSWindow *)window completionHandler:(PopupPanelCompletionBlock)handler;
@end - (IBAction)windowElementAction:(id)sender;
@protocol VLCPopupPanelController <NSObject>
@optional
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
@end @end
...@@ -66,6 +66,12 @@ ...@@ -66,6 +66,12 @@
@end @end
@interface VLCPopupPanelController()
{
PopupPanelCompletionBlock _completionBlock;
}
@end
@implementation VLCPopupPanelController @implementation VLCPopupPanelController
- (id)init - (id)init
...@@ -80,17 +86,11 @@ ...@@ -80,17 +86,11 @@
[self.window orderOut:sender]; [self.window orderOut:sender];
[NSApp endSheet: self.window]; [NSApp endSheet: self.window];
if (self.target) { if (_completionBlock)
if ([self.target respondsToSelector:@selector(panel:returnValue:item:)]) { _completionBlock(sender == _okButton ? NSOKButton : NSCancelButton, [_popupButton indexOfSelectedItem]);
if (sender == _cancelButton)
[self.target panel:self returnValue:NSCancelButton item:0];
else
[self.target panel:self returnValue:NSOKButton item:self.currentItem];
}
}
} }
- (void)runModalForWindow:(NSWindow *)window - (void)runModalForWindow:(NSWindow *)window completionHandler:(PopupPanelCompletionBlock)handler;
{ {
[self window]; [self window];
...@@ -102,12 +102,9 @@ ...@@ -102,12 +102,9 @@
for (NSString *value in self.popupButtonContent) for (NSString *value in self.popupButtonContent)
[[_popupButton menu] addItemWithTitle:value action:nil keyEquivalent:@""]; [[_popupButton menu] addItemWithTitle:value action:nil keyEquivalent:@""];
[NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil]; _completionBlock = [handler copy];
}
- (NSUInteger)currentItem [NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
{
return [_popupButton indexOfSelectedItem];
} }
@end @end
...@@ -732,39 +732,37 @@ ...@@ -732,39 +732,37 @@
[_popupPanel setOKButtonLabel:_NS("Remove")]; [_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")]; [_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]]; [_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]];
[_popupPanel setTarget:self];
[_popupPanel runModalForWindow:self.window]; __weak typeof(self) _self = self;
} [_popupPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSInteger selectedIndex) {
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (value != NSOKButton) { if (returnCode != NSOKButton) {
[_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]]; [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
return; return;
} }
/* remove selected profile from settings */ /* remove selected profile from settings */
NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]]; NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]];
[workArray removeObjectAtIndex:item]; [workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfileNames"]]; workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfileNames"]];
[workArray removeObjectAtIndex:item]; [workArray removeObjectAtIndex:selectedIndex];
[defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"]; [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
if (i_old_profile_index >= item) if (i_old_profile_index >= selectedIndex)
[defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"]; [defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"];
/* save defaults */ /* save defaults */
[defaults synchronize]; [defaults synchronize];
/* do not save deleted profile */ /* do not save deleted profile */
i_old_profile_index = -1; i_old_profile_index = -1;
/* refresh UI */ /* refresh UI */
[self resetProfileSelector]; [_self resetProfileSelector];
}];
} }
#pragma mark - #pragma mark -
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment