//
//  NamePrompter.m
//  longspear
//
//  Created by Niko Matsakis on Sat Nov 15 2003.
//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//

#import "NamePrompter.h"


@implementation NamePrompter

+ (void) promptForName:target selector:(SEL)whenadded window:(NSWindow*)win
{
  // Create the nameprompter object
  NamePrompter *newprompt = 
    [[NamePrompter alloc] initWithTarget:target selector:whenadded];
  [NSBundle loadNibNamed:@"NamePrompter" owner:newprompt];
  
  // Attach the sheet
  [NSApp beginSheet: newprompt->_nameWindow
         modalForWindow: win
         modalDelegate: nil
         didEndSelector: nil
         contextInfo: nil]; 
  [NSApp runModalForWindow: newprompt->_nameWindow]; 

  // (The app is running modally here.  When the Add or Don't Add are clicked,
  // the modal session will end.)

  // Once it's over...
  [NSApp endSheet:newprompt->_nameWindow];
  [newprompt->_nameWindow orderOut:self];
  [newprompt release];
}

- initWithTarget:target selector:(SEL)whenadded
{
  if ((self = [super init])) {
    _target = target;
    _whenAdded = whenadded;
  }
  return self;
}

- (IBAction) add:sender
{
  [_target performSelector:_whenAdded withObject:[_nameField stringValue]];
  [NSApp stopModal];
}

- (IBAction) dontAdd:sender
{
  [NSApp stopModal];
}

@end
