Re: Saving window and view state with NSDocument

2015-09-22 Thread Richard Charles
> On Sep 21, 2015, at 12:09 PM, Kurt Sutter wrote: > > I am trying to figure out how to store information about my windows and views > in a document, and how to restore it. Here is what I do in one application. Override -[NSDocument writeToURL:ofType:forSaveOperation:originalContentsURL:erro

Re: Saving window and view state with NSDocument

2015-09-22 Thread Mike Abdullah
> On 22 Sep 2015, at 10:50, Marek Hrušovský wrote: > > This is somewhat true. > I've just tested it with "NSQuitAlwaysKeepsWindows" and the restore delegate > is kicked when you quit app/launch app from the dock. However, it's not > called when you perform close on window (hit the red cross).

Re: Saving window and view state with NSDocument

2015-09-22 Thread Marek Hrušovský
This is somewhat true. I've just tested it with "NSQuitAlwaysKeepsWindows" and the restore delegate is kicked when you quit app/launch app from the dock. However, it's not called when you perform close on window (hit the red cross). On Tue, Sep 22, 2015 at 10:56 AM, Mike Abdullah wrote: > > > O

Re: Saving window and view state with NSDocument

2015-09-22 Thread Mike Abdullah
> On 22 Sep 2015, at 04:33, Kurt Sutter wrote: > > Thanks for the info > >> BTW you decided to fight against framework (as others mentioned state >> restoration is responsible for this). > > The documentation on state restoration is somewhat sparse. However, as I > understood, it only kicks

Re: Saving window and view state with NSDocument

2015-09-22 Thread Marek Hrušovský
Great study resource is TextEdit implementation (bit old but gives an idea). Try to select text - kill TextEdit.app - reopen TextEdit and see that it preserves selection. In documentation it's written that restoration is mainly used when your app is force closed due to restart. So do no expect it

Re: Saving window and view state with NSDocument

2015-09-21 Thread Kurt Sutter
Thanks for the info > BTW you decided to fight against framework (as others mentioned state > restoration is responsible for this). The documentation on state restoration is somewhat sparse. However, as I understood, it only kicks in when I re-open an application. When the user opens a docume

Re: Saving window and view state with NSDocument

2015-09-21 Thread Quincey Morris
On Sep 21, 2015, at 14:52 , Marek Hrušovský wrote: > > Personally I would do it like this: > 1. Figure out what values you need to store > 2. Create custom object called configuration; for each window one kind > 3. Make it conform nscoding and add a delegate property (which will point > to window

Re: Saving window and view state with NSDocument

2015-09-21 Thread Marek Hrušovský
Personally I would do it like this: 1. Figure out what values you need to store 2. Create custom object called configuration; for each window one kind 3. Make it conform nscoding and add a delegate property (which will point to windowcontroller) 3. implement initwithcoder/encodewithcoder 3. add thi

Re: Saving window and view state with NSDocument

2015-09-21 Thread Kurt Sutter
Thanks, Marek So how would I go at this? Since I want to store that data into the document, I’d need, in dataOfType:error:, to create a NSKeyedArchiver, and then would I just encode self.windowControllers? Then, in readFromData:ofType:error:, I would read in the coder, and in makeWindowControll

Re: Saving window and view state with NSDocument

2015-09-21 Thread Kurt Sutter
Isn’t state restoration something that goes into the app’s preferences (or somewhere else into the app’s container)? What I am looking for is some way to store that information in the document. > On 21 Sep 2015, at 20:53, Quincey Morris > wrote: > > On Sep 21, 2015, at 11:09 , Kurt Sutter

Re: Saving window and view state with NSDocument

2015-09-21 Thread Quincey Morris
On Sep 21, 2015, at 11:09 , Kurt Sutter wrote: > > 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)

Re: Saving window and view state with NSDocument

2015-09-21 Thread Marek Hrušovský
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/in

Saving window and view state with NSDocument

2015-09-21 Thread Kurt Sutter
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