Skip to main content
K.Daube
Community Expert
Community Expert
February 3, 2020
Answered

Resizing a tree view

  • February 3, 2020
  • 1 reply
  • 488 views

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

 

 

 

This topic has been closed for replies.
Correct answer K.Daube

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-extendscript.

/* 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

 

1 reply

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthorCorrect answer
Community Expert
February 7, 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 definition

I 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 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