我希望能夠對列錶框中的列表進行重新排序,最好透過拖放(這似乎不可能)或使用按鈕來重新排序。我正在尋找 JSL 的向上和向下按鈕。
更大的目標是獲取目錄中的所有文件,根據文件副檔名將它們分成兩個清單。向使用者顯示兩個列表,允許他們對文件重新排序,以便配對匹配。點擊確定從 2 個列錶框中取得檔案名稱清單並成對執行程式碼。我只需要幫助重新排序列錶框中的列表。
這是一個非常快速的按鈕版本(從Column Quick Swapper 修改 - 在 Graph Builder 中輕鬆更改多個 Y 和 X 軸列)
Names Default To Here(1);
move_items = function({lb_ref, direction}, {Default Local},
all_items = lb_ref << Get Items;
sel_items = lb_ref << Get Selected;
If(direction == "Swap",
item_order = Transform Each({sel_item}, sel_items,
Contains(all_items, sel_item)
);
new_order = all_items;
new_order[item_order] = Reverse(sel_items);
,
start_idx = Contains(all_items, sel_items[1]); // set based first found item
new_list = Filter Each({cur_item}, all_items, !Contains(sel_items, cur_item));
new_idx = If(direction == "Up",
start_idx - 1;
, direction == "Down",
start_idx + 1
,
start_idx
);
new_order = Insert(new_list, sel_items, new_idx);
);
lb_ref << Set Items(new_order);
all_items = lb_ref << Get Items;
For Each({cur_item}, sel_items,
new_idx = Contains(all_items, cur_item);
lb_ref << Set Selected(new_idx, 1, Run Script(0));
);
);
nw = New Window("Example",
H List Box(
lb_ref = List Box(
{"First Item", "Second Item", "Third Item"},
width(200),
max selected(2),
nlines(6)
),
Lineup Box(N Col(1),
btn_up = Button Box("", move_items(lb_ref, "Up"), << Set Icon("ListItemUp"), << Set Tip("Move selection up")),
btn_down = Button Box("", move_items(lb_ref, "Down"), << Set Icon("ListItemDown"), << Set Tip("Move selection down")),
)
)
);
我認為您可以使用滑鼠框進行拖放,但我更喜歡 JMP 中的按鈕(更容易創建)