Re: Per-document preferences?
Re: Per-document preferences?
- Subject: Re: Per-document preferences?
- From: James Bucanek <email@hidden>
- Date: Sat, 25 Jun 2005 07:17:50 -0700
SA Dev wrote on Friday, June 24, 2005:
>On Jun 24, 2005, at 7:16 PM, James Bucanek wrote:
>
>> As I look at the problem, I think this is exactly what I'll do:
>> Create an NSMutableDictionary and store all of the user settings
>> and layout parameters. Using NSPropertyListSerialization, I
>> shouldn't have any trouble turning a dictionary of document
>> properties and user settings into an XML or binary file that I can
>> store inside the package.
>>
>
> Okay, here's where you're missing the magic that is Cocoa. Check
>out NSDictionary's writeToFile:atomically: and its
>initWithContentsOfFile: methods. It saves the data in plist (XML)
>format.
I think I often miss the "magic of Cocoa." ;)
Personally, I thought that NSPropertyListSerialization class qualified as Cocoa magic. It only took about six lines of code to write my dictionary as an XML file. Admittedly, one line is better than six, but both are pretty amazing considering what they accomplish.
One of my problems is my own mental rules for good object oriented design. I would never put a 'writeToFile' method on the string class because strings don't/shouldn't have knowledge of a file system. So I instinctively go looking for something like [File writeString], rather than [String writeToFile:]. It has caused me to search endless in the wrong place on many occasions.
>> What I'm dreading is having to save and restore the dozens of
>> little layout variables for the window. It looked like the
>> "autosave" feature of NSTableView, et. al. was designed to remove
>> this burden from the programmer, but it seems hopelessly tied to
>> the application defaults.
>>
>
> NSStringFromRect() and NSRectFromString() functions will make a
>string that can be stored in your dictionary and turn that string
>back into a rect (frame) for your window. For the rest, as long as
>you can create (and restore from) a type that can be stored in a
>dictionary (string, number, data), you're golden.
Excellent tip! I vaguely remember seeing these at one time, but had forgotten about them. These should save me a ton of work in saving all of the NSView dimensions.
Which might not be as bad as I originally thought. Going through my view hierarchy, I think I can preserve and reconstruct the layout of the window with only about 20 dimensions.
Thanks for all of the help and advice.
Cheers,
James
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden