comparison dwtx/jface/text/reconciler/AbstractReconciler.d @ 158:25f1f92fa3df

...
author Frank Benoit <benoit@tionex.de>
date Tue, 26 Aug 2008 02:46:34 +0200
parents 7d818bd32d63
children 1a5b8f8129df
comparison
equal deleted inserted replaced
157:7f75eaa8103a 158:25f1f92fa3df
25 import dwtx.jface.text.reconciler.IReconcileResult; // packageimport 25 import dwtx.jface.text.reconciler.IReconcileResult; // packageimport
26 import dwtx.jface.text.reconciler.IReconcilerExtension; // packageimport 26 import dwtx.jface.text.reconciler.IReconcilerExtension; // packageimport
27 27
28 28
29 import dwt.dwthelper.utils; 29 import dwt.dwthelper.utils;
30 30 import tango.core.Thread;
31 31
32 import dwtx.core.runtime.Assert; 32 import dwtx.core.runtime.Assert;
33 import dwtx.core.runtime.IProgressMonitor; 33 import dwtx.core.runtime.IProgressMonitor;
34 import dwtx.core.runtime.NullProgressMonitor; 34 import dwtx.core.runtime.NullProgressMonitor;
35 import dwtx.jface.text.DocumentEvent; 35 import dwtx.jface.text.DocumentEvent;
66 66
67 67
68 /** 68 /**
69 * Background thread for the reconciling activity. 69 * Background thread for the reconciling activity.
70 */ 70 */
71 class BackgroundThread : Thread { 71 class BackgroundThread {
72 Thread thread;
72 73
73 /** Has the reconciler been canceled. */ 74 /** Has the reconciler been canceled. */
74 private bool fCanceled= false; 75 private bool fCanceled= false;
75 /** Has the reconciler been reset. */ 76 /** Has the reconciler been reset. */
76 private bool fReset= false; 77 private bool fReset= false;
84 * runs with minimal priority. 85 * runs with minimal priority.
85 * 86 *
86 * @param name the thread's name 87 * @param name the thread's name
87 */ 88 */
88 public this(String name) { 89 public this(String name) {
89 super(name); 90 thread = new Thread( &run );
90 setPriority(Thread.MIN_PRIORITY); 91 thread.name = name;
91 setDaemon(true); 92 thread.priority = Thread.MIN_PRIORITY;
93 thread.isDaemon(true);
94 }
95
96 public void start(){
97 thread.start();
92 } 98 }
93 99
94 /** 100 /**
95 * Returns whether a reconciling strategy is active right now. 101 * Returns whether a reconciling strategy is active right now.
96 * 102 *
396 * @see IReconcilingStrategy 402 * @see IReconcilingStrategy
397 */ 403 */
398 public void setIsIncrementalReconciler(bool isIncremental) { 404 public void setIsIncrementalReconciler(bool isIncremental) {
399 fIsIncrementalReconciler= isIncremental; 405 fIsIncrementalReconciler= isIncremental;
400 } 406 }
401 407
402 /** 408 /**
403 * Tells the reconciler whether it is allowed to change the document 409 * Tells the reconciler whether it is allowed to change the document
404 * inside its reconciler thread. 410 * inside its reconciler thread.
405 * <p> 411 * <p>
406 * If this is set to <code>false</code> an {@link UnsupportedOperationException} 412 * If this is set to <code>false</code> an {@link UnsupportedOperationException}
525 private void createDirtyRegion(DocumentEvent e) { 531 private void createDirtyRegion(DocumentEvent e) {
526 synchronized (fDirtyRegionQueue) { 532 synchronized (fDirtyRegionQueue) {
527 if (e.getLength() is 0 && e.getText() !is null) { 533 if (e.getLength() is 0 && e.getText() !is null) {
528 // Insert 534 // Insert
529 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); 535 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText()));
530 536
531 } else if (e.getText() is null || e.getText().length() is 0) { 537 } else if (e.getText() is null || e.getText().length() is 0) {
532 // Remove 538 // Remove
533 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); 539 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null));
534 540
535 } else { 541 } else {
536 // Replace (Remove + Insert) 542 // Replace (Remove + Insert)
537 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); 543 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null));
538 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); 544 fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText()));
539 } 545 }
570 if (!fThread.isDirty()&& fThread.isAlive()) 576 if (!fThread.isDirty()&& fThread.isAlive())
571 aboutToBeReconciled(); 577 aboutToBeReconciled();
572 578
573 if (fThread.isActive()) 579 if (fThread.isActive())
574 fProgressMonitor.setCanceled(true); 580 fProgressMonitor.setCanceled(true);
575 581
576 if (fIsIncrementalReconciler) { 582 if (fIsIncrementalReconciler) {
577 DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), fDocument.get()); 583 DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), fDocument.get());
578 createDirtyRegion(e); 584 createDirtyRegion(e);
579 } 585 }
580 586
607 /** 613 /**
608 * Hook that is called after the reconciler thread has been reset. 614 * Hook that is called after the reconciler thread has been reset.
609 */ 615 */
610 protected void reconcilerReset() { 616 protected void reconcilerReset() {
611 } 617 }
612 618
613 /** 619 /**
614 * Tells whether the code is running in this reconciler's 620 * Tells whether the code is running in this reconciler's
615 * background thread. 621 * background thread.
616 * 622 *
617 * @return <code>true</code> if running in this reconciler's background thread 623 * @return <code>true</code> if running in this reconciler's background thread
618 * @since 3.4 624 * @since 3.4
619 */ 625 */
620 protected bool isRunningInReconcilerThread() { 626 protected bool isRunningInReconcilerThread() {
621 return Thread.currentThread() is fThread; 627 return Thread.currentThread() is fThread;