comparison dwtx/text/undo/DocumentUndoEvent.d @ 129:eb30df5ca28b

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