提交 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';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
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 { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
......@@ -239,61 +239,70 @@ CommandsRegistry.registerCommand('_files.openFolderPicker', openFolderPickerComm
CommandsRegistry.registerCommand('_files.windowOpen', openWindowCommand);
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'));
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.open',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
when: filesExplorerFocusCondition,
primary: KeyCode.Enter,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.DownArrow
},
handler: openFocussedExplorerItemCommand
handler: openFocussedExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.openToSide',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
when: filesExplorerFocusCondition,
primary: KeyMod.CtrlCmd | KeyCode.Enter,
mac: {
primary: KeyMod.WinCtrl | KeyCode.Enter
},
handler: openFocussedExplorerSideBySideItemCommand
handler: openFocussedExplorerViewItemSideBySideCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.triggerRename',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
when: filesExplorerFocusCondition,
primary: KeyCode.F2,
mac: {
primary: KeyCode.Enter
},
handler: renameFocussedExplorerItemCommand
handler: renameFocussedExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.moveFileToTrash',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
when: filesExplorerFocusCondition,
primary: KeyCode.Delete,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.Backspace
},
handler: moveFocussedExplorerItemToTrashCommand
handler: moveFocussedExplorerViewItemToTrashCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.files.action.delete',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: explorerFocusCondition,
when: filesExplorerFocusCondition,
primary: KeyMod.Shift | KeyCode.Delete,
mac: {
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
......
......@@ -75,10 +75,7 @@ export const revealInExplorerCommand = (accessor: ServicesAccessor, resource: UR
});
};
export const openFocussedExplorerItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerItem(accessor, false);
export const openFocussedExplorerSideBySideItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerItem(accessor, true);
function openFocussedExplorerItem(accessor: ServicesAccessor, sideBySide: boolean): void {
function openFocussedExplorerViewItem(accessor: ServicesAccessor, sideBySide: boolean): void {
withFocussedExplorerViewItem(accessor).then(res => {
if (res) {
......@@ -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> {
const viewletService = accessor.get(IViewletService);
......@@ -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 => {
if (!explorer) {
return void 0; // hidden explorer
......@@ -169,4 +154,28 @@ export function withFocussedExplorerResource(accessor: ServicesAccessor): TPromi
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';
import { prepareActions } from 'vs/workbench/browser/actionBarRegistry';
import { ITree } from 'vs/base/parts/tree/browser/tree';
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 { 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';
......@@ -60,6 +60,7 @@ export class ExplorerView extends CollapsibleViewletView {
private resourceContext: ResourceContextKey;
private folderContext: IContextKey<boolean>;
private filesExplorerFocussedContext: IContextKey<boolean>;
private explorerFocussedContext: IContextKey<boolean>;
private shouldRefresh: boolean;
......@@ -99,6 +100,8 @@ export class ExplorerView extends CollapsibleViewletView {
this.resourceContext = instantiationService.createInstance(ResourceContextKey);
this.folderContext = ExplorerFolderContext.bindTo(contextKeyService);
this.filesExplorerFocussedContext = FilesExplorerFocussedContext.bindTo(contextKeyService);
this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService);
}
......@@ -360,10 +363,18 @@ export class ExplorerView extends CollapsibleViewletView {
}));
// Update explorer focus context
const explorerFocusTracker = DOM.trackFocus(this.explorerViewer.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.explorerFocussedContext.set(true));
explorerFocusTracker.addBlurListener(() => this.explorerFocussedContext.reset());
this.toDispose.push(explorerFocusTracker);
const viewerFocusTracker = DOM.trackFocus(this.explorerViewer.getHTMLElement());
viewerFocusTracker.addFocusListener(() => {
setTimeout(() => {
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;
}
......
......@@ -19,7 +19,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IEditorStacksModel, IStacksModelChangeEvent, IEditorGroup } from 'vs/workbench/common/editor';
import { SaveAllAction } from 'vs/workbench/parts/files/browser/fileActions';
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 { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { OpenEditor } from 'vs/workbench/parts/files/common/explorerViewModel';
......@@ -49,6 +49,7 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
private fullRefreshNeeded: boolean;
private openEditorsFocussedContext: IContextKey<boolean>;
private explorerFocussedContext: IContextKey<boolean>;
constructor(actionRunner: IActionRunner, settings: any,
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -65,7 +66,9 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
this.settings = settings;
this.model = editorGroupService.getStacksModel();
this.openEditorsFocussedContext = OpenEditorsFocussedContext.bindTo(contextKeyService);
this.explorerFocussedContext = ExplorerFocussedContext.bindTo(contextKeyService);
this.structuralRefreshDelay = 0;
this.structuralTreeRefreshScheduler = new RunOnceScheduler(() => this.structuralTreeUpdate(), this.structuralRefreshDelay);
......@@ -116,10 +119,18 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
});
// Update open editors focus context
const explorerFocusTracker = dom.trackFocus(this.tree.getHTMLElement());
explorerFocusTracker.addFocusListener(() => this.openEditorsFocussedContext.set(true));
explorerFocusTracker.addBlurListener(() => this.openEditorsFocussedContext.reset());
this.toDispose.push(explorerFocusTracker);
const viewerFocusTracker = dom.trackFocus(this.tree.getHTMLElement());
viewerFocusTracker.addFocusListener(() => {
setTimeout(() => {
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.structuralTreeUpdate();
......
......@@ -21,8 +21,9 @@ export const VIEWLET_ID = 'workbench.view.explorer';
*/
export const ExplorerViewletVisibleContext = new RawContextKey<boolean>('explorerViewletVisible', true);
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 ExplorerFocussedContext = new RawContextKey<boolean>('explorerFocus', false);
/**
* File editor input id.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册