Merge pull request #2666 from ffissore/undo-redo-fix

Undo sets the sketch to modified, even if it's not
This commit is contained in:
Federico Fissore 2015-03-01 21:16:11 +01:00
commit 9dc09e1cf4
3 changed files with 56 additions and 24 deletions

View File

@ -1365,6 +1365,7 @@ public class Editor extends JFrame implements RunnerListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
undo.undo(); undo.undo();
sketch.setModified(true);
} catch (CannotUndoException ex) { } catch (CannotUndoException ex) {
//System.out.println("Unable to undo: " + ex); //System.out.println("Unable to undo: " + ex);
//ex.printStackTrace(); //ex.printStackTrace();
@ -1386,17 +1387,11 @@ public class Editor extends JFrame implements RunnerListener {
undoItem.setEnabled(true); undoItem.setEnabled(true);
undoItem.setText(undo.getUndoPresentationName()); undoItem.setText(undo.getUndoPresentationName());
putValue(Action.NAME, undo.getUndoPresentationName()); putValue(Action.NAME, undo.getUndoPresentationName());
if (sketch != null) {
sketch.setModified(true); // 0107
}
} else { } else {
this.setEnabled(false); this.setEnabled(false);
undoItem.setEnabled(false); undoItem.setEnabled(false);
undoItem.setText(_("Undo")); undoItem.setText(_("Undo"));
putValue(Action.NAME, "Undo"); putValue(Action.NAME, "Undo");
if (sketch != null) {
sketch.setModified(false); // 0107
}
} }
} }
} }
@ -1411,6 +1406,7 @@ public class Editor extends JFrame implements RunnerListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
undo.redo(); undo.redo();
sketch.setModified(true);
} catch (CannotRedoException ex) { } catch (CannotRedoException ex) {
//System.out.println("Unable to redo: " + ex); //System.out.println("Unable to redo: " + ex);
//ex.printStackTrace(); //ex.printStackTrace();
@ -1697,10 +1693,12 @@ public class Editor extends JFrame implements RunnerListener {
document.addUndoableEditListener(new UndoableEditListener() { document.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) { public void undoableEditHappened(UndoableEditEvent e) {
if (compoundEdit != null) { if (compoundEdit != null) {
compoundEdit.addEdit(e.getEdit()); compoundEdit.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
} else if (undo != null) { } else if (undo != null) {
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea)); undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
}
if (compoundEdit != null || undo != null) {
sketch.setModified(true);
undoAction.updateUndoState(); undoAction.updateUndoState();
redoAction.updateRedoState(); redoAction.updateRedoState();
} }

View File

@ -0,0 +1,41 @@
package processing.app;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.fixture.JMenuItemFixture;
import org.junit.Test;
import processing.app.helpers.JEditTextAreaFixture;
import java.awt.*;
import static org.junit.Assert.assertEquals;
public class BlockCommentGeneratesOneUndoActionTest extends AbstractGUITest {
@Test
public void shouldUndoAndRedo() throws Exception {
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
menuEditUndo.requireDisabled();
JEditTextAreaFixture jEditTextArea = window.jEditTextArea("editor");
String previousText = jEditTextArea.getText();
jEditTextArea.selectAll();
GuiActionRunner.execute(new GuiQuery<Frame>() {
protected Frame executeInEDT() {
window.getEditor().handleCommentUncomment();
return window.getEditor();
}
});
menuEditUndo.requireEnabled();
menuEditUndo.click();
assertEquals(previousText, jEditTextArea.getText());
menuEditUndo.requireDisabled();
}
}

View File

@ -1,30 +1,23 @@
package processing.app.helpers; package processing.app.helpers;
import org.fest.swing.core.Robot;
import org.fest.swing.fixture.FrameFixture; import org.fest.swing.fixture.FrameFixture;
import processing.app.Editor;
import processing.app.syntax.JEditTextArea; import processing.app.syntax.JEditTextArea;
import java.awt.*;
public class ArduinoFrameFixture extends FrameFixture { public class ArduinoFrameFixture extends FrameFixture {
public ArduinoFrameFixture(Frame target) { private final Editor editor;
super(target);
}
public ArduinoFrameFixture(org.fest.swing.core.Robot robot, Frame target) { public ArduinoFrameFixture(Editor editor) {
super(robot, target); super(editor);
} this.editor = editor;
public ArduinoFrameFixture(Robot robot, String name) {
super(robot, name);
}
public ArduinoFrameFixture(String name) {
super(name);
} }
public JEditTextAreaFixture jEditTextArea(String name) { public JEditTextAreaFixture jEditTextArea(String name) {
return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name))); return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name)));
} }
public Editor getEditor() {
return editor;
}
} }