33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import * as nls from 'vs/nls' ;
67import { INotificationService , INotification , INotificationHandle , Severity , NotificationMessage , INotificationActions , IPromptChoice , IPromptOptions , IStatusMessageOptions , NoOpNotification } from 'vs/platform/notification/common/notification' ;
78import { INotificationsModel , NotificationsModel , ChoiceAction } from 'vs/workbench/common/notifications' ;
89import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
@@ -11,7 +12,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
1112import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation' ;
1213import { IAction , Action } from 'vs/base/common/actions' ;
1314import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
14- import * as nls from 'vs/nls' ;
1515
1616export class NotificationService extends Disposable implements INotificationService {
1717
@@ -58,58 +58,77 @@ export class NotificationService extends Disposable implements INotificationServ
5858 }
5959
6060 notify ( notification : INotification ) : INotificationHandle {
61+ const toDispose = new DisposableStore ( ) ;
6162
63+ // Handle neverShowAgain option accordingly
6264 let handle : INotificationHandle ;
63- if ( notification . neverShowAgainOptions ) {
64- const id = notification . neverShowAgainOptions . id ;
65- if ( ! ! this . storageService . get ( id , StorageScope . GLOBAL ) ) {
65+ if ( notification . neverShowAgain ) {
66+
67+ // If the user already picked to not show the notification
68+ // again, we return with a no-op notification here
69+ const id = notification . neverShowAgain . id ;
70+ if ( this . storageService . getBoolean ( id , StorageScope . GLOBAL ) ) {
6671 return new NoOpNotification ( ) ;
6772 }
6873
69- const neverShowAction = new Action (
70- 'workbench.dialog.choice .neverShowAgain' ,
74+ const neverShowAgainAction = toDispose . add ( new Action (
75+ 'workbench.notification .neverShowAgain' ,
7176 nls . localize ( 'neverShowAgain' , "Don't Show Again" ) ,
7277 undefined , true , ( ) => {
78+
79+ // Close notification
7380 handle . close ( ) ;
81+
82+ // Remember choice
7483 this . storageService . store ( id , true , StorageScope . GLOBAL ) ;
84+
7585 return Promise . resolve ( ) ;
76- } ) ;
86+ } ) ) ;
7787
78- notification . actions = notification . actions || { } ;
79- if ( notification . neverShowAgainOptions . isSecondary ) {
80- notification . actions . secondary = notification . actions . secondary || [ ] ;
81- notification . actions . secondary = [ ...notification . actions . secondary , neverShowAction ] ;
82- }
83- else {
84- notification . actions . primary = notification . actions . primary || [ ] ;
85- notification . actions . primary = [ neverShowAction , ...notification . actions . primary ] ;
88+ // Insert as primary or secondary action
89+ const actions = notification . actions || { primary : [ ] , secondary : [ ] } ;
90+ if ( ! notification . neverShowAgain . isSecondary ) {
91+ actions . primary = [ neverShowAgainAction , ...( actions . primary || [ ] ) ] ; // action comes first
92+ } else {
93+ actions . secondary = [ ...( actions . secondary || [ ] ) , neverShowAgainAction ] ; // actions comes last
8694 }
95+
96+ notification . actions = actions ;
8797 }
8898
99+ // Show notification
89100 handle = this . model . addNotification ( notification ) ;
101+
102+ // Cleanup when notification gets disposed
103+ Event . once ( handle . onDidClose ) ( ( ) => toDispose . dispose ( ) ) ;
104+
90105 return handle ;
91106 }
92107
93108 prompt ( severity : Severity , message : string , choices : IPromptChoice [ ] , options ?: IPromptOptions ) : INotificationHandle {
94109 const toDispose = new DisposableStore ( ) ;
95110
111+ // Handle neverShowAgain option accordingly
112+ if ( options && options . neverShowAgain ) {
96113
97- if ( options && options . neverShowAgainOptions ) {
98- const id = options . neverShowAgainOptions . id ;
99- if ( ! ! this . storageService . get ( id , StorageScope . GLOBAL ) ) {
114+ // If the user already picked to not show the notification
115+ // again, we return with a no-op notification here
116+ const id = options . neverShowAgain . id ;
117+ if ( this . storageService . getBoolean ( id , StorageScope . GLOBAL ) ) {
100118 return new NoOpNotification ( ) ;
101119 }
102120
103121 const neverShowAgainChoice = {
104122 label : nls . localize ( 'neverShowAgain' , "Don't Show Again" ) ,
105123 run : ( ) => this . storageService . store ( id , true , StorageScope . GLOBAL ) ,
106- isSecondary : options . neverShowAgainOptions . isSecondary
124+ isSecondary : options . neverShowAgain . isSecondary
107125 } ;
108- if ( options . neverShowAgainOptions . isSecondary ) {
109- choices = [ ...choices , neverShowAgainChoice ] ;
110- }
111- else {
112- choices = [ neverShowAgainChoice , ...choices ] ;
126+
127+ // Insert as primary or secondary action
128+ if ( ! options . neverShowAgain . isSecondary ) {
129+ choices = [ neverShowAgainChoice , ...choices ] ; // action comes first
130+ } else {
131+ choices = [ ...choices , neverShowAgainChoice ] ; // actions comes last
113132 }
114133 }
115134
0 commit comments