提交 8c000ab5 编写于 作者: I isidor

editorWithResourceFocusedContext

上级 77dee3ef
......@@ -29,7 +29,7 @@ import { DEFAULT_TERMINAL_WINDOWS, DEFAULT_TERMINAL_LINUX_READY, DEFAULT_TERMINA
import { WinTerminalService, MacTerminalService, LinuxTerminalService } from 'vs/workbench/parts/execution/electron-browser/terminalService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { EditorFocusedInOpenEditorsContext } from 'vs/workbench/parts/files/electron-browser/fileCommands';
import { EditorWithResourceFocusedInOpenEditorsContext } from 'vs/workbench/parts/files/electron-browser/fileCommands';
if (env.isWindows) {
registerSingleton(ITerminalService, WinTerminalService);
......@@ -244,7 +244,7 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
title: env.isWindows ? nls.localize('scopedConsoleActionWin', "Open in Command Prompt") :
nls.localize('scopedConsoleActionMacLinux', "Open in Terminal")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -254,5 +254,5 @@ MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
id: OPEN_INTEGRATED_TERMINAL_COMMAND_ID,
title: nls.localize('openFolderInIntegratedTerminal', "Open in Terminal")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
......@@ -70,6 +70,7 @@ export const SAVE_FILES_COMMAND_ID = 'workbench.command.files.saveFiles';
export const SAVE_FILES_LABEL = nls.localize('saveFiles', "Save All Files");
export const EditorFocusedInOpenEditorsContext = new RawContextKey<boolean>('editorFocusedInOpenEditors', false);
export const EditorWithResourceFocusedInOpenEditorsContext = new RawContextKey<boolean>('editorWithResourceFocusedInOpenEditors', false);
export const UntitledEditorFocusedInOpenEditorsContext = new RawContextKey<boolean>('untitledEditorFocusedInOpenEditors', false);
export const UntitledEditorNotFocusedInOpenEditorsContext: ContextKeyExpr = UntitledEditorFocusedInOpenEditorsContext.toNegated();
export const GroupFocusedInOpenEditorsContext = new RawContextKey<boolean>('groupFocusedInOpenEditors', false);
......@@ -615,7 +616,7 @@ function registerFileCommands(): void {
CommandsRegistry.registerCommand({
id: SAVE_FILE_COMMAND_ID,
handler: (accessor, args: IEditorContext) => {
return save(args.resource, true, accessor.get(IWorkbenchEditorService), accessor.get(IFileService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupService));
return save(args.resource, false, accessor.get(IWorkbenchEditorService), accessor.get(IFileService), accessor.get(IUntitledEditorService), accessor.get(ITextFileService), accessor.get(IEditorGroupService));
}
});
......@@ -665,7 +666,7 @@ function registerMenuItems(): void {
id: OPEN_TO_SIDE_COMMAND_ID,
title: nls.localize('openToSide', "Open to the Side")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -675,7 +676,7 @@ function registerMenuItems(): void {
id: REVEAL_IN_EXPLORER_COMMAND_ID,
title: isWindows ? nls.localize('revealInWindows', "Reveal in Explorer") : isMacintosh ? nls.localize('revealInMac', "Reveal in Finder") : nls.localize('openContainer', "Open Containing Folder")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -685,7 +686,7 @@ function registerMenuItems(): void {
id: COPY_PATH_COMMAND_ID,
title: nls.localize('copyPath', "Copy Path")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -695,7 +696,7 @@ function registerMenuItems(): void {
id: SAVE_FILE_COMMAND_ID,
title: SAVE_FILE_LABEL
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext)
when: ContextKeyExpr.and(EditorWithResourceFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext)
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -705,7 +706,7 @@ function registerMenuItems(): void {
id: REVERT_FILE_COMMAND_ID,
title: nls.localize('revert', "Revert File")
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext, UntitledEditorNotFocusedInOpenEditorsContext)
when: ContextKeyExpr.and(EditorWithResourceFocusedInOpenEditorsContext, AutoSaveNotAfterDelayContext, UntitledEditorNotFocusedInOpenEditorsContext)
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -714,7 +715,7 @@ function registerMenuItems(): void {
id: SAVE_FILE_AS_COMMAND_ID,
title: SAVE_FILE_AS_LABEL
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext)
when: ContextKeyExpr.and(EditorWithResourceFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext)
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -733,7 +734,7 @@ function registerMenuItems(): void {
id: COMPARE_WITH_SAVED_COMMAND_ID,
title: nls.localize('compareWithSaved', "Compare with Saved")
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, UntitledEditorNotFocusedInOpenEditorsContext)
when: ContextKeyExpr.and(EditorWithResourceFocusedInOpenEditorsContext, UntitledEditorNotFocusedInOpenEditorsContext)
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -743,7 +744,7 @@ function registerMenuItems(): void {
id: COMPARE_RESOURCE_COMMAND_ID,
title: nls.localize('compareWithChosen', "Compare With Chosen")
},
when: ContextKeyExpr.and(EditorFocusedInOpenEditorsContext, )
when: ContextKeyExpr.and(EditorWithResourceFocusedInOpenEditorsContext, )
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......@@ -753,7 +754,7 @@ function registerMenuItems(): void {
id: SELECT_FOR_COMPARE_COMMAND_ID,
title: nls.localize('compareSource', "Select for Compare")
},
when: EditorFocusedInOpenEditorsContext
when: EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry.appendMenuItem(MenuId.OpenEditorsContext, {
......
......@@ -40,7 +40,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { EditorFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext, GroupFocusedInOpenEditorsContext } from 'vs/workbench/parts/files/electron-browser/fileCommands';
import { EditorFocusedInOpenEditorsContext, UntitledEditorFocusedInOpenEditorsContext, GroupFocusedInOpenEditorsContext, EditorWithResourceFocusedInOpenEditorsContext } from 'vs/workbench/parts/files/electron-browser/fileCommands';
const $ = dom.$;
......@@ -59,6 +59,7 @@ export class OpenEditorsView extends ViewsViewletPanel {
private contributedContextMenu: IMenu;
private needsRefresh: boolean;
private editorFocusedContext: IContextKey<boolean>;
private editorWithResourceFocusedContext: IContextKey<boolean>;
private untitledEditorFocusedContext: IContextKey<boolean>;
private groupFocusedContext: IContextKey<boolean>;
......@@ -153,17 +154,20 @@ export class OpenEditorsView extends ViewsViewletPanel {
OpenEditorsFocusedContext.bindTo(this.list.contextKeyService);
ExplorerFocusedContext.bindTo(this.list.contextKeyService);
this.editorFocusedContext = EditorFocusedInOpenEditorsContext.bindTo(this.contextKeyService);
this.editorWithResourceFocusedContext = EditorWithResourceFocusedInOpenEditorsContext.bindTo(this.contextKeyService);
this.untitledEditorFocusedContext = UntitledEditorFocusedInOpenEditorsContext.bindTo(this.contextKeyService);
this.groupFocusedContext = GroupFocusedInOpenEditorsContext.bindTo(this.contextKeyService);
this.disposables.push(this.list.onContextMenu(e => this.onListContextMenu(e)));
this.list.onFocusChange(e => {
this.editorFocusedContext.reset();
this.editorWithResourceFocusedContext.reset();
this.groupFocusedContext.reset();
this.untitledEditorFocusedContext.reset();
const element = e.elements.length ? e.elements[0] : undefined;
if (element instanceof OpenEditor) {
this.editorFocusedContext.set(true);
this.editorWithResourceFocusedContext.set(!!element.getResource());
this.untitledEditorFocusedContext.set(element.isUntitled());
} else if (!!element) {
this.groupFocusedContext.set(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册