diff --git a/app/.classpath b/app/.classpath
index 0ddf5f0990b..b7dd58fc4bc 100644
--- a/app/.classpath
+++ b/app/.classpath
@@ -43,7 +43,7 @@
-
+
diff --git a/app/lib/rsyntaxtextarea-2.5.8.1+arduino.jar b/app/lib/rsyntaxtextarea-2.5.8.1+arduino.jar
deleted file mode 100644
index 66e48d20aa4..00000000000
Binary files a/app/lib/rsyntaxtextarea-2.5.8.1+arduino.jar and /dev/null differ
diff --git a/app/lib/rsyntaxtextarea-2.6.1.jar b/app/lib/rsyntaxtextarea-2.6.1.jar
new file mode 100644
index 00000000000..b834e2d412b
Binary files /dev/null and b/app/lib/rsyntaxtextarea-2.6.1.jar differ
diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java
index 439dcdf18e8..287d9fe4e53 100644
--- a/app/src/processing/app/Editor.java
+++ b/app/src/processing/app/Editor.java
@@ -33,20 +33,19 @@
import jssc.SerialPortException;
import processing.app.debug.RunnerException;
import processing.app.forms.PasswordAuthorizationDialog;
+import processing.app.helpers.DocumentTextChangeListener;
import processing.app.helpers.Keys;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMapException;
import processing.app.legacy.PApplet;
import processing.app.syntax.PdeKeywords;
+import processing.app.syntax.SketchTextArea;
import processing.app.tools.MenuScroller;
import processing.app.tools.Tool;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.BadLocationException;
-import javax.swing.undo.CannotRedoException;
-import javax.swing.undo.CannotUndoException;
-import javax.swing.undo.UndoManager;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
@@ -185,8 +184,6 @@ public boolean test(SketchController sketch) {
// undo fellers
private JMenuItem undoItem;
private JMenuItem redoItem;
- protected UndoAction undoAction;
- protected RedoAction redoAction;
private FindReplace find;
@@ -1273,7 +1270,7 @@ private JMenu buildEditMenu() {
undoItem = newJMenuItem(tr("Undo"), 'Z');
undoItem.setName("menuEditUndo");
- undoItem.addActionListener(undoAction = new UndoAction());
+ undoItem.addActionListener(e -> getCurrentTab().handleUndo());
menu.add(undoItem);
if (!OSUtils.isMacOS()) {
@@ -1282,7 +1279,7 @@ private JMenu buildEditMenu() {
redoItem = newJMenuItemShift(tr("Redo"), 'Z');
}
redoItem.setName("menuEditRedo");
- redoItem.addActionListener(redoAction = new RedoAction());
+ redoItem.addActionListener(e -> getCurrentTab().handleRedo());
menu.add(redoItem);
menu.addSeparator();
@@ -1478,68 +1475,10 @@ private static JMenuItem newJMenuItemAlt(String title, int what) {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
- class UndoAction extends AbstractAction {
- public UndoAction() {
- super("Undo");
- this.setEnabled(false);
- }
-
- public void actionPerformed(ActionEvent e) {
- try {
- getCurrentTab().handleUndo();
- } catch (CannotUndoException ex) {
- //System.out.println("Unable to undo: " + ex);
- //ex.printStackTrace();
- }
- }
-
- protected void updateUndoState() {
- UndoManager undo = getCurrentTab().getUndoManager();
-
- if (undo.canUndo()) {
- this.setEnabled(true);
- undoItem.setEnabled(true);
- undoItem.setText(undo.getUndoPresentationName());
- putValue(Action.NAME, undo.getUndoPresentationName());
- } else {
- this.setEnabled(false);
- undoItem.setEnabled(false);
- undoItem.setText(tr("Undo"));
- putValue(Action.NAME, "Undo");
- }
- }
- }
-
-
- class RedoAction extends AbstractAction {
- public RedoAction() {
- super("Redo");
- this.setEnabled(false);
- }
-
- public void actionPerformed(ActionEvent e) {
- try {
- getCurrentTab().handleRedo();
- } catch (CannotRedoException ex) {
- //System.out.println("Unable to redo: " + ex);
- //ex.printStackTrace();
- }
- }
-
- protected void updateRedoState() {
- UndoManager undo = getCurrentTab().getUndoManager();
-
- if (undo.canRedo()) {
- redoItem.setEnabled(true);
- redoItem.setText(undo.getRedoPresentationName());
- putValue(Action.NAME, undo.getRedoPresentationName());
- } else {
- this.setEnabled(false);
- redoItem.setEnabled(false);
- redoItem.setText(tr("Redo"));
- putValue(Action.NAME, "Redo");
- }
- }
+ protected void updateUndoRedoState() {
+ SketchTextArea textArea = getCurrentTab().getTextArea();
+ undoItem.setEnabled(textArea.canUndo());
+ redoItem.setEnabled(textArea.canRedo());
}
@@ -1610,8 +1549,7 @@ public List getTabs() {
*/
public void selectTab(final int index) {
currentTabIndex = index;
- undoAction.updateUndoState();
- redoAction.updateRedoState();
+ updateUndoRedoState();
updateTitle();
header.rebuild();
getCurrentTab().activated();
@@ -1710,6 +1648,9 @@ public void reorderTabs() {
*/
protected void addTab(SketchFile file, String contents) throws IOException {
EditorTab tab = new EditorTab(this, file, contents);
+ tab.getTextArea().getDocument()
+ .addDocumentListener(new DocumentTextChangeListener(
+ () -> updateUndoRedoState()));
tabs.add(tab);
reorderTabs();
}
diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java
index 3ca4b22bb82..c2fdbb9b464 100644
--- a/app/src/processing/app/EditorTab.java
+++ b/app/src/processing/app/EditorTab.java
@@ -44,7 +44,6 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.PlainDocument;
-import javax.swing.undo.UndoManager;
import javax.swing.text.DefaultCaret;
import javax.swing.text.Document;
@@ -53,7 +52,6 @@
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
import org.fife.ui.rtextarea.Gutter;
import org.fife.ui.rtextarea.RTextScrollPane;
-import org.fife.ui.rtextarea.RUndoManager;
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
import processing.app.helpers.DocumentTextChangeListener;
@@ -108,10 +106,6 @@ public EditorTab(Editor editor, SketchFile file, String contents)
file.setStorage(this);
applyPreferences();
add(scrollPane, BorderLayout.CENTER);
-
- RUndoManager undo = new LastUndoableEditAwareUndoManager(this.textarea, this.editor);
- document.addUndoableEditListener(undo);
- textarea.setUndoManager(undo);
}
private RSyntaxDocument createDocument(String contents) {
@@ -407,14 +401,14 @@ public void setText(String what) {
int oldLength = doc.getLength();
// The undo manager already seems to group the insert and remove together
// automatically, but better be explicit about it.
- textarea.getUndoManager().beginInternalAtomicEdit();
+ textarea.beginAtomicEdit();
try {
doc.insertString(oldLength, what, null);
doc.remove(0, oldLength);
} catch (BadLocationException e) {
System.err.println("Unexpected failure replacing text");
} finally {
- textarea.getUndoManager().endInternalAtomicEdit();
+ textarea.endAtomicEdit();
}
} finally {
caret.setUpdatePolicy(policy);
@@ -524,7 +518,8 @@ void handleSelectAll() {
void handleCommentUncomment() {
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.rstaToggleCommentAction);
action.actionPerformed(null);
-
+ // XXX: RSyntaxDocument doesn't fire DocumentListener events, it should be fixed in RSyntaxTextArea?
+ editor.updateUndoRedoState();
}
void handleDiscourseCopy() {
@@ -544,6 +539,8 @@ void handleIndentOutdent(boolean indent) {
Action action = textarea.getActionMap().get(RSyntaxTextAreaEditorKit.rstaDecreaseIndentAction);
action.actionPerformed(null);
}
+ // XXX: RSyntaxDocument doesn't fire DocumentListener events, it should be fixed in RSyntaxTextArea?
+ editor.updateUndoRedoState();
}
void handleUndo() {
@@ -554,10 +551,6 @@ void handleRedo() {
textarea.redoLastAction();
}
- public UndoManager getUndoManager() {
- return textarea.getUndoManager();
- }
-
public String getCurrentKeyword() {
String text = "";
if (textarea.getSelectedText() != null)
diff --git a/app/src/processing/app/LastUndoableEditAwareUndoManager.java b/app/src/processing/app/LastUndoableEditAwareUndoManager.java
deleted file mode 100644
index 736be42d39b..00000000000
--- a/app/src/processing/app/LastUndoableEditAwareUndoManager.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package processing.app;
-
-import javax.swing.undo.CannotRedoException;
-import javax.swing.undo.CannotUndoException;
-
-import org.fife.ui.rtextarea.RUndoManager;
-
-import processing.app.syntax.SketchTextArea;
-
-public class LastUndoableEditAwareUndoManager extends RUndoManager {
-
- private Editor editor;
-
- public LastUndoableEditAwareUndoManager(SketchTextArea textarea, Editor editor) {
- super(textarea);
- this.editor = editor;
- }
-
- @Override
- public synchronized void undo() throws CannotUndoException {
- super.undo();
- }
-
- @Override
- public synchronized void redo() throws CannotRedoException {
- super.redo();
- }
-
- @Override
- public void updateActions() {
- super.updateActions();
- editor.undoAction.updateUndoState();
- editor.redoAction.updateRedoState();
- }
-
-
-}
diff --git a/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java b/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java
index 1a213eb1e57..8607160775e 100644
--- a/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java
+++ b/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java
@@ -53,12 +53,24 @@ public void shouldUndoAndRedo() throws Exception {
jEditTextArea.selectAll();
GuiActionRunner.execute(new GuiQuery() {
-
protected Frame executeInEDT() {
window.getEditor().getCurrentTab().handleCommentUncomment();
return window.getEditor();
}
+ });
+
+ menuEditUndo.requireEnabled();
+ menuEditUndo.click();
+
+ assertEquals(previousText, jEditTextArea.getText());
+ menuEditUndo.requireDisabled();
+
+ GuiActionRunner.execute(new GuiQuery() {
+ protected Frame executeInEDT() {
+ window.getEditor().getCurrentTab().handleIndentOutdent(true);
+ return window.getEditor();
+ }
});
menuEditUndo.requireEnabled();
diff --git a/build/windows/launcher/config.xml b/build/windows/launcher/config.xml
index 0bf56ea038a..8f99be9e74c 100644
--- a/build/windows/launcher/config.xml
+++ b/build/windows/launcher/config.xml
@@ -49,7 +49,7 @@
%EXEDIR%/lib/jsch-0.1.50.jar
%EXEDIR%/lib/jssc-2.8.0.jar
%EXEDIR%/lib/pde.jar
- %EXEDIR%/lib/rsyntaxtextarea-2.5.8.1+arduino.jar
+ %EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar
%EXEDIR%/lib/xml-apis-1.3.04.jar
%EXEDIR%/lib/xml-apis-ext-1.3.04.jar
%EXEDIR%/lib/xmlgraphics-commons-2.0.jar
diff --git a/build/windows/launcher/config_debug.xml b/build/windows/launcher/config_debug.xml
index f6fbfe9e12f..dbc14656349 100644
--- a/build/windows/launcher/config_debug.xml
+++ b/build/windows/launcher/config_debug.xml
@@ -49,7 +49,7 @@
%EXEDIR%/lib/jsch-0.1.50.jar
%EXEDIR%/lib/jssc-2.8.0.jar
%EXEDIR%/lib/pde.jar
- %EXEDIR%/lib/rsyntaxtextarea-2.5.8.1+arduino.jar
+ %EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar
%EXEDIR%/lib/xml-apis-1.3.04.jar
%EXEDIR%/lib/xml-apis-ext-1.3.04.jar
%EXEDIR%/lib/xmlgraphics-commons-2.0.jar