diff --git a/src/vs/workbench/parts/files/common/files.ts b/src/vs/workbench/parts/files/common/files.ts index b61ded59645480aa77f234f9f39d1611fce5d31a..b817c70919265ccb4c615210a4076aa3ade18c6d 100644 --- a/src/vs/workbench/parts/files/common/files.ts +++ b/src/vs/workbench/parts/files/common/files.ts @@ -44,7 +44,6 @@ const openEditorsVisibleId = 'openEditorsVisible'; const openEditorsFocusId = 'openEditorsFocus'; const explorerViewletFocusId = 'explorerViewletFocus'; const explorerResourceIsFolderId = 'explorerResourceIsFolder'; -const autoSaveDisabled = 'autoSaveDisabled'; export const ExplorerViewletVisibleContext = new RawContextKey(explorerViewletVisibleId, true); export const ExplorerFolderContext = new RawContextKey(explorerResourceIsFolderId, false); @@ -52,7 +51,6 @@ export const FilesExplorerFocusedContext = new RawContextKey(filesExplo export const OpenEditorsVisibleContext = new RawContextKey(openEditorsVisibleId, false); export const OpenEditorsFocusedContext = new RawContextKey(openEditorsFocusId, true); export const ExplorerFocusedContext = new RawContextKey(explorerViewletFocusId, true); -export const AutoSaveDisabledContext = new RawContextKey(autoSaveDisabled, true); export const OpenEditorsVisibleCondition = ContextKeyExpr.has(openEditorsVisibleId); export const FilesExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(filesExplorerFocusId), ContextKeyExpr.not(InputFocusedContextKey)); diff --git a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts index d2a6b61c946b57e3bbc7d05fa45e92d971a35558..702e8c0a3f788adad0b33080760ea2367bcb5503 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts @@ -19,14 +19,14 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { ExplorerViewlet } from 'vs/workbench/parts/files/electron-browser/explorerViewlet'; -import { VIEWLET_ID, explorerItemToFileResource, AutoSaveDisabledContext } from 'vs/workbench/parts/files/common/files'; +import { VIEWLET_ID, explorerItemToFileResource } from 'vs/workbench/parts/files/common/files'; import { FileStat, OpenEditor } from 'vs/workbench/parts/files/common/explorerModel'; import errors = require('vs/base/common/errors'); import { ITree } from 'vs/base/parts/tree/browser/tree'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; -import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; +import { ITextFileService, AutoSaveNotAfterDelayContext } from 'vs/workbench/services/textfile/common/textfiles'; import { toErrorMessage } from 'vs/base/common/errorMessage'; import { basename } from 'vs/base/common/paths'; import { IListService } from 'vs/platform/list/browser/listService'; @@ -695,7 +695,7 @@ function registerMenuItems(): void { id: SAVE_FILE_COMMAND_ID, title: SAVE_FILE_LABEL }, - when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext) + when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { @@ -705,7 +705,7 @@ function registerMenuItems(): void { id: REVERT_FILE_COMMAND_ID, title: nls.localize('revert', "Revert File") }, - when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveDisabledContext, UntitledEditorNotFocusedInOpenEditorsContext) + when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext, UntitledEditorNotFocusedInOpenEditorsContext) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { @@ -717,31 +717,13 @@ function registerMenuItems(): void { when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext) }); - MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { - group: '2_save', - command: { - id: SAVE_ALL_COMMAND_ID, - title: SAVE_ALL_LABEL - }, - when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext) - }); - MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { group: '2_save', command: { id: SAVE_ALL_IN_GROUP_COMMAND_ID, title: SAVE_ALL_IN_GROUP_LABEL }, - when: ContextKeyExpr.and(GroupFocusedInOpenEditorsContext) - }); - - MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { - group: '2_save', - command: { - id: SAVE_FILES_COMMAND_ID, - title: SAVE_FILES_LABEL - }, - when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext) + when: ContextKeyExpr.and(GroupFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { @@ -751,7 +733,7 @@ function registerMenuItems(): void { id: COMPARE_WITH_SAVED_COMMAND_ID, title: nls.localize('compareWithSaved', "Compare with Saved") }, - when: EditorFocusedInOpenEditorsContext + when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorNotFocusedInOpenEditorsContext) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { @@ -761,7 +743,7 @@ function registerMenuItems(): void { id: COMPARE_RESOURCE_COMMAND_ID, title: nls.localize('compareWithChosen', "Compare With Chosen") }, - when: EditorFocusedInOpenEditorsContext + when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, ) }); MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { diff --git a/src/vs/workbench/services/textfile/common/textFileService.ts b/src/vs/workbench/services/textfile/common/textFileService.ts index 2c9af4b5615b584a22e68a2ab614a457b4495ed8..21544b454bbf83658490708761408b01bb7759e7 100644 --- a/src/vs/workbench/services/textfile/common/textFileService.ts +++ b/src/vs/workbench/services/textfile/common/textFileService.ts @@ -14,7 +14,7 @@ import Event, { Emitter } from 'vs/base/common/event'; import platform = require('vs/base/common/platform'); import { IWindowsService } from 'vs/platform/windows/common/windows'; import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; -import { IResult, ITextFileOperationResult, ITextFileService, IRawTextContent, IAutoSaveConfiguration, AutoSaveMode, SaveReason, ITextFileEditorModelManager, ITextFileEditorModel, ModelState, ISaveOptions } from 'vs/workbench/services/textfile/common/textfiles'; +import { IResult, ITextFileOperationResult, ITextFileService, IRawTextContent, IAutoSaveConfiguration, AutoSaveMode, SaveReason, ITextFileEditorModelManager, ITextFileEditorModel, ModelState, ISaveOptions, AutoSaveNotAfterDelayContext } from 'vs/workbench/services/textfile/common/textfiles'; import { ConfirmResult } from 'vs/workbench/common/editor'; import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; @@ -31,6 +31,7 @@ import { ResourceMap } from 'vs/base/common/map'; import { Schemas } from 'vs/base/common/network'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IRevertOptions } from 'vs/platform/editor/common/editor'; +import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; export interface IBackupResult { didBackup: boolean; @@ -56,6 +57,8 @@ export abstract class TextFileService implements ITextFileService { private configuredAutoSaveOnFocusChange: boolean; private configuredAutoSaveOnWindowChange: boolean; + private autoSaveNotAfterDelayContext: IContextKey; + private configuredHotExit: string; constructor( @@ -69,7 +72,8 @@ export abstract class TextFileService implements ITextFileService { protected environmentService: IEnvironmentService, private backupFileService: IBackupFileService, private windowsService: IWindowsService, - private historyService: IHistoryService + private historyService: IHistoryService, + contextKeyService: IContextKeyService ) { this.toUnbind = []; @@ -80,6 +84,7 @@ export abstract class TextFileService implements ITextFileService { this.toUnbind.push(this._onFilesAssociationChange); this._models = this.instantiationService.createInstance(TextFileEditorModelManager); + this.autoSaveNotAfterDelayContext = AutoSaveNotAfterDelayContext.bindTo(contextKeyService); const configuration = this.configurationService.getValue(); this.currentFilesAssociationConfig = configuration && configuration.files && configuration.files.associations; @@ -311,24 +316,28 @@ export abstract class TextFileService implements ITextFileService { this.configuredAutoSaveDelay = configuration && configuration.files && configuration.files.autoSaveDelay; this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnWindowChange = false; + this.autoSaveNotAfterDelayContext.set(false); break; case AutoSaveConfiguration.ON_FOCUS_CHANGE: this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveOnFocusChange = true; this.configuredAutoSaveOnWindowChange = false; + this.autoSaveNotAfterDelayContext.set(true); break; case AutoSaveConfiguration.ON_WINDOW_CHANGE: this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnWindowChange = true; + this.autoSaveNotAfterDelayContext.set(true); break; default: this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnWindowChange = false; + this.autoSaveNotAfterDelayContext.set(true); break; } diff --git a/src/vs/workbench/services/textfile/common/textfiles.ts b/src/vs/workbench/services/textfile/common/textfiles.ts index 9ac553c90ccfe9d70f127dff9d0b9cd5870f9e02..cf1675dae0a89933fd2acf472fcff7b185ed2b3a 100644 --- a/src/vs/workbench/services/textfile/common/textfiles.ts +++ b/src/vs/workbench/services/textfile/common/textfiles.ts @@ -14,6 +14,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import { ITextEditorModel } from 'vs/editor/common/services/resolverService'; import { IRawTextSource } from 'vs/editor/common/model/textSource'; import { IRevertOptions } from 'vs/platform/editor/common/editor'; +import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; /** * The save error handler can be installed on the text text file editor model to install code that executes when save errors occur. @@ -90,6 +91,7 @@ export class TextFileModelChangeEvent { } export const TEXT_FILE_SERVICE_ID = 'textFileService'; +export const AutoSaveNotAfterDelayContext = new RawContextKey('autoSaveNotAfterDelayContext', true); export interface ITextFileOperationResult { results: IResult[]; @@ -306,4 +308,4 @@ export interface ITextFileService extends IDisposable { * Convinient fast access to the hot exit file setting. */ isHotExitEnabled: boolean; -} \ No newline at end of file +} diff --git a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts index fc2e790bfb1cb7141c4b3b2702b082877b9ff73c..96422df8b9acc82764fe0598cce35c1630b9aedf 100644 --- a/src/vs/workbench/services/textfile/electron-browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/electron-browser/textFileService.ts @@ -29,6 +29,7 @@ import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { mnemonicButtonLabel } from 'vs/base/common/labels'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; export class TextFileService extends AbstractTextFileService { @@ -47,9 +48,10 @@ export class TextFileService extends AbstractTextFileService { @IMessageService messageService: IMessageService, @IBackupFileService backupFileService: IBackupFileService, @IWindowsService windowsService: IWindowsService, - @IHistoryService historyService: IHistoryService + @IHistoryService historyService: IHistoryService, + @IContextKeyService contextKeyService: IContextKeyService ) { - super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService, historyService); + super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService, historyService, contextKeyService); } public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise { diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 6898a77e7461c3e20adfe616c9be8696eb266033..826fe9cc0af9e4e236282a3f90d8ef9b3da90c6f 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -59,6 +59,7 @@ import { ITextResourceConfigurationService } from 'vs/editor/common/services/res import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position'; import { ICommandAction } from 'vs/platform/actions/common/actions'; import { IHashService } from 'vs/workbench/services/hash/common/hashService'; +import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput { return instantiationService.createInstance(FileEditorInput, resource, void 0); @@ -175,9 +176,10 @@ export class TestTextFileService extends TextFileService { @IMessageService messageService: IMessageService, @IBackupFileService backupFileService: IBackupFileService, @IWindowsService windowsService: IWindowsService, - @IHistoryService historyService: IHistoryService + @IHistoryService historyService: IHistoryService, + @IContextKeyService contextKeyService: IContextKeyService ) { - super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService, historyService); + super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService, historyService, contextKeyService); } public setPromptPath(path: string): void {