• 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
SaveDocumentTo:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SaveDocumentTo:


  • Subject: SaveDocumentTo:
  • From: Phill Kelley <email@hidden>
  • Date: Fri, 18 Apr 2003 19:12:29 +1000

G'Day!

Does anyone understand how to mimic the functionality of NSDocument's
saveDocumentTo: method?

What I'm trying to do is to implement a menu command called "Save
Selection..." which should:

1. Save only the model objects represented by the elements selected
in the view.

2. Do it in a way which behaves like saveDocumentTo:, specifically:

a. A new file is created;
b. The document's change-count is not changed; and
c. The document's title is not changed.

What I'm doing at the moment is:

1. My File menu has:

"Save" connected to FirstResponder.saveDocument:
"Save As" connected to FirstResponder.saveDocumentAs:
"Save Selection" connected to FirstResponder.performSaveSelection:

2. My document implements:

- (IBAction) performSaveSelection:(id)sender
{
itsSaveSelection = YES;
[self saveDocumentTo:sender];
}

3. The document overrides saveDocument: and saveDocumentAs: where
each is implemented like:

- (void) saveDocument:(id)sender
{
itsSaveSelection = NO;
[super saveDocument:sender];
}

4. Finally, dataRepresentationOfType includes the logic:

if (itsSaveSelection)

// return an NSData containing only the selection

else

// return an NSData containing everything

This works reliably but it seems overly complicated (as in, there's usually
an elegant way to do things in Cocoa; all you have to do is find the
sucker).

I started by messing around with saveDocumentWithDelegate but everything I
tried behaved like Save As (ie, cleared the change-count and changed the
document title) which isn't what I want.

I could also change performSaveSelection: so that it implements all the
required functionality (displaying the save sheet, and writing the
selection out to the nominated file) but that also seems like overkill for
what should, logically, be far more straightforward.

Has anyone else faced this problem? Any ideas?


Regards & thanks, Phill
_______________________________________________
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: SaveDocumentTo:
      • From: publiclook <email@hidden>
  • Prev by Date: Re: Getting a NSToolbar's window?
  • Next by Date: Re: Show / Hide Window
  • Previous by thread: Standalone services
  • Next by thread: Re: SaveDocumentTo:
  • Index(es):
    • Date
    • Thread