Skip to content

Rsta update #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<classpathentry kind="lib" path="lib/slf4j-simple-1.7.22.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.5.8.1+arduino.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.6.1.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-ext-1.3.04.jar"/>
<classpathentry kind="lib" path="lib/xmlgraphics-commons-2.0.jar"/>
Expand Down
Binary file removed app/lib/rsyntaxtextarea-2.5.8.1+arduino.jar
Binary file not shown.
Binary file added app/lib/rsyntaxtextarea-2.6.1.jar
Binary file not shown.
83 changes: 12 additions & 71 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
Expand Down Expand Up @@ -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());
}


Expand Down Expand Up @@ -1610,8 +1549,7 @@ public List<EditorTab> getTabs() {
*/
public void selectTab(final int index) {
currentTabIndex = index;
undoAction.updateUndoState();
redoAction.updateRedoState();
updateUndoRedoState();
updateTitle();
header.rebuild();
getCurrentTab().activated();
Expand Down Expand Up @@ -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();
}
Expand Down
19 changes: 6 additions & 13 deletions app/src/processing/app/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -554,10 +551,6 @@ void handleRedo() {
textarea.redoLastAction();
}

public UndoManager getUndoManager() {
return textarea.getUndoManager();
}

public String getCurrentKeyword() {
String text = "";
if (textarea.getSelectedText() != null)
Expand Down
37 changes: 0 additions & 37 deletions app/src/processing/app/LastUndoableEditAwareUndoManager.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,24 @@ public void shouldUndoAndRedo() throws Exception {
jEditTextArea.selectAll();

GuiActionRunner.execute(new GuiQuery<Frame>() {

protected Frame executeInEDT() {
window.getEditor().getCurrentTab().handleCommentUncomment();
return window.getEditor();
}
});

menuEditUndo.requireEnabled();
menuEditUndo.click();

assertEquals(previousText, jEditTextArea.getText());

menuEditUndo.requireDisabled();

GuiActionRunner.execute(new GuiQuery<Frame>() {
protected Frame executeInEDT() {
window.getEditor().getCurrentTab().handleIndentOutdent(true);
return window.getEditor();
}
});

menuEditUndo.requireEnabled();
Expand Down
2 changes: 1 addition & 1 deletion build/windows/launcher/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<cp>%EXEDIR%/lib/jsch-0.1.50.jar</cp>
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.5.8.1+arduino.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-ext-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xmlgraphics-commons-2.0.jar</cp>
Expand Down
2 changes: 1 addition & 1 deletion build/windows/launcher/config_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<cp>%EXEDIR%/lib/jsch-0.1.50.jar</cp>
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.5.8.1+arduino.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-ext-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xmlgraphics-commons-2.0.jar</cp>
Expand Down