package bluej.editor.moe;

import bluej.utility.javafx.FXPlatformRunnable;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import org.fxmisc.richtext.util.UndoUtils;
import org.fxmisc.undo.UndoManager;


| An undo/redo manager for the editor. A stack of compound edits is maintained; | the "beginCompoundEdit()" and "endCompoundEdit()" methods can be used to |* create a compound edit (which is treated as a single edit for undo/redo purposes). * * @author Davin McCall */ public class MoeUndoManager{ private UndoManager undoManager; | |private BooleanProperty canUndo; | |private BooleanProperty canRedo; | |public MoeUndoManager(MoeEditorPane editorPane) | |{ | |// We uses a plain text undo manager instead of a rich text one. | |// This is to avoid making the undo manager to record the automatic | |// styling that MoeEditor performs. | |undoManager = UndoUtils.plainTextUndoManager(editorPane); | |} | |public UndoManager getUndoManager() | |{ | |return undoManager; | |} | |/** | Runs the given edit action. See comment within. | public void compoundEdit(FXPlatformRunnable edit) { breakEdit(); edit.run(); } breakEdit(); } public BooleanExpression canUndo() { if (canUndo == null) { canUndo = new SimpleBooleanProperty(); canUndo.bind(undoManager.undoAvailableProperty()); } return canUndo; } public BooleanExpression canRedo() { if (canRedo == null) { canRedo = new SimpleBooleanProperty(); canRedo.bind(undoManager.redoAvailableProperty()); } return canRedo; } public void undo() { undoManager.undo(); } public void redo() { undoManager.redo(); } public void forgetHistory() { undoManager.forgetHistory(); }
| Stops edits before this point merging with later edits into one single undoable item | (which is what happens by default). | public void breakEdit() { undoManager.preventMerge(); } }

.   compoundEdit
.   canUndo
.   canRedo
.   undo
.   redo
.   forgetHistory
.   breakEdit




89 neLoCode + 19 LoComm