dialogIpc.ts 1.5 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Joao Moreno 已提交
6
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
7 8
import { IDialogService, IConfirmation, IConfirmationResult } from 'vs/platform/dialogs/common/dialogs';
import Severity from 'vs/base/common/severity';
J
Joao Moreno 已提交
9
import { Event } from 'vs/base/common/event';
10

J
Joao Moreno 已提交
11
export class DialogChannel implements IServerChannel {
12

J
Joao Moreno 已提交
13 14
	constructor(@IDialogService private dialogService: IDialogService) { }

J
Joao Moreno 已提交
15 16
	listen<T>(_, event: string): Event<T> {
		throw new Error(`Event not found: ${event}`);
17 18
	}

J
Joao Moreno 已提交
19
	call(_, command: string, args?: any[]): Thenable<any> {
20
		switch (command) {
21 22
			case 'show': return this.dialogService.show(args![0], args![1], args![2]);
			case 'confirm': return this.dialogService.confirm(args![0]);
23
		}
B
Benjamin Pasero 已提交
24
		return Promise.reject(new Error('invalid command'));
25 26 27 28 29 30 31
	}
}

export class DialogChannelClient implements IDialogService {

	_serviceBrand: any;

J
Joao Moreno 已提交
32
	constructor(private channel: IChannel) { }
33

B
Benjamin Pasero 已提交
34 35
	show(severity: Severity, message: string, options: string[]): Thenable<number> {
		return this.channel.call('show', [severity, message, options]);
36 37
	}

B
Benjamin Pasero 已提交
38 39
	confirm(confirmation: IConfirmation): Thenable<IConfirmationResult> {
		return this.channel.call('confirm', [confirmation]);
40 41
	}
}