• 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: Opening a file but not associating with NSDocument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opening a file but not associating with NSDocument


  • Subject: Re: Opening a file but not associating with NSDocument
  • From: Rick Mann <email@hidden>
  • Date: Thu, 19 May 2016 23:40:33 -0700

> On May 19, 2016, at 22:16 , Jerry Krinock <email@hidden> wrote:
>
>
>> On 2016 May 19, at 16:13, Rick Mann <email@hidden> wrote:
>>
>> I have a complex NSDocument with lots of files. One of those files is has a .mfst extension. If the user double-clicks one of those files, I want my app to create my NSDocument subclass, and then call a method on it to read the contents of that file, but I don't want that to be the file it then associates with the document. The actual on-disk representation is a package, and can either copy the originally-opened file contents into the package, or reference that file with an alias.
>>
>> At some point, the user will have to specify a location for the "real" document package to live. Conversely, if the user double-clicks on the real document package, I want that to behave as expected.
>>
>> How do I set up my Document Types and handle this scenario?
>
> You will need two document types (CFBundleDocumentTypes) in your Info.plist, one for your .mfst document, and one for the “real” document (NSDocument subclass / package).  The .mfst should have its “role” (CFBundleTypeRole) set to “Reader” and will have no windows.  In its -readFromURL:ofType:error:, or later, it will programatically create a “real” document by invoking -[NSDocumentController makeUntitledDocumentOfType:error:].  Cocoa will present the Save dialog the user clicks File > Save.  Then make your alias or move the original file with NSFileManager, or if this is a Core Data document, consider using BSManagedDocument which has methods to read and write so-called “additional content” into document packages.

By "Reader," do you mean "Viewer?" I see no "Reader" option.

Also, what do you mean "have no windows?" I just don't create anything in -makeWindowControllers?

> In the Document-Based App Programming Guide for Mac, read  > Alternative Design Considerations > Multiple Document Types Use Multiple NSDocument Subclasses.

Yeah, I've read through that.

I'm currently doing this. I have the two document types as you described, but both point to the same NSDocument subclass. In readFromFileWrapper(), if it's the .mfst type, I read the data in that I can, and then:

	self.fileURL = nil
	self.updateChangeCount(.ChangeReadOtherContents)

So far, this does what I would expect (creates a new document with info from the .mfst file, but if I close it, it prompts to Save As).

I have yet to write my saving code, so I don't know if this works.

--
Rick Mann
email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Opening a file but not associating with NSDocument
      • From: Jerry Krinock <email@hidden>
References: 
 >Opening a file but not associating with NSDocument (From: Rick Mann <email@hidden>)
 >Re: Opening a file but not associating with NSDocument (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Opening a file but not associating with NSDocument
  • Next by Date: NSSplitViewController contents are shifted at first
  • Previous by thread: Re: Opening a file but not associating with NSDocument
  • Next by thread: Re: Opening a file but not associating with NSDocument
  • Index(es):
    • Date
    • Thread