01: /*
02: * SimpleEdit.java
03: *
04: * Copyright (C) 1998-2003 Peter Graves
05: * $Id: SimpleEdit.java,v 1.4 2003/08/01 17:28:47 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: public final class SimpleEdit {
25: public static final int MOVE = 1;
26: public static final int SCROLL_CARET = 2;
27: public static final int LINE_EDIT = 3;
28: public static final int INSERT_LINE_SEP = 4;
29: public static final int DELETE_LINE_SEP = 5;
30: public static final int INSERT_STRING = 6;
31: public static final int FOLD = 7;
32:
33: public static boolean addUndo(Editor editor, int type) {
34: final Buffer buffer = editor.getBuffer();
35: if (!buffer.supportsUndo())
36: return true; // Not an error.
37: if (editor.getDot() == null)
38: return true; // Not an error.
39: if (buffer.needsRenumbering())
40: buffer.renumber();
41: switch (type) {
42: case MOVE:
43: buffer.addEdit(new UndoMove(editor));
44: break;
45: case SCROLL_CARET:
46: buffer.addEdit(new UndoScrollCaret(editor));
47: break;
48: case LINE_EDIT:
49: buffer.addEdit(new UndoLineEdit(editor));
50: break;
51: case INSERT_LINE_SEP:
52: buffer.addEdit(new UndoInsertLineSeparator(editor));
53: break;
54: case DELETE_LINE_SEP:
55: buffer.addEdit(new UndoDeleteLineSeparator(editor));
56: break;
57: case INSERT_STRING:
58: buffer.addEdit(new UndoInsertString(editor));
59: break;
60: case FOLD:
61: buffer.addEdit(new UndoFold(editor));
62: break;
63: default:
64: Debug.bug();
65: buffer.getUndoManager().discardAllEdits();
66: break;
67: }
68: return true;
69: }
70: }
|