comparison dwtx/jface/text/TextViewer.d @ 140:26688fec6d23

Following dsss compile errors
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 03:23:46 +0200
parents b6bad70d540a
children 75302ef3f92f
comparison
equal deleted inserted replaced
139:93a6ec48fd28 140:26688fec6d23
261 /** 261 /**
262 * Height constraint for text hovers (in characters). 262 * Height constraint for text hovers (in characters).
263 * @since 3.4 263 * @since 3.4
264 */ 264 */
265 private static final int TEXT_HOVER_HEIGHT_CHARS= 12; //used to be 10 (text font) 265 private static final int TEXT_HOVER_HEIGHT_CHARS= 12; //used to be 10 (text font)
266 266
267 /** 267 /**
268 * Represents a replace command that brings the text viewer's text widget 268 * Represents a replace command that brings the text viewer's text widget
269 * back in synchronization with text viewer's document after the document 269 * back in synchronization with text viewer's document after the document
270 * has been changed. 270 * has been changed.
271 */ 271 */
307 preservedText= e.getDocument().get(e.getOffset(), e.getLength()); 307 preservedText= e.getDocument().get(e.getOffset(), e.getLength());
308 } 308 }
309 309
310 } catch (BadLocationException x) { 310 } catch (BadLocationException x) {
311 preservedText= null; 311 preservedText= null;
312 if cast(TRACE_ERRORS) 312 if (TRACE_ERRORS)
313 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.WidgetCommand.setEvent")); //$NON-NLS-1$ 313 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.WidgetCommand.setEvent")); //$NON-NLS-1$
314 } 314 }
315 } else 315 } else
316 preservedText= null; 316 preservedText= null;
317 } 317 }
318 } 318 }
341 * @since 3.3 341 * @since 3.3
342 */ 342 */
343 public void getNextOffset(MovementEvent event) { 343 public void getNextOffset(MovementEvent event) {
344 if (event.movement !is DWT.MOVEMENT_WORD_END) 344 if (event.movement !is DWT.MOVEMENT_WORD_END)
345 return; 345 return;
346 346
347 if cast(TRACE_DOUBLE_CLICK) { 347 if (TRACE_DOUBLE_CLICK) {
348 System.out.println("\n+++"); //$NON-NLS-1$ 348 System.out_.println("\n+++"); //$NON-NLS-1$
349 print(event); 349 print(event);
350 } 350 }
351 351
352 if (fDoubleClickSelection !is null) { 352 if (fDoubleClickSelection !is null) {
353 if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y) 353 if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y)
354 event.newOffset= fDoubleClickSelection.y; 354 event.newOffset= fDoubleClickSelection.y;
355 } 355 }
356 } 356 }
360 * @since 3.3 360 * @since 3.3
361 */ 361 */
362 public void getPreviousOffset(MovementEvent event) { 362 public void getPreviousOffset(MovementEvent event) {
363 if (event.movement !is DWT.MOVEMENT_WORD_START) 363 if (event.movement !is DWT.MOVEMENT_WORD_START)
364 return; 364 return;
365 365
366 if cast(TRACE_DOUBLE_CLICK) { 366 if (TRACE_DOUBLE_CLICK) {
367 System.out.println("\n---"); //$NON-NLS-1$ 367 System.out_.println("\n---"); //$NON-NLS-1$
368 print(event); 368 print(event);
369 } 369 }
370 if (fDoubleClickSelection is null) { 370 if (fDoubleClickSelection is null) {
371 ITextDoubleClickStrategy s= cast(ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies); 371 ITextDoubleClickStrategy s= cast(ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies);
372 if (s !is null) { 372 if (s !is null) {
373 StyledText textWidget= getTextWidget(); 373 StyledText textWidget= getTextWidget();
374 s.doubleClicked(TextViewer.this); 374 s.doubleClicked(this.outer);
375 fDoubleClickSelection= textWidget.getSelection(); 375 fDoubleClickSelection= textWidget.getSelection();
376 event.newOffset= fDoubleClickSelection.x; 376 event.newOffset= fDoubleClickSelection.x;
377 if cast(TRACE_DOUBLE_CLICK) 377 if (TRACE_DOUBLE_CLICK)
378 System.out.println("- setting selection: x= " + fDoubleClickSelection.x + ", y= " + fDoubleClickSelection.y); //$NON-NLS-1$ //$NON-NLS-2$ 378 System.out_.println("- setting selection: x= " + fDoubleClickSelection.x + ", y= " + fDoubleClickSelection.y); //$NON-NLS-1$ //$NON-NLS-2$
379 } 379 }
380 } else { 380 } else {
381 if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y) 381 if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y)
382 event.newOffset= fDoubleClickSelection.x; 382 event.newOffset= fDoubleClickSelection.x;
383 } 383 }
384 } 384 }
385 } 385 }
386 386
387 /** 387 /**
388 * Print trace info about <code>MovementEvent</code>. 388 * Print trace info about <code>MovementEvent</code>.
389 * 389 *
390 * @param e the event to print 390 * @param e the event to print
391 * @since 3.3 391 * @since 3.3
392 */ 392 */
393 private void print(MovementEvent e) { 393 private void print(MovementEvent e) {
394 System.out.println("line offset: " + e.lineOffset); //$NON-NLS-1$ 394 System.out_.println("line offset: " + e.lineOffset); //$NON-NLS-1$
395 System.out.println("line: " + e.lineText); //$NON-NLS-1$ 395 System.out_.println("line: " + e.lineText); //$NON-NLS-1$
396 System.out.println("type: " + e.movement); //$NON-NLS-1$ 396 System.out_.println("type: " + e.movement); //$NON-NLS-1$
397 System.out.println("offset: " + e.offset); //$NON-NLS-1$ 397 System.out_.println("offset: " + e.offset); //$NON-NLS-1$
398 System.out.println("newOffset: " + e.newOffset); //$NON-NLS-1$ 398 System.out_.println("newOffset: " + e.newOffset); //$NON-NLS-1$
399 } 399 }
400 400
401 /** 401 /**
402 * Monitors the area of the viewer's document that is visible in the viewer. 402 * Monitors the area of the viewer's document that is visible in the viewer.
403 * If the area might have changed, it informs the text viewer about this 403 * If the area might have changed, it informs the text viewer about this
1087 1087
1088 /* 1088 /*
1089 * @see IFindReplaceTargetExtension#setScope(IRegion) 1089 * @see IFindReplaceTargetExtension#setScope(IRegion)
1090 * @since 2.0 1090 * @since 2.0
1091 */ 1091 */
1092 public void setScope(IRegion scope) { 1092 public void setScope(IRegion scope_) {
1093 if (fRange !is null) 1093 if (fRange !is null)
1094 fRange.uninstall(); 1094 fRange.uninstall();
1095 1095
1096 if (scope is null) { 1096 if (scope_ is null) {
1097 fRange= null; 1097 fRange= null;
1098 return; 1098 return;
1099 } 1099 }
1100 1100
1101 fRange= new FindReplaceRange(scope); 1101 fRange= new FindReplaceRange(scope_);
1102 fRange.setHighlightColor(fScopeHighlightColor); 1102 fRange.setHighlightColor(fScopeHighlightColor);
1103 fRange.install(); 1103 fRange.install();
1104 } 1104 }
1105 1105
1106 /* 1106 /*
1245 */ 1245 */
1246 private void setStateMask(int stateMask) { 1246 private void setStateMask(int stateMask) {
1247 fStateMask= stateMask; 1247 fStateMask= stateMask;
1248 } 1248 }
1249 } 1249 }
1250 1250
1251 /** 1251 /**
1252 * Captures and remembers the viewer state (selection and visual position). {@link TextViewer.ViewerState} 1252 * Captures and remembers the viewer state (selection and visual position). {@link TextViewer.ViewerState}
1253 * instances are normally used once and then discarded, similar to the following snippet: 1253 * instances are normally used once and then discarded, similar to the following snippet:
1254 * <pre> 1254 * <pre>
1255 * ViewerState state= new ViewerState(); // remember the state 1255 * ViewerState state= new ViewerState(); // remember the state
1256 * doStuff(); // operation that may call setRedraw() and perform complex document modifications 1256 * doStuff(); // operation that may call setRedraw() and perform complex document modifications
1257 * state.restore(true); // restore the remembered state 1257 * state.restore(true); // restore the remembered state
1258 * </pre> 1258 * </pre>
1259 * 1259 *
1260 * @since 3.3 1260 * @since 3.3
1261 */ 1261 */
1262 private final class ViewerState { 1262 private final class ViewerState {
1263 /** The position tracking the selection. */ 1263 /** The position tracking the selection. */
1264 private Position fSelection; 1264 private Position fSelection;
1287 connect(document); 1287 connect(document);
1288 } 1288 }
1289 1289
1290 /** 1290 /**
1291 * Returns the normalized selection, i.e. the the selection length is always non-negative. 1291 * Returns the normalized selection, i.e. the the selection length is always non-negative.
1292 * 1292 *
1293 * @return the normalized selection 1293 * @return the normalized selection
1294 */ 1294 */
1295 public Point getSelection() { 1295 public Point getSelection() {
1296 if (fSelection is null) 1296 if (fSelection is null)
1297 return new Point(-1, -1); 1297 return new Point(-1, -1);
1298 return new Point(fSelection.getOffset(), fSelection.getLength()); 1298 return new Point(fSelection.getOffset(), fSelection.getLength());
1299 } 1299 }
1300 1300
1301 /** 1301 /**
1302 * Updates the selection. 1302 * Updates the selection.
1303 * 1303 *
1304 * @param offset the new selection offset 1304 * @param offset the new selection offset
1305 * @param length the new selection length 1305 * @param length the new selection length
1306 */ 1306 */
1307 public void updateSelection(int offset, int length) { 1307 public void updateSelection(int offset, int length) {
1308 fSelectionSet= true; 1308 fSelectionSet= true;
1313 } 1313 }
1314 1314
1315 /** 1315 /**
1316 * Restores the state and disconnects it from the document. The selection is no longer 1316 * Restores the state and disconnects it from the document. The selection is no longer
1317 * tracked after this call. 1317 * tracked after this call.
1318 * 1318 *
1319 * @param restoreViewport <code>true</code> to restore both selection and viewport, 1319 * @param restoreViewport <code>true</code> to restore both selection and viewport,
1320 * <code>false</code> to only restore the selection 1320 * <code>false</code> to only restore the selection
1321 */ 1321 */
1322 public void restore(bool restoreViewport) { 1322 public void restore(bool restoreViewport) {
1323 if (isConnected()) 1323 if (isConnected())
1361 } 1361 }
1362 } 1362 }
1363 1363
1364 /** 1364 /**
1365 * Remembers the viewer state. 1365 * Remembers the viewer state.
1366 * 1366 *
1367 * @param document the document to remember the state of 1367 * @param document the document to remember the state of
1368 */ 1368 */
1369 private void connect(IDocument document) { 1369 private void connect(IDocument document) {
1370 Assert.isLegal(document !is null); 1370 Assert.isLegal(document !is null);
1371 Assert.isLegal(!isConnected()); 1371 Assert.isLegal(!isConnected());
1407 } 1407 }
1408 } 1408 }
1409 1409
1410 /** 1410 /**
1411 * Updates a position with the given information and clears its deletion state. 1411 * Updates a position with the given information and clears its deletion state.
1412 * 1412 *
1413 * @param position the position to update 1413 * @param position the position to update
1414 * @param offset the new selection offset 1414 * @param offset the new selection offset
1415 * @param length the new selection length 1415 * @param length the new selection length
1416 */ 1416 */
1417 private void updatePosition(Position position, int offset, int length) { 1417 private void updatePosition(Position position, int offset, int length) {
1422 } 1422 }
1423 1423
1424 /** 1424 /**
1425 * Returns the document line to keep visually stable. If the caret line is (partially) 1425 * Returns the document line to keep visually stable. If the caret line is (partially)
1426 * visible, it is returned, otherwise the topmost (partially) visible line is returned. 1426 * visible, it is returned, otherwise the topmost (partially) visible line is returned.
1427 * 1427 *
1428 * @return the visually stable line of this viewer state 1428 * @return the visually stable line of this viewer state
1429 */ 1429 */
1430 private int getStableLine() { 1430 private int getStableLine() {
1431 int stableLine; // the model line that we try to keep stable 1431 int stableLine; // the model line that we try to keep stable
1432 int caretLine= getTextWidget().getLineAtOffset(getTextWidget().getCaretOffset()); 1432 int caretLine= getTextWidget().getLineAtOffset(getTextWidget().getCaretOffset());
1433 if (caretLine < JFaceTextUtil.getPartialTopIndex(getTextWidget()) || caretLine > JFaceTextUtil.getPartialBottomIndex(getTextWidget())) { 1433 if (caretLine < JFaceTextUtil.getPartialTopIndex(getTextWidget()) || caretLine > JFaceTextUtil.getPartialBottomIndex(getTextWidget())) {
1434 stableLine= JFaceTextUtil.getPartialTopIndex(TextViewer.this); 1434 stableLine= JFaceTextUtil.getPartialTopIndex(this.outer);
1435 } else { 1435 } else {
1436 stableLine= widgetLine2ModelLine(caretLine); 1436 stableLine= widgetLine2ModelLine(caretLine);
1437 } 1437 }
1438 return stableLine; 1438 return stableLine;
1439 } 1439 }
1440 1440
1441 /** 1441 /**
1442 * Returns <code>true</code> if the viewer state is being tracked, <code>false</code> 1442 * Returns <code>true</code> if the viewer state is being tracked, <code>false</code>
1443 * otherwise. 1443 * otherwise.
1444 * 1444 *
1445 * @return the tracking state 1445 * @return the tracking state
1446 */ 1446 */
1447 private bool isConnected() { 1447 private bool isConnected() {
1448 return fUpdater !is null; 1448 return fUpdater !is null;
1449 } 1449 }
1467 } 1467 }
1468 } 1468 }
1469 1469
1470 /** 1470 /**
1471 * Internal cursor listener i.e. aggregation of mouse and key listener. 1471 * Internal cursor listener i.e. aggregation of mouse and key listener.
1472 * 1472 *
1473 * @since 3.0 1473 * @since 3.0
1474 */ 1474 */
1475 private class CursorListener : KeyListener, MouseListener { 1475 private class CursorListener : KeyListener, MouseListener {
1476 1476
1477 /** 1477 /**
1561 if (toggleRedraw) 1561 if (toggleRedraw)
1562 target.setRedraw(true); 1562 target.setRedraw(true);
1563 } 1563 }
1564 } 1564 }
1565 } 1565 }
1566 1566
1567 1567
1568 /** 1568 /**
1569 * Identifies the scrollbars as originators of a view port change. 1569 * Identifies the scrollbars as originators of a view port change.
1570 */ 1570 */
1571 protected static final int SCROLLER= 1; 1571 protected static final int SCROLLER= 1;
1572 /** 1572 /**
1841 * @param styles the DWT style bits for the viewer's control 1841 * @param styles the DWT style bits for the viewer's control
1842 */ 1842 */
1843 protected void createControl(Composite parent, int styles) { 1843 protected void createControl(Composite parent, int styles) {
1844 1844
1845 fTextWidget= createTextWidget(parent, styles); 1845 fTextWidget= createTextWidget(parent, styles);
1846 1846
1847 // Support scroll page upon MOD1+MouseWheel 1847 // Support scroll page upon MOD1+MouseWheel
1848 fTextWidget.addListener(DWT.MouseWheel, new class() Listener { 1848 fTextWidget.addListener(DWT.MouseWheel, new class() Listener {
1849 1849
1850 public void handleEvent(Event event) { 1850 public void handleEvent(Event event) {
1851 if (((event.stateMask & DWT.MOD1) is 0)) 1851 if (((event.stateMask & DWT.MOD1) is 0))
1860 fTextWidget.setTopIndex(bottomIndex); 1860 fTextWidget.setTopIndex(bottomIndex);
1861 1861
1862 updateViewportListeners(INTERNAL); 1862 updateViewportListeners(INTERNAL);
1863 } 1863 }
1864 }); 1864 });
1865 1865
1866 fTextWidget.addDisposeListener( 1866 fTextWidget.addDisposeListener(
1867 new class() DisposeListener { 1867 new class() DisposeListener {
1868 public void widgetDisposed(DisposeEvent e) { 1868 public void widgetDisposed(DisposeEvent e) {
1869 handleDispose(); 1869 handleDispose();
1870 } 1870 }
1956 /** 1956 /**
1957 * Frees all resources allocated by this viewer. Internally called when the viewer's 1957 * Frees all resources allocated by this viewer. Internally called when the viewer's
1958 * control has been disposed. 1958 * control has been disposed.
1959 */ 1959 */
1960 protected void handleDispose() { 1960 protected void handleDispose() {
1961 1961
1962 setDocument(null); 1962 setDocument(null);
1963 1963
1964 if (fPaintManager !is null) { 1964 if (fPaintManager !is null) {
1965 fPaintManager.dispose(); 1965 fPaintManager.dispose();
1966 fPaintManager= null; 1966 fPaintManager= null;
2045 2045
2046 fHyperlinkDetectors= null; 2046 fHyperlinkDetectors= null;
2047 fVisibleDocument= null; 2047 fVisibleDocument= null;
2048 fDocument= null; 2048 fDocument= null;
2049 fScroller= null; 2049 fScroller= null;
2050 2050
2051 fTextWidget= null; 2051 fTextWidget= null;
2052 } 2052 }
2053 2053
2054 2054
2055 //---- simple getters and setters 2055 //---- simple getters and setters
2083 * @deprecated since 3.1, use 2083 * @deprecated since 3.1, use
2084 * {@link ITextViewerExtension2#prependAutoEditStrategy(IAutoEditStrategy, String)} and 2084 * {@link ITextViewerExtension2#prependAutoEditStrategy(IAutoEditStrategy, String)} and
2085 * {@link ITextViewerExtension2#removeAutoEditStrategy(IAutoEditStrategy, String)} instead 2085 * {@link ITextViewerExtension2#removeAutoEditStrategy(IAutoEditStrategy, String)} instead
2086 */ 2086 */
2087 public void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType) { 2087 public void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType) {
2088 setAutoEditStrategies(new IAutoEditStrategy[] { strategy }, contentType); 2088 setAutoEditStrategies([ strategy ], contentType);
2089 } 2089 }
2090 2090
2091 /** 2091 /**
2092 * Sets the given edit strategy as the only strategy for the given content type. 2092 * Sets the given edit strategy as the only strategy for the given content type.
2093 * 2093 *
2273 */ 2273 */
2274 public void removeTextHovers(String contentType) { 2274 public void removeTextHovers(String contentType) {
2275 if (fTextHovers is null) 2275 if (fTextHovers is null)
2276 return; 2276 return;
2277 2277
2278 Iterator iter= new HashSet(fTextHovers.keySet()).iterator(); 2278 Iterator iter= (new HashSet(fTextHovers.keySet())).iterator();
2279 while (iter.hasNext()) { 2279 while (iter.hasNext()) {
2280 TextHoverKey key= cast(TextHoverKey)iter.next(); 2280 TextHoverKey key= cast(TextHoverKey)iter.next();
2281 if (key.fContentType.equals(contentType)) 2281 if (key.fContentType.equals(contentType))
2282 fTextHovers.remove(key); 2282 fTextHovers.remove(key);
2283 } 2283 }
2317 key.setStateMask(ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); 2317 key.setStateMask(ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
2318 textHover= fTextHovers.get(key); 2318 textHover= fTextHovers.get(key);
2319 } 2319 }
2320 return cast(ITextHover) textHover; 2320 return cast(ITextHover) textHover;
2321 } catch (BadLocationException x) { 2321 } catch (BadLocationException x) {
2322 if cast(TRACE_ERRORS) 2322 if (TRACE_ERRORS)
2323 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$ 2323 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$
2324 } 2324 }
2325 return null; 2325 return null;
2326 } 2326 }
2327 2327
2328 /** 2328 /**
2345 fHoverControlCreator= creator; 2345 fHoverControlCreator= creator;
2346 } 2346 }
2347 2347
2348 /** 2348 /**
2349 * {@inheritDoc} 2349 * {@inheritDoc}
2350 * 2350 *
2351 * @since 3.4 2351 * @since 3.4
2352 */ 2352 */
2353 public void setHoverEnrichMode(ITextViewerExtension8.EnrichMode mode) { 2353 public void setHoverEnrichMode(ITextViewerExtension8.EnrichMode mode) {
2354 if (fTextHoverManager is null) 2354 if (fTextHoverManager is null)
2355 return; 2355 return;
2454 return; 2454 return;
2455 2455
2456 IRegion widgetSelection= modelRange2ClosestWidgetRange(new Region(selectionOffset, selectionLength)); 2456 IRegion widgetSelection= modelRange2ClosestWidgetRange(new Region(selectionOffset, selectionLength));
2457 if (widgetSelection !is null) { 2457 if (widgetSelection !is null) {
2458 2458
2459 int[] selectionRange= new int[] { widgetSelection.getOffset(), widgetSelection.getLength() }; 2459 int[] selectionRange= [ widgetSelection.getOffset(), widgetSelection.getLength() ];
2460 validateSelectionRange(selectionRange); 2460 validateSelectionRange(selectionRange);
2461 if (selectionRange[0] >= 0) { 2461 if (selectionRange[0] >= 0) {
2462 fTextWidget.setSelectionRange(selectionRange[0], selectionRange[1]); 2462 fTextWidget.setSelectionRange(selectionRange[0], selectionRange[1]);
2463 selectionChanged(selectionRange[0], selectionRange[1]); 2463 selectionChanged(selectionRange[0], selectionRange[1]);
2464 } 2464 }
3126 * Returns the number of lines that can fully fit into the viewport. This is computed by 3126 * Returns the number of lines that can fully fit into the viewport. This is computed by
3127 * dividing the widget's client area height by the widget's line height. The result is only 3127 * dividing the widget's client area height by the widget's line height. The result is only
3128 * accurate if the widget does not use variable line heights - for that reason, clients should 3128 * accurate if the widget does not use variable line heights - for that reason, clients should
3129 * not use this method any longer and use the client area height of the text widget to find out 3129 * not use this method any longer and use the client area height of the text widget to find out
3130 * how much content fits into it. 3130 * how much content fits into it.
3131 * 3131 *
3132 * @return the view port height in lines 3132 * @return the view port height in lines
3133 * @deprecated as of 3.2 3133 * @deprecated as of 3.2
3134 */ 3134 */
3135 protected int getVisibleLinesInViewport() { 3135 protected int getVisibleLinesInViewport() {
3136 if (fTextWidget !is null) { 3136 if (fTextWidget !is null) {
3146 */ 3146 */
3147 public int getBottomIndex() { 3147 public int getBottomIndex() {
3148 3148
3149 if (fTextWidget is null) 3149 if (fTextWidget is null)
3150 return -1; 3150 return -1;
3151 3151
3152 int widgetBottom= JFaceTextUtil.getBottomIndex(fTextWidget); 3152 int widgetBottom= JFaceTextUtil.getBottomIndex(fTextWidget);
3153 return widgetLine2ModelLine(widgetBottom); 3153 return widgetLine2ModelLine(widgetBottom);
3154 } 3154 }
3155 3155
3156 /* 3156 /*
3162 int top= fTextWidget.getTopIndex(); 3162 int top= fTextWidget.getTopIndex();
3163 try { 3163 try {
3164 top= getVisibleDocument().getLineOffset(top); 3164 top= getVisibleDocument().getLineOffset(top);
3165 return widgetOffset2ModelOffset(top); 3165 return widgetOffset2ModelOffset(top);
3166 } catch (BadLocationException ex) { 3166 } catch (BadLocationException ex) {
3167 if cast(TRACE_ERRORS) 3167 if (TRACE_ERRORS)
3168 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getTopIndexStartOffset")); //$NON-NLS-1$ 3168 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getTopIndexStartOffset")); //$NON-NLS-1$
3169 } 3169 }
3170 } 3170 }
3171 3171
3172 return -1; 3172 return -1;
3173 } 3173 }
3187 3187
3188 int coverageEndOffset= coverage.getOffset() + coverage.getLength() - 1; 3188 int coverageEndOffset= coverage.getOffset() + coverage.getLength() - 1;
3189 return Math.min(coverageEndOffset, bottomEndOffset); 3189 return Math.min(coverageEndOffset, bottomEndOffset);
3190 3190
3191 } catch (BadLocationException ex) { 3191 } catch (BadLocationException ex) {
3192 if cast(TRACE_ERRORS) 3192 if (TRACE_ERRORS)
3193 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getBottomIndexEndOffset")); //$NON-NLS-1$ 3193 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getBottomIndexEndOffset")); //$NON-NLS-1$
3194 return getDocument().getLength() - 1; 3194 return getDocument().getLength() - 1;
3195 } 3195 }
3196 } 3196 }
3197 3197
3198 /* 3198 /*
3205 3205
3206 IRegion modelRange= new Region(start, length); 3206 IRegion modelRange= new Region(start, length);
3207 IRegion widgetRange= modelRange2ClosestWidgetRange(modelRange); 3207 IRegion widgetRange= modelRange2ClosestWidgetRange(modelRange);
3208 if (widgetRange !is null) { 3208 if (widgetRange !is null) {
3209 3209
3210 int[] range= new int[] { widgetRange.getOffset(), widgetRange.getLength() }; 3210 int[] range= [ widgetRange.getOffset(), widgetRange.getLength() ];
3211 validateSelectionRange(range); 3211 validateSelectionRange(range);
3212 if (range[0] >= 0) 3212 if (range[0] >= 0)
3213 internalRevealRange(range[0], range[0] + range[1]); 3213 internalRevealRange(range[0], range[0] + range[1]);
3214 3214
3215 } else { 3215 } else {
3239 if (top > -1) { 3239 if (top > -1) {
3240 3240
3241 // scroll vertically 3241 // scroll vertically
3242 int bottom= JFaceTextUtil.getBottomIndex(fTextWidget); 3242 int bottom= JFaceTextUtil.getBottomIndex(fTextWidget);
3243 int lines= bottom - top; 3243 int lines= bottom - top;
3244 3244
3245 // if the widget is not scrollable as it is displaying the entire content 3245 // if the widget is not scrollable as it is displaying the entire content
3246 // setTopIndex won't have any effect. 3246 // setTopIndex won't have any effect.
3247 3247
3248 if (startLine >= top && startLine <= bottom && endLine >= top && endLine <= bottom ) { 3248 if (startLine >= top && startLine <= bottom && endLine >= top && endLine <= bottom ) {
3249 3249
3340 final protected IRegion getExtent(int start, int end) { 3340 final protected IRegion getExtent(int start, int end) {
3341 if (end > 0 && start < end) { 3341 if (end > 0 && start < end) {
3342 Rectangle bounds= fTextWidget.getTextBounds(start, end - 1); 3342 Rectangle bounds= fTextWidget.getTextBounds(start, end - 1);
3343 return new Region(bounds.x, bounds.width); 3343 return new Region(bounds.x, bounds.width);
3344 } 3344 }
3345 3345
3346 return new Region(fTextWidget.getLocationAtOffset(start).x, 0); 3346 return new Region(fTextWidget.getLocationAtOffset(start).x, 0);
3347 } 3347 }
3348 3348
3349 /** 3349 /**
3350 * Returns the width of the representation of a text range in the 3350 * Returns the width of the representation of a text range in the
3479 * 3479 *
3480 * @param document the visible document 3480 * @param document the visible document
3481 */ 3481 */
3482 protected void setVisibleDocument(IDocument document) { 3482 protected void setVisibleDocument(IDocument document) {
3483 3483
3484 if (fVisibleDocument is document && fVisibleDocument instanceof ChildDocument) { 3484 if (fVisibleDocument is document && cast(ChildDocument)fVisibleDocument ) {
3485 // optimization for new child documents 3485 // optimization for new child documents
3486 return; 3486 return;
3487 } 3487 }
3488 3488
3489 if (fVisibleDocument !is null) { 3489 if (fVisibleDocument !is null) {
3657 */ 3657 */
3658 protected Object selectContentTypePlugin(int offset, Map plugins) { 3658 protected Object selectContentTypePlugin(int offset, Map plugins) {
3659 try { 3659 try {
3660 return selectContentTypePlugin(TextUtilities.getContentType(getDocument(), getDocumentPartitioning(), offset, true), plugins); 3660 return selectContentTypePlugin(TextUtilities.getContentType(getDocument(), getDocumentPartitioning(), offset, true), plugins);
3661 } catch (BadLocationException x) { 3661 } catch (BadLocationException x) {
3662 if cast(TRACE_ERRORS) 3662 if (TRACE_ERRORS)
3663 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$ 3663 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$
3664 } 3664 }
3665 return null; 3665 return null;
3666 } 3666 }
3667 3667
3668 /** 3668 /**
3690 * @param command the document command representing the verify event 3690 * @param command the document command representing the verify event
3691 */ 3691 */
3692 protected void customizeDocumentCommand(DocumentCommand command) { 3692 protected void customizeDocumentCommand(DocumentCommand command) {
3693 if (isIgnoringAutoEditStrategies()) 3693 if (isIgnoringAutoEditStrategies())
3694 return; 3694 return;
3695 3695
3696 IDocument document= getDocument(); 3696 IDocument document= getDocument();
3697 3697
3698 if (fTabsToSpacesConverter !is null) 3698 if (fTabsToSpacesConverter !is null)
3699 fTabsToSpacesConverter.customizeDocumentCommand(document, command); 3699 fTabsToSpacesConverter.customizeDocumentCommand(document, command);
3700 3700
3701 List strategies= cast(List) selectContentTypePlugin(command.offset, fAutoIndentStrategies); 3701 List strategies= cast(List) selectContentTypePlugin(command.offset, fAutoIndentStrategies);
3702 if (strategies is null) 3702 if (strategies is null)
3776 3776
3777 fTextWidget.showSelection(); 3777 fTextWidget.showSelection();
3778 } 3778 }
3779 } catch (BadLocationException x) { 3779 } catch (BadLocationException x) {
3780 3780
3781 if cast(TRACE_ERRORS) 3781 if (TRACE_ERRORS)
3782 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.verifyText")); //$NON-NLS-1$ 3782 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.verifyText")); //$NON-NLS-1$
3783 3783
3784 } finally { 3784 } finally {
3785 3785
3786 if (compoundChange && fUndoManager !is null) 3786 if (compoundChange && fUndoManager !is null)
3787 fUndoManager.endCompoundChange(); 3787 fUndoManager.endCompoundChange();
3967 * Copies/cuts the marked region. 3967 * Copies/cuts the marked region.
3968 * 3968 *
3969 * @param delete <code>true</code> if the region should be deleted rather than copied. 3969 * @param delete <code>true</code> if the region should be deleted rather than copied.
3970 * @since 2.0 3970 * @since 2.0
3971 */ 3971 */
3972 protected void copyMarkedRegion(bool delete) { 3972 protected void copyMarkedRegion(bool delete_) {
3973 3973
3974 if (fTextWidget is null) 3974 if (fTextWidget is null)
3975 return; 3975 return;
3976 3976
3977 if (fMarkPosition is null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) is null) 3977 if (fMarkPosition is null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) is null)
3982 if (selection.x <= widgetMarkOffset) 3982 if (selection.x <= widgetMarkOffset)
3983 fTextWidget.setSelection(selection.x, widgetMarkOffset); 3983 fTextWidget.setSelection(selection.x, widgetMarkOffset);
3984 else 3984 else
3985 fTextWidget.setSelection(widgetMarkOffset, selection.x); 3985 fTextWidget.setSelection(widgetMarkOffset, selection.x);
3986 3986
3987 if (delete) { 3987 if (delete_) {
3988 fTextWidget.cut(); 3988 fTextWidget.cut();
3989 } else { 3989 } else {
3990 fTextWidget.copy(); 3990 fTextWidget.copy();
3991 fTextWidget.setSelection(selection.x); // restore old cursor position 3991 fTextWidget.setSelection(selection.x); // restore old cursor position
3992 } 3992 }
4075 4075
4076 offset= d.getLineOffset(startLine + 1); 4076 offset= d.getLineOffset(startLine + 1);
4077 return (offset > region.getOffset() + region.getLength() ? -1 : startLine + 1); 4077 return (offset > region.getOffset() + region.getLength() ? -1 : startLine + 1);
4078 4078
4079 } catch (BadLocationException x) { 4079 } catch (BadLocationException x) {
4080 if cast(TRACE_ERRORS) 4080 if (TRACE_ERRORS)
4081 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getFirstCompleteLineOfRegion")); //$NON-NLS-1$ 4081 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getFirstCompleteLineOfRegion")); //$NON-NLS-1$
4082 } 4082 }
4083 4083
4084 return -1; 4084 return -1;
4085 } 4085 }
4086 4086
4131 * @since 2.0 4131 * @since 2.0
4132 */ 4132 */
4133 protected void shift(bool useDefaultPrefixes, bool right, bool ignoreWhitespace) { 4133 protected void shift(bool useDefaultPrefixes, bool right, bool ignoreWhitespace) {
4134 if (fUndoManager !is null) 4134 if (fUndoManager !is null)
4135 fUndoManager.beginCompoundChange(); 4135 fUndoManager.beginCompoundChange();
4136 4136
4137 IDocument d= getDocument(); 4137 IDocument d= getDocument();
4138 Map partitioners= null; 4138 Map partitioners= null;
4139 DocumentRewriteSession rewriteSession= null; 4139 DocumentRewriteSession rewriteSession= null;
4140 try { 4140 try {
4141 Point selection= getSelectedRange(); 4141 Point selection= getSelectedRange();
4177 shiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace); 4177 shiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace);
4178 } 4178 }
4179 } 4179 }
4180 4180
4181 } catch (BadLocationException x) { 4181 } catch (BadLocationException x) {
4182 if cast(TRACE_ERRORS) 4182 if (TRACE_ERRORS)
4183 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.shift_1")); //$NON-NLS-1$ 4183 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.shift_1")); //$NON-NLS-1$
4184 4184
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 ( cast(IDocumentExtension4)d ) { 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();
4217 while (startLine <= endLine) { 4217 while (startLine <= endLine) {
4218 d.replace(d.getLineOffset(startLine++), 0, prefix); 4218 d.replace(d.getLineOffset(startLine++), 0, prefix);
4219 } 4219 }
4220 4220
4221 } catch (BadLocationException x) { 4221 } catch (BadLocationException x) {
4222 if cast(TRACE_ERRORS) 4222 if (TRACE_ERRORS)
4223 System.out.println("TextViewer.shiftRight: BadLocationException"); //$NON-NLS-1$ 4223 System.out_.println("TextViewer.shiftRight: BadLocationException"); //$NON-NLS-1$
4224 } 4224 }
4225 } 4225 }
4226 4226
4227 /** 4227 /**
4228 * Shifts the specified lines to the right or to the left. On shifting to the right 4228 * Shifts the specified lines to the right or to the left. On shifting to the right
4283 d.replace(r.getOffset() - decrement, r.getLength(), ""); //$NON-NLS-1$ 4283 d.replace(r.getOffset() - decrement, r.getLength(), ""); //$NON-NLS-1$
4284 decrement += r.getLength(); 4284 decrement += r.getLength();
4285 } 4285 }
4286 4286
4287 } catch (BadLocationException x) { 4287 } catch (BadLocationException x) {
4288 if cast(TRACE_ERRORS) 4288 if (TRACE_ERRORS)
4289 System.out.println("TextViewer.shiftLeft: BadLocationException"); //$NON-NLS-1$ 4289 System.out_.println("TextViewer.shiftLeft: BadLocationException"); //$NON-NLS-1$
4290 } 4290 }
4291 } 4291 }
4292 4292
4293 /** 4293 /**
4294 * Returns whether the shown text can be printed. 4294 * Returns whether the shown text can be printed.
4304 return (printerList !is null && printerList.length > 0); 4304 return (printerList !is null && printerList.length > 0);
4305 } 4305 }
4306 4306
4307 /** 4307 /**
4308 * {@inheritDoc} 4308 * {@inheritDoc}
4309 * 4309 *
4310 * @since 3.4 4310 * @since 3.4
4311 */ 4311 */
4312 public void print(StyledTextPrintOptions options) { 4312 public void print(StyledTextPrintOptions options) {
4313 final PrintDialog dialog= new PrintDialog(fTextWidget.getShell(), DWT.PRIMARY_MODAL); 4313 final PrintDialog dialog= new PrintDialog(fTextWidget.getShell(), DWT.PRIMARY_MODAL);
4314 final PrinterData data= dialog.open(); 4314 final PrinterData data= dialog.open();
4315 4315
4316 if (data !is null) { 4316 if (data !is null) {
4317 final Printer printer= new Printer(data); 4317 final Printer printer= new Printer(data);
4318 final Runnable styledTextPrinter= fTextWidget.print(printer, options); 4318 final Runnable styledTextPrinter= fTextWidget.print(printer, options);
4319 4319
4320 Thread printingThread= new Thread("Printing") { //$NON-NLS-1$ 4320 void threadrun() {
4321 public void run() { 4321 styledTextPrinter.run();
4322 styledTextPrinter.run(); 4322 printer.dispose();
4323 printer.dispose(); 4323 }
4324 } 4324 Thread printingThread= new Thread( &threadrun );
4325 }; 4325 printingThread.name = "Printing"; //$NON-NLS-1$
4326 printingThread.start(); 4326 printingThread.start();
4327 } 4327 }
4328 } 4328 }
4329 4329
4330 /** 4330 /**
4417 4417
4418 return widgetOffset2ModelOffset(widgetPos); 4418 return widgetOffset2ModelOffset(widgetPos);
4419 } 4419 }
4420 4420
4421 } catch (BadLocationException x) { 4421 } catch (BadLocationException x) {
4422 if cast(TRACE_ERRORS) 4422 if (TRACE_ERRORS)
4423 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$ 4423 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$
4424 } 4424 }
4425 4425
4426 return -1; 4426 return -1;
4427 } 4427 }
4428 4428
4495 return modelPos; 4495 return modelPos;
4496 } 4496 }
4497 4497
4498 4498
4499 } catch (BadLocationException x) { 4499 } catch (BadLocationException x) {
4500 if cast(TRACE_ERRORS) 4500 if (TRACE_ERRORS)
4501 System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$ 4501 System.out_.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$
4502 } 4502 }
4503 4503
4504 return -1; 4504 return -1;
4505 } 4505 }
4506 4506
4550 if (range !is null) { 4550 if (range !is null) {
4551 4551
4552 range= modelStyleRange2WidgetStyleRange(range); 4552 range= modelStyleRange2WidgetStyleRange(range);
4553 if (range !is null) 4553 if (range !is null)
4554 fTextWidget.setStyleRange(range); 4554 fTextWidget.setStyleRange(range);
4555 4555
4556 ArrayList ranges= new ArrayList(presentation.getDenumerableRanges()); 4556 ArrayList ranges= new ArrayList(presentation.getDenumerableRanges());
4557 Iterator e= presentation.getNonDefaultStyleRangeIterator(); 4557 Iterator e= presentation.getNonDefaultStyleRangeIterator();
4558 while (e.hasNext()) { 4558 while (e.hasNext()) {
4559 range= cast(StyleRange) e.next(); 4559 range= cast(StyleRange) e.next();
4560 range= modelStyleRange2WidgetStyleRange(range); 4560 range= modelStyleRange2WidgetStyleRange(range);
4561 if (range !is null) 4561 if (range !is null)
4562 ranges.add(range); 4562 ranges.add(range);
4563 } 4563 }
4564 4564
4565 if (!ranges.isEmpty()) 4565 if (!ranges.isEmpty())
4566 fTextWidget.replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()])); 4566 fTextWidget.replaceStyleRanges(0, 0, (StyleRange[])ranges.toArray(new StyleRange[ranges.size()]));
4567 4567
4568 } else { 4568 } else {
4569 IRegion region= modelRange2WidgetRange(presentation.getCoverage()); 4569 IRegion region= modelRange2WidgetRange(presentation.getCoverage());
4570 if (region is null) 4570 if (region is null)
4571 return; 4571 return;
4572 4572
5449 * @since 3.1 5449 * @since 3.1
5450 */ 5450 */
5451 public void setHyperlinkDetectors(IHyperlinkDetector[] hyperlinkDetectors, int eventStateMask) { 5451 public void setHyperlinkDetectors(IHyperlinkDetector[] hyperlinkDetectors, int eventStateMask) {
5452 if (fHyperlinkDetectors !is null) { 5452 if (fHyperlinkDetectors !is null) {
5453 for (int i= 0; i < fHyperlinkDetectors.length; i++) { 5453 for (int i= 0; i < fHyperlinkDetectors.length; i++) {
5454 if (fHyperlinkDetectors[i] instanceof IHyperlinkDetectorExtension) 5454 if (cast(IHyperlinkDetectorExtension)fHyperlinkDetectors[i] )
5455 (cast(IHyperlinkDetectorExtension)fHyperlinkDetectors[i]).dispose(); 5455 (cast(IHyperlinkDetectorExtension)fHyperlinkDetectors[i]).dispose();
5456 } 5456 }
5457 } 5457 }
5458 5458
5459 bool enable= hyperlinkDetectors !is null && hyperlinkDetectors.length > 0; 5459 bool enable= hyperlinkDetectors !is null && hyperlinkDetectors.length > 0;
5460 fHyperlinkStateMask= eventStateMask; 5460 fHyperlinkStateMask= eventStateMask;
5461 fHyperlinkDetectors= hyperlinkDetectors; 5461 fHyperlinkDetectors= hyperlinkDetectors;
5462 if (enable) { 5462 if (enable) {
5463 if (fHyperlinkManager !is null) { 5463 if (fHyperlinkManager !is null) {