comparison dwtx/jface/text/source/projection/ProjectionViewer.d @ 145:02cd5f1224d3

...
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 22:31:00 +0200
parents 53b889547456
children 000f9136b8f7
comparison
equal deleted inserted replaced
144:16a71f577815 145:02cd5f1224d3
97 public static final int TOGGLE= BASE + 3; 97 public static final int TOGGLE= BASE + 3;
98 /** Operation constant for the expand all operation. */ 98 /** Operation constant for the expand all operation. */
99 public static final int EXPAND_ALL= BASE + 4; 99 public static final int EXPAND_ALL= BASE + 4;
100 /** 100 /**
101 * Operation constant for the collapse all operation. 101 * Operation constant for the collapse all operation.
102 * 102 *
103 * @since 3.2 103 * @since 3.2
104 */ 104 */
105 public static final int COLLAPSE_ALL= BASE + 5; 105 public static final int COLLAPSE_ALL= BASE + 5;
106 106
107 /** 107 /**
486 * Notifies all registered projection listeners 486 * Notifies all registered projection listeners
487 * that projection mode has been enabled. 487 * that projection mode has been enabled.
488 */ 488 */
489 protected void fireProjectionEnabled() { 489 protected void fireProjectionEnabled() {
490 if (fProjectionListeners !is null) { 490 if (fProjectionListeners !is null) {
491 Iterator e= new ArrayList(fProjectionListeners).iterator(); 491 Iterator e= (new ArrayList(fProjectionListeners)).iterator();
492 while (e.hasNext()) { 492 while (e.hasNext()) {
493 IProjectionListener l= cast(IProjectionListener) e.next(); 493 IProjectionListener l= cast(IProjectionListener) e.next();
494 l.projectionEnabled(); 494 l.projectionEnabled();
495 } 495 }
496 } 496 }
500 * Notifies all registered projection listeners 500 * Notifies all registered projection listeners
501 * that projection mode has been disabled. 501 * that projection mode has been disabled.
502 */ 502 */
503 protected void fireProjectionDisabled() { 503 protected void fireProjectionDisabled() {
504 if (fProjectionListeners !is null) { 504 if (fProjectionListeners !is null) {
505 Iterator e= new ArrayList(fProjectionListeners).iterator(); 505 Iterator e= (new ArrayList(fProjectionListeners)).iterator();
506 while (e.hasNext()) { 506 while (e.hasNext()) {
507 IProjectionListener l= cast(IProjectionListener) e.next(); 507 IProjectionListener l= cast(IProjectionListener) e.next();
508 l.projectionDisabled(); 508 l.projectionDisabled();
509 } 509 }
510 } 510 }
676 } finally { 676 } finally {
677 fHandleProjectionChanges= true; 677 fHandleProjectionChanges= true;
678 } 678 }
679 } 679 }
680 } 680 }
681 681
682 /** 682 /**
683 * Returns the first line offset &lt;= <code>offset</code>. If <code>testLastLine</code> 683 * Returns the first line offset &lt;= <code>offset</code>. If <code>testLastLine</code>
684 * is <code>true</code> and the offset is on last line then <code>offset</code> is returned. 684 * is <code>true</code> and the offset is on last line then <code>offset</code> is returned.
685 * 685 *
686 * @param document the document 686 * @param document the document
687 * @param offset the master document offset 687 * @param offset the master document offset
688 * @param testLastLine <code>true</code> if the test for the last line should be performed 688 * @param testLastLine <code>true</code> if the test for the last line should be performed
689 * @return the closest line offset &gt;= <code>offset</code> 689 * @return the closest line offset &gt;= <code>offset</code>
690 * @throws BadLocationException if the offset is invalid 690 * @throws BadLocationException if the offset is invalid
691 * @since 3.2 691 * @since 3.2
692 */ 692 */
693 private int toLineStart(IDocument document, int offset, bool testLastLine) { 693 private int toLineStart(IDocument document, int offset, bool testLastLine) {
694 if (document is null) 694 if (document is null)
695 return offset; 695 return offset;
696 696
697 if (testLastLine && offset >= document.getLineInformationOfOffset(document.getLength() - 1).getOffset()) 697 if (testLastLine && offset >= document.getLineInformationOfOffset(document.getLength() - 1).getOffset())
698 return offset; 698 return offset;
699 699
700 return document.getLineInformationOfOffset(offset).getOffset(); 700 return document.getLineInformationOfOffset(offset).getOffset();
701 } 701 }
702 702
703 /* 703 /*
704 * @see dwtx.jface.text.TextViewer#setVisibleRegion(int, int) 704 * @see dwtx.jface.text.TextViewer#setVisibleRegion(int, int)
832 } 832 }
833 833
834 /** 834 /**
835 * Makes the given range visible again while not changing the folding state of any contained 835 * Makes the given range visible again while not changing the folding state of any contained
836 * ranges. If requested, a redraw request is issued. 836 * ranges. If requested, a redraw request is issued.
837 * 837 *
838 * @param offset the offset of the range to be expanded 838 * @param offset the offset of the range to be expanded
839 * @param length the length of the range to be expanded 839 * @param length the length of the range to be expanded
840 * @param fireRedraw <code>true</code> if a redraw request should be issued, 840 * @param fireRedraw <code>true</code> if a redraw request should be issued,
841 * <code>false</code> otherwise 841 * <code>false</code> otherwise
842 * @throws BadLocationException in case the range is invalid 842 * @throws BadLocationException in case the range is invalid
934 } 934 }
935 } 935 }
936 } 936 }
937 } 937 }
938 } 938 }
939 939
940 /** 940 /**
941 * Tests whether the visible document's master document 941 * Tests whether the visible document's master document
942 * is identical to this viewer's document. 942 * is identical to this viewer's document.
943 * 943 *
944 * @return <code>true</code> if the visible document's master is 944 * @return <code>true</code> if the visible document's master is
945 * identical to this viewer's document 945 * identical to this viewer's document
946 * @since 3.1 946 * @since 3.1
947 */ 947 */
948 private bool isVisibleMasterDocumentSameAsDocument() { 948 private bool isVisibleMasterDocumentSameAsDocument() {
957 * 957 *
958 * @param event the annotation model event or <code>null</code> 958 * @param event the annotation model event or <code>null</code>
959 * @exception BadLocationException in case the annotation model event is no longer in synchronization with the document 959 * @exception BadLocationException in case the annotation model event is no longer in synchronization with the document
960 */ 960 */
961 private void catchupWithProjectionAnnotationModel(AnnotationModelEvent event) { 961 private void catchupWithProjectionAnnotationModel(AnnotationModelEvent event) {
962 962
963 if (event is null || !isVisibleMasterDocumentSameAsDocument()) { 963 if (event is null || !isVisibleMasterDocumentSameAsDocument()) {
964 964
965 fPendingAnnotationWorldChange= false; 965 fPendingAnnotationWorldChange= false;
966 reinitializeProjection(); 966 reinitializeProjection();
967 967
977 if (event.isValid()) { 977 if (event.isValid()) {
978 fPendingAnnotationWorldChange= false; 978 fPendingAnnotationWorldChange= false;
979 reinitializeProjection(); 979 reinitializeProjection();
980 } 980 }
981 } else { 981 } else {
982 982
983 Annotation[] addedAnnotations= event.getAddedAnnotations(); 983 Annotation[] addedAnnotations= event.getAddedAnnotations();
984 Annotation[] changedAnnotation= event.getChangedAnnotations(); 984 Annotation[] changedAnnotation= event.getChangedAnnotations();
985 Annotation[] removedAnnotations= event.getRemovedAnnotations(); 985 Annotation[] removedAnnotations= event.getRemovedAnnotations();
986 986
987 fCommandQueue= new ProjectionCommandQueue(); 987 fCommandQueue= new ProjectionCommandQueue();
988 988
989 bool isRedrawing= redraws(); 989 bool isRedrawing= redraws();
990 int topIndex= isRedrawing ? getTopIndex() : -1; 990 int topIndex= isRedrawing ? getTopIndex() : -1;
991 991
992 processDeletions(event, removedAnnotations, true); 992 processDeletions(event, removedAnnotations, true);
993 List coverage= new ArrayList(); 993 List coverage= new ArrayList();
994 processChanges(addedAnnotations, true, coverage); 994 processChanges(addedAnnotations, true, coverage);
995 processChanges(changedAnnotation, true, coverage); 995 processChanges(changedAnnotation, true, coverage);
996 996
997 ProjectionCommandQueue commandQueue= fCommandQueue; 997 ProjectionCommandQueue commandQueue= fCommandQueue;
998 fCommandQueue= null; 998 fCommandQueue= null;
999 999
1000 if (commandQueue.passedRedrawCostsThreshold()) { 1000 if (commandQueue.passedRedrawCostsThreshold()) {
1001 setRedraw(false); 1001 setRedraw(false);
1002 try { 1002 try {
1003 executeProjectionCommands(commandQueue, false); 1003 executeProjectionCommands(commandQueue, false);
1004 } catch (IllegalArgumentException x) { 1004 } catch (IllegalArgumentException x) {
1104 public IRegion computeCollapsedRegion(Position position) { 1104 public IRegion computeCollapsedRegion(Position position) {
1105 try { 1105 try {
1106 IDocument document= getDocument(); 1106 IDocument document= getDocument();
1107 if (document is null) 1107 if (document is null)
1108 return null; 1108 return null;
1109 1109
1110 int line= document.getLineOfOffset(position.getOffset()); 1110 int line= document.getLineOfOffset(position.getOffset());
1111 int offset= document.getLineOffset(line + 1); 1111 int offset= document.getLineOffset(line + 1);
1112 1112
1113 int length= position.getLength() - (offset - position.getOffset()); 1113 int length= position.getLength() - (offset - position.getOffset());
1114 if (length > 0) 1114 if (length > 0)
1142 int line= document.getLineOfOffset(position.getOffset()); 1142 int line= document.getLineOfOffset(position.getOffset());
1143 int offset= document.getLineOffset(line + 1); 1143 int offset= document.getLineOffset(line + 1);
1144 1144
1145 int length= position.getLength() - (offset - position.getOffset()); 1145 int length= position.getLength() - (offset - position.getOffset());
1146 if (length > 0) 1146 if (length > 0)
1147 return new IRegion[] {new Region(offset, length)}; 1147 return [new Region(offset, length)];
1148 1148
1149 return null; 1149 return null;
1150 } catch (BadLocationException x) { 1150 } catch (BadLocationException x) {
1151 return null; 1151 return null;
1152 } 1152 }
1401 /* 1401 /*
1402 * @see dwtx.jface.text.ITextViewerExtension5#getCoveredModelRanges(dwtx.jface.text.IRegion) 1402 * @see dwtx.jface.text.ITextViewerExtension5#getCoveredModelRanges(dwtx.jface.text.IRegion)
1403 */ 1403 */
1404 public IRegion[] getCoveredModelRanges(IRegion modelRange) { 1404 public IRegion[] getCoveredModelRanges(IRegion modelRange) {
1405 if (fInformationMapping is null) 1405 if (fInformationMapping is null)
1406 return new IRegion[] { new Region(modelRange.getOffset(), modelRange.getLength()) }; 1406 return [ new Region(modelRange.getOffset(), modelRange.getLength()) ];
1407 1407
1408 if ( cast(IDocumentInformationMappingExtension)fInformationMapping ) { 1408 if ( cast(IDocumentInformationMappingExtension)fInformationMapping ) {
1409 IDocumentInformationMappingExtension extension= cast(IDocumentInformationMappingExtension) fInformationMapping; 1409 IDocumentInformationMappingExtension extension= cast(IDocumentInformationMappingExtension) fInformationMapping;
1410 try { 1410 try {
1411 return extension.getExactCoverage(modelRange); 1411 return extension.getExactCoverage(modelRange);
1449 1449
1450 if (redraws()) { 1450 if (redraws()) {
1451 selection= getSelectedRange(); 1451 selection= getSelectedRange();
1452 if (exposeModelRange(new Region(selection.x, selection.y))) 1452 if (exposeModelRange(new Region(selection.x, selection.y)))
1453 return; 1453 return;
1454 1454
1455 if (selection.y is 0) 1455 if (selection.y is 0)
1456 copyMarkedRegion(true); 1456 copyMarkedRegion(true);
1457 else 1457 else
1458 copyToClipboard(selection.x, selection.y, true, textWidget); 1458 copyToClipboard(selection.x, selection.y, true, textWidget);
1459 1459
1507 1507
1508 case COLLAPSE_ALL: 1508 case COLLAPSE_ALL:
1509 if (redraws()) 1509 if (redraws())
1510 collapseAll(); 1510 collapseAll();
1511 break; 1511 break;
1512 1512
1513 case COLLAPSE: 1513 case COLLAPSE:
1514 if (redraws()) { 1514 if (redraws()) {
1515 collapse(); 1515 collapse();
1516 } 1516 }
1517 break; 1517 break;
1561 } 1561 }
1562 1562
1563 /* 1563 /*
1564 * @see dwtx.jface.text.TextViewer#copyMarkedRegion(bool) 1564 * @see dwtx.jface.text.TextViewer#copyMarkedRegion(bool)
1565 */ 1565 */
1566 protected void copyMarkedRegion(bool delete) { 1566 protected void copyMarkedRegion(bool delete_) {
1567 IRegion markedRegion= getMarkedRegion(); 1567 IRegion markedRegion= getMarkedRegion();
1568 if (markedRegion !is null) 1568 if (markedRegion !is null)
1569 copyToClipboard(markedRegion.getOffset(), markedRegion.getLength(), delete, getTextWidget()); 1569 copyToClipboard(markedRegion.getOffset(), markedRegion.getLength(), delete_, getTextWidget());
1570 } 1570 }
1571 1571
1572 private void copyToClipboard(int offset, int length, bool delete, StyledText textWidget) { 1572 private void copyToClipboard(int offset, int length, bool delete_, StyledText textWidget) {
1573 1573
1574 String copyText= null; 1574 String copyText= null;
1575 1575
1576 try { 1576 try {
1577 IDocument document= getDocument(); 1577 IDocument document= getDocument();
1591 } else if (copyText !is null) { 1591 } else if (copyText !is null) {
1592 1592
1593 Clipboard clipboard= new Clipboard(textWidget.getDisplay()); 1593 Clipboard clipboard= new Clipboard(textWidget.getDisplay());
1594 1594
1595 try { 1595 try {
1596 Transfer[] dataTypes= new Transfer[] { TextTransfer.getInstance() }; 1596 Transfer[] dataTypes= [ TextTransfer.getInstance() ];
1597 Object[] data= new Object[] { copyText }; 1597 Object[] data= [ stringcast(copyText) ];
1598 try { 1598 try {
1599 clipboard.setContents(data, dataTypes); 1599 clipboard.setContents(data, dataTypes);
1600 } catch (DWTError e) { 1600 } catch (DWTError e) {
1601 if (e.code !is DND.ERROR_CANNOT_SET_CLIPBOARD) 1601 if (e.code !is DND.ERROR_CANNOT_SET_CLIPBOARD)
1602 throw e; 1602 throw e;
1611 } finally { 1611 } finally {
1612 clipboard.dispose(); 1612 clipboard.dispose();
1613 } 1613 }
1614 } 1614 }
1615 1615
1616 if (delete) { 1616 if (delete_) {
1617 try { 1617 try {
1618 deleteTextRange(offset, length, textWidget); 1618 deleteTextRange(offset, length, textWidget);
1619 } catch (BadLocationException x) { 1619 } catch (BadLocationException x) {
1620 // XXX: should log here, but JFace Text has no Log 1620 // XXX: should log here, but JFace Text has no Log
1621 } 1621 }