1 /*****************************************************************************
2 * SharedDialogs.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2012 Felix Paul Kühne
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #import "SharedDialogs.h"
26 static VLCEnterTextPanel *_textPanelInstance = nil;
27 static VLCSelectItemInPopupPanel *_selectItemPanelInstance = nil;
29 @implementation VLCEnterTextPanel
30 + (VLCEnterTextPanel *)sharedInstance
32 return _textPanelInstance ? _textPanelInstance : [[self alloc] init];
37 if (_textPanelInstance)
40 _textPanelInstance = [super init];
42 return _textPanelInstance;
45 @synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, target=_target;
47 - (IBAction)windowElementAction:(id)sender
49 [_panel orderOut:sender];
50 [NSApp endSheet: _panel];
53 if ([self.target respondsToSelector:@selector(panel:returnValue:text:)]) {
54 if (sender == _cancel_btn)
55 [self.target panel:self returnValue:NSCancelButton text:NULL];
57 [self.target panel:self returnValue:NSOKButton text:self.enteredText];
62 - (void)runModalForWindow:(NSWindow *)window
64 [_title_lbl setStringValue:self.title];
65 [_subtitle_lbl setStringValue:self.subTitle];
66 [_cancel_btn setTitle:self.CancelButtonLabel];
67 [_ok_btn setTitle:self.OKButtonLabel];
68 [_text_fld setStringValue:@""];
70 [NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
73 - (NSString *)enteredText
75 return [_text_fld stringValue];
80 @implementation VLCSelectItemInPopupPanel
81 @synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, popupButtonContent=_popData, target=_target;
83 + (VLCSelectItemInPopupPanel *)sharedInstance
85 return _selectItemPanelInstance ? _selectItemPanelInstance : [[self alloc] init];
90 if (_selectItemPanelInstance)
93 _selectItemPanelInstance = [super init];
95 return _selectItemPanelInstance;
98 - (IBAction)windowElementAction:(id)sender
100 [_panel orderOut:sender];
101 [NSApp endSheet: _panel];
104 if ([self.target respondsToSelector:@selector(panel:returnValue:item:)]) {
105 if (sender == _cancel_btn)
106 [self.target panel:self returnValue:NSCancelButton item:0];
108 [self.target panel:self returnValue:NSOKButton item:self.currentItem];
113 - (void)runModalForWindow:(NSWindow *)window
115 [_title_lbl setStringValue:self.title];
116 [_subtitle_lbl setStringValue:self.subTitle];
117 [_cancel_btn setTitle:self.CancelButtonLabel];
118 [_ok_btn setTitle:self.OKButtonLabel];
119 [_pop removeAllItems];
120 [_pop addItemsWithTitles:self.popupButtonContent];
121 [NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
124 - (NSUInteger)currentItem
126 return [_pop indexOfSelectedItem];