• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
how do I do something after user has hit "OK" in standard save panel?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how do I do something after user has hit "OK" in standard save panel?


  • Subject: how do I do something after user has hit "OK" in standard save panel?
  • From: Donald Hall <email@hidden>
  • Date: Thu, 30 Jan 2003 00:35:51 -0700

I've been going over the documentation and scratching my head on this one all evening:

When the user saves a new document from one of the standard File menu save commands, I want to immediately get the path name of the new document after the user hits "OK". I tried overriding 'saveDocument' as shown below, but this didn't seem to work:

- (IBAction)saveDocument:(id)sender
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"saveDocument entered, fileName is %@", [self fileName]); // as expected name is null here
[super saveDocument:sender];
NSLog(@"after saving file name is %@", [self fileName]); // name is still null
if ([fileManager fileExistsAtPath:[self fileName]]) { // document was saved <-<- doesn't work!!
NSString *dataFilePath = [[NSUserDefaults standardUserDefaults] objectForKey:AMDataFileKey];
if (![fileManager fileExistsAtPath:dataFilePath]) // no valid data file specified
// make the this document the default data file
[[NSUserDefaults standardUserDefaults] setObject:[self fileName] forKey:AMDataFileKey];
}
}

I expected execution to halt at [super saveDocument] until I dismissed the save panel, but it did not. As a result the document's file name was still 'null' after I okayed the save, so my test for file existence returned NO.

Can anyone tell me how to do this, or point me at some sample code?

I also looked at

'- (void)runModalSavePanelForSaveOperation:(NSSaveOperationType)saveOperation delegate:(id)delegate didSaveSelector:(SEL)didSaveSelector contextInfo:(void *)contextInfo
'
but could not figure out how this worked. (What is the delegate? NSDocuments don't have delegates.)

I can do what I want if I use the NSWindow delegate method 'windowWillClose', but I wanted to be able to set my default data file name if the user just saved the document without closing. Should I be putting up my own NSSavePanel in my 'saveDocument'?

Thanks for any pointers.

Don
--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://appsmore.theboss.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: how do I do something after user has hit "OK" in standard save panel?
      • From: m <email@hidden>
  • Prev by Date: Re: Adding design-time 'live' functionality to IB palette items
  • Next by Date: Re: Action based undo or snapshot based undo?
  • Previous by thread: "Universal spell-check" algorithm and function morphemes
  • Next by thread: Re: how do I do something after user has hit "OK" in standard save panel?
  • Index(es):
    • Date
    • Thread