sclass G22LAScriptIDE {
settable G22Utils g22utils;
settable S noScriptSelectedMsg = "Please select or create a script to edit it";
A script;
transient SingleComponentPanel scp;
transient JLeftArrowScriptIDE[] ides;
transient JTabbedPane tabs;
class Mode {
S name;
gettable bool editable;
*(S *name, bool *editable, IF1> *scriptVar) {}
swappable IVarWithNotify scriptVar(A a) { null; }
toString { ret name; }
}
transient L modes = ll(
new Mode("Cleared for auto-run", false, script -> {
var var = new VirtualVar(
-> getVar(script.clearedForAutoRun()),
null /*text -> script.setClearedForAutoRun(text == null ?: new ClearForAutoRun(text))*/);
addWeakChangeListener(script.varClearedForAutoRun(), var);
ret var;
}),
new Mode("Saved", false, script -> getterVarOnly(script.varText())),
new Mode("Editing", true, script -> script.varEditingText())
);
*(G22Utils *g22utils) {}
visualize {
ides = new JLeftArrowScriptIDE[l(modes)];
if (scp == null) scp = singleComponentPanel();
loadScript(script);
ret scp;
}
void setScript(A script) {
if (this.script != script)
loadScript(script);
}
void loadScript(A script) {
this.script = script;
if (scp == null) ret;
if (script == null)
scp.set(jcenteredlabel(noScriptSelectedMsg()));
else {
tabs = jtabs();
for (int i, Mode mode : unpair iterateWithIndex(modes)) {
var ide = ides[i] = g22utils.leftArrowIDE();
modifyIDE(ide);
var varScript = mode.scriptVar(script);
ide.lvScript(varWithNotifyToLiveValue(S.class, varScript));
addTab(tabs, str(mode), wrapIDE(ide));
varScript.onChangeAndNow(text ->
ide.setEditable(mode.editable()));
}
scp.set(tabs);
}
}
swappable JComponent wrapIDE(JLeftArrowScriptIDE ide) {
ret ide.visualize();
}
event settingUpIDE(JLeftArrowScriptIDE ide);
swappable void modifyIDE(JLeftArrowScriptIDE ide) {
ide.showTitle(false);
settingUpIDE(ide);
}
}