提交 01373f73 编写于 作者: B Benjamin Pasero

copy path command in explorer (for #4557)

上级 10dc7423
...@@ -23,7 +23,7 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; ...@@ -23,7 +23,7 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/fileActions'; import { OpenFolderAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/fileActions';
import { copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, openFocussedExplorerItemCommand, deleteFocussedExplorerItemCommand, moveFocussedExplorerItemToTrashCommand, openFocussedExplorerSideBySideItemCommand, renameFocussedExplorerItemCommand } from 'vs/workbench/parts/files/browser/fileCommands'; import { copyPathOfFocussedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, openFocussedExplorerViewItemCommand, deleteFocussedExplorerViewItemCommand, moveFocussedExplorerViewItemToTrashCommand, openFocussedExplorerViewItemSideBySideCommand, renameFocussedExplorerViewItemCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands'; import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
...@@ -239,61 +239,70 @@ CommandsRegistry.registerCommand('_files.openFolderPicker', openFolderPickerComm ...@@ -239,61 +239,70 @@ CommandsRegistry.registerCommand('_files.openFolderPicker', openFolderPickerComm
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand); CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);
CommandsRegistry.registerCommand('workbench.action.files.openFileInNewWindow', openFileInNewWindowCommand); CommandsRegistry.registerCommand('workbench.action.files.openFileInNewWindow', openFileInNewWindowCommand);
const filesExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has('explorerViewletVisible'), ContextKeyExpr.has('filesExplorerFocus'));
const explorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has('explorerViewletVisible'), ContextKeyExpr.has('explorerFocus')); const explorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has('explorerViewletVisible'), ContextKeyExpr.has('explorerFocus'));
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.open', id: 'workbench.files.action.open',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(), weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition, when: filesExplorerFocusCondition,
primary: KeyCode.Enter, primary: KeyCode.Enter,
mac: { mac: {
primary: KeyMod.CtrlCmd | KeyCode.DownArrow primary: KeyMod.CtrlCmd | KeyCode.DownArrow
}, },
handler: openFocussedExplorerItemCommand handler: openFocussedExplorerViewItemCommand
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.openToSide', id: 'workbench.files.action.openToSide',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(), weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition, when: filesExplorerFocusCondition,
primary: KeyMod.CtrlCmd | KeyCode.Enter, primary: KeyMod.CtrlCmd | KeyCode.Enter,
mac: { mac: {
primary: KeyMod.WinCtrl | KeyCode.Enter primary: KeyMod.WinCtrl | KeyCode.Enter
}, },
handler: openFocussedExplorerSideBySideItemCommand handler: openFocussedExplorerViewItemSideBySideCommand
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.triggerRename', id: 'workbench.files.action.triggerRename',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(), weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition, when: filesExplorerFocusCondition,
primary: KeyCode.F2, primary: KeyCode.F2,
mac: { mac: {
primary: KeyCode.Enter primary: KeyCode.Enter
}, },
handler: renameFocussedExplorerItemCommand handler: renameFocussedExplorerViewItemCommand
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.moveFileToTrash', id: 'workbench.files.action.moveFileToTrash',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(), weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition, when: filesExplorerFocusCondition,
primary: KeyCode.Delete, primary: KeyCode.Delete,
mac: { mac: {
primary: KeyMod.CtrlCmd | KeyCode.Backspace primary: KeyMod.CtrlCmd | KeyCode.Backspace
}, },
handler: moveFocussedExplorerItemToTrashCommand handler: moveFocussedExplorerViewItemToTrashCommand
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.delete', id: 'workbench.files.action.delete',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(), weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition, when: filesExplorerFocusCondition,
primary: KeyMod.Shift | KeyCode.Delete, primary: KeyMod.Shift | KeyCode.Delete,
mac: { mac: {
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace
}, },
handler: deleteFocussedExplorerItemCommand handler: deleteFocussedExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.files.copyPath',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_C,
handler: copyPathOfFocussedExplorerItem
}); });
// Editor Title Context Menu // Editor Title Context Menu
......
...@@ -75,10 +75,7 @@ export const revealInExplorerCommand = (accessor: ServicesAccessor, resource: UR ...@@ -75,10 +75,7 @@ export const revealInExplorerCommand = (accessor: ServicesAccessor, resource: UR
}); });
}; };
export const openFocussedExplorerItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerItem(accessor, false); function openFocussedExplorerViewItem(accessor: ServicesAccessor, sideBySide: boolean): void {
export const openFocussedExplorerSideBySideItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerItem(accessor, true);
function openFocussedExplorerItem(accessor: ServicesAccessor, sideBySide: boolean): void {
withFocussedExplorerViewItem(accessor).then(res => { withFocussedExplorerViewItem(accessor).then(res => {
if (res) { if (res) {
...@@ -106,18 +103,6 @@ function runActionOnFocussedExplorerViewItem(accessor: ServicesAccessor, id: str ...@@ -106,18 +103,6 @@ function runActionOnFocussedExplorerViewItem(accessor: ServicesAccessor, id: str
}); });
} }
export const renameFocussedExplorerItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.triggerRename');
};
export const deleteFocussedExplorerItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.moveFileToTrash', { useTrash: false });
};
export const moveFocussedExplorerItemToTrashCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.moveFileToTrash', { useTrash: true });
};
function withExplorer(accessor: ServicesAccessor): TPromise<ExplorerViewlet> { function withExplorer(accessor: ServicesAccessor): TPromise<ExplorerViewlet> {
const viewletService = accessor.get(IViewletService); const viewletService = accessor.get(IViewletService);
...@@ -146,7 +131,7 @@ function withFocussedExplorerViewItem(accessor: ServicesAccessor): TPromise<{ ex ...@@ -146,7 +131,7 @@ function withFocussedExplorerViewItem(accessor: ServicesAccessor): TPromise<{ ex
}); });
}; };
export function withFocussedExplorerResource(accessor: ServicesAccessor): TPromise<IFileResource> { function withFocussedExplorerFileResource(accessor: ServicesAccessor): TPromise<IFileResource> {
return withExplorer(accessor).then(explorer => { return withExplorer(accessor).then(explorer => {
if (!explorer) { if (!explorer) {
return void 0; // hidden explorer return void 0; // hidden explorer
...@@ -169,4 +154,28 @@ export function withFocussedExplorerResource(accessor: ServicesAccessor): TPromi ...@@ -169,4 +154,28 @@ export function withFocussedExplorerResource(accessor: ServicesAccessor): TPromi
return explorerItemToFileResource(focussedTree.getFocus()); return explorerItemToFileResource(focussedTree.getFocus());
}); });
};
export const openFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerViewItem(accessor, false);
export const openFocussedExplorerViewItemSideBySideCommand = (accessor: ServicesAccessor) => openFocussedExplorerViewItem(accessor, true);
export const renameFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.triggerRename');
};
export const deleteFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.moveFileToTrash', { useTrash: false });
};
export const moveFocussedExplorerViewItemToTrashCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'workbench.files.action.moveFileToTrash', { useTrash: true });
};
export const copyPathOfFocussedExplorerItem = (accessor: ServicesAccessor) => {
withFocussedExplorerFileResource(accessor).then(file => {
if (file) {
copyPathCommand(accessor, file.resource);
}
});
}; };
\ No newline at end of file
...@@ -16,7 +16,7 @@ import { Action, IActionRunner, IAction } from 'vs/base/common/actions'; ...@@ -16,7 +16,7 @@ import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
import { prepareActions } from 'vs/workbench/browser/actionBarRegistry'; import { prepareActions } from 'vs/workbench/browser/actionBarRegistry';
import { ITree } from 'vs/base/parts/tree/browser/tree'; import { ITree } from 'vs/base/parts/tree/browser/tree';
import { Tree } from 'vs/base/parts/tree/browser/treeImpl'; import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IFilesConfiguration, ExplorerFolderContext, ExplorerFocussedContext } from 'vs/workbench/parts/files/common/files'; import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocussedContext, ExplorerFocussedContext } from 'vs/workbench/parts/files/common/files';
import { FileOperation, FileOperationEvent, IResolveFileOptions, FileChangeType, FileChangesEvent, IFileChange, IFileService } from 'vs/platform/files/common/files'; import { FileOperation, FileOperationEvent, IResolveFileOptions, FileChangeType, FileChangesEvent, IFileChange, IFileService } from 'vs/platform/files/common/files';
import { RefreshViewExplorerAction, NewFolderAction, NewFileAction } from 'vs/workbench/parts/files/browser/fileActions'; import { RefreshViewExplorerAction, NewFolderAction, NewFileAction } from 'vs/workbench/parts/files/browser/fileActions';
import { FileDragAndDrop, FileFilter, FileSorter, FileController, FileRenderer, FileDataSource, FileViewletState, FileAccessibilityProvider } from 'vs/workbench/parts/files/browser/views/explorerViewer'; import { FileDragAndDrop, FileFilter, FileSorter, FileController, FileRenderer, FileDataSource, FileViewletState, FileAccessibilityProvider } from 'vs/workbench/parts/files/browser/views/explorerViewer';
...@@ -60,6 +60,7 @@ export class ExplorerView extends CollapsibleViewletView { ...@@ -60,6 +60,7 @@ export class ExplorerView extends CollapsibleViewletView {
private resourceContext: ResourceContextKey; private resourceContext: ResourceContextKey;
private folderContext: IContextKey<boolean>; private folderContext: IContextKey<boolean>;
private filesExplorerFocussedContext: IContextKey<boolean>;
private explorerFocussedContext: IContextKey<boolean>; private explorerFocussedContext: IContextKey<boolean>;
private shouldRefresh: boolean; private shouldRefresh: boolean;
...@@ -99,6 +100,8 @@ export class ExplorerView extends CollapsibleViewletView { ...@@ -99,6 +100,8 @@ export class ExplorerView extends CollapsibleViewletView {
this.resourceContext = instantiationService.createInstance(ResourceContextKey); this.resourceContext = instantiationService.createInstance(ResourceContextKey);
this.folderContext = ExplorerFolderContext.bindTo(contextKeyService); this.folderContext = ExplorerFolderContext.bindTo(contextKeyService);
this.filesExplorerFocussedContext = FilesExplorerFocussedContext.bindTo(contextKeyService);
this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService); this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService);
} }
...@@ -360,10 +363,18 @@ export class ExplorerView extends CollapsibleViewletView { ...@@ -360,10 +363,18 @@ export class ExplorerView extends CollapsibleViewletView {
})); }));
// Update explorer focus context // Update explorer focus context
const explorerFocusTracker = DOM.trackFocus(this.explorerViewer.getHTMLElement()); const viewerFocusTracker = DOM.trackFocus(this.explorerViewer.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.explorerFocussedContext.set(true)); viewerFocusTracker.addFocusListener(() => {
explorerFocusTracker.addBlurListener(() => this.explorerFocussedContext.reset()); setTimeout(() => {
this.toDispose.push(explorerFocusTracker); this.filesExplorerFocussedContext.set(true);
this.explorerFocussedContext.set(true);
}, 0 /* wait for any BLUR to happen */);
});
viewerFocusTracker.addBlurListener(() => {
this.filesExplorerFocussedContext.reset();
this.explorerFocussedContext.reset();
});
this.toDispose.push(viewerFocusTracker);
return this.explorerViewer; return this.explorerViewer;
} }
......
...@@ -19,7 +19,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; ...@@ -19,7 +19,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup } from 'vs/workbench/common/editor'; import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup } from 'vs/workbench/common/editor';
import { SaveAllAction } from 'vs/workbench/parts/files/browser/fileActions'; import { SaveAllAction } from 'vs/workbench/parts/files/browser/fileActions';
import { AdaptiveCollapsibleViewletView } from 'vs/workbench/browser/viewlet'; import { AdaptiveCollapsibleViewletView } from 'vs/workbench/browser/viewlet';
import { IFilesConfiguration, VIEWLET_ID, OpenEditorsFocussedContext } from 'vs/workbench/parts/files/common/files'; import { IFilesConfiguration, VIEWLET_ID, OpenEditorsFocussedContext, ExplorerFocussedContext } from 'vs/workbench/parts/files/common/files';
import { ITextFileService, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService, AutoSaveMode } from 'vs/workbench/services/textfile/common/textfiles';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { OpenEditor } from 'vs/workbench/parts/files/common/explorerViewModel'; import { OpenEditor } from 'vs/workbench/parts/files/common/explorerViewModel';
...@@ -49,6 +49,7 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView { ...@@ -49,6 +49,7 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
private fullRefreshNeeded: boolean; private fullRefreshNeeded: boolean;
private openEditorsFocussedContext: IContextKey<boolean>; private openEditorsFocussedContext: IContextKey<boolean>;
private explorerFocussedContext: IContextKey<boolean>;
constructor(actionRunner: IActionRunner, settings: any, constructor(actionRunner: IActionRunner, settings: any,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
...@@ -65,7 +66,9 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView { ...@@ -65,7 +66,9 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
this.settings = settings; this.settings = settings;
this.model = editorGroupService.getStacksModel(); this.model = editorGroupService.getStacksModel();
this.openEditorsFocussedContext = OpenEditorsFocussedContext.bindTo(contextKeyService); this.openEditorsFocussedContext = OpenEditorsFocussedContext.bindTo(contextKeyService);
this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService);
this.structuralRefreshDelay = 0; this.structuralRefreshDelay = 0;
this.structuralTreeRefreshScheduler = new RunOnceScheduler(() => this.structuralTreeUpdate(), this.structuralRefreshDelay); this.structuralTreeRefreshScheduler = new RunOnceScheduler(() => this.structuralTreeUpdate(), this.structuralRefreshDelay);
...@@ -116,10 +119,18 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView { ...@@ -116,10 +119,18 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
}); });
// Update open editors focus context // Update open editors focus context
const explorerFocusTracker = dom.trackFocus(this.tree.getHTMLElement()); const viewerFocusTracker = dom.trackFocus(this.tree.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.openEditorsFocussedContext.set(true)); viewerFocusTracker.addFocusListener(() => {
explorerFocusTracker.addBlurListener(() => this.openEditorsFocussedContext.reset()); setTimeout(() => {
this.toDispose.push(explorerFocusTracker); this.openEditorsFocussedContext.set(true);
this.explorerFocussedContext.set(true);
}, 0 /* wait for any BLUR to happen */);
});
viewerFocusTracker.addBlurListener(() => {
this.openEditorsFocussedContext.reset();
this.explorerFocussedContext.reset();
});
this.toDispose.push(viewerFocusTracker);
this.fullRefreshNeeded = true; this.fullRefreshNeeded = true;
this.structuralTreeUpdate(); this.structuralTreeUpdate();
......
...@@ -21,8 +21,9 @@ export const VIEWLET_ID = 'workbench.view.explorer'; ...@@ -21,8 +21,9 @@ export const VIEWLET_ID = 'workbench.view.explorer';
*/ */
export const ExplorerViewletVisibleContext = new RawContextKey<boolean>('explorerViewletVisible', true); export const ExplorerViewletVisibleContext = new RawContextKey<boolean>('explorerViewletVisible', true);
export const ExplorerFolderContext = new RawContextKey<boolean>('explorerResourceIsFolder', false); export const ExplorerFolderContext = new RawContextKey<boolean>('explorerResourceIsFolder', false);
export const ExplorerFocussedContext = new RawContextKey<boolean>('explorerFocus', false); export const FilesExplorerFocussedContext = new RawContextKey<boolean>('filesExplorerFocus', false);
export const OpenEditorsFocussedContext = new RawContextKey<boolean>('openEditorsFocus', false); export const OpenEditorsFocussedContext = new RawContextKey<boolean>('openEditorsFocus', false);
export const ExplorerFocussedContext = new RawContextKey<boolean>('explorerFocus', false);
/** /**
* File editor input id. * File editor input id.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册