Saving preferences vs (or in addition to) saving data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Saving preferences vs (or in addition to) saving data
I just finished reading Klaus' great article regarding saving user preferences (http://runrev.com/newsletter/december/i ... etter4.php)
Great article! This leads me to wonder if there is a difference between saving preferences (like a text style) and the contents of say, a datagrid. Different procedures and files?
Thanks
Great article! This leads me to wonder if there is a difference between saving preferences (like a text style) and the contents of say, a datagrid. Different procedures and files?
Thanks
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
This morning I successfully implemented Klaus' handlers/functions. The idea of creating a custom property called saveme works great for my purposes.
Note to Klaus: The handlers do not include the label of roundrect buttons...easily added but wanted to let you know.
If I could now be able to store the contents of my datagrids as well I would be in terrific shape.
Note to Klaus: The handlers do not include the label of roundrect buttons...easily added but wanted to let you know.
If I could now be able to store the contents of my datagrids as well I would be in terrific shape.
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
For the other newbies (now and in the future) like me.... continuing to update my progress.
Successful in implementing arrayEncode and arrayDecode as per this article:
http://lessons.runrev.com/s/lessons/m/4 ... -it-again-
Now to see if I can combine this process with Klaus' technique in order to save all button states, field contents, images, and datagrids in the same prefs file....
Successful in implementing arrayEncode and arrayDecode as per this article:
http://lessons.runrev.com/s/lessons/m/4 ... -it-again-
Now to see if I can combine this process with Klaus' technique in order to save all button states, field contents, images, and datagrids in the same prefs file....
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Am able to use arrayEncode and then urlencode in order to get the array into one line in the prefs file. However, reversing the process... urldecode followed by arrayDecode fails:
Message execution error:
Error description: arrayDecode: failure
Hint:
Message execution error:
Error description: arrayDecode: failure
Hint:
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Lines breaks in the array... using arrayEncode and then base64encode, then replacing return with "" gets it all into 1 string...looking good!
Re: Saving preferences vs (or in addition to) saving data
Hi,
thanks for the flowers
I usually convert my datagrid contents to a TAB and CR delimited list that I can save and vise versa
to load them back into my datagrids.
The trick is to URLENCODE/URLDECODE multiline content, so it fits into one ITEM in the current line!
I have two functions for converting like this:
Hope that helps!
Best
Klaus
thanks for the flowers
I usually convert my datagrid contents to a TAB and CR delimited list that I can save and vise versa
to load them back into my datagrids.
The trick is to URLENCODE/URLDECODE multiline content, so it fits into one ITEM in the current line!
I have two functions for converting like this:
Code: Select all
## Will convert a TAB and CR delimited TEXT list into an array
## tList is the content of a simple text file that I saved before
function list2dgdata tText
put empty into tArray
set itemdel to TAB
## CYCLE through all lines and convert every item to an array key:
put 1 into tIndex
repeat for each line i in tText
## Multi line content!
put urldecode(item 1 of i) into tArray[tIndex]["file"]
## Single line content!
put item 2 of i into tArray[tIndex]["filepath"]
put item 3 of i into tArray[tIndex]["date"]
## Multi line content!
put urldecode(item 4 of i) into tArray[tIndex]["comments"]
add 1 to tIndex
end repeat
return tArray
end mk_list2dgdata
## And convert an ARRAY back into a TAB and CR delimited text file:
function dgdata2list tArray
put empty into tList
set itemdel to TAB
## Cycle through all keys of the array:
repeat for each key tIndex in tArray
## Multi line content!
put urlencode(tArray[tIndex]["file"]) & TAB into tLine
## Single line content!
put tArray[tIndex]["filepath"] & TAB after tLine
put tArray[tIndex]["date"] & TAB after tLine
## Multi line content!
put urlencode(tArray[tIndex]["comments"]) & TAB after tLine
put tLine & CR after tList
end repeat
delete char -1 of tList
## Ready to be saved as a simple textfile!
return tList
end dgdata2list
Best
Klaus
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Thank you Klaus, here is what I ended up with, seems to work fine but please let me know what you think. I have added an additional "case" to your switches.
for mk_collectprefs:
and for mk_loadprefs
~Brian
for mk_collectprefs:
Code: Select all
command mk_collectprefs
lock screen
put empty into tAllPrefs
## Loop through all cards:
repeat with i = 1 to the num of cds
put the num of controls of cd i into tNumofcontrols
## Loop through all control on card:
repeat with k = 1 to tNumofcontrols
## This work for ALL controls, even if we add more of them later to our stack!
## As long as they have their custom property "saveme" set to TRUE!
if the saveme of control k of cd i <> true then
next repeat
end if
## Now we can collect the contents of the control
## Gives -> button "name of button"
put the name of control k of cd i into tName
put word 1 of tName into tType
put word 2 of tName into tShortName
## Important step!
replace QUOTE with empty in tShortName
## Now we need to differ:
switch tType
case "field"
put empty into tStyle
## Now we need to URLENCODE the text, so we can store it in ONE line!
put urlencode(the text of fld tShortName of cd i) into tContent
break
case "group"
put the dgData of group tShortName of cd i into gridArray
put base64encode(arrayEncode( gridArray )) into tContent
replace return with "" in tContent
break
Code: Select all
command mk_loadprefs
put mk_getprefs() into tPrefs
if tPrefs = empty then
exit mk_loadprefs
end if
## We use this tab delimited format here:
## 1. Number of card
## 2. Type of control
## 3. Name of control
## 4. Style of control (only neccessary for buttons!)
## 5. Content of control
## 6. Rect of control (only neccessary for images!)
set itemdel to TAB
repeat for each line i in tPrefs
put item 1 of i into tCardNumber
put item 2 of i into tType
put item 3 of i into tShortName
put item 4 of i into tStyle
put item 5 of i into tContent
put item 6 of i into tRect
switch tType
case "field"
set the text of fld tShortName of cd tCardNumber to urldecode(tContent)
break
case "group"
put base64decode(tContent) into pData
put arrayDecode(pData) into gridArray
set the dgData of group tShortName of cd tCardNumber to gridArray
break
Re: Saving preferences vs (or in addition to) saving data
Hi Brian,
yes, sure, if this will work for you!
My article just wanted to give you the idea how one can do something like this.
Of course it can be modified to fit your special needs!
In got used to use text files, since I learned LiveCode when it was born as MetaCard
way back in 1999 and we did not have such modernistic stuff like ARRAYDE-/ENCODE!
Best
Klaus
yes, sure, if this will work for you!
My article just wanted to give you the idea how one can do something like this.
Of course it can be modified to fit your special needs!
In got used to use text files, since I learned LiveCode when it was born as MetaCard
way back in 1999 and we did not have such modernistic stuff like ARRAYDE-/ENCODE!
Best
Klaus
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Yeah I'm still using all of the rest of your handlers/functions unaltered, working great with txt file.
Thanks much
Thanks much
Re: Saving preferences vs (or in addition to) saving data
Brian
Your scripts seem to have been cut off in the middle of the switch. Could you either zip them up or put them in a simple stack so that I make sure I get the whole thing. I'm about to embark on this journey any there seems to be a clear trail to follow here.
Thanks
Kelly
Your scripts seem to have been cut off in the middle of the switch. Could you either zip them up or put them in a simple stack so that I make sure I get the whole thing. I'm about to embark on this journey any there seems to be a clear trail to follow here.
Thanks
Kelly
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Kelly the rest of the scripts are unchanged from Klaus' article (part 2) and the stacks he makes available in the article.
http://lessons.runrev.com/s/lessons/m/4 ... -it-again-
http://lessons.runrev.com/s/lessons/m/4 ... -it-again-
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Klaus: Is there a way to modify your script so that png images are encoded/decoded correctly? The jpgs are fine but it seems that the transparency of png does not survive.
Re: Saving preferences vs (or in addition to) saving data
Hi teacherguy,
oh, did not know this!
In that case you should also collect "the alphadata" of that image and set it later back AFTER setting the imabedata:
Get the picture?
Best
Klaus
oh, did not know this!
In that case you should also collect "the alphadata" of that image and set it later back AFTER setting the imabedata:
Code: Select all
...
case "image"
put empty into tStyle
if the filename of img tShortName of cd i = empty AND \
the text of img tShortname of cd i = empty then
put empty into tContent
else
put the imagedata of img tShortName of cd i into tImageData
## Step 1: convert binary data to text data:
put base64encode(tImageData) into tImageDataText
## Step 2: convert this string to ONE line:
put urlencode(tImageDataText) into tContent
## NEW!
put the ALPHAdata of img tShortName of cd i into tAlphaData
## Step 1: convert binary data to text data:
put base64encode(tAlphaData) into tAlphaDataText
## Step 2: convert this string to ONE line:
put urlencode(tAlphaDataText) into tContent2
end if
Best
Klaus
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Saving preferences vs (or in addition to) saving data
Great thanks. Another question: If a prefs file cannot be established, will the end user know?
Re: Saving preferences vs (or in addition to) saving data
Only if you tell him...teacherguy wrote:Great thanks. Another question: If a prefs file cannot be established, will the end user know?