Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 641b064eed501ace4dc4bb13bb971dc580d30373 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.text.undo;

import org.eclipse.core.runtime.Assert;

import org.eclipse.jface.text.IDocument;


/**
 * Describes document changes initiated by undo or redo.
 * <p>
 * Clients are not supposed to subclass or create instances of this class.
 * </p>
 * 
 * @see IDocumentUndoManager
 * @see IDocumentUndoListener
 * @since 3.2
 * @noinstantiate This class is not intended to be instantiated by clients.
 * @noextend This class is not intended to be subclassed by clients.
 */
public class DocumentUndoEvent {

	/**
	 * Indicates that the described document event is about to be
	 * undone.
	 */
	public static final int ABOUT_TO_UNDO= 1 << 0;

	/**
	 * Indicates that the described document event is about to be
	 * redone.
	 */
	public static final int ABOUT_TO_REDO= 1 << 1;

	/**
	 * Indicates that the described document event has been undone.
	 */
	public static final int UNDONE= 1 << 2;

	/**
	 * Indicates that the described document event has been redone.
	 */
	public static final int REDONE= 1 << 3;

	/**
	 * Indicates that the described document event is a compound undo
	 * or redo event.
	 */
	public static final int COMPOUND= 1 << 4;

	/** The changed document. */
	private IDocument fDocument;

	/** The document offset where the change begins. */
	private int fOffset;

	/** Text inserted into the document. */
	private String fText;

	/** Text replaced in the document. */
	private String fPreservedText;

	/** Bit mask of event types describing the event */
	private int fEventType;

	/** The source that triggered this event or <code>null</code> if unknown. */
	private Object fSource;

	/**
	 * Creates a new document event.
	 * 
	 * @param doc the changed document
	 * @param offset the offset of the replaced text
	 * @param text the substitution text
	 * @param preservedText the replaced text
	 * @param eventType a bit mask describing the type(s) of event
	 * @param source the source that triggered this event or <code>null</code> if unknown
	 */
	DocumentUndoEvent(IDocument doc, int offset, String text, String preservedText, int eventType, Object source) {

		Assert.isNotNull(doc);
		Assert.isTrue(offset >= 0);

		fDocument= doc;
		fOffset= offset;
		fText= text;
		fPreservedText= preservedText;
		fEventType= eventType;
		fSource= source;
	}

	/**
	 * Returns the changed document.
	 * 
	 * @return the changed document
	 */
	public IDocument getDocument() {
		return fDocument;
	}

	/**
	 * Returns the offset of the change.
	 * 
	 * @return the offset of the change
	 */
	public int getOffset() {
		return fOffset;
	}

	/**
	 * Returns the text that has been inserted.
	 * 
	 * @return the text that has been inserted
	 */
	public String getText() {
		return fText;
	}

	/**
	 * Returns the text that has been replaced.
	 * 
	 * @return the text that has been replaced
	 */
	public String getPreservedText() {
		return fPreservedText;
	}

	/**
	 * Returns the type of event that is occurring.
	 * 
	 * @return the bit mask that indicates the type (or types) of the event
	 */
	public int getEventType() {
		return fEventType;
	}

	/**
	 * Returns the source that triggered this event.
	 * 
	 * @return the source that triggered this event.
	 */
	public Object getSource() {
		return fSource;
	}

	/**
	 * Returns whether the change was a compound change or not.
	 * 
	 * @return	<code>true</code> if the undo or redo change is a
	 * 			compound change, <code>false</code> if it is not
	 */
	public boolean isCompound() {
		return (fEventType & COMPOUND) != 0;
	}
}

Back to the top