Mercurial > projects > dwt-addons
comparison dwtx/jface/text/TextViewer.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 |
---|---|
296 text= e.getText(); | 296 text= e.getText(); |
297 | 297 |
298 if (length !is 0) { | 298 if (length !is 0) { |
299 try { | 299 try { |
300 | 300 |
301 if (e instanceof SlaveDocumentEvent) { | 301 if ( cast(SlaveDocumentEvent)e ) { |
302 SlaveDocumentEvent slave= cast(SlaveDocumentEvent) e; | 302 SlaveDocumentEvent slave= cast(SlaveDocumentEvent) e; |
303 DocumentEvent master= slave.getMasterEvent(); | 303 DocumentEvent master= slave.getMasterEvent(); |
304 if (master !is null) | 304 if (master !is null) |
305 preservedText= master.getDocument().get(master.getOffset(), master.getLength()); | 305 preservedText= master.getDocument().get(master.getOffset(), master.getLength()); |
306 } else { | 306 } else { |
1123 | 1123 |
1124 IDocument document= this.outer.getDocument(); | 1124 IDocument document= this.outer.getDocument(); |
1125 | 1125 |
1126 if (replaceAll) { | 1126 if (replaceAll) { |
1127 | 1127 |
1128 if (document instanceof IDocumentExtension4) { | 1128 if ( cast(IDocumentExtension4)document ) { |
1129 IDocumentExtension4 extension= cast(IDocumentExtension4) document; | 1129 IDocumentExtension4 extension= cast(IDocumentExtension4) document; |
1130 fRewriteSession= extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL); | 1130 fRewriteSession= extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL); |
1131 } else { | 1131 } else { |
1132 this.outer.setRedraw(false); | 1132 this.outer.setRedraw(false); |
1133 this.outer.startSequentialRewriteMode(false); | 1133 this.outer.startSequentialRewriteMode(false); |
1138 fRememberedPartitioners= TextUtilities.removeDocumentPartitioners(document); | 1138 fRememberedPartitioners= TextUtilities.removeDocumentPartitioners(document); |
1139 } | 1139 } |
1140 | 1140 |
1141 } else { | 1141 } else { |
1142 | 1142 |
1143 if (document instanceof IDocumentExtension4) { | 1143 if ( cast(IDocumentExtension4)document ) { |
1144 IDocumentExtension4 extension= cast(IDocumentExtension4) document; | 1144 IDocumentExtension4 extension= cast(IDocumentExtension4) document; |
1145 extension.stopRewriteSession(fRewriteSession); | 1145 extension.stopRewriteSession(fRewriteSession); |
1146 } else { | 1146 } else { |
1147 this.outer.setRedraw(true); | 1147 this.outer.setRedraw(true); |
1148 this.outer.stopSequentialRewriteMode(); | 1148 this.outer.stopSequentialRewriteMode(); |
2387 | 2387 |
2388 if (fWidgetTokenKeeper is requester) | 2388 if (fWidgetTokenKeeper is requester) |
2389 return true; | 2389 return true; |
2390 | 2390 |
2391 bool accepted= false; | 2391 bool accepted= false; |
2392 if (fWidgetTokenKeeper instanceof IWidgetTokenKeeperExtension) { | 2392 if ( cast(IWidgetTokenKeeperExtension)fWidgetTokenKeeper ) { |
2393 IWidgetTokenKeeperExtension extension= cast(IWidgetTokenKeeperExtension) fWidgetTokenKeeper; | 2393 IWidgetTokenKeeperExtension extension= cast(IWidgetTokenKeeperExtension) fWidgetTokenKeeper; |
2394 accepted= extension.requestWidgetToken(this, priority); | 2394 accepted= extension.requestWidgetToken(this, priority); |
2395 } else { | 2395 } else { |
2396 accepted= fWidgetTokenKeeper.requestWidgetToken(this); | 2396 accepted= fWidgetTokenKeeper.requestWidgetToken(this); |
2397 } | 2397 } |
2548 | 2548 |
2549 /* | 2549 /* |
2550 * @see Viewer#setSelection(ISelection) | 2550 * @see Viewer#setSelection(ISelection) |
2551 */ | 2551 */ |
2552 public void setSelection(ISelection selection, bool reveal) { | 2552 public void setSelection(ISelection selection, bool reveal) { |
2553 if (selection instanceof ITextSelection) { | 2553 if ( cast(ITextSelection)selection ) { |
2554 ITextSelection s= cast(ITextSelection) selection; | 2554 ITextSelection s= cast(ITextSelection) selection; |
2555 setSelectedRange(s.getOffset(), s.getLength()); | 2555 setSelectedRange(s.getOffset(), s.getLength()); |
2556 if (reveal) | 2556 if (reveal) |
2557 revealRange(s.getOffset(), s.getLength()); | 2557 revealRange(s.getOffset(), s.getLength()); |
2558 } | 2558 } |
2782 protected void updateTextListeners(WidgetCommand cmd) { | 2782 protected void updateTextListeners(WidgetCommand cmd) { |
2783 List textListeners= fTextListeners; | 2783 List textListeners= fTextListeners; |
2784 if (textListeners !is null) { | 2784 if (textListeners !is null) { |
2785 textListeners= new ArrayList(textListeners); | 2785 textListeners= new ArrayList(textListeners); |
2786 DocumentEvent event= cmd.event; | 2786 DocumentEvent event= cmd.event; |
2787 if (event instanceof SlaveDocumentEvent) | 2787 if ( cast(SlaveDocumentEvent)event ) |
2788 event= (cast(SlaveDocumentEvent) event).getMasterEvent(); | 2788 event= (cast(SlaveDocumentEvent) event).getMasterEvent(); |
2789 | 2789 |
2790 TextEvent e= new TextEvent(cmd.start, cmd.length, cmd.text, cmd.preservedText, event, redraws()); | 2790 TextEvent e= new TextEvent(cmd.start, cmd.length, cmd.text, cmd.preservedText, event, redraws()); |
2791 for (int i= 0; i < textListeners.size(); i++) { | 2791 for (int i= 0; i < textListeners.size(); i++) { |
2792 ITextListener l= cast(ITextListener) textListeners.get(i); | 2792 ITextListener l= cast(ITextListener) textListeners.get(i); |
2879 * @see Viewer#setInput(Object) | 2879 * @see Viewer#setInput(Object) |
2880 */ | 2880 */ |
2881 public void setInput(Object input) { | 2881 public void setInput(Object input) { |
2882 | 2882 |
2883 IDocument document= null; | 2883 IDocument document= null; |
2884 if (input instanceof IDocument) | 2884 if ( cast(IDocument)input ) |
2885 document= cast(IDocument) input; | 2885 document= cast(IDocument) input; |
2886 | 2886 |
2887 setDocument(document); | 2887 setDocument(document); |
2888 } | 2888 } |
2889 | 2889 |
2965 * @throws BadLocationException in case the specified range is not valid in the master document | 2965 * @throws BadLocationException in case the specified range is not valid in the master document |
2966 * @since 2.1 | 2966 * @since 2.1 |
2967 * @deprecated use <code>updateSlaveDocument</code> instead | 2967 * @deprecated use <code>updateSlaveDocument</code> instead |
2968 */ | 2968 */ |
2969 protected bool updateVisibleDocument(IDocument visibleDocument, int visibleRegionOffset, int visibleRegionLength) { | 2969 protected bool updateVisibleDocument(IDocument visibleDocument, int visibleRegionOffset, int visibleRegionLength) { |
2970 if (visibleDocument instanceof ChildDocument) { | 2970 if ( cast(ChildDocument)visibleDocument ) { |
2971 ChildDocument childDocument= cast(ChildDocument) visibleDocument; | 2971 ChildDocument childDocument= cast(ChildDocument) visibleDocument; |
2972 | 2972 |
2973 IDocument document= childDocument.getParentDocument(); | 2973 IDocument document= childDocument.getParentDocument(); |
2974 int line= document.getLineOfOffset(visibleRegionOffset); | 2974 int line= document.getLineOfOffset(visibleRegionOffset); |
2975 int offset= document.getLineOffset(line); | 2975 int offset= document.getLineOffset(line); |
3552 * @return the offset of the visible region | 3552 * @return the offset of the visible region |
3553 */ | 3553 */ |
3554 protected int _getVisibleRegionOffset() { | 3554 protected int _getVisibleRegionOffset() { |
3555 | 3555 |
3556 IDocument document= getVisibleDocument(); | 3556 IDocument document= getVisibleDocument(); |
3557 if (document instanceof ChildDocument) { | 3557 if ( cast(ChildDocument)document ) { |
3558 ChildDocument cdoc= cast(ChildDocument) document; | 3558 ChildDocument cdoc= cast(ChildDocument) document; |
3559 return cdoc.getParentDocumentRange().getOffset(); | 3559 return cdoc.getParentDocumentRange().getOffset(); |
3560 } | 3560 } |
3561 | 3561 |
3562 return 0; | 3562 return 0; |
3566 * @see ITextViewer#getVisibleRegion() | 3566 * @see ITextViewer#getVisibleRegion() |
3567 */ | 3567 */ |
3568 public IRegion getVisibleRegion() { | 3568 public IRegion getVisibleRegion() { |
3569 | 3569 |
3570 IDocument document= getVisibleDocument(); | 3570 IDocument document= getVisibleDocument(); |
3571 if (document instanceof ChildDocument) { | 3571 if ( cast(ChildDocument)document ) { |
3572 Position p= (cast(ChildDocument) document).getParentDocumentRange(); | 3572 Position p= (cast(ChildDocument) document).getParentDocumentRange(); |
3573 return new Region(p.getOffset(), p.getLength()); | 3573 return new Region(p.getOffset(), p.getLength()); |
3574 } | 3574 } |
3575 | 3575 |
3576 return new Region(0, document is null ? 0 : document.getLength()); | 3576 return new Region(0, document is null ? 0 : document.getLength()); |
3579 /* | 3579 /* |
3580 * @see ITextViewer#overlapsWithVisibleRegion(int, int) | 3580 * @see ITextViewer#overlapsWithVisibleRegion(int, int) |
3581 */ | 3581 */ |
3582 public bool overlapsWithVisibleRegion(int start, int length) { | 3582 public bool overlapsWithVisibleRegion(int start, int length) { |
3583 IDocument document= getVisibleDocument(); | 3583 IDocument document= getVisibleDocument(); |
3584 if (document instanceof ChildDocument) { | 3584 if ( cast(ChildDocument)document ) { |
3585 ChildDocument cdoc= cast(ChildDocument) document; | 3585 ChildDocument cdoc= cast(ChildDocument) document; |
3586 return cdoc.getParentDocumentRange().overlapsWith(start, length); | 3586 return cdoc.getParentDocumentRange().overlapsWith(start, length); |
3587 } else if (document !is null) { | 3587 } else if (document !is null) { |
3588 int size= document.getLength(); | 3588 int size= document.getLength(); |
3589 return (start >= 0 && length >= 0 && start + length <= size); | 3589 return (start >= 0 && length >= 0 && start + length <= size); |
3931 return; | 3931 return; |
3932 | 3932 |
3933 fIgnoreAutoIndent= ignore; | 3933 fIgnoreAutoIndent= ignore; |
3934 | 3934 |
3935 IDocument document= getDocument(); | 3935 IDocument document= getDocument(); |
3936 if (document instanceof IDocumentExtension2) { | 3936 if ( cast(IDocumentExtension2)document ) { |
3937 IDocumentExtension2 extension= cast(IDocumentExtension2) document; | 3937 IDocumentExtension2 extension= cast(IDocumentExtension2) document; |
3938 if (ignore) | 3938 if (ignore) |
3939 extension.ignorePostNotificationReplaces(); | 3939 extension.ignorePostNotificationReplaces(); |
3940 else | 3940 else |
3941 extension.acceptPostNotificationReplaces(); | 3941 extension.acceptPostNotificationReplaces(); |
4154 offset--; | 4154 offset--; |
4155 lines[j + 1]= (lines[j] is -1 ? -1 : d.getLineOfOffset(offset)); | 4155 lines[j + 1]= (lines[j] is -1 ? -1 : d.getLineOfOffset(offset)); |
4156 lineCount += lines[j + 1] - lines[j] + 1; | 4156 lineCount += lines[j + 1] - lines[j] + 1; |
4157 } | 4157 } |
4158 | 4158 |
4159 if (d instanceof IDocumentExtension4) { | 4159 if ( cast(IDocumentExtension4)d ) { |
4160 IDocumentExtension4 extension= cast(IDocumentExtension4) d; | 4160 IDocumentExtension4 extension= cast(IDocumentExtension4) d; |
4161 rewriteSession= extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL); | 4161 rewriteSession= extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL); |
4162 } else { | 4162 } else { |
4163 setRedraw(false); | 4163 setRedraw(false); |
4164 startSequentialRewriteMode(true); | 4164 startSequentialRewriteMode(true); |
4185 } finally { | 4185 } finally { |
4186 | 4186 |
4187 if (partitioners !is null) | 4187 if (partitioners !is null) |
4188 TextUtilities.addDocumentPartitioners(d, partitioners); | 4188 TextUtilities.addDocumentPartitioners(d, partitioners); |
4189 | 4189 |
4190 if (d instanceof IDocumentExtension4) { | 4190 if ( cast(IDocumentExtension4)d ) { |
4191 IDocumentExtension4 extension= cast(IDocumentExtension4) d; | 4191 IDocumentExtension4 extension= cast(IDocumentExtension4) d; |
4192 extension.stopRewriteSession(rewriteSession); | 4192 extension.stopRewriteSession(rewriteSession); |
4193 } else { | 4193 } else { |
4194 stopSequentialRewriteMode(); | 4194 stopSequentialRewriteMode(); |
4195 setRedraw(true); | 4195 setRedraw(true); |
4618 * @return the viewer's visible region if smaller than input document, otherwise <code>null</code> | 4618 * @return the viewer's visible region if smaller than input document, otherwise <code>null</code> |
4619 */ | 4619 */ |
4620 protected IRegion _internalGetVisibleRegion() { | 4620 protected IRegion _internalGetVisibleRegion() { |
4621 | 4621 |
4622 IDocument document= getVisibleDocument(); | 4622 IDocument document= getVisibleDocument(); |
4623 if (document instanceof ChildDocument) { | 4623 if ( cast(ChildDocument)document ) { |
4624 Position p= (cast(ChildDocument) document).getParentDocumentRange(); | 4624 Position p= (cast(ChildDocument) document).getParentDocumentRange(); |
4625 return new Region(p.getOffset(), p.getLength()); | 4625 return new Region(p.getOffset(), p.getLength()); |
4626 } | 4626 } |
4627 | 4627 |
4628 return null; | 4628 return null; |
4798 } | 4798 } |
4799 } | 4799 } |
4800 | 4800 |
4801 fMarkPosition= null; | 4801 fMarkPosition= null; |
4802 | 4802 |
4803 if (oldDocument instanceof IDocumentExtension4) { | 4803 if ( cast(IDocumentExtension4)oldDocument ) { |
4804 IDocumentExtension4 document= cast(IDocumentExtension4) oldDocument; | 4804 IDocumentExtension4 document= cast(IDocumentExtension4) oldDocument; |
4805 document.removeDocumentRewriteSessionListener(fDocumentRewriteSessionListener); | 4805 document.removeDocumentRewriteSessionListener(fDocumentRewriteSessionListener); |
4806 } | 4806 } |
4807 | 4807 |
4808 super.inputChanged(newInput, oldInput); | 4808 super.inputChanged(newInput, oldInput); |
4809 | 4809 |
4810 if (newInput instanceof IDocumentExtension4) { | 4810 if ( cast(IDocumentExtension4)newInput ) { |
4811 IDocumentExtension4 document= cast(IDocumentExtension4) newInput; | 4811 IDocumentExtension4 document= cast(IDocumentExtension4) newInput; |
4812 document.addDocumentRewriteSessionListener(fDocumentRewriteSessionListener); | 4812 document.addDocumentRewriteSessionListener(fDocumentRewriteSessionListener); |
4813 } | 4813 } |
4814 | 4814 |
4815 IDocument newDocument= cast(IDocument) newInput; | 4815 IDocument newDocument= cast(IDocument) newInput; |
4843 * | 4843 * |
4844 * @param topIndex the top index to be set or <code>-1</code> | 4844 * @param topIndex the top index to be set or <code>-1</code> |
4845 * @since 3.0 | 4845 * @since 3.0 |
4846 */ | 4846 */ |
4847 protected void enabledRedrawing(int topIndex) { | 4847 protected void enabledRedrawing(int topIndex) { |
4848 if (fDocumentAdapter instanceof IDocumentAdapterExtension) { | 4848 if ( cast(IDocumentAdapterExtension)fDocumentAdapter ) { |
4849 IDocumentAdapterExtension extension= cast(IDocumentAdapterExtension) fDocumentAdapter; | 4849 IDocumentAdapterExtension extension= cast(IDocumentAdapterExtension) fDocumentAdapter; |
4850 StyledText textWidget= getTextWidget(); | 4850 StyledText textWidget= getTextWidget(); |
4851 if (textWidget !is null && !textWidget.isDisposed()) { | 4851 if (textWidget !is null && !textWidget.isDisposed()) { |
4852 extension.resumeForwardingDocumentChanges(); | 4852 extension.resumeForwardingDocumentChanges(); |
4853 if (topIndex > -1) { | 4853 if (topIndex > -1) { |
4877 */ | 4877 */ |
4878 protected void disableRedrawing() { | 4878 protected void disableRedrawing() { |
4879 if (fViewerState is null) | 4879 if (fViewerState is null) |
4880 fViewerState= new ViewerState(); | 4880 fViewerState= new ViewerState(); |
4881 | 4881 |
4882 if (fDocumentAdapter instanceof IDocumentAdapterExtension) { | 4882 if ( cast(IDocumentAdapterExtension)fDocumentAdapter ) { |
4883 IDocumentAdapterExtension extension= cast(IDocumentAdapterExtension) fDocumentAdapter; | 4883 IDocumentAdapterExtension extension= cast(IDocumentAdapterExtension) fDocumentAdapter; |
4884 extension.stopForwardingDocumentChanges(); | 4884 extension.stopForwardingDocumentChanges(); |
4885 } | 4885 } |
4886 | 4886 |
4887 if (fTextWidget !is null && !fTextWidget.isDisposed()) | 4887 if (fTextWidget !is null && !fTextWidget.isDisposed()) |
4947 * @since 2.0 | 4947 * @since 2.0 |
4948 * @deprecated since 3.1 use {@link IDocumentExtension4#startRewriteSession(DocumentRewriteSessionType)} instead | 4948 * @deprecated since 3.1 use {@link IDocumentExtension4#startRewriteSession(DocumentRewriteSessionType)} instead |
4949 */ | 4949 */ |
4950 protected final void startSequentialRewriteMode(bool normalized) { | 4950 protected final void startSequentialRewriteMode(bool normalized) { |
4951 IDocument document= getDocument(); | 4951 IDocument document= getDocument(); |
4952 if (document instanceof IDocumentExtension) { | 4952 if ( cast(IDocumentExtension)document ) { |
4953 IDocumentExtension extension= cast(IDocumentExtension) document; | 4953 IDocumentExtension extension= cast(IDocumentExtension) document; |
4954 extension.startSequentialRewrite(normalized); | 4954 extension.startSequentialRewrite(normalized); |
4955 } | 4955 } |
4956 } | 4956 } |
4957 | 4957 |
4961 * @since 2.0 | 4961 * @since 2.0 |
4962 * @deprecated since 3.1 use {@link IDocumentExtension4#stopRewriteSession(DocumentRewriteSession)} instead | 4962 * @deprecated since 3.1 use {@link IDocumentExtension4#stopRewriteSession(DocumentRewriteSession)} instead |
4963 */ | 4963 */ |
4964 protected final void stopSequentialRewriteMode() { | 4964 protected final void stopSequentialRewriteMode() { |
4965 IDocument document= getDocument(); | 4965 IDocument document= getDocument(); |
4966 if (document instanceof IDocumentExtension) { | 4966 if ( cast(IDocumentExtension)document ) { |
4967 IDocumentExtension extension= cast(IDocumentExtension) document; | 4967 IDocumentExtension extension= cast(IDocumentExtension) document; |
4968 extension.stopSequentialRewrite(); | 4968 extension.stopSequentialRewrite(); |
4969 } | 4969 } |
4970 } | 4970 } |
4971 | 4971 |
5107 * @param modelRange the model range | 5107 * @param modelRange the model range |
5108 * @return the corresponding widget range, or <code>null</code> | 5108 * @return the corresponding widget range, or <code>null</code> |
5109 * @since 3.1 | 5109 * @since 3.1 |
5110 */ | 5110 */ |
5111 protected IRegion modelRange2ClosestWidgetRange(IRegion modelRange) { | 5111 protected IRegion modelRange2ClosestWidgetRange(IRegion modelRange) { |
5112 if (!(fInformationMapping instanceof IDocumentInformationMappingExtension2)) | 5112 if (!( cast(IDocumentInformationMappingExtension2)fInformationMapping )) |
5113 return modelRange2WidgetRange(modelRange); | 5113 return modelRange2WidgetRange(modelRange); |
5114 | 5114 |
5115 try { | 5115 try { |
5116 if (modelRange.getLength() < 0) { | 5116 if (modelRange.getLength() < 0) { |
5117 Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength()); | 5117 Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength()); |
5357 /* | 5357 /* |
5358 * @see dwtx.jface.text.ITextViewerExtension4#moveFocusToWidgetToken() | 5358 * @see dwtx.jface.text.ITextViewerExtension4#moveFocusToWidgetToken() |
5359 * @since 3.0 | 5359 * @since 3.0 |
5360 */ | 5360 */ |
5361 public bool moveFocusToWidgetToken() { | 5361 public bool moveFocusToWidgetToken() { |
5362 if (fWidgetTokenKeeper instanceof IWidgetTokenKeeperExtension) { | 5362 if ( cast(IWidgetTokenKeeperExtension)fWidgetTokenKeeper ) { |
5363 IWidgetTokenKeeperExtension extension= cast(IWidgetTokenKeeperExtension) fWidgetTokenKeeper; | 5363 IWidgetTokenKeeperExtension extension= cast(IWidgetTokenKeeperExtension) fWidgetTokenKeeper; |
5364 return extension.setFocus(this); | 5364 return extension.setFocus(this); |
5365 } | 5365 } |
5366 return false; | 5366 return false; |
5367 } | 5367 } |