Libraryless. Click here for Pure Java version (8774L/49K).
1 | import javax.swing.undo.UndoManager; |
2 | |
3 | static <A extends JTextComponent> A jenableUndoRedo(A textcomp) { |
4 | swing { |
5 | new UndoManager undo; |
6 | vm_generalWeakSet("Undo Managers").add(undo); |
7 | setMeta(textcomp, "UndoManager", undo); |
8 | textcomp.getDocument().addUndoableEditListener(new UndoableEditListener() { |
9 | public void undoableEditHappened(UndoableEditEvent evt) { |
10 | undo.addEdit(evt.getEdit()); |
11 | } |
12 | }); |
13 | |
14 | textcomp.getActionMap().put("Undo", abstractAction("Undo", r { |
15 | if (undo.canUndo()) undo.undo() |
16 | })); |
17 | textcomp.getActionMap().put("Redo", abstractAction("Redo", r { |
18 | if (undo.canRedo()) undo.redo() |
19 | })); |
20 | textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); |
21 | textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); |
22 | } |
23 | ret textcomp; |
24 | } |
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: | 535 / 638 |
Version history: | 12 change(s) |
Referenced in: | [show references] |