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

24
LINES

< > BotCompany Repo | #1007755 // jenableUndoRedo - enable Ctrl+Z undo and Ctrl+Y redo for JTextComponent

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8774L/49K).

import javax.swing.undo.UndoManager;

static <A extends JTextComponent> A jenableUndoRedo(A textcomp) {
  swing {
    new UndoManager undo;
    vm_generalWeakSet("Undo Managers").add(undo);
    setMeta(textcomp, "UndoManager", undo);
    textcomp.getDocument().addUndoableEditListener(new UndoableEditListener() {
      public void undoableEditHappened(UndoableEditEvent evt) {
        undo.addEdit(evt.getEdit());
      }
    });
    
    textcomp.getActionMap().put("Undo", abstractAction("Undo", r {
      if (undo.canUndo()) undo.undo()
    }));
    textcomp.getActionMap().put("Redo", abstractAction("Redo", r {
      if (undo.canRedo()) undo.redo()
    }));
    textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
    textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
  }
  ret textcomp;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007755
Snippet name: jenableUndoRedo - enable Ctrl+Z undo and Ctrl+Y redo for JTextComponent
Eternal ID of this version: #1007755/13
Text MD5: 877662b272e22f95f14d1e24481b41ba
Transpilation MD5: 706ad25f8c16fdefad6b3f49282eede6
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-04 00:37:45
Source code size: 862 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 536 / 638
Version history: 12 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)