1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/*****************************************************************************
* SharedDialogs.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2012 Felix Paul Kühne
* $Id: adb04729834b34604fc378c0e22b4fb7a8afe751 $
*
* Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "SharedDialogs.h"
static VLCEnterTextPanel *_textPanelInstance = nil;
static VLCSelectItemInPopupPanel *_selectItemPanelInstance = nil;
@implementation VLCEnterTextPanel
+ (VLCEnterTextPanel *)sharedInstance
{
return _textPanelInstance ? _textPanelInstance : [[self alloc] init];
}
- (id)init
{
if (_textPanelInstance)
[self dealloc];
else
_textPanelInstance = [super init];
return _textPanelInstance;
}
@synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, target=_target;
- (IBAction)windowElementAction:(id)sender
{
[_panel orderOut:sender];
[NSApp endSheet: _panel];
if (self.target) {
if ([self.target respondsToSelector:@selector(panel:returnValue:text:)]) {
if (sender == _cancel_btn)
[self.target panel:self returnValue:NSCancelButton text:NULL];
else
[self.target panel:self returnValue:NSOKButton text:self.enteredText];
}
}
}
- (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:@""];
[NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
- (NSString *)enteredText
{
return [_text_fld stringValue];
}
@end
@implementation VLCSelectItemInPopupPanel
@synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, popupButtonContent=_popData, target=_target;
+ (VLCSelectItemInPopupPanel *)sharedInstance
{
return _selectItemPanelInstance ? _selectItemPanelInstance : [[self alloc] init];
}
- (id)init
{
if (_selectItemPanelInstance)
[self dealloc];
else
_selectItemPanelInstance = [super init];
return _selectItemPanelInstance;
}
- (IBAction)windowElementAction:(id)sender
{
[_panel orderOut:sender];
[NSApp endSheet: _panel];
if (self.target) {
if ([self.target respondsToSelector:@selector(panel:returnValue:item:)]) {
if (sender == _cancel_btn)
[self.target panel:self returnValue:NSCancelButton item:0];
else
[self.target panel:self returnValue:NSOKButton item:self.currentItem];
}
}
}
- (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];
}
- (NSUInteger)currentItem
{
return [_pop indexOfSelectedItem];
}
@end
|