mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 22:46:48 -05:00
add 'vscode.open' API command, fixes #566
This commit is contained in:
@@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
BIN
extensions/vscode-api-tests/testWorkspace/image.png
Normal file
BIN
extensions/vscode-api-tests/testWorkspace/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -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
|
||||
});
|
||||
Reference in New Issue
Block a user