Skip to content

Commit

Permalink
avoid extra commands for opening in explorer (for #4557)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Feb 20, 2017
1 parent 6480172 commit d6f1ca7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
23 changes: 2 additions & 21 deletions src/vs/workbench/parts/files/browser/fileActions.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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),
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/parts/files/browser/fileCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/parts/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/parts/files/browser/views/explorerViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/parts/files/browser/views/openEditorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/parts/files/browser/views/openEditorsViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/parts/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/**
Expand Down

0 comments on commit d6f1ca7

Please sign in to comment.