diff --git a/src/vs/workbench/parts/quickopen/common/quickopenActions.ts b/src/vs/workbench/parts/quickopen/common/quickopenActions.ts new file mode 100644 index 0000000000000000000000000000000000000000..5ab4ae75c340dc22c7f814652d30a3589e670b2c --- /dev/null +++ b/src/vs/workbench/parts/quickopen/common/quickopenActions.ts @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { TPromise } from 'vs/base/common/winjs.base'; +import nls = require('vs/nls'); +import { Action } from 'vs/base/common/actions'; +import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; +import { IConfigurationService } from "vs/platform/configuration/common/configuration"; + +export const ALL_COMMANDS_PREFIX = '>'; + +export class ShowTasksAction extends Action { + + public static ID = 'workbench.action.showTasks'; + public static LABEL = nls.localize('showTasks', "Show Task Menu"); + + constructor( + id: string, + label: string, + @IQuickOpenService private quickOpenService: IQuickOpenService, + @IConfigurationService private configurationService: IConfigurationService + ) { + super(id, label); + } + + public run(context?: any): TPromise { + const value = `${ALL_COMMANDS_PREFIX}tasks`; + this.quickOpenService.show(value); + + return TPromise.as(null); + } +} diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 126ce6252641964219e451c52fe516673e32464d..27398e464540a7261dbb0535427bf760ddfe8ab4 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; +import * as path from 'vs/base/common/paths'; import nls = require('vs/nls'); import Event, { Emitter } from 'vs/base/common/event'; import { TPromise, TValueCallback, ErrorCallback } from 'vs/base/common/winjs.base'; @@ -26,14 +27,16 @@ import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel' import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; import { IFileService, IFileStat, IFileOperationResult, FileOperationResult, IContent, CONTENT_CHANGE_EVENT_BUFFER_DELAY, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IMessageService, Severity } from 'vs/platform/message/common/message'; +import { IMessageService, Severity, IChoiceService } from 'vs/platform/message/common/message'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IModelService } from 'vs/editor/common/services/modelService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { anonymize } from 'vs/platform/telemetry/common/telemetryUtils'; import { RunOnceScheduler } from 'vs/base/common/async'; import { IRawTextSource } from 'vs/editor/common/model/textSource'; - +import { StorageScope, IStorageService } from 'vs/platform/storage/common/storage'; +import { localize } from 'vs/nls'; +import { ShowTasksAction } from 'vs/workbench/parts/quickopen/common/quickopenActions'; /** * The text file editor model listens to changes to its underlying code editor model and saves these changes through the file service back to the disk. */ @@ -85,7 +88,9 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil @ITextFileService private textFileService: ITextFileService, @IBackupFileService private backupFileService: IBackupFileService, @IEnvironmentService private environmentService: IEnvironmentService, - @IWorkspaceContextService private contextService: IWorkspaceContextService + @IWorkspaceContextService private contextService: IWorkspaceContextService, + @IChoiceService private choiceService: IChoiceService, + @IStorageService private storageService: IStorageService ) { super(modelService, modeService); @@ -316,6 +321,29 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil etag = this.lastResolvedDiskStat.etag; // otherwise respect etag to support caching } + const storageKey = 'workbench.tasks.ranTaskBefore'; + const fileName = path.relative(this.fileService['raw'].basePath, this.resource.path); + + if (this.storageService.get(storageKey) + && (fileName.match(/^gruntfile\.js$/i) || fileName.match(/^gulpfile\.js$/i) || fileName.match(/^tsconfig\.json$/i))) { + const message = localize('taskFileOpened', "Visual Studio Code has support for this type of file"); + const action = this.instantiationService.createInstance(ShowTasksAction, ShowTasksAction.ID, localize('showTasks', "Show Tasks")); + + const options = [ + action.label, + localize('neverShowAgain', "Don't show again"), + localize('close', "Close"), + ]; + + this.choiceService.choose(Severity.Info, message, options, 2).done(choice => { + switch (choice) { + case 0: return action.run(); + case 1: return this.storageService.store(storageKey, true, StorageScope.GLOBAL); + case 2: return; + } + }); + } + // Resolve Content return this.textFileService .resolveTextContent(this.resource, { acceptTextOnly: true, etag, encoding: this.preferredEncoding })