source: trunk/macosx/URLSheetWindowController.m @ 11868

Last change on this file since 11868 was 11868, checked in by livings124, 11 years ago

remember the text in the URL sheet

File size: 3.0 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 2011 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "URLSheetWindowController.h"
26#import "Controller.h"
27
28@implementation URLSheetWindowController
29
30NSString * urlString = @"";
31
32- (id) initWithController: (Controller *) controller
33{
34    if ((self = [self initWithWindowNibName: @"URLSheetWindow"]))
35    {
36        fController = controller;
37    }
38    return self;
39}
40
41- (void) awakeFromNib
42{
43    [fLabelField setStringValue: NSLocalizedString(@"Internet address of torrent file:", "URL sheet label")];
44   
45    [fTextField setStringValue: urlString];
46    [fTextField selectText: self];
47}
48
49- (IBAction) beginSheetForWindow: (NSWindow *) window
50{
51    [NSApp beginSheet: [self window] modalForWindow: window modalDelegate: self
52        didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo: nil];
53}
54
55- (void) openURLEndSheet: (id) sender
56{
57    [[self window] orderOut: sender];
58    [NSApp endSheet: [self window] returnCode: 1];
59}
60
61- (void) openURLCancelEndSheet: (id) sender
62{
63    [[self window] orderOut: sender];
64    [NSApp endSheet: [self window] returnCode: 0];
65}
66
67- (void) sheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo
68{
69    urlString = [fTextField stringValue];
70    [fController urlSheetDidEnd: self url: urlString returnCode: returnCode];
71}
72
73- (void) controlTextDidChange: (NSNotification *) notification
74{
75    NSString * string = [fTextField stringValue];
76    BOOL enable = YES;
77    if ([string isEqualToString: @""])
78        enable = NO;
79    else
80    {
81        NSRange prefixRange = [string rangeOfString: @"://"];
82        if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange))
83            enable = NO;
84    }
85   
86    [fOpenButton setEnabled: enable];
87}
88
89@end
Note: See TracBrowser for help on using the repository browser.