129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.text.edits.UndoEdit;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import java.util.ArrayList;
|
|
18 import java.util.List;
|
|
19
|
|
20 import dwtx.jface.text.BadLocationException;
|
|
21 import dwtx.jface.text.IDocument;
|
|
22
|
|
23
|
|
24 /**
|
|
25 * This class encapsulates the reverse changes of an executed text
|
|
26 * edit tree. To apply an undo memento to a document use method
|
|
27 * <code>apply(IDocument)</code>.
|
|
28 * <p>
|
|
29 * Clients can't add additional children to an undo edit nor can they
|
|
30 * add an undo edit as a child to another edit. Doing so results in
|
|
31 * both cases in a <code>MalformedTreeException<code>.
|
|
32 *
|
|
33 * @since 3.0
|
|
34 * @noinstantiate This class is not intended to be instantiated by clients.
|
|
35 */
|
|
36 public final class UndoEdit : TextEdit {
|
|
37
|
130
|
38 this() {
|
129
|
39 super(0, Integer.MAX_VALUE);
|
|
40 }
|
|
41
|
130
|
42 private this(UndoEdit other) {
|
129
|
43 super(other);
|
|
44 }
|
|
45
|
|
46 /*
|
|
47 * @see dwtx.text.edits.TextEdit#internalAdd(dwtx.text.edits.TextEdit)
|
|
48 */
|
|
49 void internalAdd(TextEdit child) throws MalformedTreeException {
|
|
50 throw new MalformedTreeException(null, this, TextEditMessages.getString("UndoEdit.no_children")); //$NON-NLS-1$
|
|
51 }
|
|
52
|
|
53 /*
|
|
54 * @see dwtx.text.edits.MultiTextEdit#aboutToBeAdded(dwtx.text.edits.TextEdit)
|
|
55 */
|
|
56 void aboutToBeAdded(TextEdit parent) {
|
|
57 throw new MalformedTreeException(parent, this, TextEditMessages.getString("UndoEdit.can_not_be_added")); //$NON-NLS-1$
|
|
58 }
|
|
59
|
|
60 UndoEdit dispatchPerformEdits(TextEditProcessor processor) throws BadLocationException {
|
|
61 return processor.executeUndo();
|
|
62 }
|
|
63
|
|
64 void dispatchCheckIntegrity(TextEditProcessor processor) throws MalformedTreeException {
|
|
65 processor.checkIntegrityUndo();
|
|
66 }
|
|
67
|
|
68 /*
|
|
69 * @see dwtx.text.edits.TextEdit#doCopy()
|
|
70 */
|
|
71 protected TextEdit doCopy() {
|
|
72 return new UndoEdit(this);
|
|
73 }
|
|
74
|
|
75 /*
|
|
76 * @see TextEdit#accept0
|
|
77 */
|
|
78 protected void accept0(TextEditVisitor visitor) {
|
|
79 bool visitChildren= visitor.visit(this);
|
|
80 if (visitChildren) {
|
|
81 acceptChildren(visitor);
|
|
82 }
|
|
83 }
|
|
84
|
|
85 /*
|
|
86 * @see TextEdit#performDocumentUpdating
|
|
87 */
|
|
88 int performDocumentUpdating(IDocument document) throws BadLocationException {
|
|
89 fDelta= 0;
|
|
90 return fDelta;
|
|
91 }
|
|
92
|
|
93 void add(ReplaceEdit edit) {
|
|
94 List children= internalGetChildren();
|
|
95 if (children is null) {
|
|
96 children= new ArrayList(2);
|
|
97 internalSetChildren(children);
|
|
98 }
|
|
99 children.add(edit);
|
|
100 }
|
|
101
|
|
102 void defineRegion(int offset, int length) {
|
|
103 internalSetOffset(offset);
|
|
104 internalSetLength(length);
|
|
105 }
|
|
106
|
|
107 bool deleteChildren() {
|
|
108 return false;
|
|
109 }
|
|
110 }
|
|
111
|