Page 1 of 1

Saving User Preferences - and using them

Posted: Tue Mar 11, 2008 10:53 pm
by bjb007
The "Getting Started" example
"Preferences pane-saving to a stack or text file"
in "Ten functional examples"
doesn't go into much detail about reading
the user preferences at startup.

Anyone know of any further info on
the subject?

Posted: Wed Mar 12, 2008 3:44 pm
by keyless
Here is an example of what I am using in a stack to read a txt at startup:

Code: Select all

on openStack
  if there is a file "C:/Documents and Settings/All Users/Application Data/CK/settings.txt" then
    put line 1 of url "file:C:/Documents and Settings/All Users/Application Data/CK/settings.txt" into fld "audURL" of stack "settings"
  else
    Answer information "Settings are at default"
  end if
end openStack
You can of course have multiple put statements using the text chunking that best fits how you saved to the file in the first place.

Posted: Wed Mar 12, 2008 6:21 pm
by Andycal
Saving is a doddle too:

Code: Select all

put the value of fld "theSize" of stack "Image" into line 1 of URL "file:preferences.txt"


Saving User Preferences - and using them

Posted: Wed Mar 12, 2008 11:36 pm
by bjb007
I was thinking more along the lines
of reading from a text file into a
variable.

I expect it's possible. As I get annoyed
by programmes which give a message like
"New settings will take effect when you
restart" I wanted to perhaps read the
settings each time they're used so that
changes take effect immediately.

Or perhaps in the case of a number of
settings read them into an array and
access them from there.

Did think of checking the date/time of the
settings file each time but that's probably
no more efficient that reading the vars.
each time they're used (which would
be quite often).

Could also set a true/false when used
changes a setting.....

Lots of possibilities. My question came
from feeling that it seemed too easy!

Posted: Thu Mar 13, 2008 3:52 am
by keyless
So use a variable instead of a Field as in our examples. Probably just extra code though as fields make great containers and you need them anyway for settings changes.

As far as when to trigger this, you really only need to do it on stack open and stack close. As the settings changes user makes during runtime can be active right away.

Your description of doing this by checking the time is easy to do, but personally sounds over engineered. If you want to have it saved to the txt right away, I would just trigger it on change of the setting, clean and simple.

Saving User Preferences - and using them

Posted: Thu Mar 13, 2008 4:36 am
by bjb007
Right, keyless.

On giving the matter further thought I
did come to the conclusion that new
settings would be used during the
current session and could then
be saved at close.

Thanks for your input.