Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 11, 2020
1 parent 31c0346 commit fd968fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/vs/workbench/api/common/apiCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import { CommandsRegistry, ICommandService, ICommandHandler } from 'vs/platform/commands/common/commands';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorViewColumn } from 'vs/workbench/api/common/shared/editor';
import { EditorGroupLayout } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
Expand All @@ -17,6 +17,7 @@ import { Schemas } from 'vs/base/common/network';
import { ILogService } from 'vs/platform/log/common/log';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IViewDescriptorService, IViewsService, ViewVisibilityState } from 'vs/workbench/common/views';
import { SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';

// -----------------------------------------------------------------
// The following commands are registered on both sides separately.
Expand Down Expand Up @@ -113,6 +114,19 @@ CommandsRegistry.registerCommand(DiffAPICommand.ID, adjustHandler(DiffAPICommand
export class OpenAPICommand {
public static readonly ID = 'vscode.open';
public static execute(executor: ICommandsExecutor, resource: URI, columnOrOptions?: vscode.ViewColumn | typeConverters.TextEditorOpenOptions, label?: string): Promise<any> {
const internalTypes = OpenAPICommand._toInternalTypes(columnOrOptions);

return OpenAPICommand._doExecute(executor, resource, internalTypes.options, internalTypes.position, label);
}
public static executeWithContext(executor: ICommandsExecutor, context: { editorOptions: IEditorOptions; sideBySide: boolean }, resource: URI, columnOrOptions?: vscode.ViewColumn | typeConverters.TextEditorOpenOptions, label?: string): Promise<any> {
const internalTypes = OpenAPICommand._toInternalTypes(columnOrOptions);

const options = { ...(internalTypes.options ?? Object.create(null)), ...context.editorOptions };
const position = context.sideBySide ? SIDE_GROUP : internalTypes.position;

return OpenAPICommand._doExecute(executor, resource, options, position, label);
}
private static _toInternalTypes(columnOrOptions?: vscode.ViewColumn | typeConverters.TextEditorOpenOptions): { position: number | undefined, options: ITextEditorOptions | undefined } {
let options: ITextEditorOptions | undefined;
let position: EditorViewColumn | undefined;

Expand All @@ -125,6 +139,9 @@ export class OpenAPICommand {
}
}

return { position, options };
}
private static _doExecute(executor: ICommandsExecutor, resource: URI, options: ITextEditorOptions | undefined, position: number | undefined, label: string | undefined): Promise<any> {
return executor.executeCommand('_workbench.open', [
resource,
options,
Expand Down
10 changes: 8 additions & 2 deletions src/vs/workbench/contrib/views/browser/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { IHoverDelegate, IHoverDelegateOptions } from 'vs/base/browser/ui/iconLa
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IIconLabelMarkdownString } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { renderMarkdownAsPlaintext } from 'vs/base/browser/markdownRenderer';
import { OpenAPICommand } from 'vs/workbench/api/common/apiCommands';

class Root implements ITreeItem {
label = { label: 'root' };
Expand Down Expand Up @@ -462,8 +463,13 @@ export class TreeView extends Disposable implements ITreeView {
return;
}
const selection = this.tree!.getSelection();
if ((selection.length === 1) && selection[0].command) {
this.commandService.executeCommand(selection[0].command.id, ...(selection[0].command.arguments || []));
const command = selection[0].command;
if ((selection.length === 1) && command) {
if (command.id === OpenAPICommand.ID) {
OpenAPICommand.executeWithContext(this.commandService, e, command.arguments?.[0], command.arguments?.[1], command.arguments?.[2]);
} else {
this.commandService.executeCommand(command.id, ...(command.arguments || []));
}
}
}));

Expand Down

0 comments on commit fd968fe

Please sign in to comment.