Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1027563 // Undo Manager [Include]

JavaX fragment (include)

new L<UndoableWithAnswer> undoList;

void addUndo(UndoableWithAnswer undo) {
  if (undo == null) ret;
  undoList.add(undo);
  change();
  print("Undo added: " + undo);
}
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");
}

S undoActions(S s) {
  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();
  null;
}

// API

UndoableWithAnswer lastUndo() {
  ret dm_q(() -> last(undoList));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027563
Snippet name: Undo Manager [Include]
Eternal ID of this version: #1027563/2
Text MD5: ef8ad959c4cfa9c11765bf96f687ec79
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-23 22:47:42
Source code size: 772 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 183 / 484
Version history: 1 change(s)
Referenced in: [show references]