Mercurial > projects > dwt-addons
comparison dwtx/jface/text/DefaultUndoManager.d @ 134:51e6e63f930e
Regex fix for casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 01:46:20 +0200 |
parents | 7d818bd32d63 |
children | 65801ad2b265 |
comparison
equal
deleted
inserted
replaced
133:7d818bd32d63 | 134:51e6e63f930e |
---|---|
287 */ | 287 */ |
288 protected void undoTextChange() { | 288 protected void undoTextChange() { |
289 try { | 289 try { |
290 IDocument document= fTextViewer.getDocument(); | 290 IDocument document= fTextViewer.getDocument(); |
291 if (document instanceof IDocumentExtension4) | 291 if (document instanceof IDocumentExtension4) |
292 ((IDocumentExtension4)document).replace(fStart, fText.length(), fPreservedText, fUndoModificationStamp); | 292 (cast(IDocumentExtension4)document).replace(fStart, fText.length(), fPreservedText, fUndoModificationStamp); |
293 else | 293 else |
294 document.replace(fStart, fText.length(), fPreservedText); | 294 document.replace(fStart, fText.length(), fPreservedText); |
295 } catch (BadLocationException x) { | 295 } catch (BadLocationException x) { |
296 } | 296 } |
297 } | 297 } |
303 public bool canUndo() { | 303 public bool canUndo() { |
304 | 304 |
305 if (isConnected() && isValid()) { | 305 if (isConnected() && isValid()) { |
306 IDocument doc= fTextViewer.getDocument(); | 306 IDocument doc= fTextViewer.getDocument(); |
307 if (doc instanceof IDocumentExtension4) { | 307 if (doc instanceof IDocumentExtension4) { |
308 long docStamp= ((IDocumentExtension4)doc).getModificationStamp(); | 308 long docStamp= (cast(IDocumentExtension4)doc).getModificationStamp(); |
309 | 309 |
310 // Normal case: an undo is valid if its redo will restore document | 310 // Normal case: an undo is valid if its redo will restore document |
311 // to its current modification stamp | 311 // to its current modification stamp |
312 bool canUndo= docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || | 312 bool canUndo= docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || |
313 docStamp is getRedoModificationStamp(); | 313 docStamp is getRedoModificationStamp(); |
359 */ | 359 */ |
360 public bool canRedo() { | 360 public bool canRedo() { |
361 if (isConnected() && isValid()) { | 361 if (isConnected() && isValid()) { |
362 IDocument doc= fTextViewer.getDocument(); | 362 IDocument doc= fTextViewer.getDocument(); |
363 if (doc instanceof IDocumentExtension4) { | 363 if (doc instanceof IDocumentExtension4) { |
364 long docStamp= ((IDocumentExtension4)doc).getModificationStamp(); | 364 long docStamp= (cast(IDocumentExtension4)doc).getModificationStamp(); |
365 return docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || | 365 return docStamp is IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP || |
366 docStamp is getUndoModificationStamp(); | 366 docStamp is getUndoModificationStamp(); |
367 } | 367 } |
368 // if there is no timestamp to check, simply return true per the 3.0.1 behavior | 368 // if there is no timestamp to check, simply return true per the 3.0.1 behavior |
369 return true; | 369 return true; |
418 */ | 418 */ |
419 protected void redoTextChange() { | 419 protected void redoTextChange() { |
420 try { | 420 try { |
421 IDocument document= fTextViewer.getDocument(); | 421 IDocument document= fTextViewer.getDocument(); |
422 if (document instanceof IDocumentExtension4) | 422 if (document instanceof IDocumentExtension4) |
423 ((IDocumentExtension4)document).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp); | 423 (cast(IDocumentExtension4)document).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp); |
424 else | 424 else |
425 fTextViewer.getDocument().replace(fStart, fEnd - fStart, fText); | 425 fTextViewer.getDocument().replace(fStart, fEnd - fStart, fText); |
426 } catch (BadLocationException x) { | 426 } catch (BadLocationException x) { |
427 } | 427 } |
428 } | 428 } |
615 if (size > 0) { | 615 if (size > 0) { |
616 | 616 |
617 TextCommand c; | 617 TextCommand c; |
618 | 618 |
619 for (int i= size -1; i > 0; --i) { | 619 for (int i= size -1; i > 0; --i) { |
620 c= (TextCommand) fCommands.get(i); | 620 c= cast(TextCommand) fCommands.get(i); |
621 c.undoTextChange(); | 621 c.undoTextChange(); |
622 } | 622 } |
623 | 623 |
624 c= (TextCommand) fCommands.get(0); | 624 c= cast(TextCommand) fCommands.get(0); |
625 c.undo(monitor, uiInfo); | 625 c.undo(monitor, uiInfo); |
626 } | 626 } |
627 | 627 |
628 return Status.OK_STATUS; | 628 return Status.OK_STATUS; |
629 } | 629 } |
638 if (size > 0) { | 638 if (size > 0) { |
639 | 639 |
640 TextCommand c; | 640 TextCommand c; |
641 | 641 |
642 for (int i= 0; i < size -1; ++i) { | 642 for (int i= 0; i < size -1; ++i) { |
643 c= (TextCommand) fCommands.get(i); | 643 c= cast(TextCommand) fCommands.get(i); |
644 c.redoTextChange(); | 644 c.redoTextChange(); |
645 } | 645 } |
646 | 646 |
647 c= (TextCommand) fCommands.get(size -1); | 647 c= cast(TextCommand) fCommands.get(size -1); |
648 c.redo(monitor, uiInfo); | 648 c.redo(monitor, uiInfo); |
649 } | 649 } |
650 return Status.OK_STATUS; | 650 return Status.OK_STATUS; |
651 } | 651 } |
652 | 652 |
716 */ | 716 */ |
717 protected long getUndoModificationStamp() { | 717 protected long getUndoModificationStamp() { |
718 if (fStart > -1) | 718 if (fStart > -1) |
719 return super.getUndoModificationStamp(); | 719 return super.getUndoModificationStamp(); |
720 else if (fCommands.size() > 0) | 720 else if (fCommands.size() > 0) |
721 return ((TextCommand)fCommands.get(0)).getUndoModificationStamp(); | 721 return (cast(TextCommand)fCommands.get(0)).getUndoModificationStamp(); |
722 | 722 |
723 return fUndoModificationStamp; | 723 return fUndoModificationStamp; |
724 } | 724 } |
725 | 725 |
726 /** | 726 /** |
731 */ | 731 */ |
732 protected long getRedoModificationStamp() { | 732 protected long getRedoModificationStamp() { |
733 if (fStart > -1) | 733 if (fStart > -1) |
734 return super.getRedoModificationStamp(); | 734 return super.getRedoModificationStamp(); |
735 else if (fCommands.size() > 0) | 735 else if (fCommands.size() > 0) |
736 return ((TextCommand)fCommands.get(fCommands.size()-1)).getRedoModificationStamp(); | 736 return (cast(TextCommand)fCommands.get(fCommands.size()-1)).getRedoModificationStamp(); |
737 | 737 |
738 return fRedoModificationStamp; | 738 return fRedoModificationStamp; |
739 } | 739 } |
740 } | 740 } |
741 | 741 |
886 public void run() { | 886 public void run() { |
887 // if we are undoing/redoing a command we generated, then ignore | 887 // if we are undoing/redoing a command we generated, then ignore |
888 // the document changes associated with this undo or redo. | 888 // the document changes associated with this undo or redo. |
889 if (event.getOperation() instanceof TextCommand) { | 889 if (event.getOperation() instanceof TextCommand) { |
890 if (fTextViewer instanceof TextViewer) | 890 if (fTextViewer instanceof TextViewer) |
891 ((TextViewer)fTextViewer).ignoreAutoEditStrategies(true); | 891 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(true); |
892 listenToTextChanges(false); | 892 listenToTextChanges(false); |
893 | 893 |
894 // in the undo case only, make sure compounds are closed | 894 // in the undo case only, make sure compounds are closed |
895 if (type is OperationHistoryEvent.ABOUT_TO_UNDO) { | 895 if (type is OperationHistoryEvent.ABOUT_TO_UNDO) { |
896 if (fFoldingIntoCompoundChange) { | 896 if (fFoldingIntoCompoundChange) { |
916 fTextViewer.getTextWidget().getDisplay().syncExec(new Runnable() { | 916 fTextViewer.getTextWidget().getDisplay().syncExec(new Runnable() { |
917 public void run() { | 917 public void run() { |
918 listenToTextChanges(true); | 918 listenToTextChanges(true); |
919 fOperation= null; | 919 fOperation= null; |
920 if (fTextViewer instanceof TextViewer) | 920 if (fTextViewer instanceof TextViewer) |
921 ((TextViewer)fTextViewer).ignoreAutoEditStrategies(false); | 921 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(false); |
922 } | 922 } |
923 }); | 923 }); |
924 } | 924 } |
925 break; | 925 break; |
926 } | 926 } |
1457 * @param length the length of the range | 1457 * @param length the length of the range |
1458 * @since 3.0 | 1458 * @since 3.0 |
1459 */ | 1459 */ |
1460 protected void selectAndReveal(int offset, int length) { | 1460 protected void selectAndReveal(int offset, int length) { |
1461 if (fTextViewer instanceof ITextViewerExtension5) { | 1461 if (fTextViewer instanceof ITextViewerExtension5) { |
1462 ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; | 1462 ITextViewerExtension5 extension= cast(ITextViewerExtension5) fTextViewer; |
1463 extension.exposeModelRange(new Region(offset, length)); | 1463 extension.exposeModelRange(new Region(offset, length)); |
1464 } else if (!fTextViewer.overlapsWithVisibleRegion(offset, length)) | 1464 } else if (!fTextViewer.overlapsWithVisibleRegion(offset, length)) |
1465 fTextViewer.resetVisibleRegion(); | 1465 fTextViewer.resetVisibleRegion(); |
1466 | 1466 |
1467 fTextViewer.setSelectedRange(offset, length); | 1467 fTextViewer.setSelectedRange(offset, length); |