129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 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.undo.DocumentUndoEvent;
|
|
14
|
131
|
15 import dwtx.text.undo.DocumentUndoManager; // packageimport
|
|
16 import dwtx.text.undo.DocumentUndoManagerRegistry; // packageimport
|
|
17 import dwtx.text.undo.IDocumentUndoListener; // packageimport
|
|
18 import dwtx.text.undo.UndoMessages; // packageimport
|
|
19 import dwtx.text.undo.IDocumentUndoManager; // packageimport
|
|
20
|
|
21
|
129
|
22 import dwt.dwthelper.utils;
|
|
23
|
|
24
|
|
25 import dwtx.core.runtime.Assert;
|
|
26 import dwtx.jface.text.IDocument;
|
|
27
|
|
28
|
|
29 /**
|
|
30 * Describes document changes initiated by undo or redo.
|
|
31 * <p>
|
|
32 * Clients are not supposed to subclass or create instances of this class.
|
|
33 * </p>
|
130
|
34 *
|
129
|
35 * @see IDocumentUndoManager
|
|
36 * @see IDocumentUndoListener
|
|
37 * @since 3.2
|
|
38 * @noinstantiate This class is not intended to be instantiated by clients.
|
|
39 * @noextend This class is not intended to be subclassed by clients.
|
|
40 */
|
|
41 public class DocumentUndoEvent {
|
|
42
|
|
43 /**
|
|
44 * Indicates that the described document event is about to be
|
|
45 * undone.
|
|
46 */
|
147
|
47 public static const int ABOUT_TO_UNDO= 1 << 0;
|
129
|
48
|
|
49 /**
|
|
50 * Indicates that the described document event is about to be
|
|
51 * redone.
|
|
52 */
|
147
|
53 public static const int ABOUT_TO_REDO= 1 << 1;
|
129
|
54
|
|
55 /**
|
|
56 * Indicates that the described document event has been undone.
|
|
57 */
|
147
|
58 public static const int UNDONE= 1 << 2;
|
129
|
59
|
|
60 /**
|
|
61 * Indicates that the described document event has been redone.
|
|
62 */
|
147
|
63 public static const int REDONE= 1 << 3;
|
129
|
64
|
|
65 /**
|
|
66 * Indicates that the described document event is a compound undo
|
|
67 * or redo event.
|
|
68 */
|
147
|
69 public static const int COMPOUND= 1 << 4;
|
129
|
70
|
|
71 /** The changed document. */
|
|
72 private IDocument fDocument;
|
|
73
|
|
74 /** The document offset where the change begins. */
|
|
75 private int fOffset;
|
|
76
|
|
77 /** Text inserted into the document. */
|
|
78 private String fText;
|
|
79
|
|
80 /** Text replaced in the document. */
|
|
81 private String fPreservedText;
|
|
82
|
|
83 /** Bit mask of event types describing the event */
|
|
84 private int fEventType;
|
|
85
|
|
86 /** The source that triggered this event or <code>null</code> if unknown. */
|
|
87 private Object fSource;
|
|
88
|
|
89 /**
|
|
90 * Creates a new document event.
|
130
|
91 *
|
129
|
92 * @param doc the changed document
|
|
93 * @param offset the offset of the replaced text
|
|
94 * @param text the substitution text
|
|
95 * @param preservedText the replaced text
|
|
96 * @param eventType a bit mask describing the type(s) of event
|
|
97 * @param source the source that triggered this event or <code>null</code> if unknown
|
|
98 */
|
130
|
99 this(IDocument doc, int offset, String text, String preservedText, int eventType, Object source) {
|
129
|
100
|
|
101 Assert.isNotNull(doc);
|
|
102 Assert.isTrue(offset >= 0);
|
|
103
|
|
104 fDocument= doc;
|
|
105 fOffset= offset;
|
|
106 fText= text;
|
|
107 fPreservedText= preservedText;
|
|
108 fEventType= eventType;
|
|
109 fSource= source;
|
|
110 }
|
|
111
|
|
112 /**
|
|
113 * Returns the changed document.
|
130
|
114 *
|
129
|
115 * @return the changed document
|
|
116 */
|
|
117 public IDocument getDocument() {
|
|
118 return fDocument;
|
|
119 }
|
|
120
|
|
121 /**
|
|
122 * Returns the offset of the change.
|
130
|
123 *
|
129
|
124 * @return the offset of the change
|
|
125 */
|
|
126 public int getOffset() {
|
|
127 return fOffset;
|
|
128 }
|
|
129
|
|
130 /**
|
|
131 * Returns the text that has been inserted.
|
130
|
132 *
|
129
|
133 * @return the text that has been inserted
|
|
134 */
|
|
135 public String getText() {
|
|
136 return fText;
|
|
137 }
|
|
138
|
|
139 /**
|
|
140 * Returns the text that has been replaced.
|
130
|
141 *
|
129
|
142 * @return the text that has been replaced
|
|
143 */
|
|
144 public String getPreservedText() {
|
|
145 return fPreservedText;
|
|
146 }
|
|
147
|
|
148 /**
|
|
149 * Returns the type of event that is occurring.
|
130
|
150 *
|
129
|
151 * @return the bit mask that indicates the type (or types) of the event
|
|
152 */
|
|
153 public int getEventType() {
|
|
154 return fEventType;
|
|
155 }
|
|
156
|
|
157 /**
|
|
158 * Returns the source that triggered this event.
|
130
|
159 *
|
129
|
160 * @return the source that triggered this event.
|
|
161 */
|
|
162 public Object getSource() {
|
|
163 return fSource;
|
|
164 }
|
|
165
|
|
166 /**
|
|
167 * Returns whether the change was a compound change or not.
|
130
|
168 *
|
129
|
169 * @return <code>true</code> if the undo or redo change is a
|
|
170 * compound change, <code>false</code> if it is not
|
|
171 */
|
|
172 public bool isCompound() {
|
|
173 return (fEventType & COMPOUND) !is 0;
|
|
174 }
|
|
175 }
|