Copy link to clipboard
Copied
Hi all.
In my project I have a listbox that is populated dinamically through an array.
var my_arr= [];
.....
var myListBox = add_list (win, my_arr);
function add_list (container, my_arr) {
var list_data = container.add("listbox", undefined, my_arr, {multiselect: true, numberOfColumns: 1, showHeaders: true, columnTitles: ["TITLE"], columnWidths: [150]});
return list_data;
}
.....
Now I need two show more info for each item , so I set showColumns = 2 and through .subItems I added the required info, and here start the problems.
First problem : while running the code the data are shown as expected, but I can no longer operate over them.
Second problem : if I run the whole code in a function I can no longer show the data.
Here the code :
#targetengine WorkInProgress
my_arr = [];
myTest();
function myTest() {
var win = new Window ("palette", "Two columns");
var myButton = win.add("button", undefined, "Folder");
var myListBox = add_list (win, my_arr);
function add_list (container, my_arr) {
var list_data = container.add("listbox", undefined, my_arr, {multiselect: true, numberOfColumns: 2, showHeaders: true, columnTitles: [" > BOOK CONTENTS", " INFO "], columnWidths: [150,90]});
return list_data;
}
myListBox.bounds = [0,0,250,250];
var btn_group = win.add("group");
var up_btn = btn_group.add("button", undefined, "UP");
var dw_btn = btn_group.add("button", undefined, "DOWN");
var quit = win.add("button", undefined, "CLOSE");
myButton.onClick = function() {
the_book = File.openDialog ("");
if (myListBox.items.length > 0) {
my_arr = [];
upd_data(myListBox, my_arr);
}
getBookDocs(the_book);
}
up_btn.onClick = function () {
var selItems = [];
for (var c = 0; c < myListBox.selection.length; c++) {
if (myListBox.selection
.selected) { selItems.push(myListBox.selection
.index); }
}
selItems.sort();
for (var m = 0; m < selItems.length; m++) {
var movefrom = selItems
; var moveto = selItems
- 1; if (moveto < 0) {
return;
} else {
my_arr.splice(moveto, 0, my_arr.splice(movefrom, 1)[0]);
}
}
upd_data(myListBox, my_arr);
for (var s = selItems.length - 1; s >= 0; s--) {
for (var a = 0; a < myListBox.items.length; a++) {
if (selItems
=== myListBox.items.index) {myListBox.items[a - 1].selected = true;
}
}
}
};
dw_btn.onClick = function () {
var selItems = [];
for (var c = 0; c < myListBox.selection.length; c++) {
if (myListBox.selection
.selected) { selItems.push(myListBox.selection
.index); }
}
selItems.sort();
for (var m = selItems.length - 1; m >= 0; m--) {
var movefrom = selItems
; var moveto = selItems
+ 1; if (moveto > my_arr.length - 1) {
return;
} else {
my_arr.splice(moveto, 0, my_arr.splice(movefrom, 1)[0]);
}
}
upd_data(myListBox, my_arr);
for (var s = selItems.length - 1; s >= 0; s--) {
for (var a = 0; a < myListBox.items.length; a++) {
if (selItems
=== myListBox.items.index) {myListBox.items[a + 1].selected = true;
}
}
}
};
quit.onClick = function() {
win.close();
}
win.center();
win.show();
}
function getBookDocs(doc) {
app.open(doc);
var book_ref = app.activeBook;
for (var x3 = 0; x3 < book_ref.bookContents.length; x3++) {
var full = book_ref.bookContents[x3].name;
var no_ext = full.substring(0,full.indexOf("."));
myListBox.add("item", no_ext);
if (book_ref.bookContents[x3].status === BookContentStatus.NORMAL) {
myListBox.items[x3].subItems[0].text = ""; // it's ok
} else if (book_ref.bookContents[x3].status === BookContentStatus.DOCUMENT_OUT_OF_DATE) {
myListBox.items[x3].subItems[0].text = "MOD"; // modified
} else if (book_ref.bookContents[x3].status === BookContentStatus.MISSING_DOCUMENT) {
myListBox.items[x3].subItems[0].text = "N_A"; // not available
} else if (book_ref.bookContents[x3].status === BookContentStatus.DOCUMENT_IS_OPEN) {
myListBox.items[x3].subItems[0].text = "A_O"; //already open
}
}
book_ref.close();
return doc;
}
function upd_data(obj_data, arr_data) {
obj_data.removeAll();
var x2 = 0;
while (obj_data.items.length < arr_data.length) {
obj_data.add("item", arr_data[x2]);
x2++;
}
}
Any help is really appreciated.
Copy link to clipboard
Copied
These days I have no time to find a solution, but I think I understood that the addition of subItems has transformed the array into an array of objects.
Just an idea for now, I have to investigate it ...
Copy link to clipboard
Copied
Thinking back to the problem, and ignoring for now the addition of subitems, if I use the array (my_arr) to store data, it can not be an array of objects but possibly an array of listitems. But if I use the object (myListBox), then it must be a subject of listitems .... possible?
Starting from the assumption that an array is an object, then an array of listitems is an object of listitems.
Assuming that this reasoning is right, when I add the subitems to the array, it becomes what? And if I add them to the object?
As you can easily understand, I am very confused ....
Copy link to clipboard
Copied
In the last weeks I had to deal with other things, just a couple of days ago I could start again with scripting.
Reviewing what I had done so far, I have concluded that I am not able to solve this problem. So I've decided to take another route ... but even here there are problems 😞
I interested look at : "Refresh" listbox to show array images
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more