1 /******************************************************************************
2 * $Id: URLSheetWindowController.m 13254 2012-03-13 03:39:56Z livings124 $
4 * Copyright (c) 2011-2012 Transmission authors and contributors
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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 *****************************************************************************/
25 #import "URLSheetWindowController.h"
26 #import "Controller.h"
28 @interface URLSheetWindowController (Private)
30 - (void) updateOpenButtonForURL: (NSString *) string;
34 @implementation URLSheetWindowController
36 NSString * urlString = nil;
38 - (id) initWithController: (Controller *) controller
40 if ((self = [self initWithWindowNibName: @"URLSheetWindow"]))
42 fController = controller;
49 [fLabelField setStringValue: NSLocalizedString(@"Internet address of torrent file:", "URL sheet label")];
53 [fTextField setStringValue: urlString];
54 [fTextField selectText: self];
56 [self updateOpenButtonForURL: urlString];
59 [fOpenButton setTitle: NSLocalizedString(@"Open", "URL sheet button")];
60 [fCancelButton setTitle: NSLocalizedString(@"Cancel", "URL sheet button")];
62 [fOpenButton sizeToFit];
63 [fCancelButton sizeToFit];
65 //size the two buttons the same
66 NSRect openFrame = [fOpenButton frame];
67 openFrame.size.width += 10.0;
68 NSRect cancelFrame = [fCancelButton frame];
69 cancelFrame.size.width += 10.0;
71 if (NSWidth(openFrame) > NSWidth(cancelFrame))
72 cancelFrame.size.width = NSWidth(openFrame);
74 openFrame.size.width = NSWidth(cancelFrame);
76 openFrame.origin.x = NSWidth([[self window] frame]) - NSWidth(openFrame) - 20.0 + 6.0; //I don't know why the extra 6.0 is needed
77 [fOpenButton setFrame: openFrame];
79 cancelFrame.origin.x = NSMinX(openFrame) - NSWidth(cancelFrame);
80 [fCancelButton setFrame: cancelFrame];
83 - (void) openURLEndSheet: (id) sender
85 [[self window] orderOut: sender];
86 [NSApp endSheet: [self window] returnCode: 1];
89 - (void) openURLCancelEndSheet: (id) sender
91 [[self window] orderOut: sender];
92 [NSApp endSheet: [self window] returnCode: 0];
95 - (NSString *) urlString
97 return [[[fTextField stringValue] retain] autorelease];
100 - (void) controlTextDidChange: (NSNotification *) notification
102 [self updateOpenButtonForURL: [fTextField stringValue]];
107 @implementation URLSheetWindowController (Private)
109 - (void) updateOpenButtonForURL: (NSString *) string
112 if ([string isEqualToString: @""])
116 NSRange prefixRange = [string rangeOfString: @"://"];
117 if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange))
121 [fOpenButton setEnabled: enable];