Names Default To Here(1);
// To initialize Combo Box
init_dt_list = Get Data Table List() << Get Name;
If(N Items(init_dt_list) == 0,
Throw("No tables open");
);
dt = Current Data Table();
init_dt_idx = Contains(init_dt_list, dt << get name());
nw = New Window("test",
window:dt = dt;
H List Box(
Lineup Box(N Col(2),
window:cb_table = Combo Box(init_dt_list, << Set(init_dt_idx), << Set Function(function({this},
// must be done this way to recover from no tables open?
If((this << get selected) != "(SELECT TABLE)",
all_items = this << get items;
If(Contains(all_items, "(SELECT TABLE)"),
this << Remove Item(Contains(all_items, "(SELECT TABLE)"));
);
window:dt = Datatable((this << get selected));<BR />
// redo filter col selector
(window:ob_column_selection << child) << Delete Box();
Eval(EvalExpr(nw:ob_column_selection << Append(V List Box(
window:fcs = Filter Col Selector(Datatable(Expr(Datatable(window:dt))), << Set N Lines(5)),
window:fcs[IfBox(1)] << Set(1);
))));
);
)),
<< Set Tip("Data Table")
),
window:btn_table = Button Box("", << Set Function(function({this},
window:dt = Datatable(window:cb_table << Get Selected);
window:dt << Bring Window To Front;
)),
<< Set Icon("ActivateDataTable"),
<< Set Tip("View Data Table")
)
),
window:ob_column_selection = Outline Box("Column Selector",
V List Box( // Necessary evil for easier filter col selector updating
window:fcs = Filter Col Selector(Datatable(dt), << Set N Lines(5)),
window:fcs[IfBox(1)] << Set(1)
)
)
)
);
// Functions for different changes in data table list
Eval(EvalExpr(f_open = function({dtab},
cur_dts = Reverse(Get Data Table List() << Get Name);
cur_dt = Expr(nw:cb_table) << Get Selected;
If(cur_dt == "(no tables)",
nw:dt = Datatable(dtab);
);
Expr(nw:cb_table) << Set Items(cur_dts);
Expr(nw:cb_table) << Set(Contains(cur_dts, cur_dt));
If(N items(cur_dts) == 1,
// add (SELECT TABLE) temp item to recover from empty table situation
Expr(nw:cb_table) << Append Item("(SELECT TABLE)");
Expr(nw:cb_table) << Set(2, Run Script(0));
);
)));
Eval(EvalExpr(f_rename = function({dtab, b},
cur_dts = Reverse(Get Data Table List() << Get Name);
cur_dt = Expr(nw:cb_table) << Get Selected;
Substitute Into(cur_dts, b, (dtab << get name));
If(cur_dt == b,
cur_dt = dtab << get name;
);
Expr(nw:cb_table) << Set Items(cur_dts);
Expr(nw:cb_table) << Set(Contains(cur_dts, cur_dt));
)));
Eval(EvalExpr(f_close = function({dtab},
cur_dts = Reverse(Get Data Table List() << Get Name);
Remove From(cur_dts, Contains(cur_dts, dtab << get name));
cur_dt = Expr(nw:cb_table) << Get Selected;
If(cur_dt == dtab << get name(),
cur_dt = Current Data Table() << get name;
);
nw:cb_table << Set Items(cur_dts);
Expr(nw:cb_table) << Set(Contains(cur_dts, cur_dt));
If(N Items(cur_dts) == 0,
nw:cb_table << Set Items({"(no tables)"});
);
)));
// Subscription to data table list
aSub = Subscribe to Data Table List(, OnOpen(f_open));
Eval(EvalExpr(Subscribe to Data Table List(Expr(aSub), On Rename(f_rename))));
Eval(EvalExpr(Subscribe to Data Table List(Expr(aSub), OnClose(f_close))));
// To remove subscription
Eval(EvalExpr(nw << On Close(
Try(Unsubscribe to Data Table List(Expr(aSub), "ALL"));
)));