Re: Saving window and view state with NSDocument
Re: Saving window and view state with NSDocument
- Subject: Re: Saving window and view state with NSDocument
- From: Marek Hrušovský <email@hidden>
- Date: Mon, 21 Sep 2015 20:22:20 +0200
I am far from architect but each window has an option "initWithCoder" and
within XIB you can specify option "prefer coder instantiation". The
information you want to store is not related to the model object (within
document) cannot be reused.
So basically I would implement NSCoder methods encode/init withCoder
Marek.
On Mon, Sep 21, 2015 at 8:09 PM, Kurt Sutter <email@hidden> wrote:
> Hi all
>
> I am trying to figure out how to store information about my windows and
> views in a document, and how to restore it. Note that I am talking about
> storing the information in the document itself, not in the application’s
> preferences settings.
>
> Specifically, I have a child of NSDocument that saves its model data using
> dataOfType:error: and restores it using readFromData:ofType:error: That
> works fine. Now, that document may have a variable number of windows for
> showing aspects of the data of the document’s model, and each window has a
> number of views. The windows and views contain state information, such as
> scroll positions, window positions, zoom factors, etc.
>
> I want the state information of the windows and views to be stored in the
> document so that the same windows and views reopen when the user opens the
> document.
>
> What is the best way to do that? I guess I have to take two steps:
>
> (a) collect that state information in dataOfType:error: and store it in
> the NSData object to be returned and
> (b) retrieve that data from the NSDocument in readFromData:ofType:error:
> and then somehow apply it in the NSDocument’s makeWindowControllers method.
>
> While both of this is certainly feasible, I am not sure what is the most
> elegant way to do it. Do I run encodeWithCoder against the document’s
> window controllers during save, and then somehow restore the window
> controllers in the makeWindowControllers? Or what else?
>
> I have tried to find pointers on how to do this in the most elegant
> manner, but I found nothing useful. So I would greatly appreciate any
> proposals.
>
> Thanks in advance
>
> Kurt
> _______________________________________________
>
> 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
_______________________________________________
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