提交 a941b59f 编写于 作者: J Johannes Rieken

add 'vscode.open' API command, fixes #566

上级 5ed2332c
......@@ -7,7 +7,7 @@
import * as assert from 'assert';
import {join} from 'path';
import {commands, workspace, window, Uri} from 'vscode';
import {commands, workspace, window, Uri, ViewColumn} from 'vscode';
suite('commands namespace tests', () => {
......@@ -103,4 +103,14 @@ suite('commands namespace tests', () => {
return Promise.all([a, b, c, d]);
});
test('api-command: vscode.open', function () {
let uri = Uri.file(join(workspace.rootPath, './image.png'));
let a = commands.executeCommand('vscode.open', uri).then(() => assert.ok(true), () => assert.ok(false));
let b = commands.executeCommand('vscode.open', uri, ViewColumn.Two).then(() => assert.ok(true), () => assert.ok(false));
let c = commands.executeCommand('vscode.open').then(() => assert.ok(false), () => assert.ok(true));
let d = commands.executeCommand('vscode.open', uri, true).then(() => assert.ok(false), () => assert.ok(true));
return Promise.all([a, b, c, d]);
});
});
......@@ -208,6 +208,16 @@ class ExtHostApiCommands {
{ name: 'title', description: '(optional) Human readable title for the diff editor', constraint: v => v === void 0 || typeof v === 'string' }
]
});
this._register('vscode.open', (resource: URI, column: vscode.ViewColumn) => {
return this._commands.executeCommand('_workbench.open', [resource, typeConverters.fromViewColumn(column)]);
}, {
description: 'Opens the provided resource in the editor. Can be a text or binary file.',
args: [
{ name: 'resource', description: 'Resource to open', constraint: URI },
{ name: 'column', description: '(optional) Column in which to open', constraint: v => v === void 0 || typeof v === 'number' }
]
});
}
// --- command impl
......
......@@ -491,4 +491,20 @@ KeybindingsRegistry.registerCommandDesc({
},
when: undefined,
primary: undefined
});
KeybindingsRegistry.registerCommandDesc({
id: '_workbench.open',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(0),
handler(accessor: ServicesAccessor, args: [URI, number]) {
const editorService = accessor.get(IWorkbenchEditorService);
let [resource, column] = args;
return editorService.openEditor({ resource }, column).then(() => {
return void 0;
});
},
when: undefined,
primary: undefined
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册