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

"paste" as command for explorer (for #4557)

上级 f3d8873b
......@@ -11,7 +11,7 @@ import { isMacintosh } from 'vs/base/common/platform';
import { ActionItem, BaseActionItem, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor } from 'vs/workbench/browser/actionBarRegistry';
import { IEditorInputActionContext, IEditorInputAction, EditorInputActionContributor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { GlobalNewUntitledFileAction, SaveFileAsAction, OpenFileAction, ShowOpenedFileInNewWindow, CopyPathAction, GlobalCopyPathAction, RevealInOSAction, GlobalRevealInOSAction, FocusOpenEditorsView, FocusFilesExplorer, GlobalCompareResourcesAction, GlobalNewFileAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView } from 'vs/workbench/parts/files/browser/fileActions';
import { GlobalNewUntitledFileAction, SaveFileAsAction, OpenFileAction, ShowOpenedFileInNewWindow, CopyPathAction, GlobalCopyPathAction, RevealInOSAction, GlobalRevealInOSAction, pasteIntoFocusedFilesExplorerViewItem, FocusOpenEditorsView, FocusFilesExplorer, GlobalCompareResourcesAction, GlobalNewFileAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView } from 'vs/workbench/parts/files/browser/fileActions';
import { RevertLocalChangesAction, AcceptLocalChangesAction, CONFLICT_RESOLUTION_SCHEME } from 'vs/workbench/parts/files/browser/saveErrorHandler';
import { SyncActionDescriptor, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
......@@ -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 { copyFocussedExplorerViewItem, revealInOSFocussedExplorerItem, openFocussedOpenedEditorsViewItemCommand, openFocussedExplorerItemSideBySideCommand, copyPathOfFocussedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, openFocussedExplorerViewItemCommand, deleteFocussedExplorerViewItemCommand, moveFocussedExplorerViewItemToTrashCommand, renameFocussedExplorerViewItemCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { copyFocusedFilesExplorerViewItem, revealInOSFocusedFilesExplorerItem, openFocusedOpenedEditorsViewItemCommand, openFocusedExplorerItemSideBySideCommand, copyPathOfFocusedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, openFocussedFilesExplorerViewItemCommand, deleteFocusedFilesExplorerViewItemCommand, moveFocusedFilesExplorerViewItemToTrashCommand, renameFocusedFilesExplorerViewItemCommand } 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';
......@@ -246,7 +246,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
when: OpenedEditorsFocusCondition,
primary: KeyCode.Enter,
handler: openFocussedOpenedEditorsViewItemCommand
handler: openFocusedOpenedEditorsViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -257,7 +257,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
mac: {
primary: KeyMod.CtrlCmd | KeyCode.DownArrow
},
handler: openFocussedExplorerViewItemCommand
handler: openFocussedFilesExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -268,7 +268,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
mac: {
primary: KeyMod.WinCtrl | KeyCode.Enter
},
handler: openFocussedExplorerItemSideBySideCommand
handler: openFocusedExplorerItemSideBySideCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -279,7 +279,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
mac: {
primary: KeyCode.Enter
},
handler: renameFocussedExplorerViewItemCommand
handler: renameFocusedFilesExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -290,7 +290,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
mac: {
primary: KeyMod.CtrlCmd | KeyCode.Backspace
},
handler: moveFocussedExplorerViewItemToTrashCommand
handler: moveFocusedFilesExplorerViewItemToTrashCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -301,7 +301,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
mac: {
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace
},
handler: deleteFocussedExplorerViewItemCommand
handler: deleteFocusedFilesExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -309,7 +309,15 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
when: FilesExplorerFocusCondition,
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
handler: copyFocussedExplorerViewItem
handler: copyFocusedFilesExplorerViewItem
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'filesExplorer.paste',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
when: FilesExplorerFocusCondition,
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
handler: pasteIntoFocusedFilesExplorerViewItem
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -320,7 +328,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
win: {
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_C
},
handler: copyPathOfFocussedExplorerItem
handler: copyPathOfFocusedExplorerItem
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
......@@ -331,7 +339,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
win: {
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_R
},
handler: revealInOSFocussedExplorerItem
handler: revealInOSFocusedFilesExplorerItem
});
// Editor Title Context Menu
......
......@@ -40,7 +40,7 @@ import { IQuickOpenService, IFilePickOpenEntry } from 'vs/platform/quickOpen/com
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { Position, IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService, IConstructorSignature2 } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, IConstructorSignature2, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService, IMessageWithAction, IConfirmation, Severity, CancelAction } from 'vs/platform/message/common/message';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { Keybinding, KeyMod, KeyCode } from 'vs/base/common/keyCodes';
......@@ -49,7 +49,7 @@ import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { revealInOSCommand, revealInExplorerCommand, copyPathCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { withFocussedFilesExplorerViewItem, revealInOSCommand, revealInExplorerCommand, copyPathCommand } from 'vs/workbench/parts/files/browser/fileCommands';
export interface IEditableData {
action: IAction;
......@@ -923,7 +923,7 @@ export class CopyFileAction extends BaseFileAction {
// Paste File/Folder
export class PasteFileAction extends BaseFileAction {
public static ID = 'workbench.files.action.pasteFile';
public static ID = 'filesExplorer.paste';
private tree: ITree;
......@@ -984,6 +984,19 @@ export class PasteFileAction extends BaseFileAction {
}
}
export const pasteIntoFocusedFilesExplorerViewItem = (accessor: ServicesAccessor) => {
const instantiationService = accessor.get(IInstantiationService);
withFocussedFilesExplorerViewItem(accessor).then(res => {
if (res.item) {
const pasteAction = instantiationService.createInstance(PasteFileAction, res.tree, res.item);
if (pasteAction._isEnabled()) {
pasteAction.run().done(null, errors.onUnexpectedError);
}
}
});
};
// Duplicate File/Folder
export class DuplicateFileAction extends BaseFileAction {
private tree: ITree;
......
......@@ -77,8 +77,8 @@ export const revealInExplorerCommand = (accessor: ServicesAccessor, resource: UR
});
};
function openFocussedExplorerViewItem(accessor: ServicesAccessor, sideBySide: boolean): void {
withFocussedExplorerViewItem(accessor).then(res => {
function openFocusedFilesExplorerViewItem(accessor: ServicesAccessor, sideBySide: boolean): void {
withFocussedFilesExplorerViewItem(accessor).then(res => {
if (res) {
// Directory: Toggle expansion
......@@ -105,8 +105,8 @@ function openFocussedOpenedEditorsViewItem(accessor: ServicesAccessor, sideBySid
});
}
function runActionOnFocussedExplorerViewItem(accessor: ServicesAccessor, id: string, context?: any): void {
withFocussedExplorerViewItem(accessor).then(res => {
function runActionOnFocusedFilesExplorerViewItem(accessor: ServicesAccessor, id: string, context?: any): void {
withFocussedFilesExplorerViewItem(accessor).then(res => {
if (res) {
res.explorer.getViewletState().actionProvider.runAction(res.tree, res.item, id, context).done(null, errors.onUnexpectedError);
}
......@@ -124,7 +124,7 @@ function withVisibleExplorer(accessor: ServicesAccessor): TPromise<ExplorerViewl
return viewletService.openViewlet(VIEWLET_ID, false);
};
function withFocussedExplorerViewItem(accessor: ServicesAccessor): TPromise<{ explorer: ExplorerViewlet, tree: ITree, item: FileStat }> {
export function withFocussedFilesExplorerViewItem(accessor: ServicesAccessor): TPromise<{ explorer: ExplorerViewlet, tree: ITree, item: FileStat }> {
return withVisibleExplorer(accessor).then(explorer => {
if (!explorer || !explorer.getExplorerView()) {
return void 0; // empty folder or hidden explorer
......@@ -159,8 +159,8 @@ function withFocussedOpenEditorsViewItem(accessor: ServicesAccessor): TPromise<{
});
};
function withFocussedExplorerItem(accessor: ServicesAccessor): TPromise<FileStat | OpenEditor> {
return withFocussedExplorerViewItem(accessor).then(res => {
function withFocusedExplorerItem(accessor: ServicesAccessor): TPromise<FileStat | OpenEditor> {
return withFocussedFilesExplorerViewItem(accessor).then(res => {
if (res) {
return res.item;
}
......@@ -175,27 +175,27 @@ function withFocussedExplorerItem(accessor: ServicesAccessor): TPromise<FileStat
}) as TPromise<FileStat | OpenEditor>; // TypeScript fail
};
export const openFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => openFocussedExplorerViewItem(accessor, false);
export const openFocussedOpenedEditorsViewItemCommand = (accessor: ServicesAccessor) => openFocussedOpenedEditorsViewItem(accessor, false);
export const openFocussedFilesExplorerViewItemCommand = (accessor: ServicesAccessor) => openFocusedFilesExplorerViewItem(accessor, false);
export const openFocusedOpenedEditorsViewItemCommand = (accessor: ServicesAccessor) => openFocussedOpenedEditorsViewItem(accessor, false);
export const renameFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'filesExplorer.rename');
export const renameFocusedFilesExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocusedFilesExplorerViewItem(accessor, 'filesExplorer.rename');
};
export const deleteFocussedExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'filesExplorer.moveFileToTrash', { useTrash: false });
export const deleteFocusedFilesExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocusedFilesExplorerViewItem(accessor, 'filesExplorer.moveFileToTrash', { useTrash: false });
};
export const moveFocussedExplorerViewItemToTrashCommand = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'filesExplorer.moveFileToTrash', { useTrash: true });
export const moveFocusedFilesExplorerViewItemToTrashCommand = (accessor: ServicesAccessor) => {
runActionOnFocusedFilesExplorerViewItem(accessor, 'filesExplorer.moveFileToTrash', { useTrash: true });
};
export const copyFocussedExplorerViewItem = (accessor: ServicesAccessor) => {
runActionOnFocussedExplorerViewItem(accessor, 'filesExplorer.copy');
export const copyFocusedFilesExplorerViewItem = (accessor: ServicesAccessor) => {
runActionOnFocusedFilesExplorerViewItem(accessor, 'filesExplorer.copy');
};
export const copyPathOfFocussedExplorerItem = (accessor: ServicesAccessor) => {
withFocussedExplorerItem(accessor).then(item => {
export const copyPathOfFocusedExplorerItem = (accessor: ServicesAccessor) => {
withFocusedExplorerItem(accessor).then(item => {
const file = explorerItemToFileResource(item);
if (file) {
copyPathCommand(accessor, file.resource);
......@@ -203,18 +203,18 @@ export const copyPathOfFocussedExplorerItem = (accessor: ServicesAccessor) => {
});
};
export const openFocussedExplorerItemSideBySideCommand = (accessor: ServicesAccessor) => {
withFocussedExplorerItem(accessor).then(item => {
export const openFocusedExplorerItemSideBySideCommand = (accessor: ServicesAccessor) => {
withFocusedExplorerItem(accessor).then(item => {
if (item instanceof FileStat) {
openFocussedExplorerViewItem(accessor, true);
openFocusedFilesExplorerViewItem(accessor, true);
} else {
openFocussedOpenedEditorsViewItem(accessor, true);
}
});
};
export const revealInOSFocussedExplorerItem = (accessor: ServicesAccessor) => {
withFocussedExplorerItem(accessor).then(item => {
export const revealInOSFocusedFilesExplorerItem = (accessor: ServicesAccessor) => {
withFocusedExplorerItem(accessor).then(item => {
const file = explorerItemToFileResource(item);
if (file) {
revealInOSCommand(accessor, file.resource);
......
......@@ -27,7 +27,7 @@ import { ContributableActionProvider } from 'vs/workbench/browser/actionBarRegis
import { IFilesConfiguration } from 'vs/workbench/parts/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IFileOperationResult, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
import { DuplicateFileAction, ImportFileAction, PasteFileAction, keybindingForAction, IEditableData, IFileViewletState } from 'vs/workbench/parts/files/browser/fileActions';
import { DuplicateFileAction, ImportFileAction, keybindingForAction, IEditableData, IFileViewletState } from 'vs/workbench/parts/files/browser/fileActions';
import { IDataSource, ITree, IElementCallback, IAccessibilityProvider, IRenderer, ContextMenuEvent, ISorter, IFilter, IDragAndDrop, IDragAndDropData, IDragOverReaction, DRAG_OVER_ACCEPT_BUBBLE_DOWN, DRAG_OVER_ACCEPT_BUBBLE_DOWN_COPY, DRAG_OVER_ACCEPT_BUBBLE_UP, DRAG_OVER_ACCEPT_BUBBLE_UP_COPY, DRAG_OVER_REJECT } from 'vs/base/parts/tree/browser/tree';
import { DesktopDragAndDropData, ExternalElementsDragAndDropData } from 'vs/base/parts/tree/browser/treeDnd';
import { ClickBehavior, DefaultController } from 'vs/base/parts/tree/browser/treeDefaults';
......@@ -45,7 +45,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IMessageService, IConfirmation, Severity } from 'vs/platform/message/common/message';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Keybinding, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Keybinding, KeyCode } from 'vs/base/common/keyCodes';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
......@@ -390,9 +390,6 @@ export class FileController extends DefaultController {
this.contributedContextMenu = menuService.createMenu(MenuId.ExplorerContext, contextKeyService);
// Paste
this.downKeyBindingDispatcher.set(KeyMod.CtrlCmd | KeyCode.KEY_V, (t, e) => this.onPaste(t, e));
this.state = state;
}
......@@ -502,20 +499,6 @@ export class FileController extends DefaultController {
return true;
}
private onPaste(tree: ITree, event: IKeyboardEvent): boolean {
const stat: FileStat = tree.getFocus() || tree.getInput() /* root */;
if (stat) {
const pasteAction = this.instantiationService.createInstance(PasteFileAction, tree, stat);
if (pasteAction._isEnabled()) {
pasteAction.run().done(null, errors.onUnexpectedError);
return true;
}
}
return false;
}
private openEditor(stat: FileStat, preserveFocus: boolean, sideBySide: boolean, pinned = false): void {
if (stat && !stat.isDirectory) {
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'explorer' });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册