first version of simple clipboard API, #217

This commit is contained in:
Johannes Rieken
2018-10-08 12:38:26 +02:00
parent e202759899
commit 1580cd1846
6 changed files with 79 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ import { ExtHostComments } from './extHostComments';
import { ExtHostSearch } from './extHostSearch';
import { ExtHostUrls } from './extHostUrls';
import { localize } from 'vs/nls';
import { ExtHostClipboard } from 'vs/workbench/api/node/extHostClipboard';
export interface IExtensionApiFactory {
(extension: IExtensionDescription): typeof vscode;
@@ -134,6 +135,7 @@ export function createApiFactory(
rpcProtocol.assertRegistered(expected);
// Other instances
const extHostClipboard = new ExtHostClipboard(rpcProtocol);
const extHostMessageService = new ExtHostMessageService(rpcProtocol);
const extHostDialogs = new ExtHostDialogs(rpcProtocol);
const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
@@ -237,6 +239,10 @@ export function createApiFactory(
get onDidChangeLogLevel() {
checkProposedApiEnabled(extension);
return extHostLogService.onDidChangeLogLevel;
},
get clipboard(): vscode.Clipboard {
checkProposedApiEnabled(extension);
return extHostClipboard;
}
});

View File

@@ -86,6 +86,11 @@ export interface IMainContext extends IRPCProtocol {
// --- main thread
export interface MainThreadClipboardShape extends IDisposable {
$readText(): Promise<string>;
$writeText(value: string): Promise<void>;
}
export interface MainThreadCommandsShape extends IDisposable {
$registerCommand(id: string): void;
$unregisterCommand(id: string): void;
@@ -1014,6 +1019,7 @@ export interface ExtHostCommentsShape {
// --- proxy identifiers
export const MainContext = {
MainThreadClipboard: <ProxyIdentifier<MainThreadClipboardShape>>createMainId<MainThreadClipboardShape>('MainThreadClipboard'),
MainThreadCommands: <ProxyIdentifier<MainThreadCommandsShape>>createMainId<MainThreadCommandsShape>('MainThreadCommands'),
MainThreadComments: createMainId<MainThreadCommentsShape>('MainThreadComments'),
MainThreadConfiguration: createMainId<MainThreadConfigurationShape>('MainThreadConfiguration'),

View File

@@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IMainContext, MainContext, MainThreadClipboardShape } from 'vs/workbench/api/node/extHost.protocol';
import * as vscode from 'vscode';
export class ExtHostClipboard implements vscode.Clipboard {
private readonly _proxy: MainThreadClipboardShape;
constructor(mainContext: IMainContext) {
this._proxy = mainContext.getProxy(MainContext.MainThreadClipboard);
}
readText(): Promise<string> {
return this._proxy.$readText();
}
writeText(value: string): Promise<void> {
return this._proxy.$writeText(value);
}
}