1 21 22 package org.armedbear.j; 23 24 public final class SimpleEdit 25 { 26 public static final int MOVE = 1; 27 public static final int SCROLL_CARET = 2; 28 public static final int LINE_EDIT = 3; 29 public static final int INSERT_LINE_SEP = 4; 30 public static final int DELETE_LINE_SEP = 5; 31 public static final int INSERT_STRING = 6; 32 public static final int FOLD = 7; 33 34 public static boolean addUndo(Editor editor, int type) 35 { 36 final Buffer buffer = editor.getBuffer(); 37 if (!buffer.supportsUndo()) 38 return true; if (editor.getDot() == null) 40 return true; if (buffer.needsRenumbering()) 42 buffer.renumber(); 43 switch (type) { 44 case MOVE: 45 buffer.addEdit(new UndoMove(editor)); 46 break; 47 case SCROLL_CARET: 48 buffer.addEdit(new UndoScrollCaret(editor)); 49 break; 50 case LINE_EDIT: 51 buffer.addEdit(new UndoLineEdit(editor)); 52 break; 53 case INSERT_LINE_SEP: 54 buffer.addEdit(new UndoInsertLineSeparator(editor)); 55 break; 56 case DELETE_LINE_SEP: 57 buffer.addEdit(new UndoDeleteLineSeparator(editor)); 58 break; 59 case INSERT_STRING: 60 buffer.addEdit(new UndoInsertString(editor)); 61 break; 62 case FOLD: 63 buffer.addEdit(new UndoFold(editor)); 64 break; 65 default: 66 Debug.bug(); 67 buffer.getUndoManager().discardAllEdits(); 68 break; 69 } 70 return true; 71 } 72 } 73 | Popular Tags |