]> git.sesse.net Git - vlc/blob - modules/gui/macosx/SharedDialogs.m
Consistent strings to avoid duplications
[vlc] / modules / gui / macosx / SharedDialogs.m
1 /*****************************************************************************
2  * SharedDialogs.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2012 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #import "SharedDialogs.h"
25
26 static VLCEnterTextPanel *_textPanelInstance = nil;
27 static VLCSelectItemInPopupPanel *_selectItemPanelInstance = nil;
28
29 @implementation VLCEnterTextPanel
30 + (VLCEnterTextPanel *)sharedInstance
31 {
32     return _textPanelInstance ? _textPanelInstance : [[self alloc] init];
33 }
34
35 - (id)init
36 {
37     if (_textPanelInstance)
38         [self dealloc];
39     else
40         _textPanelInstance = [super init];
41
42     return _textPanelInstance;
43 }
44
45 @synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, target=_target;
46
47 - (IBAction)windowElementAction:(id)sender
48 {
49     [_panel orderOut:sender];
50     [NSApp endSheet: _panel];
51
52     if (self.target) {
53         if ([self.target respondsToSelector:@selector(panel:returnValue:text:)]) {
54             if (sender == _cancel_btn)
55                 [self.target panel:self returnValue:NSCancelButton text:NULL];
56             else
57                 [self.target panel:self returnValue:NSOKButton text:self.enteredText];
58         }
59     }
60 }
61
62 - (void)runModalForWindow:(NSWindow *)window
63 {
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:@""];
69
70     [NSApp beginSheet:_panel modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
71 }
72
73 - (NSString *)enteredText
74 {
75     return [_text_fld stringValue];
76 }
77
78 @end
79
80 @implementation VLCSelectItemInPopupPanel
81 @synthesize title=_title, subTitle=_subtitle, OKButtonLabel=_okTitle, CancelButtonLabel=_cancelTitle, popupButtonContent=_popData, target=_target;
82
83 + (VLCSelectItemInPopupPanel *)sharedInstance
84 {
85     return _selectItemPanelInstance ? _selectItemPanelInstance : [[self alloc] init];
86 }
87
88 - (id)init
89 {
90     if (_selectItemPanelInstance)
91         [self dealloc];
92     else
93         _selectItemPanelInstance = [super init];
94
95     return _selectItemPanelInstance;
96 }
97
98 - (IBAction)windowElementAction:(id)sender
99 {
100     [_panel orderOut:sender];
101     [NSApp endSheet: _panel];
102
103     if (self.target) {
104         if ([self.target respondsToSelector:@selector(panel:returnValue:item:)]) {
105             if (sender == _cancel_btn)
106                 [self.target panel:self returnValue:NSCancelButton item:0];
107             else
108                 [self.target panel:self returnValue:NSOKButton item:self.currentItem];
109         }
110     }
111 }
112
113 - (void)runModalForWindow:(NSWindow *)window
114 {
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];
122 }
123
124 - (NSUInteger)currentItem
125 {
126     return [_pop indexOfSelectedItem];
127 }
128
129 @end