comparison dwtx/text/undo/DocumentUndoManager.d @ 134:51e6e63f930e

Regex fix for casts
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 01:46:20 +0200
parents c4fb132a086c
children 6dcb0baaa031
comparison
equal deleted inserted replaced
133:7d818bd32d63 134:51e6e63f930e
148 * Undo the change described by this change. 148 * Undo the change described by this change.
149 */ 149 */
150 protected void undoTextChange() { 150 protected void undoTextChange() {
151 try { 151 try {
152 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) 152 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4)
153 ((IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fText 153 (cast(IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fText
154 .length(), fPreservedText, fUndoModificationStamp); 154 .length(), fPreservedText, fUndoModificationStamp);
155 else 155 else
156 fDocumentUndoManager.fDocument.replace(fStart, fText.length(), 156 fDocumentUndoManager.fDocument.replace(fStart, fText.length(),
157 fPreservedText); 157 fPreservedText);
158 } catch (BadLocationException x) { 158 } catch (BadLocationException x) {
163 * @see dwtx.core.commands.operations.IUndoableOperation#canUndo() 163 * @see dwtx.core.commands.operations.IUndoableOperation#canUndo()
164 */ 164 */
165 public bool canUndo() { 165 public bool canUndo() {
166 if (isValid()) { 166 if (isValid()) {
167 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) { 167 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) {
168 long docStamp= ((IDocumentExtension4) fDocumentUndoManager.fDocument) 168 long docStamp= (cast(IDocumentExtension4) fDocumentUndoManager.fDocument)
169 .getModificationStamp(); 169 .getModificationStamp();
170 170
171 // Normal case: an undo is valid if its redo will restore 171 // Normal case: an undo is valid if its redo will restore
172 // document to its current modification stamp 172 // document to its current modification stamp
173 bool canUndo= docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP 173 bool canUndo= docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP
233 * @see dwtx.core.commands.operations.IUndoableOperation#canRedo() 233 * @see dwtx.core.commands.operations.IUndoableOperation#canRedo()
234 */ 234 */
235 public bool canRedo() { 235 public bool canRedo() {
236 if (isValid()) { 236 if (isValid()) {
237 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) { 237 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) {
238 long docStamp= ((IDocumentExtension4) fDocumentUndoManager.fDocument) 238 long docStamp= (cast(IDocumentExtension4) fDocumentUndoManager.fDocument)
239 .getModificationStamp(); 239 .getModificationStamp();
240 return docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP 240 return docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP
241 || docStamp is getUndoModificationStamp(); 241 || docStamp is getUndoModificationStamp();
242 } 242 }
243 // if there is no timestamp to check, simply return true per the 243 // if there is no timestamp to check, simply return true per the
282 * Re-applies the change described by this change. 282 * Re-applies the change described by this change.
283 */ 283 */
284 protected void redoTextChange() { 284 protected void redoTextChange() {
285 try { 285 try {
286 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) 286 if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4)
287 ((IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp); 287 (cast(IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp);
288 else 288 else
289 fDocumentUndoManager.fDocument.replace(fStart, fEnd - fStart, fText); 289 fDocumentUndoManager.fDocument.replace(fStart, fEnd - fStart, fText);
290 } catch (BadLocationException x) { 290 } catch (BadLocationException x) {
291 } 291 }
292 } 292 }
469 469
470 int size= fChanges.size(); 470 int size= fChanges.size();
471 if (size > 0) { 471 if (size > 0) {
472 UndoableTextChange c; 472 UndoableTextChange c;
473 473
474 c= (UndoableTextChange) fChanges.get(0); 474 c= cast(UndoableTextChange) fChanges.get(0);
475 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, true); 475 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, true);
476 476
477 for (int i= size - 1; i >= 0; --i) { 477 for (int i= size - 1; i >= 0; --i) {
478 c= (UndoableTextChange) fChanges.get(i); 478 c= cast(UndoableTextChange) fChanges.get(i);
479 c.undoTextChange(); 479 c.undoTextChange();
480 } 480 }
481 fDocumentUndoManager.resetProcessChangeState(); 481 fDocumentUndoManager.resetProcessChangeState();
482 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, 482 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo,
483 DocumentUndoEvent.UNDONE, true); 483 DocumentUndoEvent.UNDONE, true);
492 492
493 int size= fChanges.size(); 493 int size= fChanges.size();
494 if (size > 0) { 494 if (size > 0) {
495 495
496 UndoableTextChange c; 496 UndoableTextChange c;
497 c= (UndoableTextChange) fChanges.get(size - 1); 497 c= cast(UndoableTextChange) fChanges.get(size - 1);
498 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, true); 498 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, true);
499 499
500 for (int i= 0; i <= size - 1; ++i) { 500 for (int i= 0; i <= size - 1; ++i) {
501 c= (UndoableTextChange) fChanges.get(i); 501 c= cast(UndoableTextChange) fChanges.get(i);
502 c.redoTextChange(); 502 c.redoTextChange();
503 } 503 }
504 fDocumentUndoManager.resetProcessChangeState(); 504 fDocumentUndoManager.resetProcessChangeState();
505 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.REDONE, true); 505 fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.REDONE, true);
506 } 506 }
564 */ 564 */
565 protected long getUndoModificationStamp() { 565 protected long getUndoModificationStamp() {
566 if (fStart > -1) 566 if (fStart > -1)
567 return super.getUndoModificationStamp(); 567 return super.getUndoModificationStamp();
568 else if (fChanges.size() > 0) 568 else if (fChanges.size() > 0)
569 return ((UndoableTextChange) fChanges.get(0)) 569 return (cast(UndoableTextChange) fChanges.get(0))
570 .getUndoModificationStamp(); 570 .getUndoModificationStamp();
571 571
572 return fUndoModificationStamp; 572 return fUndoModificationStamp;
573 } 573 }
574 574
577 */ 577 */
578 protected long getRedoModificationStamp() { 578 protected long getRedoModificationStamp() {
579 if (fStart > -1) 579 if (fStart > -1)
580 return super.getRedoModificationStamp(); 580 return super.getRedoModificationStamp();
581 else if (fChanges.size() > 0) 581 else if (fChanges.size() > 0)
582 return ((UndoableTextChange) fChanges.get(fChanges.size() - 1)) 582 return (cast(UndoableTextChange) fChanges.get(fChanges.size() - 1))
583 .getRedoModificationStamp(); 583 .getRedoModificationStamp();
584 584
585 return fRedoModificationStamp; 585 return fRedoModificationStamp;
586 } 586 }
587 } 587 }
934 void fireDocumentUndo(int offset, String text, String preservedText, Object source, int eventType, bool isCompound) { 934 void fireDocumentUndo(int offset, String text, String preservedText, Object source, int eventType, bool isCompound) {
935 eventType= isCompound ? eventType | DocumentUndoEvent.COMPOUND : eventType; 935 eventType= isCompound ? eventType | DocumentUndoEvent.COMPOUND : eventType;
936 DocumentUndoEvent event= new DocumentUndoEvent(fDocument, offset, text, preservedText, eventType, source); 936 DocumentUndoEvent event= new DocumentUndoEvent(fDocument, offset, text, preservedText, eventType, source);
937 Object[] listeners= fDocumentUndoListeners.getListeners(); 937 Object[] listeners= fDocumentUndoListeners.getListeners();
938 for (int i= 0; i < listeners.length; i++) { 938 for (int i= 0; i < listeners.length; i++) {
939 ((IDocumentUndoListener)listeners[i]).documentUndoNotification(event); 939 (cast(IDocumentUndoListener)listeners[i]).documentUndoNotification(event);
940 } 940 }
941 } 941 }
942 942
943 /** 943 /**
944 * Adds any listeners needed to track the document and the operations 944 * Adds any listeners needed to track the document and the operations
1258 IUndoableOperation [] operations= OperationHistoryFactory.getOperationHistory().getUndoHistory(oldUndoContext); 1258 IUndoableOperation [] operations= OperationHistoryFactory.getOperationHistory().getUndoHistory(oldUndoContext);
1259 for (int i= 0; i < operations.length; i++) { 1259 for (int i= 0; i < operations.length; i++) {
1260 // First replace the undo context 1260 // First replace the undo context
1261 IUndoableOperation op= operations[i]; 1261 IUndoableOperation op= operations[i];
1262 if (op instanceof IContextReplacingOperation) { 1262 if (op instanceof IContextReplacingOperation) {
1263 ((IContextReplacingOperation)op).replaceContext(oldUndoContext, getUndoContext()); 1263 (cast(IContextReplacingOperation)op).replaceContext(oldUndoContext, getUndoContext());
1264 } else { 1264 } else {
1265 op.addContext(getUndoContext()); 1265 op.addContext(getUndoContext());
1266 op.removeContext(oldUndoContext); 1266 op.removeContext(oldUndoContext);
1267 } 1267 }
1268 // Now update the manager that owns the text edit. 1268 // Now update the manager that owns the text edit.
1269 if (op instanceof UndoableTextChange) { 1269 if (op instanceof UndoableTextChange) {
1270 ((UndoableTextChange)op).fDocumentUndoManager= this; 1270 (cast(UndoableTextChange)op).fDocumentUndoManager= this;
1271 } 1271 }
1272 } 1272 }
1273 1273
1274 IUndoableOperation op= OperationHistoryFactory.getOperationHistory().getUndoOperation(getUndoContext()); 1274 IUndoableOperation op= OperationHistoryFactory.getOperationHistory().getUndoOperation(getUndoContext());
1275 if (op !is null && !(op instanceof UndoableTextChange)) 1275 if (op !is null && !(op instanceof UndoableTextChange))
1282 // This also serves to synchronize the modification stamps with the documents. 1282 // This also serves to synchronize the modification stamps with the documents.
1283 UndoableTextChange cmd= new UndoableTextChange(this); 1283 UndoableTextChange cmd= new UndoableTextChange(this);
1284 cmd.fStart= cmd.fEnd= 0; 1284 cmd.fStart= cmd.fEnd= 0;
1285 cmd.fText= cmd.fPreservedText= ""; //$NON-NLS-1$ 1285 cmd.fText= cmd.fPreservedText= ""; //$NON-NLS-1$
1286 if (fDocument instanceof IDocumentExtension4) { 1286 if (fDocument instanceof IDocumentExtension4) {
1287 cmd.fRedoModificationStamp= ((IDocumentExtension4)fDocument).getModificationStamp(); 1287 cmd.fRedoModificationStamp= (cast(IDocumentExtension4)fDocument).getModificationStamp();
1288 if (op !is null) 1288 if (op !is null)
1289 cmd.fUndoModificationStamp= ((UndoableTextChange)op).fRedoModificationStamp; 1289 cmd.fUndoModificationStamp= (cast(UndoableTextChange)op).fRedoModificationStamp;
1290 } 1290 }
1291 addToOperationHistory(cmd); 1291 addToOperationHistory(cmd);
1292 } 1292 }
1293 1293
1294 1294