From c51c77c88f58cb8b3211df68fa5afe4ec554ad41 Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 5 Jan 2018 11:06:38 +0100 Subject: [PATCH] explorer: only pass uri as a context fixes #41157 --- .../files/electron-browser/fileActions.ts | 71 +++++++------------ .../electron-browser/views/explorerView.ts | 2 +- .../electron-browser/views/explorerViewer.ts | 12 +--- 3 files changed, 27 insertions(+), 58 deletions(-) diff --git a/src/vs/workbench/parts/files/electron-browser/fileActions.ts b/src/vs/workbench/parts/files/electron-browser/fileActions.ts index 8ed19009de2..d39e684d6c7 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileActions.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileActions.ts @@ -8,7 +8,7 @@ import 'vs/css!./media/fileactions'; import { TPromise } from 'vs/base/common/winjs.base'; import nls = require('vs/nls'); -import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform'; +import { isWindows, isLinux } from 'vs/base/common/platform'; import { sequence, ITask, always } from 'vs/base/common/async'; import paths = require('vs/base/common/paths'); import resources = require('vs/base/common/resources'); @@ -51,19 +51,12 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IListService, ListWidget } from 'vs/platform/list/browser/listService'; import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IEvent } from 'vs/platform/contextview/browser/contextView'; export interface IEditableData { action: IAction; validator: IInputValidator; } -export interface IExplorerContext { - viewletState: IFileViewletState; - event?: IEvent; - stat: FileStat; -} - export interface IFileViewletState { getEditableData(stat: IFileStat): IEditableData; setEditable(stat: IFileStat, editableData: IEditableData): void; @@ -662,18 +655,6 @@ class BaseDeleteFileAction extends BaseFileAction { this.tree.clearHighlight(); } - // Read context - if (context) { - if (context.event) { - const bypassTrash = (isMacintosh && context.event.altKey) || (!isMacintosh && context.event.shiftKey); - if (bypassTrash) { - this.useTrash = false; - } - } else if (typeof context.useTrash === 'boolean') { - this.useTrash = context.useTrash; - } - } - let primaryButton: string; if (this.useTrash) { primaryButton = isWindows ? nls.localize('deleteButtonLabelRecycleBin', "&&Move to Recycle Bin") : nls.localize({ key: 'deleteButtonLabelTrash', comment: ['&& denotes a mnemonic'] }, "&&Move to Trash"); @@ -1549,13 +1530,24 @@ if (!diag) { }); } +interface IExplorerContext { + viewletState: IFileViewletState; + stat: FileStat; +} + +function getContext(tree: ListWidget, viewletService: IViewletService): IExplorerContext { + // These commands can only be triggered when explorer viewlet is visible so get it using the active viewlet + return { stat: tree.getFocus(), viewletState: (viewletService.getActiveViewlet()).getViewletState() }; +} + // TODO@isidor these commands are calling into actions due to the complex inheritance action structure. // It should be the other way around, that actions call into commands. CommandsRegistry.registerCommand({ id: NEW_FILE_COMMAND_ID, - handler: (accessor, resource: URI, explorerContext: IExplorerContext) => { + handler: (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const newFileAction = instantationService.createInstance(NewFileAction, listService.lastFocusedList, explorerContext.stat); return newFileAction.run(explorerContext); @@ -1564,69 +1556,56 @@ CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({ id: NEW_FOLDER_COMMAND_ID, - handler: (accessor, resource: URI, explorerContext: IExplorerContext) => { + handler: (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const newFolderAction = instantationService.createInstance(NewFolderAction, listService.lastFocusedList, explorerContext.stat); return newFolderAction.run(explorerContext); } }); -function getContext(tree: ListWidget, viewletService: IViewletService): IExplorerContext { - return { stat: tree.getFocus(), viewletState: (viewletService.getActiveViewlet()).getViewletState() }; -} - -export const renameHandler = (accessor: ServicesAccessor, resource: URI, explorerContext: IExplorerContext) => { +export const renameHandler = (accessor: ServicesAccessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); - if (!explorerContext) { - explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); - } + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const renameAction = instantationService.createInstance(TriggerRenameFileAction, listService.lastFocusedList, explorerContext.stat); return renameAction.run(explorerContext); }; -export const moveFileToTrashHandler = (accessor, resource: URI, explorerContext: IExplorerContext) => { +export const moveFileToTrashHandler = (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); - if (!explorerContext) { - explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); - } + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const moveFileToTrashAction = instantationService.createInstance(BaseDeleteFileAction, listService.lastFocusedList, explorerContext.stat, true); return moveFileToTrashAction.run(explorerContext); }; -export const deleteFileHandler = (accessor, resource: URI, explorerContext: IExplorerContext) => { +export const deleteFileHandler = (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); - if (!explorerContext) { - explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); - } + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const deleteFileAction = instantationService.createInstance(BaseDeleteFileAction, listService.lastFocusedList, explorerContext.stat, false); return deleteFileAction.run(explorerContext); }; -export const copyFileHandler = (accessor, resource: URI, explorerContext: IExplorerContext) => { +export const copyFileHandler = (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); - if (!explorerContext) { - explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); - } + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const copyFileAction = instantationService.createInstance(CopyFileAction, listService.lastFocusedList, explorerContext.stat); return copyFileAction.run(); }; -export const pasteFileHandler = (accessor, resource: URI, explorerContext: IExplorerContext) => { +export const pasteFileHandler = (accessor) => { const instantationService = accessor.get(IInstantiationService); const listService = accessor.get(IListService); - if (!explorerContext) { - explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); - } + const explorerContext = getContext(listService.lastFocusedList, accessor.get(IViewletService)); const pasteFileAction = instantationService.createInstance(PasteFileAction, listService.lastFocusedList, explorerContext.stat); return pasteFileAction.run(); diff --git a/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts b/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts index 4b8c029d678..b821ad5dc7d 100644 --- a/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/electron-browser/views/explorerView.ts @@ -395,7 +395,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView public createViewer(container: Builder): WorkbenchTree { const dataSource = this.instantiationService.createInstance(FileDataSource); const renderer = this.instantiationService.createInstance(FileRenderer, this.viewletState); - const controller = this.instantiationService.createInstance(FileController, this.viewletState); + const controller = this.instantiationService.createInstance(FileController); this.disposables.push(controller); const sorter = this.instantiationService.createInstance(FileSorter); this.disposables.push(sorter); diff --git a/src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts b/src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts index 631831a7d9b..4911690221a 100644 --- a/src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts +++ b/src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts @@ -327,13 +327,11 @@ export class FileAccessibilityProvider implements IAccessibilityProvider { // Explorer Controller export class FileController extends DefaultController implements IDisposable { - private state: FileViewletState; private contributedContextMenu: IMenu; private toDispose: IDisposable[]; - constructor(state: FileViewletState, - @IWorkbenchEditorService private editorService: IWorkbenchEditorService, + constructor( @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IContextMenuService private contextMenuService: IContextMenuService, @ITelemetryService private telemetryService: ITelemetryService, @IMenuService menuService: IMenuService, @@ -345,7 +343,6 @@ export class FileController extends DefaultController implements IDisposable { this.contributedContextMenu = menuService.createMenu(MenuId.ExplorerContext, contextKeyService); this.toDispose.push(this.contributedContextMenu); - this.state = state; } public onLeftClick(tree: ITree, stat: FileStat | Model, event: IMouseEvent, origin: string = 'mouse'): boolean { @@ -430,13 +427,6 @@ export class FileController extends DefaultController implements IDisposable { fillInActions(this.contributedContextMenu, { arg: stat instanceof FileStat ? stat.resource : undefined, shouldForwardArgs: true }, actions); return TPromise.as(actions); }, - getActionsContext: (event) => { - return { - viewletState: this.state, - stat, - event - }; - }, onHide: (wasCancelled?: boolean) => { if (wasCancelled) { tree.DOMFocus(); -- GitLab