Skip to content

Commit

Permalink
first version of simple clipboard API, #217
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Oct 8, 2018
1 parent e202759 commit 1580cd1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ declare module 'vscode' {
export function sampleFunction(): Thenable<any>;
}

//#region Joh - clipboard https://github.com/Microsoft/vscode/issues/217

export interface Clipboard {
readText(): Promise<string>;
writeText(value: string): Promise<void>;
}

export namespace env {
export const clipboard: Clipboard;
}

//#endregion

//#region Joh - read/write in chunks

export interface FileSystemProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { LanguageConfigurationFileHandler } from 'vs/workbench/parts/codeEditor/

// --- mainThread participants
import 'vs/workbench/api/node/apiCommands';
import './mainThreadClipboard';
import './mainThreadCommands';
import './mainThreadConfiguration';
import './mainThreadDebugService';
Expand Down
27 changes: 27 additions & 0 deletions src/vs/workbench/api/electron-browser/mainThreadClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*---------------------------------------------------------------------------------------------
* 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 { clipboard } from 'electron';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { MainContext, MainThreadClipboardShape } from '../node/extHost.protocol';

@extHostNamedCustomer(MainContext.MainThreadClipboard)
export class MainThreadCommands implements MainThreadClipboardShape {

dispose(): void {
// nothing
}

$readText(): Promise<string> {
return Promise.resolve(clipboard.readText());
}

$writeText(value: string): Promise<void> {
clipboard.writeText(value);
return undefined;
}
}
6 changes: 6 additions & 0 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -237,6 +239,10 @@ export function createApiFactory(
get onDidChangeLogLevel() {
checkProposedApiEnabled(extension);
return extHostLogService.onDidChangeLogLevel;
},
get clipboard(): vscode.Clipboard {
checkProposedApiEnabled(extension);
return extHostClipboard;
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
Expand Down
26 changes: 26 additions & 0 deletions src/vs/workbench/api/node/extHostClipboard.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 1580cd1

Please sign in to comment.