• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

What's the benefit of defining your UI with a string?

New Here ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

I see a lot of scripts that define their UI in a string and then add it to the panel, like this:

                    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "My Panel Name", [0, 0, 300, 300]);

                    res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                              // Then a whole bunch of groups of tabs

                    }"

                    //Add resource string to panel

                    myPanel.grp = myPanel.add(res);

What benefit does this give you compared to defining each group / tab / etc as a variable and using standard scripting?

TOPICS
Scripting

Views

428

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 19, 2017 Apr 19, 2017

Copy link to clipboard

Copied

It's faster and more tidy to declare a resource string than to write out the code. That said there are limitations/bugs in the resource implementation though - for example the ListBox control doesn't recognize the listbox-specific elements like numberOfColumns and showHeaders when encoded in a resource strong vs doing it the normal way.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Horshack​ :

The 4th argument to add is an object (the creation properties), and must be declared as 'properties' (an object) in the ressouces as well:

var myList = myGroup.add("listbox", undefined, undefined, {numberOfColumns: 2, columnTitles: ["name", "value"], showHeaders: true});

"{/**/

    myList: ListBox{properties:{numberOfColumns: 2, columnTitles: ['name', 'value'], showHeaders: true}},\

    }";

alert(myGroup.myList.properties.numberOfColumns);    // true

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

Thanks for this. I had tried all combinations before, including without any enclosing brackets and also with "creation_properties" as the nested named bracket. Prior attempts would create the instance props within the LB but wouldn't actually be used by the LB logic. Did you find this by creating a LB the traditional way and inspecting the object? Because I couldn't find naming it "properties" in the documentation when I was first trying to troubleshoot it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

LATEST

You can find infos on this in the Extend Script Tool Kit object model viewer (ScriptUI classes section), or the JavaScriptToolsGuide_[version].pdf


Every UI element has a 'properties' attribute, which remain 'undefined' until you actually set its value to some object.

You can put whatever you want in that object, but some specific property names will be recognized by ScriptUI and given special meanings (this depends on the element type, for instance 'readonly' is recognized for the type "edittext"; 'items', 'numberOfColumns',... for the type "dropdownlist", etc).

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines