Resizing a tree view

Adobe Community Professional ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Dear friends,

My script finally shall create a tree view displaying the heading-structure of a document.
One detail is that window and tree should be resizeable.
It's easy to resize the window, but for the tree to adapt to the new space I have no success.
It's also a question to me, why the OnResiz is triggered before I touch the created window.

Do You have any ideas where I need to change?

Klaus

 

 

/* TreeViewResize.jsx ====== UTF-8 =========================================
              Create a tree contents and experiment with resizing
Refrence      C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\SDK\Samples\javascript\SnpCreateTreeView.jsx
              Rick Quatro's DocNav.jsx
*/
main ();

function main () {
	var j, k, oTree, wViewTree;

  wViewTree = new Window("palette", "Static (generated) tree", undefined, {resizeable: true});

	oTree = wViewTree.add("treeview");
// oTree.preferredSize = [300, 200];
	for(var j = 0;j < 10;j++)	{        // Add static items to the list, in a hierarchical structure.
		oTree.add("node", "Item " + j);	
		for(k = 0; k < 4; k++) {
			oTree.items[j].add("item", "Sub Item " + k);
		}
	}
// --- behaviour of the window -------------------
  wViewTree.onResize = Resize (wViewTree, oTree);
// --- final actions -----------------------------
  ExpandNode(oTree);
  wViewTree.show();
} // end of main

function Resize (wViewTree, oTree) { // Resize window and tree =============
var wSize;
  wViewTree.layout.resize (); 
  alert ("Why is this entered  before I do a resize?");
/* --- this poart does not work at all 
  wSize = wViewTree.preferredSize;
$.bp(true);
//oTree.minimumSize = [wSize[0]-30, wSize[1]-30];
  wViewTree.show();
*/
} // end of Resize

function ExpandNode (tree){ // Expand all nodes to see the tree ============
  tree.expanded = true;
  var branches = tree.items;
  for (var i = 0; i < branches.length; i++) {
    if (branches[i].type == 'node') {
      ExpandNode (branches[i]);
    }
  }
} // end of ExpandNode

 

 

 

TOPICS
Scripting

Views

254

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Feb 07, 2020 Feb 07, 2020
It turns out, that The tree view must be 'filled' There must be a group in which the tree view will be placed The resize function should not be outside the function with the window definitionI got the 'inspiration' from https://stackoverflow.com/questions/46459921/recursively-populate-treeview-from-paths-in-extendscript./* TreeViewResize.jsx ====== UTF-8 ========================================= Create a tree contents and experiment with resizing Refrence …CS6\ExtendScript Too...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

LATEST

It turns out, that

  • The tree view must be 'filled'
  • There must be a group in which the tree view will be placed
  • The resize function should not be outside the function with the window definition

I got the 'inspiration' from https://stackoverflow.com/questions/46459921/recursively-populate-treeview-from-paths-in-extendscrip....

/* TreeViewResize.jsx ====== UTF-8 =========================================
              Create a tree contents and experiment with resizing
Refrence      …CS6\ExtendScript Toolkit CS6\SDK\Samples\javascript\SnpCreateTreeView.jsx
*/
main ();

function main () {
  var j, k, oTree, wPalT;
  wPalT = new Window("palette", "Static (generated) tree", undefined, {resizeable: true});
  wPalT.g1 = wPalT.add("group"); 
  wPalT.g1.alignment = ["fill", "fill"];
  oTree = wPalT.g1.add("treeview", undefined);
  oTree.preferredSize = [150, 200];
  oTree.alignment = ["fill", "fill"];
  for(var j = 0;j < 10;j++)	{// Add static items to the list
    oTree.add("node", "Item " + j);	
    for(k = 0; k < 4; k++) {
      oTree.items[j].add("item", "Sub Item " + k);
    }
  }
// --- behaviour of the window -------------------
  wPalT.onResize = function () {
    this.layout.resize();
  }
// --- final actions -----------------------------
  ExpandNode(oTree);
  wPalT.show();
} // end of main

function ExpandNode (tree){ // Expand all nodes to see the tree ============
  tree.expanded = true;
  var branches = tree.items;
  for (var i = 0; i < branches.length; i++) {
    if (branches[i].type == 'node') {
      ExpandNode (branches[i]);
    }
  }
} // end of ExpandNode

 

Likes

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