undo/redo shortcuts
This commit is contained in:
parent
cfccb29fae
commit
0f5b95ad05
|
@ -6,7 +6,7 @@ import java.net.URL;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class rusEFIVersion {
|
||||
public static final int CONSOLE_VERSION = 20211107;
|
||||
public static final int CONSOLE_VERSION = 20211111;
|
||||
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
|
||||
|
||||
public static long classBuildTimeMillis() {
|
||||
|
|
|
@ -22,7 +22,7 @@ public class LuaScriptPanel {
|
|||
private final UIContext context;
|
||||
private final JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
private final AnyCommand command;
|
||||
private final JTextArea scriptText = new JTextArea();
|
||||
private final TextEditor scriptText = new TextEditor();
|
||||
private boolean isFirstRender = true;
|
||||
|
||||
public LuaScriptPanel(UIContext context, Node config) {
|
||||
|
@ -48,8 +48,7 @@ public class LuaScriptPanel {
|
|||
|
||||
// Center panel - script editor and log
|
||||
JPanel scriptPanel = new JPanel(new BorderLayout());
|
||||
scriptText.setTabSize(2);
|
||||
scriptPanel.add(scriptText, BorderLayout.CENTER);
|
||||
scriptPanel.add(scriptText.getControl(), BorderLayout.CENTER);
|
||||
|
||||
//centerPanel.add(, BorderLayout.WEST);
|
||||
JPanel messagesPanel = new JPanel(new BorderLayout());
|
||||
|
@ -72,12 +71,7 @@ public class LuaScriptPanel {
|
|||
mainPanel.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
trueLayout(mainPanel);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
centerPanel.setDividerLocation(centerPanel.getSize().width / 2);
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(() -> centerPanel.setDividerLocation(centerPanel.getSize().width / 2));
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package com.rusefi.ui.lua;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.undo.CannotRedoException;
|
||||
import javax.swing.undo.CannotUndoException;
|
||||
import javax.swing.undo.UndoManager;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* open question how much of text editor we want
|
||||
* <p>
|
||||
* todo: Find text feature?
|
||||
*/
|
||||
public class TextEditor {
|
||||
private final JTextArea textArea = new JTextArea();
|
||||
|
||||
public TextEditor() {
|
||||
textArea.setTabSize(2);
|
||||
|
||||
installUndoRedoKeystrokes();
|
||||
}
|
||||
|
||||
private void installUndoRedoKeystrokes() {
|
||||
KeyStroke undoKeyStroke = KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_Z, InputEvent.CTRL_MASK);
|
||||
KeyStroke redoKeyStroke = KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_Y, InputEvent.CTRL_MASK);
|
||||
|
||||
UndoManager undoManager = new UndoManager();
|
||||
|
||||
Document document = textArea.getDocument();
|
||||
document.addUndoableEditListener(e -> undoManager.addEdit(e.getEdit()));
|
||||
|
||||
// Map undo action
|
||||
textArea.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(undoKeyStroke, "undoKeyStroke");
|
||||
textArea.getActionMap().put("undoKeyStroke", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
undoManager.undo();
|
||||
} catch (CannotUndoException cue) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
});
|
||||
// Map redo action
|
||||
textArea.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(redoKeyStroke, "redoKeyStroke");
|
||||
textArea.getActionMap().put("redoKeyStroke", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
undoManager.redo();
|
||||
} catch (CannotRedoException cre) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JTextArea getControl() {
|
||||
return textArea;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
textArea.setText(text);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return textArea.getText();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue