提交 77dee3ef 编写于 作者: I isidor

autoSaveNotAfterDelayContext

上级 df38fac4
...@@ -44,7 +44,6 @@ const openEditorsVisibleId = 'openEditorsVisible'; ...@@ -44,7 +44,6 @@ const openEditorsVisibleId = 'openEditorsVisible';
const openEditorsFocusId = 'openEditorsFocus'; const openEditorsFocusId = 'openEditorsFocus';
const explorerViewletFocusId = 'explorerViewletFocus'; const explorerViewletFocusId = 'explorerViewletFocus';
const explorerResourceIsFolderId = 'explorerResourceIsFolder'; const explorerResourceIsFolderId = 'explorerResourceIsFolder';
const autoSaveDisabled = 'autoSaveDisabled';
export const ExplorerViewletVisibleContext = new RawContextKey<boolean>(explorerViewletVisibleId, true); export const ExplorerViewletVisibleContext = new RawContextKey<boolean>(explorerViewletVisibleId, true);
export const ExplorerFolderContext = new RawContextKey<boolean>(explorerResourceIsFolderId, false); export const ExplorerFolderContext = new RawContextKey<boolean>(explorerResourceIsFolderId, false);
...@@ -52,7 +51,6 @@ export const FilesExplorerFocusedContext = new RawContextKey<boolean>(filesExplo ...@@ -52,7 +51,6 @@ export const FilesExplorerFocusedContext = new RawContextKey<boolean>(filesExplo
export const OpenEditorsVisibleContext = new RawContextKey<boolean>(openEditorsVisibleId, false); export const OpenEditorsVisibleContext = new RawContextKey<boolean>(openEditorsVisibleId, false);
export const OpenEditorsFocusedContext = new RawContextKey<boolean>(openEditorsFocusId, true); export const OpenEditorsFocusedContext = new RawContextKey<boolean>(openEditorsFocusId, true);
export const ExplorerFocusedContext = new RawContextKey<boolean>(explorerViewletFocusId, true); export const ExplorerFocusedContext = new RawContextKey<boolean>(explorerViewletFocusId, true);
export const AutoSaveDisabledContext = new RawContextKey<boolean>(autoSaveDisabled, true);
export const OpenEditorsVisibleCondition = ContextKeyExpr.has(openEditorsVisibleId); export const OpenEditorsVisibleCondition = ContextKeyExpr.has(openEditorsVisibleId);
export const FilesExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(filesExplorerFocusId), ContextKeyExpr.not(InputFocusedContextKey)); export const FilesExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(filesExplorerFocusId), ContextKeyExpr.not(InputFocusedContextKey));
......
...@@ -19,14 +19,14 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation ...@@ -19,14 +19,14 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ExplorerViewlet } from 'vs/workbench/parts/files/electron-browser/explorerViewlet'; 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 { FileStat, OpenEditor } from 'vs/workbench/parts/files/common/explorerModel';
import errors = require('vs/base/common/errors'); import errors = require('vs/base/common/errors');
import { ITree } from 'vs/base/parts/tree/browser/tree'; import { ITree } from 'vs/base/parts/tree/browser/tree';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IMessageService, Severity } from 'vs/platform/message/common/message'; 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 { toErrorMessage } from 'vs/base/common/errorMessage';
import { basename } from 'vs/base/common/paths'; import { basename } from 'vs/base/common/paths';
import { IListService } from 'vs/platform/list/browser/listService'; import { IListService } from 'vs/platform/list/browser/listService';
...@@ -695,7 +695,7 @@ function registerMenuItems(): void { ...@@ -695,7 +695,7 @@ function registerMenuItems(): void {
id: SAVE_FILE_COMMAND_ID, id: SAVE_FILE_COMMAND_ID,
title: SAVE_FILE_LABEL title: SAVE_FILE_LABEL
}, },
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext) when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext)
}); });
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
...@@ -705,7 +705,7 @@ function registerMenuItems(): void { ...@@ -705,7 +705,7 @@ function registerMenuItems(): void {
id: REVERT_FILE_COMMAND_ID, id: REVERT_FILE_COMMAND_ID,
title: nls.localize('revert', "Revert File") title: nls.localize('revert', "Revert File")
}, },
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveDisabledContext, UntitledEditorNotFocusedInOpenEditorsContext) when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext, UntitledEditorNotFocusedInOpenEditorsContext)
}); });
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
...@@ -717,31 +717,13 @@ function registerMenuItems(): void { ...@@ -717,31 +717,13 @@ function registerMenuItems(): void {
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext) 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, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: '2_save', group: '2_save',
command: { command: {
id: SAVE_ALL_IN_GROUP_COMMAND_ID, id: SAVE_ALL_IN_GROUP_COMMAND_ID,
title: SAVE_ALL_IN_GROUP_LABEL title: SAVE_ALL_IN_GROUP_LABEL
}, },
when: ContextKeyExpr.and(GroupFocusedInOpenEditorsContext) when: ContextKeyExpr.and(GroupFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext)
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
group: '2_save',
command: {
id: SAVE_FILES_COMMAND_ID,
title: SAVE_FILES_LABEL
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext)
}); });
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
...@@ -751,7 +733,7 @@ function registerMenuItems(): void { ...@@ -751,7 +733,7 @@ function registerMenuItems(): void {
id: COMPARE_WITH_SAVED_COMMAND_ID, id: COMPARE_WITH_SAVED_COMMAND_ID,
title: nls.localize('compareWithSaved', "Compare with Saved") title: nls.localize('compareWithSaved', "Compare with Saved")
}, },
when: EditorFocusedInOpenEditorsContext when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorNotFocusedInOpenEditorsContext)
}); });
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
...@@ -761,7 +743,7 @@ function registerMenuItems(): void { ...@@ -761,7 +743,7 @@ function registerMenuItems(): void {
id: COMPARE_RESOURCE_COMMAND_ID, id: COMPARE_RESOURCE_COMMAND_ID,
title: nls.localize('compareWithChosen', "Compare With Chosen") title: nls.localize('compareWithChosen', "Compare With Chosen")
}, },
when: EditorFocusedInOpenEditorsContext when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, )
}); });
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, { MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......
...@@ -14,7 +14,7 @@ import Event, { Emitter } from 'vs/base/common/event'; ...@@ -14,7 +14,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import platform = require('vs/base/common/platform'); import platform = require('vs/base/common/platform');
import { IWindowsService } from 'vs/platform/windows/common/windows'; import { IWindowsService } from 'vs/platform/windows/common/windows';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; 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 { ConfirmResult } from 'vs/workbench/common/editor';
import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle'; import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
...@@ -31,6 +31,7 @@ import { ResourceMap } from 'vs/base/common/map'; ...@@ -31,6 +31,7 @@ import { ResourceMap } from 'vs/base/common/map';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IRevertOptions } from 'vs/platform/editor/common/editor'; import { IRevertOptions } from 'vs/platform/editor/common/editor';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export interface IBackupResult { export interface IBackupResult {
didBackup: boolean; didBackup: boolean;
...@@ -56,6 +57,8 @@ export abstract class TextFileService implements ITextFileService { ...@@ -56,6 +57,8 @@ export abstract class TextFileService implements ITextFileService {
private configuredAutoSaveOnFocusChange: boolean; private configuredAutoSaveOnFocusChange: boolean;
private configuredAutoSaveOnWindowChange: boolean; private configuredAutoSaveOnWindowChange: boolean;
private autoSaveNotAfterDelayContext: IContextKey<boolean>;
private configuredHotExit: string; private configuredHotExit: string;
constructor( constructor(
...@@ -69,7 +72,8 @@ export abstract class TextFileService implements ITextFileService { ...@@ -69,7 +72,8 @@ export abstract class TextFileService implements ITextFileService {
protected environmentService: IEnvironmentService, protected environmentService: IEnvironmentService,
private backupFileService: IBackupFileService, private backupFileService: IBackupFileService,
private windowsService: IWindowsService, private windowsService: IWindowsService,
private historyService: IHistoryService private historyService: IHistoryService,
contextKeyService: IContextKeyService
) { ) {
this.toUnbind = []; this.toUnbind = [];
...@@ -80,6 +84,7 @@ export abstract class TextFileService implements ITextFileService { ...@@ -80,6 +84,7 @@ export abstract class TextFileService implements ITextFileService {
this.toUnbind.push(this._onFilesAssociationChange); this.toUnbind.push(this._onFilesAssociationChange);
this._models = this.instantiationService.createInstance(TextFileEditorModelManager); this._models = this.instantiationService.createInstance(TextFileEditorModelManager);
this.autoSaveNotAfterDelayContext = AutoSaveNotAfterDelayContext.bindTo(contextKeyService);
const configuration = this.configurationService.getValue<IFilesConfiguration>(); const configuration = this.configurationService.getValue<IFilesConfiguration>();
this.currentFilesAssociationConfig = configuration && configuration.files && configuration.files.associations; this.currentFilesAssociationConfig = configuration && configuration.files && configuration.files.associations;
...@@ -311,24 +316,28 @@ export abstract class TextFileService implements ITextFileService { ...@@ -311,24 +316,28 @@ export abstract class TextFileService implements ITextFileService {
this.configuredAutoSaveDelay = configuration && configuration.files && configuration.files.autoSaveDelay; this.configuredAutoSaveDelay = configuration && configuration.files && configuration.files.autoSaveDelay;
this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnFocusChange = false;
this.configuredAutoSaveOnWindowChange = false; this.configuredAutoSaveOnWindowChange = false;
this.autoSaveNotAfterDelayContext.set(false);
break; break;
case AutoSaveConfiguration.ON_FOCUS_CHANGE: case AutoSaveConfiguration.ON_FOCUS_CHANGE:
this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveDelay = void 0;
this.configuredAutoSaveOnFocusChange = true; this.configuredAutoSaveOnFocusChange = true;
this.configuredAutoSaveOnWindowChange = false; this.configuredAutoSaveOnWindowChange = false;
this.autoSaveNotAfterDelayContext.set(true);
break; break;
case AutoSaveConfiguration.ON_WINDOW_CHANGE: case AutoSaveConfiguration.ON_WINDOW_CHANGE:
this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveDelay = void 0;
this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnFocusChange = false;
this.configuredAutoSaveOnWindowChange = true; this.configuredAutoSaveOnWindowChange = true;
this.autoSaveNotAfterDelayContext.set(true);
break; break;
default: default:
this.configuredAutoSaveDelay = void 0; this.configuredAutoSaveDelay = void 0;
this.configuredAutoSaveOnFocusChange = false; this.configuredAutoSaveOnFocusChange = false;
this.configuredAutoSaveOnWindowChange = false; this.configuredAutoSaveOnWindowChange = false;
this.autoSaveNotAfterDelayContext.set(true);
break; break;
} }
......
...@@ -14,6 +14,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ...@@ -14,6 +14,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { ITextEditorModel } from 'vs/editor/common/services/resolverService'; import { ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { IRawTextSource } from 'vs/editor/common/model/textSource'; import { IRawTextSource } from 'vs/editor/common/model/textSource';
import { IRevertOptions } from 'vs/platform/editor/common/editor'; 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. * 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 { ...@@ -90,6 +91,7 @@ export class TextFileModelChangeEvent {
} }
export const TEXT_FILE_SERVICE_ID = 'textFileService'; export const TEXT_FILE_SERVICE_ID = 'textFileService';
export const AutoSaveNotAfterDelayContext = new RawContextKey<boolean>('autoSaveNotAfterDelayContext', true);
export interface ITextFileOperationResult { export interface ITextFileOperationResult {
results: IResult[]; results: IResult[];
...@@ -306,4 +308,4 @@ export interface ITextFileService extends IDisposable { ...@@ -306,4 +308,4 @@ export interface ITextFileService extends IDisposable {
* Convinient fast access to the hot exit file setting. * Convinient fast access to the hot exit file setting.
*/ */
isHotExitEnabled: boolean; isHotExitEnabled: boolean;
} }
\ No newline at end of file
...@@ -29,6 +29,7 @@ import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; ...@@ -29,6 +29,7 @@ import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows'; import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { mnemonicButtonLabel } from 'vs/base/common/labels'; import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export class TextFileService extends AbstractTextFileService { export class TextFileService extends AbstractTextFileService {
...@@ -47,9 +48,10 @@ export class TextFileService extends AbstractTextFileService { ...@@ -47,9 +48,10 @@ export class TextFileService extends AbstractTextFileService {
@IMessageService messageService: IMessageService, @IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService, @IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService, @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<IRawTextContent> { public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
...@@ -59,6 +59,7 @@ import { ITextResourceConfigurationService } from 'vs/editor/common/services/res ...@@ -59,6 +59,7 @@ import { ITextResourceConfigurationService } from 'vs/editor/common/services/res
import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position'; import { IPosition, Position as EditorPosition } from 'vs/editor/common/core/position';
import { ICommandAction } from 'vs/platform/actions/common/actions'; import { ICommandAction } from 'vs/platform/actions/common/actions';
import { IHashService } from 'vs/workbench/services/hash/common/hashService'; 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 { export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, void 0); return instantiationService.createInstance(FileEditorInput, resource, void 0);
...@@ -175,9 +176,10 @@ export class TestTextFileService extends TextFileService { ...@@ -175,9 +176,10 @@ export class TestTextFileService extends TextFileService {
@IMessageService messageService: IMessageService, @IMessageService messageService: IMessageService,
@IBackupFileService backupFileService: IBackupFileService, @IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService, @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 { public setPromptPath(path: string): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册