Commit 4da13fbc authored by David Fuhrmann's avatar David Fuhrmann

macosx: Modernize and fix shared dialog panels

Splits PopupPanel and TextfieldPanel into two xib files and
creates NSWindowController subclasses for each panel.

Each user of the panel gets its own window controller instance.
This is needed as the same kind of window can be shown multiple
times simultaneously (e.g. both in video and audio effects).

This also did not work with the previous implementation of the
2.2 branch and fixes broken behaviour.
parent beab9340
......@@ -151,12 +151,13 @@ EXTRA_DIST += \
extras/package/macosx/Resources/English.lproj/Open.xib \
extras/package/macosx/Resources/English.lproj/PlaylistAccessoryView.xib \
extras/package/macosx/Resources/English.lproj/PlaylistMenu.xib \
extras/package/macosx/Resources/English.lproj/PopupPanel.xib \
extras/package/macosx/Resources/English.lproj/Preferences.xib \
extras/package/macosx/Resources/English.lproj/ResumeDialog.xib \
extras/package/macosx/Resources/English.lproj/SharedDialogs.xib \
extras/package/macosx/Resources/English.lproj/SimplePreferences.xib \
extras/package/macosx/Resources/English.lproj/StreamOutput.xib \
extras/package/macosx/Resources/English.lproj/SyncTracks.xib \
extras/package/macosx/Resources/English.lproj/TextfieldPanel.xib \
extras/package/macosx/Resources/English.lproj/VideoEffects.xib \
extras/package/macosx/Resources/fspanel/fs_background.png \
extras/package/macosx/Resources/fspanel/fs_background@2x.png \
......
......@@ -24,6 +24,9 @@
#import <Cocoa/Cocoa.h>
@class VLCPopupPanelController;
@class VLCTextfieldPanelController;
@interface VLCAudioEffects : NSWindowController
/* generic */
......@@ -101,6 +104,9 @@
@property (readwrite, weak) IBOutlet NSTextField *filterNormLevelLabel;
@property (readwrite, weak) IBOutlet NSButton *filterKaraokeCheckbox;
@property (strong) VLCPopupPanelController *popupPanel;
@property (strong) VLCTextfieldPanelController *textfieldPanel;
/* generic */
- (IBAction)profileSelectorAction:(id)sender;
......
......@@ -91,6 +91,9 @@
self = [super initWithWindowNibName:@"AudioEffects"];
if (self) {
i_old_profile_index = -1;
self.popupPanel = [[VLCPopupPanelController alloc] init];
self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
}
return self;
......@@ -359,30 +362,28 @@
- (void)addAudioEffectsProfile:(id)sender
{
/* show panel */
VLCEnterTextPanel *panel = [VLCEnterTextPanel sharedInstance];
[panel setTitle: _NS("Duplicate current profile for a new profile")];
[panel setSubTitle: _NS("Enter a name for the new profile:")];
[panel setCancelButtonLabel: _NS("Cancel")];
[panel setOKButtonLabel: _NS("Save")];
[panel setTarget:self];
[_textfieldPanel setTitle: _NS("Duplicate current profile for a new profile")];
[_textfieldPanel setSubTitle: _NS("Enter a name for the new profile:")];
[_textfieldPanel setCancelButtonLabel: _NS("Cancel")];
[_textfieldPanel setOKButtonLabel: _NS("Save")];
[_textfieldPanel setTarget:self];
b_genericAudioProfileInInteraction = YES;
[panel runModalForWindow:self.window];
[_textfieldPanel runModalForWindow:self.window];
}
- (void)removeAudioEffectsProfile:(id)sender
{
/* show panel */
VLCSelectItemInPopupPanel *panel = [VLCSelectItemInPopupPanel sharedInstance];
[panel setTitle:_NS("Remove a preset")];
[panel setSubTitle:_NS("Select the preset you would like to remove:")];
[panel setOKButtonLabel:_NS("Remove")];
[panel setCancelButtonLabel:_NS("Cancel")];
[panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
[panel setTarget:self];
[_popupPanel setTitle:_NS("Remove a preset")];
[_popupPanel setSubTitle:_NS("Select the preset you would like to remove:")];
[_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"AudioEffectProfileNames"]];
[_popupPanel setTarget:self];
b_genericAudioProfileInInteraction = YES;
[panel runModalForWindow:self.window];
[_popupPanel runModalForWindow:self.window];
}
#pragma mark -
......@@ -600,7 +601,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
- (IBAction)addPresetAction:(id)sender
{
/* show panel */
VLCEnterTextPanel *panel = [VLCEnterTextPanel sharedInstance];
VLCTextfieldPanelController *panel = [[VLCTextfieldPanelController alloc] init];
[panel setTitle: _NS("Save current selection as new preset")];
[panel setSubTitle: _NS("Enter a name for the new preset:")];
[panel setCancelButtonLabel: _NS("Cancel")];
......@@ -611,7 +612,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
[panel runModalForWindow:self.window];
}
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
- (void)panel:(VLCTextfieldPanelController *)panel returnValue:(NSUInteger)value text:(NSString *)text
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
......@@ -691,7 +692,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
- (IBAction)deletePresetAction:(id)sender
{
VLCSelectItemInPopupPanel *panel = [VLCSelectItemInPopupPanel sharedInstance];
VLCPopupPanelController *panel = [[VLCPopupPanelController alloc] init];
[panel setTitle:_NS("Remove a preset")];
[panel setSubTitle:_NS("Select the preset you would like to remove:")];
[panel setOKButtonLabel:_NS("Remove")];
......@@ -703,7 +704,7 @@ static bool GetEqualizerStatus(intf_thread_t *p_custom_intf,
[panel runModalForWindow:self.window];
}
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
if (!b_genericAudioProfileInInteraction) {
if (value == NSOKButton) {
......
......@@ -22,10 +22,11 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import "SharedDialogs.h"
@class VLCDropDisabledImageView;
@class VLCDragDropView;
@class VLCPopupPanelController;
@class VLCTextfieldPanelController;
@interface VLCConvertAndSave : NSWindowController
......@@ -127,6 +128,10 @@
@property (weak) IBOutlet NSButton *streamOkButton;
// other properties
@property (strong) VLCPopupPanelController *popupPanel;
@property (strong) VLCTextfieldPanelController *textfieldPanel;
@property (readwrite, nonatomic, retain) NSString * MRL;
@property (readwrite, nonatomic, retain) NSString * outputDestination;
@property (readwrite, retain) NSArray * profileNames;
......@@ -161,7 +166,7 @@
- (IBAction)streamAnnouncementToggle:(id)sender;
- (IBAction)sdpFileLocationSelector:(id)sender;
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text;
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
- (void)panel:(VLCTextfieldPanelController *)panel returnValue:(NSUInteger)value text:(NSString *)text;
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
@end
......@@ -25,6 +25,7 @@
#import "intf.h"
#import "playlist.h"
#import "misc.h"
#import "SharedDialogs.h"
#import <vlc_common.h>
#import <vlc_url.h>
......@@ -121,7 +122,10 @@
- (id)init
{
self = [super initWithWindowNibName:@"ConvertAndSave"];
if (self) {
self.popupPanel = [[VLCPopupPanelController alloc] init];
self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
}
return self;
}
......@@ -326,15 +330,14 @@
- (IBAction)deleteProfileAction:(id)sender
{
/* show panel */
VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
[panel setTitle:_NS("Remove a profile")];
[panel setSubTitle:_NS("Select the profile you would like to remove:")];
[panel setOKButtonLabel:_NS("Remove")];
[panel setCancelButtonLabel:_NS("Cancel")];
[panel setPopupButtonContent:self.profileNames];
[panel setTarget:self];
[panel runModalForWindow:self.window];
[_popupPanel setTitle:_NS("Remove a profile")];
[_popupPanel setSubTitle:_NS("Select the profile you would like to remove:")];
[_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:self.profileNames];
[_popupPanel setTarget:self];
[_popupPanel runModalForWindow:self.window];
}
- (IBAction)iWantAFile:(id)sender
......@@ -442,18 +445,16 @@
[_customizeSubsPopup setEnabled:enableSettings];
}
- (IBAction)newProfileAction:(id)sender
{
/* show panel */
VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
[panel setTitle: _NS("Save as new profile")];
[panel setSubTitle: _NS("Enter a name for the new profile:")];
[panel setCancelButtonLabel: _NS("Cancel")];
[panel setOKButtonLabel: _NS("Save")];
[panel setTarget:self];
[panel runModalForWindow:_customizePanel];
[_textfieldPanel setTitle: _NS("Save as new profile")];
[_textfieldPanel setSubTitle: _NS("Enter a name for the new profile:")];
[_textfieldPanel setCancelButtonLabel: _NS("Cancel")];
[_textfieldPanel setOKButtonLabel: _NS("Save")];
[_textfieldPanel setTarget:self];
[_textfieldPanel runModalForWindow:_customizePanel];
}
#pragma mark -
......@@ -604,7 +605,7 @@
return NO;
}
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
- (void)panel:(VLCTextfieldPanelController *)panel returnValue:(NSUInteger)value text:(NSString *)text
{
if (value == NSOKButton) {
if ([text length] > 0) {
......@@ -631,7 +632,7 @@
}
}
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
if (value == NSOKButton) {
/* remove requested profile from the arrays */
......
......@@ -23,16 +23,13 @@
#import <Cocoa/Cocoa.h>
@interface VLCEnterTextPanel : NSObject
{
IBOutlet id _panel;
IBOutlet id _title_lbl;
IBOutlet id _subtitle_lbl;
IBOutlet id _text_fld;
IBOutlet id _cancel_btn;
IBOutlet id _ok_btn;
}
+ (VLCEnterTextPanel *)sharedInstance;
@interface VLCTextfieldPanelController : NSWindowController
@property (weak) IBOutlet NSTextField *titleLabel;
@property (weak) IBOutlet NSTextField *subtitleLabel;
@property (weak) IBOutlet NSTextField *textField;
@property (weak) IBOutlet NSButton *cancelButton;
@property (weak) IBOutlet NSButton *okButton;
@property (readwrite, assign) NSString *title;
@property (readwrite, assign) NSString *subTitle;
......@@ -47,21 +44,18 @@
@end
@protocol VLCEnterTextPanel <NSObject>
@protocol VLCTextfieldPanelController <NSObject>
@optional
- (void)panel:(VLCEnterTextPanel *)view returnValue:(NSUInteger)value text:(NSString *)text;
- (void)panel:(VLCTextfieldPanelController *)view returnValue:(NSUInteger)value text:(NSString *)text;
@end
@interface VLCSelectItemInPopupPanel : NSObject
{
IBOutlet id _panel;
IBOutlet id _title_lbl;
IBOutlet id _subtitle_lbl;
IBOutlet id _pop;
IBOutlet id _cancel_btn;
IBOutlet id _ok_btn;
}
+ (VLCSelectItemInPopupPanel *)sharedInstance;
@interface VLCPopupPanelController : NSWindowController
@property (weak) IBOutlet NSTextField *titleLabel;
@property (weak) IBOutlet NSTextField *subtitleLabel;
@property (weak) IBOutlet NSPopUpButton *popupButton;
@property (weak) IBOutlet NSButton *cancelButton;
@property (weak) IBOutlet NSButton *okButton;
@property (readwrite, assign) NSString *title;
@property (readwrite, assign) NSString *subTitle;
......@@ -77,7 +71,7 @@
@end
@protocol VLCSelectItemInPopupPanel <NSObject>
@protocol VLCPopupPanelController <NSObject>
@optional
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
@end
......@@ -23,27 +23,24 @@
#import "SharedDialogs.h"
@implementation VLCEnterTextPanel
+ (VLCEnterTextPanel *)sharedInstance
{
static VLCEnterTextPanel *sharedInstance = nil;
static dispatch_once_t pred;
@implementation VLCTextfieldPanelController
dispatch_once(&pred, ^{
sharedInstance = [VLCEnterTextPanel new];
});
- (id)init
{
self = [super initWithWindowNibName:@"TextfieldPanel"];
return sharedInstance;
return self;
}
- (IBAction)windowElementAction:(id)sender
{
[_panel orderOut:sender];
[NSApp endSheet: _panel];
[self.window orderOut:sender];
[NSApp endSheet: self.window];
if (self.target) {
if ([self.target respondsToSelector:@selector(panel:returnValue:text:)]) {
if (sender == _cancel_btn)
if (sender == _cancelButton)
[self.target panel:self returnValue:NSCancelButton text:NULL];
else
[self.target panel:self returnValue:NSOKButton text:self.enteredText];
......@@ -53,44 +50,41 @@
- (void)runModalForWindow:(NSWindow *)window
{
[_title_lbl setStringValue:self.title];
[_subtitle_lbl setStringValue:self.subTitle];
[_cancel_btn setTitle:self.CancelButtonLabel];
[_ok_btn setTitle:self.OKButtonLabel];
[_text_fld setStringValue:@""];
[self window];
[_titleLabel setStringValue:self.title];
[_subtitleLabel setStringValue:self.subTitle];
[_cancelButton setTitle:self.CancelButtonLabel];
[_okButton setTitle:self.OKButtonLabel];
[_textField setStringValue:@""];
[NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
[NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
- (NSString *)enteredText
{
return [_text_fld stringValue];
return [_textField stringValue];
}
@end
@implementation VLCSelectItemInPopupPanel
@implementation VLCPopupPanelController
+ (VLCSelectItemInPopupPanel *)sharedInstance
- (id)init
{
static VLCSelectItemInPopupPanel *sharedInstance = nil;
static dispatch_once_t pred;
self = [super initWithWindowNibName:@"PopupPanel"];
dispatch_once(&pred, ^{
sharedInstance = [VLCSelectItemInPopupPanel new];
});
return sharedInstance;
return self;
}
- (IBAction)windowElementAction:(id)sender
{
[_panel orderOut:sender];
[NSApp endSheet: _panel];
[self.window orderOut:sender];
[NSApp endSheet: self.window];
if (self.target) {
if ([self.target respondsToSelector:@selector(panel:returnValue:item:)]) {
if (sender == _cancel_btn)
if (sender == _cancelButton)
[self.target panel:self returnValue:NSCancelButton item:0];
else
[self.target panel:self returnValue:NSOKButton item:self.currentItem];
......@@ -100,18 +94,22 @@
- (void)runModalForWindow:(NSWindow *)window
{
[_title_lbl setStringValue:self.title];
[_subtitle_lbl setStringValue:self.subTitle];
[_cancel_btn setTitle:self.CancelButtonLabel];
[_ok_btn setTitle:self.OKButtonLabel];
[_pop removeAllItems];
[_pop addItemsWithTitles:self.popupButtonContent];
[NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
[self window];
[_titleLabel setStringValue:self.title];
[_subtitleLabel setStringValue:self.subTitle];
[_cancelButton setTitle:self.CancelButtonLabel];
[_okButton setTitle:self.OKButtonLabel];
[_popupButton removeAllItems];
for (NSString *value in self.popupButtonContent)
[[_popupButton menu] addItemWithTitle:value action:nil keyEquivalent:@""];
[NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
- (NSUInteger)currentItem
{
return [_pop indexOfSelectedItem];
return [_popupButton indexOfSelectedItem];
}
@end
......@@ -23,6 +23,9 @@
#import <Cocoa/Cocoa.h>
@class VLCPopupPanelController;
@class VLCTextfieldPanelController;
@interface VLCVideoEffects : NSWindowController
/* generic */
......@@ -141,6 +144,9 @@
@property (readwrite, weak) IBOutlet NSSlider *addLogoTransparencySlider;
@property (readwrite, weak) IBOutlet NSButton *anaglyphCheckbox;
@property (strong) VLCPopupPanelController *popupPanel;
@property (strong) VLCTextfieldPanelController *textfieldPanel;
/* text field / stepper binding values */
/* use setter to modify gui elements */
@property (nonatomic) int cropLeftValue;
......
......@@ -50,6 +50,9 @@
self = [super initWithWindowNibName:@"VideoEffects"];
if (self) {
i_old_profile_index = -1;
self.popupPanel = [[VLCPopupPanelController alloc] init];
self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
}
return self;
......@@ -666,17 +669,16 @@
- (void)addProfile:(id)sender
{
/* show panel */
VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
[panel setTitle: _NS("Duplicate current profile for a new profile")];
[panel setSubTitle: _NS("Enter a name for the new profile:")];
[panel setCancelButtonLabel: _NS("Cancel")];
[panel setOKButtonLabel: _NS("Save")];
[panel setTarget:self];
[panel runModalForWindow:self.window];
[_textfieldPanel setTitle: _NS("Duplicate current profile for a new profile")];
[_textfieldPanel setSubTitle: _NS("Enter a name for the new profile:")];
[_textfieldPanel setCancelButtonLabel: _NS("Cancel")];
[_textfieldPanel setOKButtonLabel: _NS("Save")];
[_textfieldPanel setTarget:self];
[_textfieldPanel runModalForWindow:self.window];
}
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
- (void)panel:(VLCTextfieldPanelController *)panel returnValue:(NSUInteger)value text:(NSString *)text
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
......@@ -727,18 +729,17 @@
- (void)removeProfile:(id)sender
{
/* show panel */
VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
[panel setTitle:_NS("Remove a preset")];
[panel setSubTitle:_NS("Select the preset you would like to remove:")];
[panel setOKButtonLabel:_NS("Remove")];
[panel setCancelButtonLabel:_NS("Cancel")];
[panel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]];
[panel setTarget:self];
[panel runModalForWindow:self.window];
[_popupPanel setTitle:_NS("Remove a preset")];
[_popupPanel setSubTitle:_NS("Select the preset you would like to remove:")];
[_popupPanel setOKButtonLabel:_NS("Remove")];
[_popupPanel setCancelButtonLabel:_NS("Cancel")];
[_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]];
[_popupPanel setTarget:self];
[_popupPanel runModalForWindow:self.window];
}
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
......
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