VLCTextfieldPanelController.m 2.15 KB
Newer Older
1
/*****************************************************************************
2
 * VLCTextfieldPanelController.m: MacOS X interface module
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *****************************************************************************
 * Copyright (C) 2012 Felix Paul Kühne
 * $Id$
 *
 * 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.
 *****************************************************************************/

24
#import "VLCTextfieldPanelController.h"
25

26 27 28 29 30 31 32
@interface VLCTextfieldPanelController()
{
    TextfieldPanelCompletionBlock _completionBlock;
}

@end

33 34
@implementation VLCTextfieldPanelController

35

36 37 38
- (id)init
{
    self = [super initWithWindowNibName:@"TextfieldPanel"];
39

40
    return self;
41 42 43 44
}

- (IBAction)windowElementAction:(id)sender
{
45 46
    [self.window orderOut:sender];
    [NSApp endSheet: self.window];
47

48 49
    if (_completionBlock)
        _completionBlock(sender == _okButton ? NSOKButton : NSCancelButton, [_textField stringValue]);
50 51
}

52
- (void)runModalForWindow:(NSWindow *)window completionHandler:(TextfieldPanelCompletionBlock)handler;
53
{
54 55
    [self window];

56 57 58 59
    [_titleLabel setStringValue:self.titleString];
    [_subtitleLabel setStringValue:self.subTitleString];
    [_cancelButton setTitle:self.cancelButtonString];
    [_okButton setTitle:self.okButtonString];
60
    [_textField setStringValue:@""];
61

62
    _completionBlock = [handler copy];
63

64
    [NSApp beginSheet:self.window modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:nil];
65 66 67
}

@end