!7 concept Scenario { S name; LS conditions; LS actions; toString { ret "Scenario " + quote(name); } } cmodule Scenarios > DynCRUD { transient Scenario selected; new L undoList; NameBasedVoiceCRUD scenariosCRUD = new(Scenario, "scenario"); S answer(S s) { ret dm_q(() -> { print("answering: " + s); new Matches m; // undo actions if "undo" ret singleUndo(); if "anything to undo" ret empty(undoList) ? "Nothing to undo" : n2(undoList, "undoable action"); if "clear undos" ret "OK" with clearUndos(); ret scenariosCRUD.answer(s); }); } void addUndo(UndoableWithAnswer undo) { if (undo == null) ret; undoList.add(undo); change(); print("Undo added: " + undo); } afterVisualize { addComponent(crud.buttons, jbutton("Talk to me", rThread talkToMe)); } void talkToMe enter { dm_showConversationPopupForModule(); } void clearUndos q { if (empty(undoList)) ret; undoList.clear(); change; print("Undo list cleared"); } S singleUndo() { UndoableWithAnswer undo = popLast(undoList); if (undo == null) ret "Nothing to undo"; change(); ret or2(undo.undo(), "Last action undone"); } // API UndoableWithAnswer lastUndo() { ret dm_q(() -> last(undoList)); } }