@@ -7,10 +7,10 @@ import 'vs/css!./media/progressService';
7
7
8
8
import { localize } from 'vs/nls' ;
9
9
import { IDisposable , dispose , DisposableStore , Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
10
- import { IProgressService , IProgressOptions , IProgressStep , ProgressLocation , IProgress , Progress , IProgressCompositeOptions , IProgressNotificationOptions , IProgressRunner , IProgressIndicator , IProgressWindowOptions } from 'vs/platform/progress/common/progress' ;
10
+ import { IProgressService , IProgressOptions , IProgressStep , ProgressLocation , IProgress , Progress , IProgressCompositeOptions , IProgressNotificationOptions , IProgressRunner , IProgressIndicator , IProgressWindowOptions , IProgressDialogOptions } from 'vs/platform/progress/common/progress' ;
11
11
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet' ;
12
12
import { StatusbarAlignment , IStatusbarService , IStatusbarEntryAccessor , IStatusbarEntry } from 'vs/workbench/services/statusbar/common/statusbar' ;
13
- import { timeout } from 'vs/base/common/async' ;
13
+ import { RunOnceScheduler , timeout } from 'vs/base/common/async' ;
14
14
import { ProgressBadge , IActivityService } from 'vs/workbench/services/activity/common/activity' ;
15
15
import { INotificationService , Severity , INotificationHandle } from 'vs/platform/notification/common/notification' ;
16
16
import { Action } from 'vs/base/common/actions' ;
@@ -438,7 +438,7 @@ export class ProgressService extends Disposable implements IProgressService {
438
438
return promise ;
439
439
}
440
440
441
- private showOnActivityBar < P extends Promise < R > , R = unknown > ( viewletId : string , options : IProgressCompositeOptions , promise : P ) {
441
+ private showOnActivityBar < P extends Promise < R > , R = unknown > ( viewletId : string , options : IProgressCompositeOptions , promise : P ) : void {
442
442
let activityProgress : IDisposable ;
443
443
let delayHandle : any = setTimeout ( ( ) => {
444
444
delayHandle = undefined ;
@@ -501,8 +501,9 @@ export class ProgressService extends Disposable implements IProgressService {
501
501
return promise ;
502
502
}
503
503
504
- private withDialogProgress < P extends Promise < R > , R = unknown > ( options : IProgressOptions , task : ( progress : IProgress < IProgressStep > ) => P , onDidCancel ?: ( choice ?: number ) => void ) : P {
504
+ private withDialogProgress < P extends Promise < R > , R = unknown > ( options : IProgressDialogOptions , task : ( progress : IProgress < IProgressStep > ) => P , onDidCancel ?: ( choice ?: number ) => void ) : P {
505
505
const disposables = new DisposableStore ( ) ;
506
+
506
507
const allowableCommands = [
507
508
'workbench.action.quit' ,
508
509
'workbench.action.reloadWindow' ,
@@ -515,7 +516,6 @@ export class ProgressService extends Disposable implements IProgressService {
515
516
let dialog : Dialog ;
516
517
517
518
const createDialog = ( message : string ) => {
518
-
519
519
const buttons = options . buttons || [ ] ;
520
520
buttons . push ( options . cancellable ? localize ( 'cancel' , "Cancel" ) : localize ( 'dismiss' , "Dismiss" ) ) ;
521
521
@@ -525,6 +525,7 @@ export class ProgressService extends Disposable implements IProgressService {
525
525
buttons ,
526
526
{
527
527
type : 'pending' ,
528
+ detail : options . detail ,
528
529
cancelId : buttons . length - 1 ,
529
530
keyEventProcessor : ( event : StandardKeyboardEvent ) => {
530
531
const resolved = this . keybindingService . softDispatch ( event , this . layoutService . container ) ;
@@ -540,22 +541,37 @@ export class ProgressService extends Disposable implements IProgressService {
540
541
disposables . add ( dialog ) ;
541
542
disposables . add ( attachDialogStyler ( dialog , this . themeService ) ) ;
542
543
543
- dialog . show ( ) . then ( ( dialogResult ) => {
544
- if ( typeof onDidCancel === 'function' ) {
545
- onDidCancel ( dialogResult . button ) ;
546
- }
544
+ dialog . show ( ) . then ( dialogResult => {
545
+ onDidCancel ?.( dialogResult . button ) ;
547
546
548
547
dispose ( dialog ) ;
549
548
} ) ;
550
549
551
550
return dialog ;
552
551
} ;
553
552
554
- const updateDialog = ( message ?: string ) => {
555
- if ( message && ! dialog ) {
556
- dialog = createDialog ( message ) ;
557
- } else if ( message ) {
558
- dialog . updateMessage ( message ) ;
553
+ // In order to support the `delay` option, we use a scheduler
554
+ // that will guard each access to the dialog behind a delay
555
+ // that is either the original delay for one invocation and
556
+ // otherwise runs without delay.
557
+ let delay = options . delay ?? 0 ;
558
+ let latestMessage : string | undefined = undefined ;
559
+ const scheduler = disposables . add ( new RunOnceScheduler ( ( ) => {
560
+ delay = 0 ; // since we have run once, we reset the delay
561
+
562
+ if ( latestMessage && ! dialog ) {
563
+ dialog = createDialog ( latestMessage ) ;
564
+ } else if ( latestMessage ) {
565
+ dialog . updateMessage ( latestMessage ) ;
566
+ }
567
+ } , 0 ) ) ;
568
+
569
+ const updateDialog = function ( message ?: string ) : void {
570
+ latestMessage = message ;
571
+
572
+ // Make sure to only run one dialog update and not multiple
573
+ if ( ! scheduler . isScheduled ( ) ) {
574
+ scheduler . schedule ( delay ) ;
559
575
}
560
576
} ;
561
577
@@ -569,6 +585,10 @@ export class ProgressService extends Disposable implements IProgressService {
569
585
dispose ( disposables ) ;
570
586
} ) ;
571
587
588
+ if ( options . title ) {
589
+ updateDialog ( options . title ) ;
590
+ }
591
+
572
592
return promise ;
573
593
}
574
594
}
0 commit comments