Skip to main content
Joachim Hiller
Known Participant
September 6, 2016
Answered

Save settings for panels

  • September 6, 2016
  • 2 replies
  • 1088 views

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?

This topic has been closed for replies.
Correct answer DBarranca

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

http://htmlpanelsbook.com

2 replies

Jarda Bereza
Inspiring
September 7, 2016

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

Joachim Hiller
Known Participant
September 8, 2016

many thanks for the answer,

but in this case I create an HTML Panel
Joe

DBarranca
DBarrancaCorrect answer
Legend
September 6, 2016

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

http://htmlpanelsbook.com

Joachim Hiller
Known Participant
September 6, 2016

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?

DBarranca
Legend
September 7, 2016

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