129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006 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.IDocumentUndoManager;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import dwtx.core.commands.ExecutionException;
|
|
18 import dwtx.core.commands.operations.IUndoContext;
|
|
19
|
|
20 /**
|
|
21 * Interface for a document undo manager. Tracks changes in a document and
|
|
22 * builds a history of text commands that describe the undoable changes to the
|
|
23 * document.
|
|
24 * <p>
|
|
25 * Clients must explicitly connect to the undo manager to express their interest
|
|
26 * in the undo history. Clients should disconnect from the undo manager when
|
|
27 * they are no longer interested in tracking the undo history. If there are no
|
|
28 * clients connected to the undo manager, it will not track the document's
|
|
29 * changes and will dispose of any history that was previously kept.</p>
|
|
30 * <p>
|
|
31 * Clients may also listen to the undo manager for notifications before and
|
|
32 * after undo or redo events are performed. Clients must connect to the undo
|
|
33 * manager in addition to registering listeners.</p>
|
|
34 * <p>
|
|
35 * Clients may implement this interface.
|
|
36 * </p>
|
|
37 *
|
|
38 * @see DocumentUndoManagerRegistry
|
|
39 * @see IDocumentUndoListener
|
|
40 * @see dwtx.jface.text.IDocument
|
|
41 * @since 3.2
|
|
42 */
|
|
43 public interface IDocumentUndoManager {
|
|
44
|
|
45 /**
|
|
46 * Adds the specified listener to the list of document undo listeners that
|
|
47 * are notified before and after changes are undone or redone in the
|
|
48 * document. This method has no effect if the instance being added is
|
|
49 * already in the list.
|
|
50 * <p>
|
|
51 * Notifications will not be received if there are no clients connected to
|
|
52 * the receiver. Registering a document undo listener does not implicitly
|
|
53 * connect the listener to the receiver.</p>
|
|
54 * <p>
|
|
55 * Document undo listeners must be prepared to receive notifications from a
|
|
56 * background thread. Any UI access occurring inside the implementation must
|
|
57 * be properly synchronized using the techniques specified by the client's
|
|
58 * widget library.</p>
|
|
59 *
|
|
60 * @param listener the document undo listener to be added as a listener
|
|
61 */
|
|
62 void addDocumentUndoListener(IDocumentUndoListener listener);
|
|
63
|
|
64 /**
|
|
65 * Removes the specified listener from the list of document undo listeners.
|
|
66 * <p>
|
|
67 * Removing a listener which is not registered has no effect
|
|
68 * </p>
|
|
69 *
|
|
70 * @param listener the document undo listener to be removed
|
|
71 */
|
|
72 void removeDocumentUndoListener(IDocumentUndoListener listener);
|
|
73
|
|
74 /**
|
|
75 * Returns the undo context registered for this document
|
|
76 *
|
|
77 * @return the undo context registered for this document
|
|
78 */
|
|
79 IUndoContext getUndoContext();
|
|
80
|
|
81 /**
|
|
82 * Closes the currently open text edit and open a new one.
|
|
83 */
|
|
84 void commit();
|
|
85
|
|
86 /**
|
|
87 * Connects to the undo manager. Used to signify that a client is monitoring
|
|
88 * the history kept by the undo manager. This message has no effect if the
|
|
89 * client is already connected.
|
|
90 *
|
|
91 * @param client the object connecting to the undo manager
|
|
92 */
|
|
93 void connect(Object client);
|
|
94
|
|
95 /**
|
|
96 * Disconnects from the undo manager. Used to signify that a client is no
|
|
97 * longer monitoring the history kept by the undo manager. If all clients
|
|
98 * have disconnected from the undo manager, the undo history will be
|
|
99 * deleted.
|
|
100 *
|
|
101 * @param client the object disconnecting from the undo manager
|
|
102 */
|
|
103 void disconnect(Object client);
|
|
104
|
|
105 /**
|
|
106 * Signals the undo manager that all subsequent changes until
|
|
107 * <code>endCompoundChange</code> is called are to be undone in one piece.
|
|
108 */
|
|
109 void beginCompoundChange();
|
|
110
|
|
111 /**
|
|
112 * Signals the undo manager that the sequence of changes which started with
|
|
113 * <code>beginCompoundChange</code> has been finished. All subsequent
|
|
114 * changes are considered to be individually undo-able.
|
|
115 */
|
|
116 void endCompoundChange();
|
|
117
|
|
118 /**
|
|
119 * Sets the limit of the undo history to the specified value. The provided
|
|
120 * limit will supersede any previously set limit.
|
|
121 *
|
|
122 * @param undoLimit the length of this undo manager's history
|
|
123 */
|
|
124 void setMaximalUndoLevel(int undoLimit);
|
|
125
|
|
126 /**
|
|
127 * Resets the history of the undo manager. After that call,
|
|
128 * there aren't any undo-able or redo-able text changes.
|
|
129 */
|
|
130 void reset();
|
|
131
|
|
132 /**
|
|
133 * Returns whether at least one text change can be rolled back.
|
|
134 *
|
|
135 * @return <code>true</code> if at least one text change can be rolled back
|
|
136 */
|
|
137 bool undoable();
|
|
138
|
|
139 /**
|
|
140 * Returns whether at least one text change can be repeated. A text change
|
|
141 * can be repeated only if it was executed and rolled back.
|
|
142 *
|
|
143 * @return <code>true</code> if at least on text change can be repeated
|
|
144 */
|
|
145 bool redoable();
|
|
146
|
|
147 /**
|
|
148 * Rolls back the most recently executed text change.
|
|
149 *
|
|
150 * @throws ExecutionException if an exception occurred during undo
|
|
151 */
|
|
152 void undo() throws ExecutionException;
|
|
153
|
|
154 /**
|
|
155 * Repeats the most recently rolled back text change.
|
|
156 *
|
|
157 * @throws ExecutionException if an exception occurred during redo
|
|
158 */
|
|
159 void redo() throws ExecutionException;
|
|
160
|
|
161 /**
|
|
162 * Transfers the undo history from the specified document undo manager to
|
|
163 * this undo manager. This message should only be used when it is known
|
|
164 * that the content of the document of the original undo manager when the
|
|
165 * last undo operation was recorded is the same as this undo manager's
|
|
166 * current document content, since the undo history is based on document
|
|
167 * indexes. It is the responsibility of the caller
|
|
168 * to ensure that this call is used correctly.
|
|
169 *
|
|
170 * @param manager the document undo manger whose history is to be transferred to the receiver
|
|
171 */
|
|
172 public void transferUndoHistory(IDocumentUndoManager manager);
|
|
173
|
|
174 }
|