diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts b/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts index 4e29427fbb9..87d31a4e598 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensionTipsService.ts @@ -3,23 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import URI from 'vs/base/common/uri'; import { localize } from 'vs/nls'; import {forEach} from 'vs/base/common/collections'; import {IDisposable, dispose} from 'vs/base/common/lifecycle'; -import {TPromise as Promise} from 'vs/base/common/winjs.base'; -import {Action} from 'vs/base/common/actions'; import {match} from 'vs/base/common/glob'; import {IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService, LocalExtensionType} from 'vs/platform/extensionManagement/common/extensionManagement'; import { IExtensionsConfiguration, ConfigurationKey } from './extensions'; import {IModelService} from 'vs/editor/common/services/modelService'; +import {IModel} from 'vs/editor/common/editorCommon'; import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'; import product from 'vs/platform/product'; -import { IMessageService, CloseAction } from 'vs/platform/message/common/message'; +import { IChoiceService } from 'vs/platform/message/common/message'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction } from './extensionsActions'; import Severity from 'vs/base/common/severity'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import {Schemas} from 'vs/base/common/network'; export class ExtensionTipsService implements IExtensionTipsService { @@ -35,7 +34,7 @@ export class ExtensionTipsService implements IExtensionTipsService { @IExtensionGalleryService private _galleryService: IExtensionGalleryService, @IModelService private _modelService: IModelService, @IStorageService private storageService: IStorageService, - @IMessageService private messageService: IMessageService, + @IChoiceService private choiceService: IChoiceService, @IExtensionManagementService private extensionsService: IExtensionManagementService, @IInstantiationService private instantiationService: IInstantiationService, @IConfigurationService private configurationService: IConfigurationService @@ -83,15 +82,21 @@ export class ExtensionTipsService implements IExtensionTipsService { } }); - this._disposables.push(this._modelService.onModelAdded(model => this._suggest(model.uri))); - this._modelService.getModels().forEach(model => this._suggest(model.uri)); + this._modelService.onModelAdded(this._suggest, this, this._disposables); + this._modelService.getModels().forEach(model => this._suggest(model)); } - private _suggest(uri: URI): Promise { + private _suggest(model: IModel): void { + const uri = model.uri; + if (!uri) { return; } + if (uri.scheme === Schemas.inMemory || uri.scheme === Schemas.internal || uri.scheme === Schemas.vscode) { + return; + } + // re-schedule this bit of the operation to be off // the critical path - in case glob-match is slow setImmediate(() => { @@ -123,20 +128,25 @@ export class ExtensionTipsService implements IExtensionTipsService { } const message = localize('reallyRecommended', "It is recommended to install the '{0}' extension.", id); - const neverAgainAction = new Action('neverShowAgain', localize('neverShowAgain', "Don't show again"), null, true, () => { - this.importantRecommendationsIgnoreList.push(id); - this.storageService.store( - 'extensionsAssistant/importantRecommendationsIgnore', - JSON.stringify(this.importantRecommendationsIgnoreList), - StorageScope.GLOBAL - ); - return Promise.as(true); - }); const recommendationsAction = this.instantiationService.createInstance(ShowRecommendedExtensionsAction, ShowRecommendedExtensionsAction.ID, localize('showRecommendations', "Show Recommendations")); + const options = [ + recommendationsAction.label, + localize('neverShowAgain', "Don't show again"), + localize('close', "Close") + ]; - this.messageService.show(Severity.Info, { - message, - actions: [recommendationsAction, neverAgainAction, CloseAction] + this.choiceService.choose(Severity.Info, message, options).done(choice => { + switch (choice) { + case 0: return recommendationsAction.run(); + case 1: + this.importantRecommendationsIgnoreList.push(id); + + return this.storageService.store( + 'extensionsAssistant/importantRecommendationsIgnore', + JSON.stringify(this.importantRecommendationsIgnoreList), + StorageScope.GLOBAL + ); + } }); }); }); @@ -165,15 +175,19 @@ export class ExtensionTipsService implements IExtensionTipsService { } const message = localize('workspaceRecommended', "This workspace has extension recommendations."); - const neverAgainAction = new Action('neverShowAgain', localize('neverShowAgain', "Don't show again"), null, true, () => { - this.storageService.store(storageKey, true, StorageScope.WORKSPACE); - return Promise.as(true); - }); - const recommendationsAction = this.instantiationService.createInstance(ShowWorkspaceRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction.ID, localize('showRecommendations', "Show Recommendations")); + const action = this.instantiationService.createInstance(ShowWorkspaceRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction.ID, localize('showRecommendations', "Show Recommendations")); - this.messageService.show(Severity.Info, { - message, - actions: [recommendationsAction, neverAgainAction, CloseAction] + const options = [ + action.label, + localize('neverShowAgain', "Don't show again"), + localize('close', "Close") + ]; + + this.choiceService.choose(Severity.Info, message, options).done(choice => { + switch (choice) { + case 0: return action.run(); + case 1: return this.storageService.store(storageKey, true, StorageScope.WORKSPACE); + } }); }); }