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

Re: SaveDocumentTo:


  • Subject: Re: SaveDocumentTo:
  • From: publiclook <email@hidden>
  • Date: Fri, 18 Apr 2003 10:28:41 -0400

There is no magic about the NSDocument class etc. in Cocoa. The TextEdit example shows how to roll your own document classes. I think there is an example in "Cocoa Programming" too. You don't have to call saveDocumentTo: at all. Just write a -dataRepresentationOfSelection method, call it from your performSaveSelection: method and save the data in any file you want.

On Friday, April 18, 2003, at 05:12 AM, Phill Kelley wrote:

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.
_______________________________________________
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.

References: 
 >SaveDocumentTo: (From: Phill Kelley <email@hidden>)

  • Prev by Date: memory. and a lot of continual small object allocations and deallocations.
  • Next by Date: Re: Make the action of a NSMenuItem, which has a subMenu, to work
  • Previous by thread: SaveDocumentTo:
  • Next by thread: memory. and a lot of continual small object allocations and deallocations.
  • Index(es):
    • Date
    • Thread