comparison dwtx/jface/text/DefaultUndoManager.d @ 138:b6bad70d540a

Regex instanceof changes
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 02:26:23 +0200
parents 25170b5a8951
children 26688fec6d23
comparison
equal deleted inserted replaced
137:25170b5a8951 138:b6bad70d540a
286 * @since 2.0 286 * @since 2.0
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 ( cast(IDocumentExtension4)document )
292 (cast(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 }
302 */ 302 */
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 ( cast(IDocumentExtension4)doc ) {
308 long docStamp= (cast(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 ||
358 * @since 3.1 358 * @since 3.1
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 ( cast(IDocumentExtension4)doc ) {
364 long docStamp= (cast(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
417 * @since 2.0 417 * @since 2.0
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 ( cast(IDocumentExtension4)document )
423 (cast(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 }
885 fTextViewer.getTextWidget().getDisplay().syncExec(new class() Runnable { 885 fTextViewer.getTextWidget().getDisplay().syncExec(new class() Runnable {
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 ( cast(TextViewer)fTextViewer )
891 (cast(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) {
915 if (event.getOperation() is fOperation) { 915 if (event.getOperation() is fOperation) {
916 fTextViewer.getTextWidget().getDisplay().syncExec(new class() Runnable { 916 fTextViewer.getTextWidget().getDisplay().syncExec(new class() 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 ( cast(TextViewer)fTextViewer )
921 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(false); 921 (cast(TextViewer)fTextViewer).ignoreAutoEditStrategies(false);
922 } 922 }
923 }); 923 });
924 } 924 }
925 break; 925 break;
1456 * @param offset the offset of the range 1456 * @param offset the offset of the range
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 ( cast(ITextViewerExtension5)fTextViewer ) {
1462 ITextViewerExtension5 extension= cast(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