mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
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:
commit
9dc09e1cf4
@ -1365,6 +1365,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
undo.undo();
|
||||
sketch.setModified(true);
|
||||
} catch (CannotUndoException ex) {
|
||||
//System.out.println("Unable to undo: " + ex);
|
||||
//ex.printStackTrace();
|
||||
@ -1386,17 +1387,11 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
undoItem.setEnabled(true);
|
||||
undoItem.setText(undo.getUndoPresentationName());
|
||||
putValue(Action.NAME, undo.getUndoPresentationName());
|
||||
if (sketch != null) {
|
||||
sketch.setModified(true); // 0107
|
||||
}
|
||||
} else {
|
||||
this.setEnabled(false);
|
||||
undoItem.setEnabled(false);
|
||||
undoItem.setText(_("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) {
|
||||
try {
|
||||
undo.redo();
|
||||
sketch.setModified(true);
|
||||
} catch (CannotRedoException ex) {
|
||||
//System.out.println("Unable to redo: " + ex);
|
||||
//ex.printStackTrace();
|
||||
@ -1697,10 +1693,12 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
document.addUndoableEditListener(new UndoableEditListener() {
|
||||
public void undoableEditHappened(UndoableEditEvent e) {
|
||||
if (compoundEdit != null) {
|
||||
compoundEdit.addEdit(e.getEdit());
|
||||
|
||||
compoundEdit.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
|
||||
} else if (undo != null) {
|
||||
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
|
||||
}
|
||||
if (compoundEdit != null || undo != null) {
|
||||
sketch.setModified(true);
|
||||
undoAction.updateUndoState();
|
||||
redoAction.updateRedoState();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -1,30 +1,23 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.fest.swing.core.Robot;
|
||||
import org.fest.swing.fixture.FrameFixture;
|
||||
import processing.app.Editor;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ArduinoFrameFixture extends FrameFixture {
|
||||
|
||||
public ArduinoFrameFixture(Frame target) {
|
||||
super(target);
|
||||
}
|
||||
private final Editor editor;
|
||||
|
||||
public ArduinoFrameFixture(org.fest.swing.core.Robot robot, Frame target) {
|
||||
super(robot, target);
|
||||
}
|
||||
|
||||
public ArduinoFrameFixture(Robot robot, String name) {
|
||||
super(robot, name);
|
||||
}
|
||||
|
||||
public ArduinoFrameFixture(String name) {
|
||||
super(name);
|
||||
public ArduinoFrameFixture(Editor editor) {
|
||||
super(editor);
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public JEditTextAreaFixture jEditTextArea(String name) {
|
||||
return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name)));
|
||||
}
|
||||
|
||||
public Editor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user