myUndoManager.addEdit(e.getEdit());
}
};
myTextComponent.getDocument().addUndoableEditListener(myUndoableEditListener);
myOldKeymap = myTextComponent.getKeymap();
Keymap keymap = JTextComponent.addKeymap(null, myOldKeymap);
com.intellij.openapi.keymap.Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
Shortcut[] undoShortcuts = activeKeymap.getShortcuts("$Undo");
Shortcut[] redoShortcuts = activeKeymap.getShortcuts("$Redo");
Action undoAction = new AbstractAction ("Undo") {
public void actionPerformed(ActionEvent e) {
if (myUndoManager.canUndo())
myUndoManager.undo();
}
};
Action redoAction = new AbstractAction ("Redo") {
public void actionPerformed(ActionEvent e) {
if (myUndoManager.canRedo())
myUndoManager.redo();
}
};
for (Shortcut undoShortcut : undoShortcuts) {
if (undoShortcut instanceof KeyboardShortcut) {
keymap.addActionForKeyStroke(((KeyboardShortcut)undoShortcut).getFirstKeyStroke(), undoAction);
}
}
for (Shortcut redoShortcut : redoShortcuts) {
if (redoShortcut instanceof KeyboardShortcut) {
keymap.addActionForKeyStroke(((KeyboardShortcut)redoShortcut).getFirstKeyStroke(), redoAction);
}
}
myTextComponent.setKeymap(keymap);
}