concept G22LeftArrowScript > ConceptWithChangeListeners { settableWithVar S description; // the script (last "saved" version) settableWithVar S text; // the latest code that has been cleared to auto-run (if any) settableWithVar ClearForAutoRun clearedForAutoRun; // text currently being modified in an editor (or null) // Note that "" doesn't count as null. settableWithVar S editingText; @Override void _doneLoading2() { //print("_doneLoading " + this); cMigrateField(this, "code", "text"); } S myType() { ret dropPrefix("G22", shortClassName(this)); } toString { ret or2(description, myType() + " " + id); } void initEditingText { editingText(unnull(or(editingText, text))); } void receiveEditingText(S text) { printVars_shorten("receiveEditingText", +text); editingText(text); } S stableText() { ret text; } void completeEdit aka save() { S t = editingText; printVars_shorten("completeEdit", +t); if (t != null) { setTextWithHistory(t); printVars_shorten("completeEdit", +editingText); } } void setTextWithHistory(S text) { if (eq(this.text, text)) ret; text(text); saveTextToHistory(); } S textForEditing() { initEditingText(); ret editingText; } File historyFile() { ret fileInConceptsDir("History/" + shortDynName(this) + id + ".history"); } void saveTextToHistory() { saveFieldToHistory("text", text); } void saveFieldToHistory(S field, S value) { File historyFile = historyFile(); if (historyFile == null) ret; S contents = value == null ? "empty" : " (" + nLines(value) + ", " + nChars(value) + "):\n" + indentx(value) + "\n" + "\n"; appendToTextFile(historyFile, "\n===\n" + "Concept ID: " + id + "\n" + "Date: " + dateWithMSUTC() + "\n" + firstToUpper(field) + contents + "===" + "\n"); } bool isSaved() { ret text != null; } bool isEditing() { ret editedText() != null; } bool isClearForAutoRun() { ret clearedForAutoRun != null; } S editedText() { ret eq(editingText, text) ? null : editingText; } S codeForAutoRun() { ret getVar(clearedForAutoRun()); } void clearForAutoRun { if (!isSaved()) ret; S text = text(); saveFieldToHistory("Auto-runnable code", text); clearedForAutoRun(new ClearForAutoRun(text)); } void forgetAutoRunCode { if (!isClearForAutoRun()) ret; saveFieldToHistory("Auto-runnable code", null); clearedForAutoRun(null); compileResultForAutoRun = null; } GazelleV_LeftArrowScriptParser makeParser() { ret g22utils(_concepts).leftArrowParser(); } LASCompileResult newCompileResult() { ret new LASCompileResult; } transient LASCompileResult compileResultForAutoRun; LASCompileResult compileForAutoRun() { S code = codeForAutoRun(); if (code == null) null; var cr = compileResultForAutoRun; if (cr != null && eq(cr.script, code)) ret cr; cr = newCompileResult(); cr.script(code); var g22utils = assertNotNull(+g22utils(_concepts())); var parser = makeParser(); cr.parser(parser); cr.compile(); ret compileResultForAutoRun = cr; } }