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

avoid extra commands for opening in explorer (for #4557)

上级 64801727
......@@ -23,11 +23,11 @@ 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 { copyFocusedFilesExplorerViewItem, revealInOSFocusedFilesExplorerItem, openFocusedOpenedEditorsViewItemCommand, openFocusedExplorerItemSideBySideCommand, copyPathOfFocusedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, openFocussedFilesExplorerViewItemCommand, deleteFocusedFilesExplorerViewItemCommand, moveFocusedFilesExplorerViewItemToTrashCommand, renameFocusedFilesExplorerViewItemCommand } from 'vs/workbench/parts/files/browser/fileCommands';
import { copyFocusedFilesExplorerViewItem, revealInOSFocusedFilesExplorerItem, openFocusedExplorerItemSideBySideCommand, copyPathOfFocusedExplorerItem, copyPathCommand, revealInExplorerCommand, revealInOSCommand, openFolderPickerCommand, openWindowCommand, openFileInNewWindowCommand, 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';
import { explorerItemToFileResource, ExplorerFocusCondition, OpenedEditorsFocusCondition, FilesExplorerFocusCondition } from 'vs/workbench/parts/files/common/files';
import { explorerItemToFileResource, ExplorerFocusCondition, FilesExplorerFocusCondition } from 'vs/workbench/parts/files/common/files';
class FilesViewerActionContributor extends ActionBarContributor {
......@@ -241,25 +241,6 @@ CommandsRegistry.registerCommand('workbench.action.files.openFileInNewWindow', o
const explorerCommandsWeightBonus = 10; // give our commands a little bit more weight over other default list/tree commands
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'openEditors.open',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
when: OpenedEditorsFocusCondition,
primary: KeyCode.Enter,
handler: openFocusedOpenedEditorsViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'filesExplorer.open',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
when: FilesExplorerFocusCondition,
primary: KeyCode.Enter,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.DownArrow
},
handler: openFocussedFilesExplorerViewItemCommand
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'explorer.openToSide',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(explorerCommandsWeightBonus),
......
......@@ -175,9 +175,6 @@ function withFocusedExplorerItem(accessor: ServicesAccessor): TPromise<FileStat
}) as TPromise<FileStat | OpenEditor>; // TypeScript fail
};
export const openFocussedFilesExplorerViewItemCommand = (accessor: ServicesAccessor) => openFocusedFilesExplorerViewItem(accessor, false);
export const openFocusedOpenedEditorsViewItemCommand = (accessor: ServicesAccessor) => openFocussedOpenedEditorsViewItem(accessor, false);
export const renameFocusedFilesExplorerViewItemCommand = (accessor: ServicesAccessor) => {
runActionOnFocusedFilesExplorerViewItem(accessor, 'filesExplorer.rename');
};
......
......@@ -368,6 +368,13 @@ export class ExplorerView extends CollapsibleViewletView {
this.folderContext.set(e.focus && e.focus.isDirectory);
}));
// Open when selecting via keyboard
this.toDispose.push(this.explorerViewer.addListener2('selection', event => {
if (event && event.payload && event.payload.origin === 'keyboard') {
controller.openEditor(this.tree.getFocus(), { pinned: false, sideBySide: false, preserveFocus: false });
}
}));
return this.explorerViewer;
}
......
......@@ -450,7 +450,7 @@ export class FileController extends DefaultController {
tree.setSelection([stat], payload);
if (!stat.isDirectory) {
this.openEditor(stat, preserveFocus, event && (event.ctrlKey || event.metaKey), isDoubleClick);
this.openEditor(stat, { preserveFocus, sideBySide: event && (event.ctrlKey || event.metaKey), pinned: isDoubleClick });
}
}
......@@ -499,11 +499,11 @@ export class FileController extends DefaultController {
return true;
}
private openEditor(stat: FileStat, preserveFocus: boolean, sideBySide: boolean, pinned = false): void {
public openEditor(stat: FileStat, options: { preserveFocus: boolean; sideBySide: boolean; pinned: boolean; }): void {
if (stat && !stat.isDirectory) {
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'explorer' });
this.editorService.openEditor({ resource: stat.resource, options: { preserveFocus, pinned } }, sideBySide).done(null, errors.onUnexpectedError);
this.editorService.openEditor({ resource: stat.resource, options }, options.sideBySide).done(null, errors.onUnexpectedError);
}
}
}
......
......@@ -124,6 +124,13 @@ export class OpenEditorsView extends AdaptiveCollapsibleViewletView {
// Register to list service
this.toDispose.push(this.listService.register(this.tree, [this.explorerFocussedContext, this.openEditorsFocussedContext]));
// Open when selecting via keyboard
this.toDispose.push(this.tree.addListener2('selection', event => {
if (event && event.payload && event.payload.origin === 'keyboard') {
controller.openEditor(this.tree.getFocus(), { pinned: false, sideBySide: false, preserveFocus: false });
}
}));
this.fullRefreshNeeded = true;
this.structuralTreeUpdate();
}
......
......@@ -8,7 +8,7 @@ import errors = require('vs/base/common/errors');
import { TPromise } from 'vs/base/common/winjs.base';
import { IAction } from 'vs/base/common/actions';
import { EditorLabel } from 'vs/workbench/browser/labels';
import treedefaults = require('vs/base/parts/tree/browser/treeDefaults');
import { DefaultController, ClickBehavior, DefaultDragAndDrop } from 'vs/base/parts/tree/browser/treeDefaults';
import { IDataSource, ITree, IAccessibilityProvider, IDragAndDropData, IDragOverReaction, DRAG_OVER_ACCEPT, DRAG_OVER_REJECT, ContextMenuEvent, IRenderer } from 'vs/base/parts/tree/browser/tree';
import { ExternalElementsDragAndDropData, ElementsDragAndDropData, DesktopDragAndDropData } from 'vs/base/parts/tree/browser/treeDnd';
import { ActionBar, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
......@@ -164,7 +164,7 @@ export class Renderer implements IRenderer {
}
}
export class Controller extends treedefaults.DefaultController {
export class Controller extends DefaultController {
constructor(private actionProvider: ActionProvider, private model: IEditorStacksModel,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
......@@ -173,7 +173,7 @@ export class Controller extends treedefaults.DefaultController {
@ITelemetryService private telemetryService: ITelemetryService,
@IKeybindingService private keybindingService: IKeybindingService
) {
super({ clickBehavior: treedefaults.ClickBehavior.ON_MOUSE_DOWN, keyboardSupport: false });
super({ clickBehavior: ClickBehavior.ON_MOUSE_DOWN, keyboardSupport: false });
}
public onClick(tree: ITree, element: any, event: IMouseEvent): boolean {
......@@ -226,7 +226,7 @@ export class Controller extends treedefaults.DefaultController {
}
tree.setSelection([element], payload);
this.openEditor(element, isDoubleClick, event.ctrlKey || event.metaKey);
this.openEditor(element, { preserveFocus: !isDoubleClick, pinned: isDoubleClick, sideBySide: event.ctrlKey || event.metaKey });
}
return true;
......@@ -273,15 +273,15 @@ export class Controller extends treedefaults.DefaultController {
return true;
}
private openEditor(element: OpenEditor, pinEditor: boolean, openToSide: boolean): void {
public openEditor(element: OpenEditor, options: { preserveFocus: boolean; pinned: boolean; sideBySide: boolean; }): void {
if (element) {
this.telemetryService.publicLog('workbenchActionExecuted', { id: 'workbench.files.openFile', from: 'openEditors' });
let position = this.model.positionOfGroup(element.editorGroup);
if (openToSide && position !== Position.THREE) {
if (options.sideBySide && position !== Position.THREE) {
position++;
}
this.editorGroupService.activateGroup(this.model.groupAt(position));
this.editorService.openEditor(element.editorInput, { preserveFocus: !pinEditor, pinned: pinEditor }, position)
this.editorService.openEditor(element.editorInput, options, position)
.done(() => this.editorGroupService.activateGroup(this.model.groupAt(position)), errors.onUnexpectedError);
}
}
......@@ -416,7 +416,7 @@ export class ActionProvider extends ContributableActionProvider {
}
}
export class DragAndDrop extends treedefaults.DefaultDragAndDrop {
export class DragAndDrop extends DefaultDragAndDrop {
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
......
......@@ -32,7 +32,6 @@ export const OpenEditorsFocussedContext = new RawContextKey<boolean>(openEditors
export const ExplorerFocussedContext = new RawContextKey<boolean>(explorerViewletFocusId, false);
export const FilesExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(filesExplorerFocusId));
export const OpenedEditorsFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(openEditorsFocusId));
export const ExplorerFocusCondition = ContextKeyExpr.and(ContextKeyExpr.has(explorerViewletVisibleId), ContextKeyExpr.has(explorerViewletFocusId));
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册