Mercurial > projects > dwt-addons
comparison dwtx/jface/text/DocumentCommand.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 7926b636c282 |
children |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
16 | 16 |
17 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport | 17 import dwtx.jface.text.IDocumentPartitioningListener; // packageimport |
18 import dwtx.jface.text.IRegion; // packageimport | 18 import dwtx.jface.text.IRegion; // packageimport |
19 import dwtx.jface.text.IDocumentListener; // packageimport | 19 import dwtx.jface.text.IDocumentListener; // packageimport |
20 import dwtx.jface.text.IDocument; // packageimport | 20 import dwtx.jface.text.IDocument; // packageimport |
21 import dwtx.jface.text.BadLocationException; // packageimport | |
22 import dwtx.jface.text.DefaultPositionUpdater; // packageimport | |
23 import dwtx.jface.text.Position; // packageimport | |
24 import dwtx.jface.text.BadPositionCategoryException; // packageimport | |
21 | 25 |
22 import dwt.dwthelper.utils; | 26 import dwt.dwthelper.utils; |
23 import dwtx.dwtxhelper.Collection; | 27 import dwtx.dwtxhelper.Collection; |
28 import tango.core.Exception; | |
24 | 29 |
25 import dwt.events.VerifyEvent; | 30 import dwt.events.VerifyEvent; |
26 import dwtx.core.runtime.Assert; | 31 import dwtx.core.runtime.Assert; |
27 | 32 |
28 | 33 |
60 * @param owner the document command owner, may be <code>null</code> | 65 * @param owner the document command owner, may be <code>null</code> |
61 * @since 3.0 | 66 * @since 3.0 |
62 */ | 67 */ |
63 public this(int offset, int length, String text, IDocumentListener owner) { | 68 public this(int offset, int length, String text, IDocumentListener owner) { |
64 if (offset < 0 || length < 0) | 69 if (offset < 0 || length < 0) |
65 throw new IllegalArgumentException(); | 70 throw new IllegalArgumentException(null); |
66 fOffset= offset; | 71 fOffset= offset; |
67 fLength= length; | 72 fLength= length; |
68 fText= text; | 73 fText= text; |
69 fOwner= owner; | 74 fOwner= owner; |
70 } | 75 } |
73 * Returns the length delta for this command. | 78 * Returns the length delta for this command. |
74 * | 79 * |
75 * @return the length delta for this command | 80 * @return the length delta for this command |
76 */ | 81 */ |
77 public int getDeltaLength() { | 82 public int getDeltaLength() { |
78 return (fText is null ? 0 : fText.length()) - fLength; | 83 return (fText is null ? 0 : fText.length) - fLength; |
79 } | 84 } |
80 | 85 |
81 /** | 86 /** |
82 * Executes the document command on the specified document. | 87 * Executes the document command on the specified document. |
83 * | 88 * |
139 * Creates a reverse list iterator. | 144 * Creates a reverse list iterator. |
140 * @param listIterator the iterator that this reverse iterator is based upon | 145 * @param listIterator the iterator that this reverse iterator is based upon |
141 */ | 146 */ |
142 public this(ListIterator listIterator) { | 147 public this(ListIterator listIterator) { |
143 if (listIterator is null) | 148 if (listIterator is null) |
144 throw new IllegalArgumentException(); | 149 throw new IllegalArgumentException(null); |
145 fListIterator= listIterator; | 150 fListIterator= listIterator; |
146 } | 151 } |
147 | 152 |
148 /* | 153 /* |
149 * @see java.util.Iterator#hasNext() | 154 * @see java.util.Iterator#hasNext() |
188 * @param command the original command | 193 * @param command the original command |
189 * @param forward the direction | 194 * @param forward the direction |
190 */ | 195 */ |
191 public this(List commands, Command command, bool forward) { | 196 public this(List commands, Command command, bool forward) { |
192 if (commands is null || command is null) | 197 if (commands is null || command is null) |
193 throw new IllegalArgumentException(); | 198 throw new IllegalArgumentException(null); |
194 fIterator= forward ? commands.iterator() : new ReverseListIterator(commands.listIterator(commands.size())); | 199 fIterator= forward ? commands.iterator() : new ReverseListIterator(commands.listIterator(commands.size())); |
195 fCommand= command; | 200 fCommand= command; |
196 fForward= forward; | 201 fForward= forward; |
197 } | 202 } |
198 | 203 |
207 * @see java.util.Iterator#next() | 212 * @see java.util.Iterator#next() |
208 */ | 213 */ |
209 public Object next() { | 214 public Object next() { |
210 | 215 |
211 if (!hasNext()) | 216 if (!hasNext()) |
212 throw new NoSuchElementException(); | 217 throw new NoSuchElementException(null); |
213 | 218 |
214 if (fCommand is null) | 219 if (fCommand is null) |
215 return fIterator.next(); | 220 return fIterator.next(); |
216 | 221 |
217 if (!fIterator.hasNext()) { | 222 if (!fIterator.hasNext()) { |
230 final Command tempCommand= fCommand; | 235 final Command tempCommand= fCommand; |
231 fCommand= command; | 236 fCommand= command; |
232 return tempCommand; | 237 return tempCommand; |
233 | 238 |
234 } else { | 239 } else { |
235 throw new IllegalArgumentException(); | 240 throw new IllegalArgumentException(null); |
236 } | 241 } |
237 } | 242 } |
238 | 243 |
239 /* | 244 /* |
240 * @see java.util.Iterator#remove() | 245 * @see java.util.Iterator#remove() |
264 public int caretOffset; | 269 public int caretOffset; |
265 /** | 270 /** |
266 * Additional document commands. | 271 * Additional document commands. |
267 * @since 2.1 | 272 * @since 2.1 |
268 */ | 273 */ |
269 private const List fCommands= new ArrayList(); | 274 private const List fCommands; |
270 /** | 275 /** |
271 * Indicates whether the caret should be shifted by this command. | 276 * Indicates whether the caret should be shifted by this command. |
272 * @since 3.0 | 277 * @since 3.0 |
273 */ | 278 */ |
274 public bool shiftsCaret; | 279 public bool shiftsCaret; |
275 | 280 |
276 | 281 |
277 /** | 282 /** |
278 * Creates a new document command. | 283 * Creates a new document command. |
279 */ | 284 */ |
280 protected this() { | 285 /+protected+/ this() { |
286 fCommands= new ArrayList(); | |
281 } | 287 } |
282 | 288 |
283 /** | 289 /** |
284 * Translates a verify event into a document replace command using the given offset. | 290 * Translates a verify event into a document replace command using the given offset. |
285 * | 291 * |
433 } catch (BadLocationException e) { | 439 } catch (BadLocationException e) { |
434 // ignore | 440 // ignore |
435 } catch (BadPositionCategoryException e) { | 441 } catch (BadPositionCategoryException e) { |
436 // ignore | 442 // ignore |
437 } finally { | 443 } finally { |
444 delegate(){ | |
438 if (updateCaret()) { | 445 if (updateCaret()) { |
439 document.removePositionUpdater(updater); | 446 document.removePositionUpdater(updater); |
440 try { | 447 try { |
441 document.removePositionCategory(getCategory()); | 448 document.removePositionCategory(getCategory()); |
442 } catch (BadPositionCategoryException e) { | 449 } catch (BadPositionCategoryException e) { |
443 Assert.isTrue(false); | 450 Assert.isTrue(false); |
444 } | 451 } |
445 caretOffset= caretPosition.getOffset(); | 452 caretOffset= caretPosition.getOffset(); |
446 } | 453 } |
454 }(); | |
447 } | 455 } |
448 } | 456 } |
449 | 457 |
450 /** | 458 /** |
451 * Returns <code>true</code> if the caret offset should be updated, <code>false</code> otherwise. | 459 * Returns <code>true</code> if the caret offset should be updated, <code>false</code> otherwise. |