提交 d1ab538d 编写于 作者: B Benjamin Pasero

editor context keys - renames and deprecations

上级 5cca952f
......@@ -5,7 +5,7 @@
import 'vs/css!./media/editorgroupview';
import { EditorGroup, IEditorOpenOptions, EditorCloseEvent, ISerializedEditorGroup, isSerializedEditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { EditorInput, EditorOptions, GroupIdentifier, SideBySideEditorInput, CloseDirection, IEditorCloseEvent, EditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, EditorStickyContext, EditorPinnedContext } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, GroupIdentifier, SideBySideEditorInput, CloseDirection, IEditorCloseEvent, EditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, EditorStickyContext, EditorPinnedContext, Deprecated_EditorPinnedContext, Deprecated_EditorDirtyContext } from 'vs/workbench/common/editor';
import { Event, Emitter, Relay } from 'vs/base/common/event';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { addClass, addClasses, Dimension, trackFocus, toggleClass, removeClass, addDisposableListener, EventType, EventHelper, findParentWithClass, clearNode, isAncestor } from 'vs/base/browser/dom';
......@@ -218,7 +218,9 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
private handleGroupContextKeys(contextKeyService: IContextKeyService): void {
const groupActiveEditorDirtyContext = EditorDirtyContext.bindTo(contextKeyService);
const deprecatedGroupActiveEditorDirtyContext = Deprecated_EditorDirtyContext.bindTo(contextKeyService);
const groupActiveEditorPinnedContext = EditorPinnedContext.bindTo(contextKeyService);
const deprecatedGroupActiveEditorPinnedContext = Deprecated_EditorPinnedContext.bindTo(contextKeyService);
const groupActiveEditorStickyContext = EditorStickyContext.bindTo(contextKeyService);
const groupEditorsCountContext = EditorGroupEditorsCountContext.bindTo(contextKeyService);
......@@ -230,9 +232,14 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const activeEditor = this._group.activeEditor;
if (activeEditor) {
groupActiveEditorDirtyContext.set(activeEditor.isDirty() && !activeEditor.isSaving());
activeEditorListener.value = activeEditor.onDidChangeDirty(() => groupActiveEditorDirtyContext.set(activeEditor.isDirty() && !activeEditor.isSaving()));
deprecatedGroupActiveEditorDirtyContext.set(activeEditor.isDirty() && !activeEditor.isSaving());
activeEditorListener.value = activeEditor.onDidChangeDirty(() => {
groupActiveEditorDirtyContext.set(activeEditor.isDirty() && !activeEditor.isSaving());
deprecatedGroupActiveEditorDirtyContext.set(activeEditor.isDirty() && !activeEditor.isSaving());
});
} else {
groupActiveEditorDirtyContext.set(false);
deprecatedGroupActiveEditorDirtyContext.set(false);
}
};
......@@ -247,6 +254,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
case GroupChangeKind.EDITOR_PIN:
if (e.editor && e.editor === this._group.activeEditor) {
groupActiveEditorPinnedContext.set(this._group.isPinned(this._group.activeEditor));
deprecatedGroupActiveEditorPinnedContext.set(this._group.isPinned(this._group.activeEditor));
}
break;
case GroupChangeKind.EDITOR_STICKY:
......
......@@ -30,6 +30,12 @@ export const EditorPinnedContext = new RawContextKey<boolean>('activeEditorIsNot
export const EditorStickyContext = new RawContextKey<boolean>('activeEditorIsPinned', false);
export const EditorReadonlyContext = new RawContextKey<boolean>('activeEditorIsReadonly', false);
/** TODO@ben remove me eventually */
/** @deprecated */
export const Deprecated_EditorPinnedContext = new RawContextKey<boolean>('editorPinned', false);
/** @deprecated */
export const Deprecated_EditorDirtyContext = new RawContextKey<boolean>('groupActiveEditorDirty', false);
// Editor Kind Context Keys
export const ActiveEditorContext = new RawContextKey<string | null>('activeEditor', null);
export const ActiveEditorAvailableEditorIdsContext = new RawContextKey<string>('activeEditorAvailableEditorIds', '');
......
......@@ -10,7 +10,7 @@ import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTI
import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { openWindowCommand, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID, OPEN_TO_SIDE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_COMMAND_ID, SAVE_FILE_LABEL, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL, SAVE_ALL_IN_GROUP_COMMAND_ID, OpenEditorsGroupContext, COMPARE_WITH_SAVED_COMMAND_ID, COMPARE_RESOURCE_COMMAND_ID, SELECT_FOR_COMPARE_COMMAND_ID, ResourceSelectedForCompareContext, DirtyEditorContext, COMPARE_SELECTED_COMMAND_ID, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL, SAVE_FILES_COMMAND_ID, COPY_RELATIVE_PATH_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_LABEL, newWindowCommand, ReadonlyEditorContext, OPEN_WITH_EXPLORER_COMMAND_ID, NEW_UNTITLED_FILE_COMMAND_ID, NEW_UNTITLED_FILE_LABEL } from 'vs/workbench/contrib/files/browser/fileCommands';
import { openWindowCommand, COPY_PATH_COMMAND_ID, REVEAL_IN_EXPLORER_COMMAND_ID, OPEN_TO_SIDE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_COMMAND_ID, SAVE_FILE_LABEL, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL, SAVE_ALL_IN_GROUP_COMMAND_ID, OpenEditorsGroupContext, COMPARE_WITH_SAVED_COMMAND_ID, COMPARE_RESOURCE_COMMAND_ID, SELECT_FOR_COMPARE_COMMAND_ID, ResourceSelectedForCompareContext, OpenEditorsDirtyEditorContext, COMPARE_SELECTED_COMMAND_ID, REMOVE_ROOT_FOLDER_COMMAND_ID, REMOVE_ROOT_FOLDER_LABEL, SAVE_FILES_COMMAND_ID, COPY_RELATIVE_PATH_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_COMMAND_ID, SAVE_FILE_WITHOUT_FORMATTING_LABEL, newWindowCommand, OpenEditorsReadonlyEditorContext, OPEN_WITH_EXPLORER_COMMAND_ID, NEW_UNTITLED_FILE_COMMAND_ID, NEW_UNTITLED_FILE_LABEL } from 'vs/workbench/contrib/files/browser/fileCommands';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
......@@ -259,7 +259,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
command: {
id: SAVE_FILE_COMMAND_ID,
title: SAVE_FILE_LABEL,
precondition: DirtyEditorContext
precondition: OpenEditorsDirtyEditorContext
},
when: ContextKeyExpr.or(
// Untitled Editors
......@@ -269,7 +269,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
// Not: editor groups
OpenEditorsGroupContext.toNegated(),
// Not: readonly editors
ReadonlyEditorContext.toNegated(),
OpenEditorsReadonlyEditorContext.toNegated(),
// Not: auto save after short delay
AutoSaveAfterShortDelayContext.toNegated()
)
......@@ -282,13 +282,13 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
command: {
id: REVERT_FILE_COMMAND_ID,
title: nls.localize('revert', "Revert File"),
precondition: DirtyEditorContext
precondition: OpenEditorsDirtyEditorContext
},
when: ContextKeyExpr.and(
// Not: editor groups
OpenEditorsGroupContext.toNegated(),
// Not: readonly editors
ReadonlyEditorContext.toNegated(),
OpenEditorsReadonlyEditorContext.toNegated(),
// Not: untitled editors (revert closes them)
ResourceContextKey.Scheme.notEqualsTo(Schemas.untitled),
// Not: auto save after short delay
......@@ -314,7 +314,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
command: {
id: COMPARE_WITH_SAVED_COMMAND_ID,
title: nls.localize('compareWithSaved', "Compare with Saved"),
precondition: DirtyEditorContext
precondition: OpenEditorsDirtyEditorContext
},
when: ContextKeyExpr.and(ResourceContextKey.IsFileSystemResource, AutoSaveAfterShortDelayContext.toNegated(), WorkbenchListDoubleSelection.toNegated())
});
......
......@@ -74,8 +74,8 @@ export const SAVE_ALL_IN_GROUP_COMMAND_ID = 'workbench.files.action.saveAllInGro
export const SAVE_FILES_COMMAND_ID = 'workbench.action.files.saveFiles';
export const OpenEditorsGroupContext = new RawContextKey<boolean>('groupFocusedInOpenEditors', false);
export const DirtyEditorContext = new RawContextKey<boolean>('dirtyEditorFocusedInOpenEditors', false);
export const ReadonlyEditorContext = new RawContextKey<boolean>('readonlyEditorFocusedInOpenEditors', false);
export const OpenEditorsDirtyEditorContext = new RawContextKey<boolean>('dirtyEditorFocusedInOpenEditors', false);
export const OpenEditorsReadonlyEditorContext = new RawContextKey<boolean>('readonlyEditorFocusedInOpenEditors', false);
export const ResourceSelectedForCompareContext = new RawContextKey<boolean>('resourceSelectedForCompare', false);
export const REMOVE_ROOT_FOLDER_COMMAND_ID = 'removeRootFolder';
......
......@@ -31,7 +31,7 @@ import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { DirtyEditorContext, OpenEditorsGroupContext, ReadonlyEditorContext } from 'vs/workbench/contrib/files/browser/fileCommands';
import { OpenEditorsDirtyEditorContext, OpenEditorsGroupContext, OpenEditorsReadonlyEditorContext } from 'vs/workbench/contrib/files/browser/fileCommands';
import { ResourceContextKey } from 'vs/workbench/common/resources';
import { ResourcesDropHandler, fillResourceDataTransfers, CodeDataTransfers, containsDragType } from 'vs/workbench/browser/dnd';
import { ViewPane } from 'vs/workbench/browser/parts/views/viewPaneContainer';
......@@ -243,8 +243,8 @@ export class OpenEditorsView extends ViewPane {
this.resourceContext = this.instantiationService.createInstance(ResourceContextKey);
this._register(this.resourceContext);
this.groupFocusedContext = OpenEditorsGroupContext.bindTo(this.contextKeyService);
this.dirtyEditorFocusedContext = DirtyEditorContext.bindTo(this.contextKeyService);
this.readonlyEditorFocusedContext = ReadonlyEditorContext.bindTo(this.contextKeyService);
this.dirtyEditorFocusedContext = OpenEditorsDirtyEditorContext.bindTo(this.contextKeyService);
this.readonlyEditorFocusedContext = OpenEditorsReadonlyEditorContext.bindTo(this.contextKeyService);
this._register(this.list.onContextMenu(e => this.onListContextMenu(e)));
this.list.onDidChangeFocus(e => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册