1//
2//  PXNamePrompter.m
3//  Pixel Editor
4//
5//  Created by Open Sword Group on Thu May 01 2003.
6
7// Copyright (c) 2003,2004 Open Sword Group
8
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13//  of the Software, and to permit persons to whom the Software is furnished to
14// do so, subject to the following conditions:
15
16// The above copyright notice and this permission notice shall be included
17//in all copies or substantial portions of the Software.
18
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
24// OR OTHER DEALINGS IN THE SOFTWARE.
25
26//  Author : Andy Matuschak
27//  Created  on Tue Dec 09 2003.
28
29#import "PXNamePrompter.h"
30#import "PXCanvasView.h"
31
32@implementation PXNamePrompter
33
34- (id) init
35{
36  if ( ! ( self = [super init] ) )
37    return nil;
38
39  if (! [NSBundle loadNibNamed:@"PXNamePrompt" owner: self] )
40    NSLog(@"Could not load Nib Named PXNamePrompt");
41
42  return self;
43}
44
45- (void)setDelegate: (id)newDelegate
46{
47  _delegate = newDelegate;
48}
49
50- (void)promptInWindow:(NSWindow *) window context:(id)contextInfo
51{
52  [self promptInWindow:window
53	context:contextInfo
54	promptString:@"Please name the new configuration."
55	defaultEntry:@""];
56}
57
58#warning string is not use ? ???
59- (void)promptInWindow:(NSWindow *) window context:(id) contextInfo promptString:(NSString* )string defaultEntry:(NSString *)entry
60{
61  _context = contextInfo;
62
63
64  [NSApp beginSheet:panel
65	 modalForWindow:window
66	 modalDelegate:nil
67	 didEndSelector:NULL
68	 contextInfo:NULL];
69
70  [nameField setStringValue:entry];
71}
72
73//Action from 'use this entered name" button
74//TODO probably warm the use if it is empty.
75// Maybye do external check or use formater for nameField
76- (IBAction)useEnteredName:(id)sender
77{
78  if([[nameField stringValue] isEqualToString:@""])
79    return;
80
81  if( [_delegate respondsToSelector:@selector(prompter:didFinishWithName:context:)] )
82    [_delegate prompter:self didFinishWithName:[nameField stringValue] context:_context];
83
84  [NSApp endSheet:panel];
85  [panel close];
86}
87
88//Action from 'use this entered name" button
89//this method end the sheet (OSX), close the panel
90//and send prompter:didCancelWithContext: to the delegate
91- (IBAction)cancel:(id)sender
92{
93  [NSApp endSheet:panel];
94
95  [panel close];
96
97  if( [_delegate respondsToSelector:@selector(prompter:didCancelWithContext:)] )
98    [_delegate prompter:self didCancelWithContext:_context];
99}
100
101//
102// Accessor method
103//
104-(NSPanel *) namePrompterPanel
105{
106  return panel;
107}
108
109@end
110