Copy link to clipboard
Copied
I got a question - is there a good workaround how to save settings of a panel? I intend to offer different options of a panel, which the user shall be able to turn off and on. I thought of saving the settings as Json-file. I just don't know how to do this best, or does anyone have a better idea or another way to get the result?
You can set Persistence on (so that when the user re-opens the panel **in the same PS session** it will keep the same status), or alternatively use LocalStorage, for sessions independent persistence.
Davide Barranca
Copy link to clipboard
Copied
You can set Persistence on (so that when the user re-opens the panel **in the same PS session** it will keep the same status), or alternatively use LocalStorage, for sessions independent persistence.
Davide Barranca
Copy link to clipboard
Copied
Thanks for the quick answer. Does this mean that the LocalStorage stays saved permanently? I have the LocalStorage of the browser in mind. is that right? isn't that deleted at some point?
Copy link to clipboard
Copied
I assume that you are referring to (HTML) Panels – am I right?
If this is the case, yes, Local Storage is the same that's featured in browser. It's there (I mean, the stuff you save there) until you yourself delete it – otherwise it's permanent.
If you rely on scripted dialogs instead (ScriptUI and not HTML Panels) customOptions are a similar feature that you can use.
Davide
Copy link to clipboard
Copied
Thanks for the answers, which helps me a lot.
yes it is an HTML Panel.
Joe
Copy link to clipboard
Copied
you can use
"app.putCustomOptions('yourID',decriptor,true);" //true = persistent
I am using it for JSX Dialog not html panel. But it could be similar with html panel too. But I can't guarantee it now.
My code looks like this:
var settingsToRemember = {};
settingsToRemember.splitBy=win.sliderPanel.te.text;
settingsToRemember.chRemoveOriginal=win.bottomGroup.chRemoveOriginal.value;
settingsToRemember.dropdownSplitingCharactersOptions=dropdownSplitingCharactersOptions.selection.index;
settingsToRemember.chLineBreak=win.specialPanel.chLineBreak.value;
settingsToRemember.chLineEnd=win.specialPanel.chLineEnd.value;
settingsToRemember.chTab=win.specialPanel.chTab.value;
settingsToRemember.chLetter=win.specialPanel.chLetter.value;
settingsToRemember.chParagraphStyles=paragraphSplit;
settingsToRemember.chCharacterStyles=characterSplit;
var desc = new ActionDescriptor();// create a descriptor to hold value
desc.putString(0, jamJSON.stringify(settingsToRemember)); // f*ck Action descriptor system... use serialized JSON instead
app.putCustomOptions('
Split', desc, true );// store the descriptor by unique name
jamJSON is not native function
And this is for reading settings:
var desc = app.getCustomOptions("
Split"); var formSettings = jamJSON.parse(desc.getString(0));
win.sliderPanel.te.text=formSettings.splitBy;
dropdownSplitingCharactersOptions.selection=formSettings.dropdownSplitingCharactersOptions;
win.specialPanel.chLetter.value = formSettings.chLetter;
win.specialPanel.chParagraphStyles.value = formSettings.chParagraphStyles;
win.specialPanel.chCharacterStyles.value = formSettings.chCharacterStyles;
win.specialPanel.chTab.value = formSettings.chTab;
win.specialPanel.chLineEnd.value = formSettings.chLineEnd;
win.specialPanel.chLineBreak.value = formSettings.chLineBreak;
win.bottomGroup.chRemoveOriginal.value = formSettings.chRemoveOriginal;
jamJSON
Copy link to clipboard
Copied
many thanks for the answer,
but in this case I create an HTML Panel
Joe