Mercurial > projects > dwt-addons
annotate dwtx/jface/text/AbstractDocument.d @ 172:d994a8b2cdf7
again compile fixes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 10 Sep 2008 23:14:02 +0200 |
parents | 1a5b8f8129df |
children |
rev | line source |
---|---|
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 | |
131 | 14 |
151 | 15 module dwtx.jface.text.AbstractDocument; |
16 | |
131 | 17 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
18 import dwtx.jface.text.DefaultTextHover; // packageimport | |
19 import dwtx.jface.text.AbstractInformationControl; // packageimport | |
20 import dwtx.jface.text.TextUtilities; // packageimport | |
21 import dwtx.jface.text.IInformationControlCreatorExtension; // packageimport | |
22 import dwtx.jface.text.AbstractInformationControlManager; // packageimport | |
23 import dwtx.jface.text.ITextViewerExtension2; // packageimport | |
24 import dwtx.jface.text.IDocumentPartitioner; // packageimport | |
25 import dwtx.jface.text.DefaultIndentLineAutoEditStrategy; // packageimport | |
26 import dwtx.jface.text.ITextSelection; // packageimport | |
27 import dwtx.jface.text.Document; // packageimport | |
28 import dwtx.jface.text.FindReplaceDocumentAdapterContentProposalProvider; // packageimport | |
29 import dwtx.jface.text.ITextListener; // packageimport | |
30 import dwtx.jface.text.BadPartitioningException; // packageimport | |
31 import dwtx.jface.text.ITextViewerExtension5; // packageimport | |
32 import dwtx.jface.text.IDocumentPartitionerExtension3; // packageimport | |
33 import dwtx.jface.text.IUndoManager; // packageimport | |
34 import dwtx.jface.text.ITextHoverExtension2; // packageimport | |
35 import dwtx.jface.text.IRepairableDocument; // packageimport | |
36 import dwtx.jface.text.IRewriteTarget; // packageimport | |
37 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
38 import dwtx.jface.text.RewriteSessionEditProcessor; // packageimport | |
39 import dwtx.jface.text.TextViewerHoverManager; // packageimport | |
40 import dwtx.jface.text.DocumentRewriteSession; // packageimport | |
41 import dwtx.jface.text.TextViewer; // packageimport | |
42 import dwtx.jface.text.ITextViewerExtension8; // packageimport | |
43 import dwtx.jface.text.RegExMessages; // packageimport | |
44 import dwtx.jface.text.IDelayedInputChangeProvider; // packageimport | |
45 import dwtx.jface.text.ITextOperationTargetExtension; // packageimport | |
46 import dwtx.jface.text.IWidgetTokenOwner; // packageimport | |
47 import dwtx.jface.text.IViewportListener; // packageimport | |
48 import dwtx.jface.text.GapTextStore; // packageimport | |
49 import dwtx.jface.text.MarkSelection; // packageimport | |
50 import dwtx.jface.text.IDocumentPartitioningListenerExtension; // packageimport | |
51 import dwtx.jface.text.IDocumentAdapterExtension; // packageimport | |
52 import dwtx.jface.text.IInformationControlExtension; // packageimport | |
53 import dwtx.jface.text.IDocumentPartitioningListenerExtension2; // packageimport | |
54 import dwtx.jface.text.DefaultDocumentAdapter; // packageimport | |
55 import dwtx.jface.text.ITextViewerExtension3; // packageimport | |
56 import dwtx.jface.text.IInformationControlCreator; // packageimport | |
57 import dwtx.jface.text.TypedRegion; // packageimport | |
58 import dwtx.jface.text.ISynchronizable; // packageimport | |
59 import dwtx.jface.text.IMarkRegionTarget; // packageimport | |
60 import dwtx.jface.text.TextViewerUndoManager; // packageimport | |
61 import dwtx.jface.text.IRegion; // packageimport | |
62 import dwtx.jface.text.IInformationControlExtension2; // packageimport | |
63 import dwtx.jface.text.IDocumentExtension4; // packageimport | |
64 import dwtx.jface.text.IDocumentExtension2; // packageimport | |
65 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | |
66 import dwtx.jface.text.DefaultInformationControl; // packageimport | |
67 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | |
68 import dwtx.jface.text.DocumentClone; // packageimport | |
69 import dwtx.jface.text.DefaultUndoManager; // packageimport | |
70 import dwtx.jface.text.IFindReplaceTarget; // packageimport | |
71 import dwtx.jface.text.IAutoEditStrategy; // packageimport | |
72 import dwtx.jface.text.ILineTrackerExtension; // packageimport | |
73 import dwtx.jface.text.IUndoManagerExtension; // packageimport | |
74 import dwtx.jface.text.TextSelection; // packageimport | |
75 import dwtx.jface.text.DefaultAutoIndentStrategy; // packageimport | |
76 import dwtx.jface.text.IAutoIndentStrategy; // packageimport | |
77 import dwtx.jface.text.IPainter; // packageimport | |
78 import dwtx.jface.text.IInformationControl; // packageimport | |
79 import dwtx.jface.text.IInformationControlExtension3; // packageimport | |
80 import dwtx.jface.text.ITextViewerExtension6; // packageimport | |
81 import dwtx.jface.text.IInformationControlExtension4; // packageimport | |
82 import dwtx.jface.text.DefaultLineTracker; // packageimport | |
83 import dwtx.jface.text.IDocumentInformationMappingExtension; // packageimport | |
84 import dwtx.jface.text.IRepairableDocumentExtension; // packageimport | |
85 import dwtx.jface.text.ITextHover; // packageimport | |
86 import dwtx.jface.text.FindReplaceDocumentAdapter; // packageimport | |
87 import dwtx.jface.text.ILineTracker; // packageimport | |
88 import dwtx.jface.text.Line; // packageimport | |
89 import dwtx.jface.text.ITextViewerExtension; // packageimport | |
90 import dwtx.jface.text.IDocumentAdapter; // packageimport | |
91 import dwtx.jface.text.TextEvent; // packageimport | |
92 import dwtx.jface.text.BadLocationException; // packageimport | |
93 import dwtx.jface.text.AbstractLineTracker; // packageimport | |
94 import dwtx.jface.text.TreeLineTracker; // packageimport | |
95 import dwtx.jface.text.ITextPresentationListener; // packageimport | |
96 import dwtx.jface.text.Region; // packageimport | |
97 import dwtx.jface.text.ITextViewer; // packageimport | |
98 import dwtx.jface.text.IDocumentInformationMapping; // packageimport | |
99 import dwtx.jface.text.MarginPainter; // packageimport | |
100 import dwtx.jface.text.IPaintPositionManager; // packageimport | |
101 import dwtx.jface.text.TextPresentation; // packageimport | |
102 import dwtx.jface.text.IFindReplaceTargetExtension; // packageimport | |
103 import dwtx.jface.text.ISlaveDocumentManagerExtension; // packageimport | |
104 import dwtx.jface.text.ISelectionValidator; // packageimport | |
105 import dwtx.jface.text.IDocumentExtension; // packageimport | |
106 import dwtx.jface.text.PropagatingFontFieldEditor; // packageimport | |
107 import dwtx.jface.text.ConfigurableLineTracker; // packageimport | |
108 import dwtx.jface.text.SlaveDocumentEvent; // packageimport | |
109 import dwtx.jface.text.IDocumentListener; // packageimport | |
110 import dwtx.jface.text.PaintManager; // packageimport | |
111 import dwtx.jface.text.IFindReplaceTargetExtension3; // packageimport | |
112 import dwtx.jface.text.ITextDoubleClickStrategy; // packageimport | |
113 import dwtx.jface.text.IDocumentExtension3; // packageimport | |
114 import dwtx.jface.text.Position; // packageimport | |
115 import dwtx.jface.text.TextMessages; // packageimport | |
116 import dwtx.jface.text.CopyOnWriteTextStore; // packageimport | |
117 import dwtx.jface.text.WhitespaceCharacterPainter; // packageimport | |
118 import dwtx.jface.text.IPositionUpdater; // packageimport | |
119 import dwtx.jface.text.DefaultTextDoubleClickStrategy; // packageimport | |
120 import dwtx.jface.text.ListLineTracker; // packageimport | |
121 import dwtx.jface.text.ITextInputListener; // packageimport | |
122 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
123 import dwtx.jface.text.IWidgetTokenKeeperExtension; // packageimport | |
124 import dwtx.jface.text.IInputChangedListener; // packageimport | |
125 import dwtx.jface.text.ITextOperationTarget; // packageimport | |
126 import dwtx.jface.text.IDocumentInformationMappingExtension2; // packageimport | |
127 import dwtx.jface.text.ITextViewerExtension7; // packageimport | |
128 import dwtx.jface.text.IInformationControlExtension5; // packageimport | |
129 import dwtx.jface.text.IDocumentRewriteSessionListener; // packageimport | |
130 import dwtx.jface.text.JFaceTextUtil; // packageimport | |
131 import dwtx.jface.text.AbstractReusableInformationControlCreator; // packageimport | |
132 import dwtx.jface.text.TabsToSpacesConverter; // packageimport | |
133 import dwtx.jface.text.CursorLinePainter; // packageimport | |
134 import dwtx.jface.text.ITextHoverExtension; // packageimport | |
135 import dwtx.jface.text.IEventConsumer; // packageimport | |
136 import dwtx.jface.text.IDocument; // packageimport | |
137 import dwtx.jface.text.IWidgetTokenKeeper; // packageimport | |
138 import dwtx.jface.text.DocumentCommand; // packageimport | |
139 import dwtx.jface.text.TypedPosition; // packageimport | |
140 import dwtx.jface.text.IEditingSupportRegistry; // packageimport | |
141 import dwtx.jface.text.IDocumentPartitionerExtension; // packageimport | |
142 import dwtx.jface.text.AbstractHoverInformationControlManager; // packageimport | |
143 import dwtx.jface.text.IEditingSupport; // packageimport | |
144 import dwtx.jface.text.IMarkSelection; // packageimport | |
145 import dwtx.jface.text.ISlaveDocumentManager; // packageimport | |
146 import dwtx.jface.text.DocumentEvent; // packageimport | |
147 import dwtx.jface.text.DocumentPartitioningChangedEvent; // packageimport | |
148 import dwtx.jface.text.ITextStore; // packageimport | |
149 import dwtx.jface.text.JFaceTextMessages; // packageimport | |
150 import dwtx.jface.text.DocumentRewriteSessionEvent; // packageimport | |
151 import dwtx.jface.text.SequentialRewriteTextStore; // packageimport | |
152 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | |
153 import dwtx.jface.text.TextAttribute; // packageimport | |
154 import dwtx.jface.text.ITextViewerExtension4; // packageimport | |
155 import dwtx.jface.text.ITypedRegion; // packageimport | |
156 | |
129 | 157 import dwt.dwthelper.utils; |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
151
diff
changeset
|
158 import dwtx.dwtxhelper.Collection; |
162 | 159 import dwtx.dwtxhelper.regex; |
160 import tango.text.convert.Format; | |
129 | 161 |
162 import dwtx.core.runtime.Assert; | |
163 import dwtx.core.runtime.ListenerList; | |
164 | |
165 | |
166 /** | |
167 * Abstract default implementation of <code>IDocument</code> and its extension | |
168 * interfaces {@link dwtx.jface.text.IDocumentExtension}, | |
169 * {@link dwtx.jface.text.IDocumentExtension2}, | |
170 * {@link dwtx.jface.text.IDocumentExtension3}, | |
171 * {@link dwtx.jface.text.IDocumentExtension4}, as well as | |
172 * {@link dwtx.jface.text.IRepairableDocument}. | |
173 * <p> | |
174 * | |
175 * An <code>AbstractDocument</code> supports the following implementation | |
176 * plug-ins: | |
177 * <ul> | |
178 * <li>a text store implementing {@link dwtx.jface.text.ITextStore} for | |
179 * storing and managing the document's content,</li> | |
180 * <li>a line tracker implementing {@link dwtx.jface.text.ILineTracker} | |
181 * to map character positions to line numbers and vice versa</li> | |
182 * </ul> | |
183 * The document can dynamically change the text store when switching between | |
184 * sequential rewrite mode and normal mode. | |
185 * <p> | |
186 * | |
187 * This class must be subclassed. Subclasses must configure which implementation | |
188 * plug-ins the document instance should use. Subclasses are not intended to | |
189 * overwrite existing methods. | |
190 * | |
191 * @see dwtx.jface.text.ITextStore | |
192 * @see dwtx.jface.text.ILineTracker | |
193 */ | |
194 public abstract class AbstractDocument : IDocument, IDocumentExtension, IDocumentExtension2, IDocumentExtension3, IDocumentExtension4, IRepairableDocument, IRepairableDocumentExtension { | |
195 | |
196 /** | |
197 * Tells whether this class is in debug mode. | |
198 * @since 3.1 | |
199 */ | |
147 | 200 private static const bool DEBUG= false; |
129 | 201 |
202 | |
203 /** | |
204 * Inner class to bundle a registered post notification replace operation together with its | |
205 * owner. | |
206 * | |
207 * @since 2.0 | |
208 */ | |
209 static private class RegisteredReplace { | |
210 /** The owner of this replace operation. */ | |
211 IDocumentListener fOwner; | |
212 /** The replace operation */ | |
213 IDocumentExtension.IReplace fReplace; | |
214 | |
215 /** | |
216 * Creates a new bundle object. | |
217 * @param owner the document listener owning the replace operation | |
218 * @param replace the replace operation | |
219 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
220 this(IDocumentListener owner, IDocumentExtension.IReplace replace) { |
129 | 221 fOwner= owner; |
222 fReplace= replace; | |
223 } | |
224 } | |
225 | |
226 | |
227 /** The document's text store */ | |
228 private ITextStore fStore; | |
229 /** The document's line tracker */ | |
230 private ILineTracker fTracker; | |
231 /** The registered document listeners */ | |
232 private ListenerList fDocumentListeners; | |
233 /** The registered pre-notified document listeners */ | |
234 private ListenerList fPrenotifiedDocumentListeners; | |
235 /** The registered document partitioning listeners */ | |
236 private ListenerList fDocumentPartitioningListeners; | |
237 /** All positions managed by the document ordered by their start positions. */ | |
238 private Map fPositions; | |
239 /** | |
240 * All positions managed by the document ordered by there end positions. | |
241 * @since 3.4 | |
242 */ | |
243 private Map fEndPositions; | |
244 /** All registered document position updaters */ | |
245 private List fPositionUpdaters; | |
246 /** | |
247 * The list of post notification changes | |
248 * @since 2.0 | |
249 */ | |
250 private List fPostNotificationChanges; | |
251 /** | |
252 * The reentrance count for post notification changes. | |
253 * @since 2.0 | |
254 */ | |
255 private int fReentranceCount= 0; | |
256 /** | |
257 * Indicates whether post notification change processing has been stopped. | |
258 * @since 2.0 | |
259 */ | |
260 private int fStoppedCount= 0; | |
261 /** | |
262 * Indicates whether the registration of post notification changes should be ignored. | |
263 * @since 2.1 | |
264 */ | |
265 private bool fAcceptPostNotificationReplaces= true; | |
266 /** | |
267 * Indicates whether the notification of listeners has been stopped. | |
268 * @since 2.1 | |
269 */ | |
270 private int fStoppedListenerNotification= 0; | |
271 /** | |
272 * The document event to be sent after listener notification has been resumed. | |
273 * @since 2.1 | |
274 */ | |
275 private DocumentEvent fDeferredDocumentEvent; | |
276 /** | |
277 * The registered document partitioners. | |
278 * @since 3.0 | |
279 */ | |
280 private Map fDocumentPartitioners; | |
281 /** | |
282 * The partitioning changed event. | |
283 * @since 3.0 | |
284 */ | |
285 private DocumentPartitioningChangedEvent fDocumentPartitioningChangedEvent; | |
286 /** | |
287 * The find/replace document adapter. | |
288 * @since 3.0 | |
289 */ | |
290 private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter; | |
291 /** | |
292 * The active document rewrite session. | |
293 * @since 3.1 | |
294 */ | |
295 private DocumentRewriteSession fDocumentRewriteSession; | |
296 /** | |
297 * The registered document rewrite session listeners. | |
298 * @since 3.1 | |
299 */ | |
300 private List fDocumentRewriteSessionListeners; | |
301 /** | |
302 * The current modification stamp. | |
303 * @since 3.1 | |
304 */ | |
305 private long fModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; | |
306 /** | |
307 * Keeps track of next modification stamp. | |
308 * @since 3.1.1 | |
309 */ | |
310 private long fNextModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; | |
311 /** | |
312 * This document's default line delimiter. | |
313 * @since 3.1 | |
314 */ | |
315 private String fInitialLineDelimiter; | |
316 | |
317 | |
318 /** | |
319 * The default constructor does not perform any configuration | |
320 * but leaves it to the clients who must first initialize the | |
321 * implementation plug-ins and then call <code>completeInitialization</code>. | |
322 * Results in the construction of an empty document. | |
323 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
324 protected this() { |
129 | 325 fModificationStamp= getNextModificationStamp(); |
326 } | |
327 | |
328 | |
329 /** | |
330 * Returns the document's text store. Assumes that the | |
331 * document has been initialized with a text store. | |
332 * | |
333 * @return the document's text store | |
334 */ | |
335 protected ITextStore getStore() { | |
162 | 336 Assert.isNotNull(cast(Object)fStore); |
129 | 337 return fStore; |
338 } | |
339 | |
340 /** | |
341 * Returns the document's line tracker. Assumes that the | |
342 * document has been initialized with a line tracker. | |
343 * | |
344 * @return the document's line tracker | |
345 */ | |
346 protected ILineTracker getTracker() { | |
162 | 347 Assert.isNotNull(cast(Object)fTracker); |
129 | 348 return fTracker; |
349 } | |
350 | |
351 /** | |
352 * Returns the document's document listeners. | |
353 * | |
354 * @return the document's document listeners | |
355 */ | |
356 protected List getDocumentListeners() { | |
357 return Arrays.asList(fDocumentListeners.getListeners()); | |
358 } | |
359 | |
360 /** | |
361 * Returns the document's partitioning listeners. | |
362 * | |
363 * @return the document's partitioning listeners | |
364 */ | |
365 protected List getDocumentPartitioningListeners() { | |
366 return Arrays.asList(fDocumentPartitioningListeners.getListeners()); | |
367 } | |
368 | |
369 /** | |
370 * Returns all positions managed by the document grouped by category. | |
371 * | |
372 * @return the document's positions | |
373 */ | |
374 protected Map getDocumentManagedPositions() { | |
375 return fPositions; | |
376 } | |
377 | |
378 /* | |
379 * @see dwtx.jface.text.IDocument#getDocumentPartitioner() | |
380 */ | |
381 public IDocumentPartitioner getDocumentPartitioner() { | |
382 return getDocumentPartitioner(DEFAULT_PARTITIONING); | |
383 } | |
384 | |
385 | |
386 | |
387 //--- implementation configuration interface ------------ | |
388 | |
389 /** | |
390 * Sets the document's text store. | |
391 * Must be called at the beginning of the constructor. | |
392 * | |
393 * @param store the document's text store | |
394 */ | |
395 protected void setTextStore(ITextStore store) { | |
396 fStore= store; | |
397 } | |
398 | |
399 /** | |
400 * Sets the document's line tracker. | |
401 * Must be called at the beginning of the constructor. | |
402 * | |
403 * @param tracker the document's line tracker | |
404 */ | |
405 protected void setLineTracker(ILineTracker tracker) { | |
406 fTracker= tracker; | |
407 } | |
408 | |
409 /* | |
410 * @see dwtx.jface.text.IDocument#setDocumentPartitioner(dwtx.jface.text.IDocumentPartitioner) | |
411 */ | |
412 public void setDocumentPartitioner(IDocumentPartitioner partitioner) { | |
413 setDocumentPartitioner(DEFAULT_PARTITIONING, partitioner); | |
414 } | |
415 | |
416 /** | |
417 * Initializes document listeners, positions, and position updaters. | |
418 * Must be called inside the constructor after the implementation plug-ins | |
419 * have been set. | |
420 */ | |
421 protected void completeInitialization() { | |
422 | |
423 fPositions= new HashMap(); | |
424 fEndPositions= new HashMap(); | |
425 fPositionUpdaters= new ArrayList(); | |
426 fDocumentListeners= new ListenerList(ListenerList.IDENTITY); | |
427 fPrenotifiedDocumentListeners= new ListenerList(ListenerList.IDENTITY); | |
428 fDocumentPartitioningListeners= new ListenerList(ListenerList.IDENTITY); | |
429 fDocumentRewriteSessionListeners= new ArrayList(); | |
430 | |
431 addPositionCategory(DEFAULT_CATEGORY); | |
432 addPositionUpdater(new DefaultPositionUpdater(DEFAULT_CATEGORY)); | |
433 } | |
434 | |
435 | |
436 //------------------------------------------------------- | |
437 | |
438 /* | |
439 * @see dwtx.jface.text.IDocument#addDocumentListener(dwtx.jface.text.IDocumentListener) | |
440 */ | |
441 public void addDocumentListener(IDocumentListener listener) { | |
162 | 442 Assert.isNotNull(cast(Object)listener); |
443 fDocumentListeners.add(cast(Object)listener); | |
129 | 444 } |
445 | |
446 /* | |
447 * @see dwtx.jface.text.IDocument#removeDocumentListener(dwtx.jface.text.IDocumentListener) | |
448 */ | |
449 public void removeDocumentListener(IDocumentListener listener) { | |
162 | 450 Assert.isNotNull(cast(Object)listener); |
451 fDocumentListeners.remove(cast(Object)listener); | |
129 | 452 } |
453 | |
454 /* | |
455 * @see dwtx.jface.text.IDocument#addPrenotifiedDocumentListener(dwtx.jface.text.IDocumentListener) | |
456 */ | |
457 public void addPrenotifiedDocumentListener(IDocumentListener listener) { | |
162 | 458 Assert.isNotNull(cast(Object)listener); |
459 fPrenotifiedDocumentListeners.add(cast(Object)listener); | |
129 | 460 } |
461 | |
462 /* | |
463 * @see dwtx.jface.text.IDocument#removePrenotifiedDocumentListener(dwtx.jface.text.IDocumentListener) | |
464 */ | |
465 public void removePrenotifiedDocumentListener(IDocumentListener listener) { | |
162 | 466 Assert.isNotNull(cast(Object)listener); |
467 fPrenotifiedDocumentListeners.remove(cast(Object)listener); | |
129 | 468 } |
469 | |
470 /* | |
471 * @see dwtx.jface.text.IDocument#addDocumentPartitioningListener(dwtx.jface.text.IDocumentPartitioningListener) | |
472 */ | |
473 public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) { | |
162 | 474 Assert.isNotNull(cast(Object)listener); |
475 fDocumentPartitioningListeners.add(cast(Object)listener); | |
129 | 476 } |
477 | |
478 /* | |
479 * @see dwtx.jface.text.IDocument#removeDocumentPartitioningListener(dwtx.jface.text.IDocumentPartitioningListener) | |
480 */ | |
481 public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) { | |
162 | 482 Assert.isNotNull(cast(Object)listener); |
483 fDocumentPartitioningListeners.remove(cast(Object)listener); | |
129 | 484 } |
485 | |
486 /* | |
487 * @see dwtx.jface.text.IDocument#addPosition(java.lang.String, dwtx.jface.text.Position) | |
488 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
489 public void addPosition(String category, Position position) { |
129 | 490 |
491 if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) | |
492 throw new BadLocationException(); | |
493 | |
494 if (category is null) | |
495 throw new BadPositionCategoryException(); | |
496 | |
134 | 497 List list= cast(List) fPositions.get(category); |
129 | 498 if (list is null) |
499 throw new BadPositionCategoryException(); | |
500 list.add(computeIndexInPositionList(list, position.offset), position); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
501 |
134 | 502 List endPositions= cast(List) fEndPositions.get(category); |
129 | 503 if (endPositions is null) |
504 throw new BadPositionCategoryException(); | |
505 endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position); | |
506 } | |
507 | |
508 /* | |
509 * @see dwtx.jface.text.IDocument#addPosition(dwtx.jface.text.Position) | |
510 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
511 public void addPosition(Position position) { |
129 | 512 try { |
513 addPosition(DEFAULT_CATEGORY, position); | |
514 } catch (BadPositionCategoryException e) { | |
515 } | |
516 } | |
517 | |
518 /* | |
519 * @see dwtx.jface.text.IDocument#addPositionCategory(java.lang.String) | |
520 */ | |
521 public void addPositionCategory(String category) { | |
522 | |
523 if (category is null) | |
524 return; | |
525 | |
526 if (!containsPositionCategory(category)) { | |
527 fPositions.put(category, new ArrayList()); | |
528 fEndPositions.put(category, new ArrayList()); | |
529 } | |
530 } | |
531 | |
532 /* | |
533 * @see dwtx.jface.text.IDocument#addPositionUpdater(dwtx.jface.text.IPositionUpdater) | |
534 */ | |
535 public void addPositionUpdater(IPositionUpdater updater) { | |
536 insertPositionUpdater(updater, fPositionUpdaters.size()); | |
537 } | |
538 | |
539 /* | |
540 * @see dwtx.jface.text.IDocument#containsPosition(java.lang.String, int, int) | |
541 */ | |
542 public bool containsPosition(String category, int offset, int length) { | |
543 | |
544 if (category is null) | |
545 return false; | |
546 | |
134 | 547 List list= cast(List) fPositions.get(category); |
129 | 548 if (list is null) |
549 return false; | |
550 | |
551 int size= list.size(); | |
552 if (size is 0) | |
553 return false; | |
554 | |
555 int index= computeIndexInPositionList(list, offset); | |
556 if (index < size) { | |
134 | 557 Position p= cast(Position) list.get(index); |
129 | 558 while (p !is null && p.offset is offset) { |
559 if (p.length is length) | |
560 return true; | |
561 ++ index; | |
134 | 562 p= (index < size) ? cast(Position) list.get(index) : null; |
129 | 563 } |
564 } | |
565 | |
566 return false; | |
567 } | |
568 | |
569 /* | |
570 * @see dwtx.jface.text.IDocument#containsPositionCategory(java.lang.String) | |
571 */ | |
572 public bool containsPositionCategory(String category) { | |
573 if (category !is null) | |
574 return fPositions.containsKey(category); | |
575 return false; | |
576 } | |
577 | |
578 | |
579 /** | |
580 * Computes the index in the list of positions at which a position with the given | |
581 * offset would be inserted. The position is supposed to become the first in this list | |
582 * of all positions with the same offset. | |
583 * | |
584 * @param positions the list in which the index is computed | |
585 * @param offset the offset for which the index is computed | |
586 * @return the computed index | |
587 * | |
588 * @see IDocument#computeIndexInCategory(String, int) | |
589 * @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, bool)} | |
590 */ | |
591 protected int computeIndexInPositionList(List positions, int offset) { | |
592 return computeIndexInPositionList(positions, offset, true); | |
593 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
594 |
129 | 595 /** |
596 * Computes the index in the list of positions at which a position with the given | |
597 * position would be inserted. The position to insert is supposed to become the first | |
598 * in this list of all positions with the same position. | |
599 * | |
600 * @param positions the list in which the index is computed | |
601 * @param offset the offset for which the index is computed | |
602 * @param orderedByOffset <code>true</code> if ordered by offset, false if ordered by end position | |
603 * @return the computed index | |
604 * @since 3.4 | |
605 */ | |
606 protected int computeIndexInPositionList(List positions, int offset, bool orderedByOffset) { | |
607 if (positions.size() is 0) | |
608 return 0; | |
609 | |
610 int left= 0; | |
611 int right= positions.size() -1; | |
612 int mid= 0; | |
613 Position p= null; | |
614 | |
615 while (left < right) { | |
616 | |
617 mid= (left + right) / 2; | |
618 | |
134 | 619 p= cast(Position) positions.get(mid); |
129 | 620 int pOffset= getOffset(orderedByOffset, p); |
621 if (offset < pOffset) { | |
622 if (left is mid) | |
623 right= left; | |
624 else | |
625 right= mid -1; | |
626 } else if (offset > pOffset) { | |
627 if (right is mid) | |
628 left= right; | |
629 else | |
630 left= mid +1; | |
631 } else if (offset is pOffset) { | |
632 left= right= mid; | |
633 } | |
634 | |
635 } | |
636 | |
637 int pos= left; | |
134 | 638 p= cast(Position) positions.get(pos); |
129 | 639 int pPosition= getOffset(orderedByOffset, p); |
640 if (offset > pPosition) { | |
641 // append to the end | |
642 pos++; | |
643 } else { | |
644 // entry will become the first of all entries with the same offset | |
645 do { | |
646 --pos; | |
647 if (pos < 0) | |
648 break; | |
134 | 649 p= cast(Position) positions.get(pos); |
129 | 650 pPosition= getOffset(orderedByOffset, p); |
651 } while (offset is pPosition); | |
652 ++pos; | |
653 } | |
654 | |
655 Assert.isTrue(0 <= pos && pos <= positions.size()); | |
656 | |
657 return pos; | |
658 } | |
659 | |
660 /* | |
661 * @since 3.4 | |
662 */ | |
663 private int getOffset(bool orderedByOffset, Position position) { | |
664 if (orderedByOffset || position.getLength() is 0) | |
665 return position.getOffset(); | |
666 return position.getOffset() + position.getLength() - 1; | |
667 } | |
668 | |
669 /* | |
670 * @see dwtx.jface.text.IDocument#computeIndexInCategory(java.lang.String, int) | |
671 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
672 public int computeIndexInCategory(String category, int offset) { |
129 | 673 |
674 if (0 > offset || offset > getLength()) | |
675 throw new BadLocationException(); | |
676 | |
134 | 677 List c= cast(List) fPositions.get(category); |
129 | 678 if (c is null) |
679 throw new BadPositionCategoryException(); | |
680 | |
681 return computeIndexInPositionList(c, offset); | |
682 } | |
683 | |
684 /** | |
685 * Fires the document partitioning changed notification to all registered | |
686 * document partitioning listeners. Uses a robust iterator. | |
687 * | |
688 * @deprecated as of 2.0. Use <code>fireDocumentPartitioningChanged(IRegion)</code> instead. | |
689 */ | |
690 protected void fireDocumentPartitioningChanged() { | |
691 if (fDocumentPartitioningListeners is null) | |
692 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
693 |
129 | 694 Object[] listeners= fDocumentPartitioningListeners.getListeners(); |
695 for (int i= 0; i < listeners.length; i++) | |
134 | 696 (cast(IDocumentPartitioningListener)listeners[i]).documentPartitioningChanged(this); |
129 | 697 } |
698 | |
699 /** | |
700 * Fires the document partitioning changed notification to all registered | |
701 * document partitioning listeners. Uses a robust iterator. | |
702 * | |
703 * @param region the region in which partitioning has changed | |
704 * | |
705 * @see IDocumentPartitioningListenerExtension | |
706 * @since 2.0 | |
707 * @deprecated as of 3.0. Use | |
708 * <code>fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent)</code> | |
709 * instead. | |
710 */ | |
711 protected void fireDocumentPartitioningChanged(IRegion region) { | |
712 if (fDocumentPartitioningListeners is null) | |
713 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
714 |
129 | 715 Object[] listeners= fDocumentPartitioningListeners.getListeners(); |
716 for (int i= 0; i < listeners.length; i++) { | |
134 | 717 IDocumentPartitioningListener l= cast(IDocumentPartitioningListener)listeners[i]; |
138 | 718 if ( cast(IDocumentPartitioningListenerExtension)l ) |
134 | 719 (cast(IDocumentPartitioningListenerExtension) l).documentPartitioningChanged(this, region); |
129 | 720 else |
721 l.documentPartitioningChanged(this); | |
722 } | |
723 } | |
724 | |
725 /** | |
726 * Fires the document partitioning changed notification to all registered | |
727 * document partitioning listeners. Uses a robust iterator. | |
728 * | |
729 * @param event the document partitioning changed event | |
730 * | |
731 * @see IDocumentPartitioningListenerExtension2 | |
732 * @since 3.0 | |
733 */ | |
734 protected void fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent event) { | |
735 if (fDocumentPartitioningListeners is null) | |
736 return; | |
737 | |
738 Object[] listeners= fDocumentPartitioningListeners.getListeners(); | |
739 for (int i= 0; i < listeners.length; i++) { | |
134 | 740 IDocumentPartitioningListener l= cast(IDocumentPartitioningListener)listeners[i]; |
138 | 741 if ( cast(IDocumentPartitioningListenerExtension2)l ) { |
134 | 742 IDocumentPartitioningListenerExtension2 extension2= cast(IDocumentPartitioningListenerExtension2) l; |
129 | 743 extension2.documentPartitioningChanged(event); |
138 | 744 } else if ( cast(IDocumentPartitioningListenerExtension)l ) { |
134 | 745 IDocumentPartitioningListenerExtension extension= cast(IDocumentPartitioningListenerExtension) l; |
129 | 746 extension.documentPartitioningChanged(this, event.getCoverage()); |
747 } else { | |
748 l.documentPartitioningChanged(this); | |
749 } | |
750 } | |
751 } | |
752 | |
753 /** | |
754 * Fires the given document event to all registers document listeners informing them | |
755 * about the forthcoming document manipulation. Uses a robust iterator. | |
756 * | |
757 * @param event the event to be sent out | |
758 */ | |
759 protected void fireDocumentAboutToBeChanged(DocumentEvent event) { | |
760 | |
761 // IDocumentExtension | |
762 if (fReentranceCount is 0) | |
763 flushPostNotificationChanges(); | |
764 | |
765 if (fDocumentPartitioners !is null) { | |
766 Iterator e= fDocumentPartitioners.values().iterator(); | |
767 while (e.hasNext()) { | |
134 | 768 IDocumentPartitioner p= cast(IDocumentPartitioner) e.next(); |
138 | 769 if ( cast(IDocumentPartitionerExtension3)p ) { |
134 | 770 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) p; |
129 | 771 if (extension.getActiveRewriteSession() !is null) |
772 continue; | |
773 } | |
774 p.documentAboutToBeChanged(event); | |
775 } | |
776 } | |
777 | |
778 Object[] listeners= fPrenotifiedDocumentListeners.getListeners(); | |
779 for (int i= 0; i < listeners.length; i++) | |
134 | 780 (cast(IDocumentListener)listeners[i]).documentAboutToBeChanged(event); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
781 |
129 | 782 listeners= fDocumentListeners.getListeners(); |
783 for (int i= 0; i < listeners.length; i++) | |
134 | 784 (cast(IDocumentListener)listeners[i]).documentAboutToBeChanged(event); |
129 | 785 } |
786 | |
787 | |
788 /** | |
789 * Updates document partitioning and document positions according to the | |
790 * specification given by the document event. | |
791 * | |
792 * @param event the document event describing the change to which structures must be adapted | |
793 */ | |
794 protected void updateDocumentStructures(DocumentEvent event) { | |
795 | |
796 if (fDocumentPartitioners !is null) { | |
797 fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this); | |
798 Iterator e= fDocumentPartitioners.keySet().iterator(); | |
799 while (e.hasNext()) { | |
162 | 800 String partitioning= stringcast( e.next() ); |
134 | 801 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning); |
129 | 802 |
138 | 803 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 804 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 805 if (extension.getActiveRewriteSession() !is null) |
806 continue; | |
807 } | |
808 | |
138 | 809 if ( cast(IDocumentPartitionerExtension)partitioner ) { |
134 | 810 IDocumentPartitionerExtension extension= cast(IDocumentPartitionerExtension) partitioner; |
129 | 811 IRegion r= extension.documentChanged2(event); |
812 if (r !is null) | |
813 fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, r.getOffset(), r.getLength()); | |
814 } else { | |
815 if (partitioner.documentChanged(event)) | |
816 fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, 0, event.getDocument().getLength()); | |
817 } | |
818 } | |
819 } | |
820 | |
821 if (fPositions.size() > 0) | |
822 updatePositions(event); | |
823 } | |
824 | |
825 /** | |
826 * Notifies all listeners about the given document change. Uses a robust | |
827 * iterator. | |
828 * <p> | |
829 * Executes all registered post notification replace operation. | |
830 * | |
831 * @param event the event to be sent out. | |
832 */ | |
833 protected void doFireDocumentChanged(DocumentEvent event) { | |
834 bool changed= fDocumentPartitioningChangedEvent !is null && !fDocumentPartitioningChangedEvent.isEmpty(); | |
835 IRegion change= changed ? fDocumentPartitioningChangedEvent.getCoverage() : null; | |
836 doFireDocumentChanged(event, changed, change); | |
837 } | |
838 | |
839 /** | |
840 * Notifies all listeners about the given document change. | |
841 * Uses a robust iterator. <p> | |
842 * Executes all registered post notification replace operation. | |
843 * | |
844 * @param event the event to be sent out | |
845 * @param firePartitionChange <code>true</code> if a partition change notification should be sent | |
846 * @param partitionChange the region whose partitioning changed | |
847 * @since 2.0 | |
848 * @deprecated as of 3.0. Use <code>doFireDocumentChanged2(DocumentEvent)</code> instead; this method will be removed. | |
849 */ | |
850 protected void doFireDocumentChanged(DocumentEvent event, bool firePartitionChange, IRegion partitionChange) { | |
851 doFireDocumentChanged2(event); | |
852 } | |
853 | |
854 /** | |
855 * Notifies all listeners about the given document change. Uses a robust | |
856 * iterator. | |
857 * <p> | |
858 * Executes all registered post notification replace operation. | |
859 * <p> | |
860 * This method will be renamed to <code>doFireDocumentChanged</code>. | |
861 * | |
862 * @param event the event to be sent out | |
863 * @since 3.0 | |
864 */ | |
865 protected void doFireDocumentChanged2(DocumentEvent event) { | |
866 | |
867 DocumentPartitioningChangedEvent p= fDocumentPartitioningChangedEvent; | |
868 fDocumentPartitioningChangedEvent= null; | |
869 if (p !is null && !p.isEmpty()) | |
870 fireDocumentPartitioningChanged(p); | |
871 | |
872 Object[] listeners= fPrenotifiedDocumentListeners.getListeners(); | |
873 for (int i= 0; i < listeners.length; i++) | |
134 | 874 (cast(IDocumentListener)listeners[i]).documentChanged(event); |
129 | 875 |
876 listeners= fDocumentListeners.getListeners(); | |
877 for (int i= 0; i < listeners.length; i++) | |
134 | 878 (cast(IDocumentListener)listeners[i]).documentChanged(event); |
129 | 879 |
880 // IDocumentExtension | |
881 ++ fReentranceCount; | |
882 try { | |
883 if (fReentranceCount is 1) | |
884 executePostNotificationChanges(); | |
885 } finally { | |
886 -- fReentranceCount; | |
887 } | |
888 } | |
889 | |
890 /** | |
891 * Updates the internal document structures and informs all document listeners | |
892 * if listener notification has been enabled. Otherwise it remembers the event | |
893 * to be sent to the listeners on resume. | |
894 * | |
895 * @param event the document event to be sent out | |
896 */ | |
897 protected void fireDocumentChanged(DocumentEvent event) { | |
898 updateDocumentStructures(event); | |
899 | |
900 if (fStoppedListenerNotification is 0) | |
901 doFireDocumentChanged(event); | |
902 else | |
903 fDeferredDocumentEvent= event; | |
904 } | |
905 | |
906 /* | |
907 * @see dwtx.jface.text.IDocument#getChar(int) | |
908 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
909 public char getChar(int pos) { |
129 | 910 if ((0 > pos) || (pos >= getLength())) |
911 throw new BadLocationException(); | |
912 return getStore().get(pos); | |
913 } | |
914 | |
915 /* | |
916 * @see dwtx.jface.text.IDocument#getContentType(int) | |
917 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
918 public String getContentType(int offset) { |
129 | 919 String contentType= null; |
920 try { | |
921 contentType= getContentType(DEFAULT_PARTITIONING, offset, false); | |
162 | 922 //Assert.isNotNull(contentType); |
129 | 923 } catch (BadPartitioningException e) { |
924 Assert.isTrue(false); | |
925 } | |
926 return contentType; | |
927 } | |
928 | |
929 /* | |
930 * @see dwtx.jface.text.IDocument#getLegalContentTypes() | |
931 */ | |
932 public String[] getLegalContentTypes() { | |
933 String[] contentTypes= null; | |
934 try { | |
935 contentTypes= getLegalContentTypes(DEFAULT_PARTITIONING); | |
162 | 936 //Assert.isNotNull(contentTypes); |
129 | 937 } catch (BadPartitioningException e) { |
938 Assert.isTrue(false); | |
939 } | |
940 return contentTypes; | |
941 } | |
942 | |
943 /* | |
944 * @see dwtx.jface.text.IDocument#getLength() | |
945 */ | |
946 public int getLength() { | |
947 return getStore().getLength(); | |
948 } | |
949 | |
950 /* | |
951 * @see dwtx.jface.text.IDocument#getLineDelimiter(int) | |
952 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
953 public String getLineDelimiter(int line) { |
129 | 954 return getTracker().getLineDelimiter(line); |
955 } | |
956 | |
957 /* | |
958 * @see dwtx.jface.text.IDocument#getLegalLineDelimiters() | |
959 */ | |
960 public String[] getLegalLineDelimiters() { | |
961 return getTracker().getLegalLineDelimiters(); | |
962 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
963 |
129 | 964 /* |
965 * @see dwtx.jface.text.IDocumentExtension4#getDefaultLineDelimiter() | |
966 * @since 3.1 | |
967 */ | |
968 public String getDefaultLineDelimiter() { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
969 |
129 | 970 String lineDelimiter= null; |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
971 |
129 | 972 try { |
973 lineDelimiter= getLineDelimiter(0); | |
974 } catch (BadLocationException x) { | |
975 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
976 |
129 | 977 if (lineDelimiter !is null) |
978 return lineDelimiter; | |
979 | |
980 if (fInitialLineDelimiter !is null) | |
981 return fInitialLineDelimiter; | |
982 | |
983 String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ | |
984 String[] delimiters= getLegalLineDelimiters(); | |
985 Assert.isTrue(delimiters.length > 0); | |
986 for (int i= 0; i < delimiters.length; i++) { | |
987 if (delimiters[i].equals(sysLineDelimiter)) { | |
988 lineDelimiter= sysLineDelimiter; | |
989 break; | |
990 } | |
991 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
992 |
129 | 993 if (lineDelimiter is null) |
994 lineDelimiter= delimiters[0]; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
995 |
129 | 996 return lineDelimiter; |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
997 |
129 | 998 } |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
999 |
129 | 1000 /* |
1001 * @see dwtx.jface.text.IDocumentExtension4#setInitialLineDelimiter(java.lang.String) | |
1002 * @since 3.1 | |
1003 */ | |
1004 public void setInitialLineDelimiter(String lineDelimiter) { | |
1005 Assert.isNotNull(lineDelimiter); | |
1006 fInitialLineDelimiter= lineDelimiter; | |
1007 } | |
1008 | |
1009 /* | |
1010 * @see dwtx.jface.text.IDocument#getLineLength(int) | |
1011 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1012 public int getLineLength(int line) { |
129 | 1013 return getTracker().getLineLength(line); |
1014 } | |
1015 | |
1016 /* | |
1017 * @see dwtx.jface.text.IDocument#getLineOfOffset(int) | |
1018 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1019 public int getLineOfOffset(int pos) { |
129 | 1020 return getTracker().getLineNumberOfOffset(pos); |
1021 } | |
1022 | |
1023 /* | |
1024 * @see dwtx.jface.text.IDocument#getLineOffset(int) | |
1025 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1026 public int getLineOffset(int line) { |
129 | 1027 return getTracker().getLineOffset(line); |
1028 } | |
1029 | |
1030 /* | |
1031 * @see dwtx.jface.text.IDocument#getLineInformation(int) | |
1032 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1033 public IRegion getLineInformation(int line) { |
129 | 1034 return getTracker().getLineInformation(line); |
1035 } | |
1036 | |
1037 /* | |
1038 * @see dwtx.jface.text.IDocument#getLineInformationOfOffset(int) | |
1039 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1040 public IRegion getLineInformationOfOffset(int offset) { |
129 | 1041 return getTracker().getLineInformationOfOffset(offset); |
1042 } | |
1043 | |
1044 /* | |
1045 * @see dwtx.jface.text.IDocument#getNumberOfLines() | |
1046 */ | |
1047 public int getNumberOfLines() { | |
1048 return getTracker().getNumberOfLines(); | |
1049 } | |
1050 | |
1051 /* | |
1052 * @see dwtx.jface.text.IDocument#getNumberOfLines(int, int) | |
1053 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1054 public int getNumberOfLines(int offset, int length) { |
129 | 1055 return getTracker().getNumberOfLines(offset, length); |
1056 } | |
1057 | |
1058 /* | |
1059 * @see dwtx.jface.text.IDocument#computeNumberOfLines(java.lang.String) | |
1060 */ | |
1061 public int computeNumberOfLines(String text) { | |
1062 return getTracker().computeNumberOfLines(text); | |
1063 } | |
1064 | |
1065 /* | |
1066 * @see dwtx.jface.text.IDocument#getPartition(int) | |
1067 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1068 public ITypedRegion getPartition(int offset) { |
129 | 1069 ITypedRegion partition= null; |
1070 try { | |
1071 partition= getPartition(DEFAULT_PARTITIONING, offset, false); | |
162 | 1072 // Assert.isNotNull(cast(Object)partition); |
129 | 1073 } catch (BadPartitioningException e) { |
1074 Assert.isTrue(false); | |
1075 } | |
1076 return partition; | |
1077 } | |
1078 | |
1079 /* | |
1080 * @see dwtx.jface.text.IDocument#computePartitioning(int, int) | |
1081 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1082 public ITypedRegion[] computePartitioning(int offset, int length) { |
129 | 1083 ITypedRegion[] partitioning= null; |
1084 try { | |
1085 partitioning= computePartitioning(DEFAULT_PARTITIONING, offset, length, false); | |
162 | 1086 // Assert.isNotNull(cast(Object)partitioning); |
129 | 1087 } catch (BadPartitioningException e) { |
1088 Assert.isTrue(false); | |
1089 } | |
1090 return partitioning; | |
1091 } | |
1092 | |
1093 /* | |
1094 * @see dwtx.jface.text.IDocument#getPositions(java.lang.String) | |
1095 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1096 public Position[] getPositions(String category) { |
129 | 1097 |
1098 if (category is null) | |
1099 throw new BadPositionCategoryException(); | |
1100 | |
134 | 1101 List c= cast(List) fPositions.get(category); |
129 | 1102 if (c is null) |
1103 throw new BadPositionCategoryException(); | |
1104 | |
1105 Position[] positions= new Position[c.size()]; | |
1106 c.toArray(positions); | |
1107 return positions; | |
1108 } | |
1109 | |
1110 /* | |
1111 * @see dwtx.jface.text.IDocument#getPositionCategories() | |
1112 */ | |
1113 public String[] getPositionCategories() { | |
1114 String[] categories= new String[fPositions.size()]; | |
1115 Iterator keys= fPositions.keySet().iterator(); | |
1116 for (int i= 0; i < categories.length; i++) | |
162 | 1117 categories[i]= stringcast( keys.next()); |
129 | 1118 return categories; |
1119 } | |
1120 | |
1121 /* | |
1122 * @see dwtx.jface.text.IDocument#getPositionUpdaters() | |
1123 */ | |
1124 public IPositionUpdater[] getPositionUpdaters() { | |
162 | 1125 return arraycast!(IPositionUpdater)(fPositionUpdaters.toArray()); |
129 | 1126 } |
1127 | |
1128 /* | |
1129 * @see dwtx.jface.text.IDocument#get() | |
1130 */ | |
1131 public String get() { | |
1132 return getStore().get(0, getLength()); | |
1133 } | |
1134 | |
1135 /* | |
1136 * @see dwtx.jface.text.IDocument#get(int, int) | |
1137 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1138 public String get(int pos, int length) { |
129 | 1139 int myLength= getLength(); |
1140 if ((0 > pos) || (0 > length) || (pos + length > myLength)) | |
1141 throw new BadLocationException(); | |
1142 return getStore().get(pos, length); | |
1143 } | |
1144 | |
1145 /* | |
1146 * @see dwtx.jface.text.IDocument#insertPositionUpdater(dwtx.jface.text.IPositionUpdater, int) | |
1147 */ | |
1148 public void insertPositionUpdater(IPositionUpdater updater, int index) { | |
1149 | |
1150 for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { | |
162 | 1151 if (fPositionUpdaters.get(i) is cast(Object)updater) |
129 | 1152 return; |
1153 } | |
1154 | |
1155 if (index is fPositionUpdaters.size()) | |
162 | 1156 fPositionUpdaters.add(cast(Object)updater); |
129 | 1157 else |
162 | 1158 fPositionUpdaters.add(index, cast(Object)updater); |
129 | 1159 } |
1160 | |
1161 /* | |
1162 * @see dwtx.jface.text.IDocument#removePosition(java.lang.String, dwtx.jface.text.Position) | |
1163 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1164 public void removePosition(String category, Position position) { |
129 | 1165 |
1166 if (position is null) | |
1167 return; | |
1168 | |
1169 if (category is null) | |
1170 throw new BadPositionCategoryException(); | |
1171 | |
134 | 1172 List c= cast(List) fPositions.get(category); |
129 | 1173 if (c is null) |
1174 throw new BadPositionCategoryException(); | |
1175 removeFromPositionsList(c, position, true); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1176 |
134 | 1177 List endPositions= cast(List) fEndPositions.get(category); |
129 | 1178 if (endPositions is null) |
1179 throw new BadPositionCategoryException(); | |
1180 removeFromPositionsList(endPositions, position, false); | |
1181 } | |
1182 | |
1183 /** | |
1184 * Remove the given position form the given list of positions based on identity not equality. | |
1185 * | |
1186 * @param positions a list of positions | |
1187 * @param position the position to remove | |
1188 * @param orderedByOffset true if <code>positions</code> is ordered by offset, false if ordered by end position | |
1189 * @since 3.4 | |
1190 */ | |
1191 private void removeFromPositionsList(List positions, Position position, bool orderedByOffset) { | |
1192 int size= positions.size(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1193 |
129 | 1194 //Assume position is somewhere near it was before |
1195 int index= computeIndexInPositionList(positions, orderedByOffset ? position.offset : position.offset + position.length - 1, orderedByOffset); | |
1196 if (index < size && positions.get(index) is position) { | |
1197 positions.remove(index); | |
1198 return; | |
1199 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1200 |
129 | 1201 int back= index - 1; |
1202 int forth= index + 1; | |
1203 while (back >= 0 || forth < size) { | |
1204 if (back >= 0) { | |
1205 if (position is positions.get(back)) { | |
1206 positions.remove(back); | |
1207 return; | |
1208 } | |
1209 back--; | |
1210 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1211 |
129 | 1212 if (forth < size) { |
1213 if (position is positions.get(forth)) { | |
1214 positions.remove(forth); | |
1215 return; | |
1216 } | |
1217 forth++; | |
1218 } | |
1219 } | |
1220 } | |
1221 | |
1222 /* | |
1223 * @see dwtx.jface.text.IDocument#removePosition(dwtx.jface.text.Position) | |
1224 */ | |
1225 public void removePosition(Position position) { | |
1226 try { | |
1227 removePosition(DEFAULT_CATEGORY, position); | |
1228 } catch (BadPositionCategoryException e) { | |
1229 } | |
1230 } | |
1231 | |
1232 /* | |
1233 * @see dwtx.jface.text.IDocument#removePositionCategory(java.lang.String) | |
1234 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1235 public void removePositionCategory(String category) { |
129 | 1236 |
1237 if (category is null) | |
1238 return; | |
1239 | |
1240 if ( !containsPositionCategory(category)) | |
1241 throw new BadPositionCategoryException(); | |
1242 | |
1243 fPositions.remove(category); | |
1244 fEndPositions.remove(category); | |
1245 } | |
1246 | |
1247 /* | |
1248 * @see dwtx.jface.text.IDocument#removePositionUpdater(dwtx.jface.text.IPositionUpdater) | |
1249 */ | |
1250 public void removePositionUpdater(IPositionUpdater updater) { | |
1251 for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { | |
162 | 1252 if (fPositionUpdaters.get(i) is cast(Object)updater) { |
129 | 1253 fPositionUpdaters.remove(i); |
1254 return; | |
1255 } | |
1256 } | |
1257 } | |
1258 | |
1259 private long getNextModificationStamp() { | |
1260 if (fNextModificationStamp is Long.MAX_VALUE || fNextModificationStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) | |
1261 fNextModificationStamp= 0; | |
1262 else | |
1263 fNextModificationStamp= fNextModificationStamp + 1; | |
1264 | |
1265 return fNextModificationStamp; | |
1266 } | |
1267 | |
1268 /* | |
1269 * @see dwtx.jface.text.IDocumentExtension4#getModificationStamp() | |
1270 * @since 3.1 | |
1271 */ | |
1272 public long getModificationStamp() { | |
1273 return fModificationStamp; | |
1274 } | |
1275 | |
1276 /* | |
1277 * @see dwtx.jface.text.IDocument#replace(int, int, java.lang.String) | |
1278 * @since 3.1 | |
1279 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1280 public void replace(int pos, int length, String text, long modificationStamp) { |
129 | 1281 if ((0 > pos) || (0 > length) || (pos + length > getLength())) |
1282 throw new BadLocationException(); | |
1283 | |
1284 DocumentEvent e= new DocumentEvent(this, pos, length, text); | |
1285 fireDocumentAboutToBeChanged(e); | |
1286 | |
1287 getStore().replace(pos, length, text); | |
1288 getTracker().replace(pos, length, text); | |
1289 | |
1290 fModificationStamp= modificationStamp; | |
1291 fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp); | |
1292 e.fModificationStamp= fModificationStamp; | |
1293 | |
1294 fireDocumentChanged(e); | |
1295 } | |
1296 | |
1297 /** | |
1298 * {@inheritDoc} | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1299 * |
129 | 1300 * @since 3.4 |
1301 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1302 public bool isLineInformationRepairNeeded(int offset, int length, String text) { |
129 | 1303 return false; |
1304 } | |
1305 | |
1306 /* | |
1307 * @see dwtx.jface.text.IDocument#replace(int, int, java.lang.String) | |
1308 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1309 public void replace(int pos, int length, String text) { |
162 | 1310 if (length is 0 && (text is null || text.length is 0)) |
129 | 1311 replace(pos, length, text, getModificationStamp()); |
1312 else | |
1313 replace(pos, length, text, getNextModificationStamp()); | |
1314 } | |
1315 | |
1316 /* | |
1317 * @see dwtx.jface.text.IDocument#set(java.lang.String) | |
1318 */ | |
1319 public void set(String text) { | |
1320 set(text, getNextModificationStamp()); | |
1321 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1322 |
129 | 1323 /* |
1324 * @see dwtx.jface.text.IDocumentExtension4#set(java.lang.String, long) | |
1325 * @since 3.1 | |
1326 */ | |
1327 public void set(String text, long modificationStamp) { | |
1328 int length= getStore().getLength(); | |
1329 | |
1330 DocumentEvent e= new DocumentEvent(this, 0, length, text); | |
1331 fireDocumentAboutToBeChanged(e); | |
1332 | |
1333 getStore().set(text); | |
1334 getTracker().set(text); | |
1335 | |
1336 fModificationStamp= modificationStamp; | |
1337 fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp); | |
1338 e.fModificationStamp= fModificationStamp; | |
1339 | |
1340 fireDocumentChanged(e); | |
1341 } | |
1342 | |
1343 /** | |
1344 * Updates all positions of all categories to the change described by the | |
1345 * document event. All registered document updaters are called in the | |
1346 * sequence they have been arranged. Uses a robust iterator. | |
1347 * | |
1348 * @param event the document event describing the change to which to adapt | |
1349 * the positions | |
1350 */ | |
1351 protected void updatePositions(DocumentEvent event) { | |
1352 List list= new ArrayList(fPositionUpdaters); | |
1353 Iterator e= list.iterator(); | |
1354 while (e.hasNext()) { | |
134 | 1355 IPositionUpdater u= cast(IPositionUpdater) e.next(); |
129 | 1356 u.update(event); |
1357 } | |
1358 } | |
1359 | |
1360 /* | |
1361 * @see dwtx.jface.text.IDocument#search(int, java.lang.String, bool, bool, bool) | |
1362 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1363 public int search(int startPosition, String findString, bool forwardSearch, bool caseSensitive, bool wholeWord) { |
129 | 1364 try { |
1365 IRegion region= getFindReplaceDocumentAdapter().find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false); | |
1366 return region is null ? -1 : region.getOffset(); | |
1367 } catch (IllegalStateException ex) { | |
1368 return -1; | |
1369 } catch (PatternSyntaxException ex) { | |
1370 return -1; | |
1371 } | |
1372 } | |
1373 | |
1374 /** | |
1375 * Returns the find/replace adapter for this document. | |
1376 * | |
1377 * @return this document's find/replace document adapter | |
1378 * @since 3.0 | |
1379 */ | |
1380 private FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() { | |
1381 if (fFindReplaceDocumentAdapter is null) | |
1382 fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(this); | |
1383 | |
1384 return fFindReplaceDocumentAdapter; | |
1385 } | |
1386 | |
1387 /** | |
1388 * Flushes all registered post notification changes. | |
1389 * | |
1390 * @since 2.0 | |
1391 */ | |
1392 private void flushPostNotificationChanges() { | |
1393 if (fPostNotificationChanges !is null) | |
1394 fPostNotificationChanges.clear(); | |
1395 } | |
1396 | |
1397 /** | |
1398 * Executes all registered post notification changes. The process is | |
1399 * repeated until no new post notification changes are added. | |
1400 * | |
1401 * @since 2.0 | |
1402 */ | |
1403 private void executePostNotificationChanges() { | |
1404 | |
1405 if (fStoppedCount > 0) | |
1406 return; | |
1407 | |
1408 while (fPostNotificationChanges !is null) { | |
1409 List changes= fPostNotificationChanges; | |
1410 fPostNotificationChanges= null; | |
1411 | |
1412 Iterator e= changes.iterator(); | |
1413 while (e.hasNext()) { | |
134 | 1414 RegisteredReplace replace= cast(RegisteredReplace) e.next(); |
129 | 1415 replace.fReplace.perform(this, replace.fOwner); |
1416 } | |
1417 } | |
1418 } | |
1419 | |
1420 /* | |
1421 * @see dwtx.jface.text.IDocumentExtension2#acceptPostNotificationReplaces() | |
1422 * @since 2.1 | |
1423 */ | |
1424 public void acceptPostNotificationReplaces() { | |
1425 fAcceptPostNotificationReplaces= true; | |
1426 } | |
1427 | |
1428 /* | |
1429 * @see dwtx.jface.text.IDocumentExtension2#ignorePostNotificationReplaces() | |
1430 * @since 2.1 | |
1431 */ | |
1432 public void ignorePostNotificationReplaces() { | |
1433 fAcceptPostNotificationReplaces= false; | |
1434 } | |
1435 | |
1436 /* | |
1437 * @see dwtx.jface.text.IDocumentExtension#registerPostNotificationReplace(dwtx.jface.text.IDocumentListener, dwtx.jface.text.IDocumentExtension.IReplace) | |
1438 * @since 2.0 | |
1439 */ | |
1440 public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { | |
1441 if (fAcceptPostNotificationReplaces) { | |
1442 if (fPostNotificationChanges is null) | |
1443 fPostNotificationChanges= new ArrayList(1); | |
1444 fPostNotificationChanges.add(new RegisteredReplace(owner, replace)); | |
1445 } | |
1446 } | |
1447 | |
1448 /* | |
1449 * @see dwtx.jface.text.IDocumentExtension#stopPostNotificationProcessing() | |
1450 * @since 2.0 | |
1451 */ | |
1452 public void stopPostNotificationProcessing() { | |
1453 ++ fStoppedCount; | |
1454 } | |
1455 | |
1456 /* | |
1457 * @see dwtx.jface.text.IDocumentExtension#resumePostNotificationProcessing() | |
1458 * @since 2.0 | |
1459 */ | |
1460 public void resumePostNotificationProcessing() { | |
1461 -- fStoppedCount; | |
1462 if (fStoppedCount is 0 && fReentranceCount is 0) | |
1463 executePostNotificationChanges(); | |
1464 } | |
1465 | |
1466 /* | |
1467 * @see dwtx.jface.text.IDocumentExtension#startSequentialRewrite(bool) | |
1468 * @since 2.0 | |
1469 */ | |
1470 public void startSequentialRewrite(bool normalized) { | |
1471 } | |
1472 | |
1473 /* | |
1474 * @see dwtx.jface.text.IDocumentExtension#stopSequentialRewrite() | |
1475 * @since 2.0 | |
1476 */ | |
1477 public void stopSequentialRewrite() { | |
1478 } | |
1479 | |
1480 /* | |
1481 * @see dwtx.jface.text.IDocumentExtension2#resumeListenerNotification() | |
1482 * @since 2.1 | |
1483 */ | |
1484 public void resumeListenerNotification() { | |
1485 -- fStoppedListenerNotification; | |
1486 if (fStoppedListenerNotification is 0) { | |
1487 resumeDocumentListenerNotification(); | |
1488 } | |
1489 } | |
1490 | |
1491 /* | |
1492 * @see dwtx.jface.text.IDocumentExtension2#stopListenerNotification() | |
1493 * @since 2.1 | |
1494 */ | |
1495 public void stopListenerNotification() { | |
1496 ++ fStoppedListenerNotification; | |
1497 } | |
1498 | |
1499 /** | |
1500 * Resumes the document listener notification by sending out the remembered | |
1501 * partition changed and document event. | |
1502 * | |
1503 * @since 2.1 | |
1504 */ | |
1505 private void resumeDocumentListenerNotification() { | |
1506 if (fDeferredDocumentEvent !is null) { | |
1507 DocumentEvent event= fDeferredDocumentEvent; | |
1508 fDeferredDocumentEvent= null; | |
1509 doFireDocumentChanged(event); | |
1510 } | |
1511 } | |
1512 | |
1513 /* | |
1514 * @see dwtx.jface.text.IDocumentExtension3#computeZeroLengthPartitioning(java.lang.String, int, int) | |
1515 * @since 3.0 | |
1516 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1517 public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, bool includeZeroLengthPartitions) { |
129 | 1518 if ((0 > offset) || (0 > length) || (offset + length > getLength())) |
1519 throw new BadLocationException(); | |
1520 | |
1521 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1522 | |
138 | 1523 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1524 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1525 return (cast(IDocumentPartitionerExtension2) partitioner).computePartitioning(offset, length, includeZeroLengthPartitions); |
129 | 1526 } else if (partitioner !is null) { |
1527 checkStateOfPartitioner(partitioner, partitioning); | |
1528 return partitioner.computePartitioning(offset, length); | |
1529 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1530 return [ new TypedRegion(offset, length, DEFAULT_CONTENT_TYPE) ]; |
129 | 1531 else |
1532 throw new BadPartitioningException(); | |
1533 } | |
1534 | |
1535 /* | |
1536 * @see dwtx.jface.text.IDocumentExtension3#getZeroLengthContentType(java.lang.String, int) | |
1537 * @since 3.0 | |
1538 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1539 public String getContentType(String partitioning, int offset, bool preferOpenPartitions) { |
129 | 1540 if ((0 > offset) || (offset > getLength())) |
1541 throw new BadLocationException(); | |
1542 | |
1543 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1544 | |
138 | 1545 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1546 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1547 return (cast(IDocumentPartitionerExtension2) partitioner).getContentType(offset, preferOpenPartitions); |
129 | 1548 } else if (partitioner !is null) { |
1549 checkStateOfPartitioner(partitioner, partitioning); | |
1550 return partitioner.getContentType(offset); | |
1551 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
1552 return DEFAULT_CONTENT_TYPE; | |
1553 else | |
1554 throw new BadPartitioningException(); | |
1555 } | |
1556 | |
1557 /* | |
1558 * @see dwtx.jface.text.IDocumentExtension3#getDocumentPartitioner(java.lang.String) | |
1559 * @since 3.0 | |
1560 */ | |
1561 public IDocumentPartitioner getDocumentPartitioner(String partitioning) { | |
134 | 1562 return fDocumentPartitioners !is null ? cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning) : null; |
129 | 1563 } |
1564 | |
1565 /* | |
1566 * @see dwtx.jface.text.IDocumentExtension3#getLegalContentTypes(java.lang.String) | |
1567 * @since 3.0 | |
1568 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1569 public String[] getLegalContentTypes(String partitioning) { |
129 | 1570 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); |
1571 if (partitioner !is null) | |
1572 return partitioner.getLegalContentTypes(); | |
1573 if (DEFAULT_PARTITIONING.equals(partitioning)) | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1574 return [ DEFAULT_CONTENT_TYPE ]; |
129 | 1575 throw new BadPartitioningException(); |
1576 } | |
1577 | |
1578 /* | |
1579 * @see dwtx.jface.text.IDocumentExtension3#getZeroLengthPartition(java.lang.String, int) | |
1580 * @since 3.0 | |
1581 */ | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1582 public ITypedRegion getPartition(String partitioning, int offset, bool preferOpenPartitions) { |
129 | 1583 if ((0 > offset) || (offset > getLength())) |
1584 throw new BadLocationException(); | |
1585 | |
1586 IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning); | |
1587 | |
138 | 1588 if ( cast(IDocumentPartitionerExtension2)partitioner ) { |
129 | 1589 checkStateOfPartitioner(partitioner, partitioning); |
134 | 1590 return (cast(IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions); |
129 | 1591 } else if (partitioner !is null) { |
1592 checkStateOfPartitioner(partitioner, partitioning); | |
1593 return partitioner.getPartition(offset); | |
1594 } else if (DEFAULT_PARTITIONING.equals(partitioning)) | |
1595 return new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE); | |
1596 else | |
1597 throw new BadPartitioningException(); | |
1598 } | |
1599 | |
1600 /* | |
1601 * @see dwtx.jface.text.IDocumentExtension3#getPartitionings() | |
1602 * @since 3.0 | |
1603 */ | |
1604 public String[] getPartitionings() { | |
1605 if (fDocumentPartitioners is null) | |
1606 return new String[0]; | |
162 | 1607 return stringcast(fDocumentPartitioners.keySet().toArray()); |
129 | 1608 } |
1609 | |
1610 /* | |
1611 * @see dwtx.jface.text.IDocumentExtension3#setDocumentPartitioner(java.lang.String, dwtx.jface.text.IDocumentPartitioner) | |
1612 * @since 3.0 | |
1613 */ | |
1614 public void setDocumentPartitioner(String partitioning, IDocumentPartitioner partitioner) { | |
1615 if (partitioner is null) { | |
1616 if (fDocumentPartitioners !is null) { | |
1617 fDocumentPartitioners.remove(partitioning); | |
1618 if (fDocumentPartitioners.size() is 0) | |
1619 fDocumentPartitioners= null; | |
1620 } | |
1621 } else { | |
1622 if (fDocumentPartitioners is null) | |
1623 fDocumentPartitioners= new HashMap(); | |
162 | 1624 fDocumentPartitioners.put(partitioning, cast(Object)partitioner); |
129 | 1625 } |
1626 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1627 event.setPartitionChange(partitioning, 0, getLength()); | |
1628 fireDocumentPartitioningChanged(event); | |
1629 } | |
1630 | |
1631 /* | |
1632 * @see dwtx.jface.text.IRepairableDocument#repairLineInformation() | |
1633 * @since 3.0 | |
1634 */ | |
1635 public void repairLineInformation() { | |
1636 getTracker().set(get()); | |
1637 } | |
1638 | |
1639 /** | |
1640 * Fires the given event to all registered rewrite session listeners. Uses robust iterators. | |
1641 * | |
1642 * @param event the event to be fired | |
1643 * @since 3.1 | |
1644 */ | |
1645 protected void fireRewriteSessionChanged(DocumentRewriteSessionEvent event) { | |
1646 if (fDocumentRewriteSessionListeners.size() > 0) { | |
1647 List list= new ArrayList(fDocumentRewriteSessionListeners); | |
1648 Iterator e= list.iterator(); | |
1649 while (e.hasNext()) { | |
134 | 1650 IDocumentRewriteSessionListener l= cast(IDocumentRewriteSessionListener) e.next(); |
129 | 1651 l.documentRewriteSessionChanged(event); |
1652 } | |
1653 } | |
1654 } | |
1655 | |
1656 /* | |
1657 * @see dwtx.jface.text.IDocumentExtension4#getActiveRewriteSession() | |
1658 */ | |
1659 public final DocumentRewriteSession getActiveRewriteSession() { | |
1660 return fDocumentRewriteSession; | |
1661 } | |
1662 | |
1663 /* | |
1664 * @see dwtx.jface.text.IDocumentExtension4#startRewriteSession(dwtx.jface.text.DocumentRewriteSessionType) | |
1665 * @since 3.1 | |
1666 */ | |
1667 public DocumentRewriteSession startRewriteSession(DocumentRewriteSessionType sessionType) { | |
1668 | |
1669 if (getActiveRewriteSession() !is null) | |
1670 throw new IllegalStateException(); | |
1671 | |
1672 | |
1673 fDocumentRewriteSession= new DocumentRewriteSession(sessionType); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1674 if (DEBUG) |
162 | 1675 System.out_.println(Format("AbstractDocument: Starting rewrite session: {}", fDocumentRewriteSession)); //$NON-NLS-1$ |
129 | 1676 |
1677 fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, fDocumentRewriteSession, DocumentRewriteSessionEvent.SESSION_START)); | |
1678 | |
1679 startRewriteSessionOnPartitioners(fDocumentRewriteSession); | |
1680 | |
1681 ILineTracker tracker= getTracker(); | |
138 | 1682 if ( cast(ILineTrackerExtension)tracker ) { |
134 | 1683 ILineTrackerExtension extension= cast(ILineTrackerExtension) tracker; |
129 | 1684 extension.startRewriteSession(fDocumentRewriteSession); |
1685 } | |
1686 | |
1687 if (DocumentRewriteSessionType.SEQUENTIAL is sessionType) | |
1688 startSequentialRewrite(false); | |
1689 else if (DocumentRewriteSessionType.STRICTLY_SEQUENTIAL is sessionType) | |
1690 startSequentialRewrite(true); | |
1691 | |
1692 return fDocumentRewriteSession; | |
1693 } | |
1694 | |
1695 /** | |
1696 * Starts the given rewrite session. | |
1697 * | |
1698 * @param session the rewrite session | |
1699 * @since 3.1 | |
1700 */ | |
1701 protected final void startRewriteSessionOnPartitioners(DocumentRewriteSession session) { | |
1702 if (fDocumentPartitioners !is null) { | |
1703 Iterator e= fDocumentPartitioners.values().iterator(); | |
1704 while (e.hasNext()) { | |
1705 Object partitioner= e.next(); | |
138 | 1706 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 1707 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1708 extension.startRewriteSession(session); |
1709 } | |
1710 } | |
1711 } | |
1712 } | |
1713 | |
1714 /* | |
1715 * @see dwtx.jface.text.IDocumentExtension4#stopRewriteSession(dwtx.jface.text.DocumentRewriteSession) | |
1716 * @since 3.1 | |
1717 */ | |
1718 public void stopRewriteSession(DocumentRewriteSession session) { | |
1719 if (fDocumentRewriteSession is session) { | |
1720 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1721 if (DEBUG) |
162 | 1722 System.out_.println(Format("AbstractDocument: Stopping rewrite session: {}", session)); //$NON-NLS-1$ |
129 | 1723 |
1724 DocumentRewriteSessionType sessionType= session.getSessionType(); | |
1725 if (DocumentRewriteSessionType.SEQUENTIAL is sessionType || DocumentRewriteSessionType.STRICTLY_SEQUENTIAL is sessionType) | |
1726 stopSequentialRewrite(); | |
1727 | |
1728 ILineTracker tracker= getTracker(); | |
138 | 1729 if ( cast(ILineTrackerExtension)tracker ) { |
134 | 1730 ILineTrackerExtension extension= cast(ILineTrackerExtension) tracker; |
129 | 1731 extension.stopRewriteSession(session, get()); |
1732 } | |
1733 | |
1734 stopRewriteSessionOnPartitioners(fDocumentRewriteSession); | |
1735 | |
1736 fDocumentRewriteSession= null; | |
1737 fireRewriteSessionChanged(new DocumentRewriteSessionEvent(this, session, DocumentRewriteSessionEvent.SESSION_STOP)); | |
1738 } | |
1739 } | |
1740 | |
1741 /** | |
1742 * Stops the given rewrite session. | |
1743 * | |
1744 * @param session the rewrite session | |
1745 * @since 3.1 | |
1746 */ | |
1747 protected final void stopRewriteSessionOnPartitioners(DocumentRewriteSession session) { | |
1748 if (fDocumentPartitioners !is null) { | |
1749 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1750 Iterator e= fDocumentPartitioners.keySet().iterator(); | |
1751 while (e.hasNext()) { | |
162 | 1752 String partitioning= stringcast( e.next()); |
134 | 1753 IDocumentPartitioner partitioner= cast(IDocumentPartitioner) fDocumentPartitioners.get(partitioning); |
138 | 1754 if ( cast(IDocumentPartitionerExtension3)partitioner ) { |
134 | 1755 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1756 extension.stopRewriteSession(session); |
1757 event.setPartitionChange(partitioning, 0, getLength()); | |
1758 } | |
1759 } | |
1760 if (!event.isEmpty()) | |
1761 fireDocumentPartitioningChanged(event); | |
1762 } | |
1763 } | |
1764 | |
1765 /* | |
1766 * @see dwtx.jface.text.IDocumentExtension4#addDocumentRewriteSessionListener(dwtx.jface.text.IDocumentRewriteSessionListener) | |
1767 * @since 3.1 | |
1768 */ | |
1769 public void addDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener) { | |
162 | 1770 Assert.isNotNull(cast(Object)listener); |
1771 if (! fDocumentRewriteSessionListeners.contains(cast(Object)listener)) | |
1772 fDocumentRewriteSessionListeners.add(cast(Object)listener); | |
129 | 1773 } |
1774 | |
1775 /* | |
1776 * @see dwtx.jface.text.IDocumentExtension4#removeDocumentRewriteSessionListener(dwtx.jface.text.IDocumentRewriteSessionListener) | |
1777 * @since 3.1 | |
1778 */ | |
1779 public void removeDocumentRewriteSessionListener(IDocumentRewriteSessionListener listener) { | |
162 | 1780 Assert.isNotNull(cast(Object)listener); |
1781 fDocumentRewriteSessionListeners.remove(cast(Object)listener); | |
129 | 1782 } |
1783 | |
1784 /** | |
1785 * Checks the state for the given partitioner and stops the | |
1786 * active rewrite session. | |
1787 * | |
1788 * @param partitioner the document partitioner to be checked | |
1789 * @param partitioning the document partitioning the partitioner is registered for | |
1790 * @since 3.1 | |
1791 */ | |
1792 protected final void checkStateOfPartitioner(IDocumentPartitioner partitioner, String partitioning) { | |
138 | 1793 if (!( cast(IDocumentPartitionerExtension3)partitioner )) |
129 | 1794 return; |
1795 | |
134 | 1796 IDocumentPartitionerExtension3 extension= cast(IDocumentPartitionerExtension3) partitioner; |
129 | 1797 DocumentRewriteSession session= extension.getActiveRewriteSession(); |
1798 if (session !is null) { | |
1799 extension.stopRewriteSession(session); | |
1800 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1801 if (DEBUG) |
162 | 1802 System.out_.println(Format("AbstractDocument: Flushing rewrite session for partition type: {}", partitioning)); //$NON-NLS-1$ |
129 | 1803 |
1804 DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); | |
1805 event.setPartitionChange(partitioning, 0, getLength()); | |
1806 fireDocumentPartitioningChanged(event); | |
1807 } | |
1808 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1809 |
129 | 1810 /** |
1811 * Returns all positions of the given category that are inside the given region. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1812 * |
129 | 1813 * @param category the position category |
1814 * @param offset the start position of the region, must be >= 0 | |
1815 * @param length the length of the region, must be >= 0 | |
1816 * @param canStartBefore if <code>true</code> then positions are included | |
1817 * which start before the region if they end at or after the regions start | |
1818 * @param canEndAfter if <code>true</code> then positions are included | |
1819 * which end after the region if they start at or before the regions end | |
1820 * @return all positions inside the region of the given category | |
1821 * @throws BadPositionCategoryException if category is undefined in this document | |
1822 * @since 3.4 | |
1823 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1824 public Position[] getPositions(String category, int offset, int length, bool canStartBefore, bool canEndAfter) { |
129 | 1825 if (canStartBefore && canEndAfter || (!canStartBefore && !canEndAfter)) { |
1826 List documentPositions; | |
1827 if (canStartBefore && canEndAfter) { | |
1828 if (offset < getLength() / 2) { | |
1829 documentPositions= getStartingPositions(category, 0, offset + length); | |
1830 } else { | |
1831 documentPositions= getEndingPositions(category, offset, getLength() - offset + 1); | |
1832 } | |
1833 } else { | |
1834 documentPositions= getStartingPositions(category, offset, length); | |
1835 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1836 |
129 | 1837 ArrayList list= new ArrayList(documentPositions.size()); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1838 |
129 | 1839 Position region= new Position(offset, length); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1840 |
129 | 1841 for (Iterator iterator= documentPositions.iterator(); iterator.hasNext();) { |
134 | 1842 Position position= cast(Position) iterator.next(); |
129 | 1843 if (isWithinRegion(region, position, canStartBefore, canEndAfter)) { |
1844 list.add(position); | |
1845 } | |
1846 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1847 |
129 | 1848 Position[] positions= new Position[list.size()]; |
1849 list.toArray(positions); | |
1850 return positions; | |
1851 } else if (canStartBefore) { | |
1852 List list= getEndingPositions(category, offset, length); | |
1853 Position[] positions= new Position[list.size()]; | |
1854 list.toArray(positions); | |
1855 return positions; | |
1856 } else { | |
1857 Assert.isLegal(canEndAfter && !canStartBefore); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1858 |
129 | 1859 List list= getStartingPositions(category, offset, length); |
1860 Position[] positions= new Position[list.size()]; | |
1861 list.toArray(positions); | |
1862 return positions; | |
1863 } | |
1864 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1865 |
129 | 1866 /* |
1867 * @since 3.4 | |
1868 */ | |
1869 private bool isWithinRegion(Position region, Position position, bool canStartBefore, bool canEndAfter) { | |
1870 if (canStartBefore && canEndAfter) { | |
1871 return region.overlapsWith(position.getOffset(), position.getLength()); | |
1872 } else if (canStartBefore) { | |
1873 return region.includes(position.getOffset() + position.getLength() - 1); | |
1874 } else if (canEndAfter) { | |
1875 return region.includes(position.getOffset()); | |
1876 } else { | |
1877 int start= position.getOffset(); | |
1878 return region.includes(start) && region.includes(start + position.getLength() - 1); | |
1879 } | |
1880 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1881 |
129 | 1882 /** |
1883 * A list of positions in the given category with an offset inside the given | |
1884 * region. The order of the positions is arbitrary. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1885 * |
129 | 1886 * @param category the position category |
1887 * @param offset the offset of the region | |
1888 * @param length the length of the region | |
1889 * @return a list of the positions in the region | |
1890 * @throws BadPositionCategoryException if category is undefined in this document | |
1891 * @since 3.4 | |
1892 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1893 private List getStartingPositions(String category, int offset, int length) { |
134 | 1894 List positions= cast(List) fPositions.get(category); |
129 | 1895 if (positions is null) |
1896 throw new BadPositionCategoryException(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1897 |
129 | 1898 int indexStart= computeIndexInPositionList(positions, offset, true); |
1899 int indexEnd= computeIndexInPositionList(positions, offset + length, true); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1900 |
129 | 1901 return positions.subList(indexStart, indexEnd); |
1902 } | |
1903 | |
1904 /** | |
1905 * A list of positions in the given category with an end position inside | |
1906 * the given region. The order of the positions is arbitrary. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1907 * |
129 | 1908 * @param category the position category |
1909 * @param offset the offset of the region | |
1910 * @param length the length of the region | |
1911 * @return a list of the positions in the region | |
1912 * @throws BadPositionCategoryException if category is undefined in this document | |
1913 * @since 3.4 | |
1914 */ | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
1915 private List getEndingPositions(String category, int offset, int length) { |
134 | 1916 List positions= cast(List) fEndPositions.get(category); |
129 | 1917 if (positions is null) |
1918 throw new BadPositionCategoryException(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1919 |
129 | 1920 int indexStart= computeIndexInPositionList(positions, offset, false); |
1921 int indexEnd= computeIndexInPositionList(positions, offset + length, false); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
1922 |
129 | 1923 return positions.subList(indexStart, indexEnd); |
1924 } | |
1925 | |
1926 | |
1927 } |