mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 02:58:31 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
81
src/vs/platform/message/common/message.ts
Normal file
81
src/vs/platform/message/common/message.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import nls = require('vs/nls');
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
|
||||
export interface IMessageWithAction {
|
||||
message: string;
|
||||
actions: Action[];
|
||||
source?: string;
|
||||
}
|
||||
|
||||
export interface IConfirmation {
|
||||
title?: string;
|
||||
type?: 'none' | 'info' | 'error' | 'question' | 'warning';
|
||||
message: string;
|
||||
detail?: string;
|
||||
primaryButton?: string;
|
||||
secondaryButton?: string;
|
||||
}
|
||||
|
||||
export const CloseAction = new Action('close.message', nls.localize('close', "Close"), null, true, () => TPromise.as(true));
|
||||
export const LaterAction = new Action('later.message', nls.localize('later', "Later"), null, true, () => TPromise.as(true));
|
||||
export const CancelAction = new Action('cancel.message', nls.localize('cancel', "Cancel"), null, true, () => TPromise.as(true));
|
||||
|
||||
export const IMessageService = createDecorator<IMessageService>('messageService');
|
||||
|
||||
export interface IMessageService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Tells the service to show a message with a given severity
|
||||
* the returned function can be used to hide the message again
|
||||
*/
|
||||
show(sev: Severity, message: string): () => void;
|
||||
show(sev: Severity, message: Error): () => void;
|
||||
show(sev: Severity, message: string[]): () => void;
|
||||
show(sev: Severity, message: Error[]): () => void;
|
||||
show(sev: Severity, message: IMessageWithAction): () => void;
|
||||
|
||||
/**
|
||||
* Hide any messages showing currently.
|
||||
*/
|
||||
hideAll(): void;
|
||||
|
||||
/**
|
||||
* Ask the user for confirmation.
|
||||
*/
|
||||
confirm(confirmation: IConfirmation): boolean;
|
||||
}
|
||||
|
||||
export const IChoiceService = createDecorator<IChoiceService>('choiceService');
|
||||
|
||||
export interface IChoiceService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Prompt the user for a choice between multiple options.
|
||||
*
|
||||
* @param when `modal` is true, this will block the user until chooses.
|
||||
*
|
||||
* @returns A promise with the selected choice index. The promise is cancellable
|
||||
* which hides the message. The promise can return an error, meaning that
|
||||
* the user refused to choose.
|
||||
*
|
||||
* When `modal` is true and user refused to choose, then promise with index of
|
||||
* `Cancel` option is returned. If there is no such option then promise with
|
||||
* `0` index is returned.
|
||||
*/
|
||||
choose(severity: Severity, message: string, options: string[], cancelId: number, modal?: boolean): TPromise<number>;
|
||||
}
|
||||
|
||||
export import Severity = Severity;
|
||||
39
src/vs/platform/message/common/messageIpc.ts
Normal file
39
src/vs/platform/message/common/messageIpc.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
|
||||
|
||||
export interface IChoiceChannel extends IChannel {
|
||||
call(command: 'choose'): TPromise<number>;
|
||||
call(command: string, arg?: any): TPromise<any>;
|
||||
}
|
||||
|
||||
export class ChoiceChannel implements IChoiceChannel {
|
||||
|
||||
constructor( @IChoiceService private choiceService: IChoiceService) {
|
||||
}
|
||||
|
||||
call(command: string, args?: [Severity, string, string[], number, boolean]): TPromise<any> {
|
||||
switch (command) {
|
||||
case 'choose': return this.choiceService.choose(args[0], args[1], args[2], args[3], args[4]);
|
||||
}
|
||||
return TPromise.wrapError(new Error('invalid command'));
|
||||
}
|
||||
}
|
||||
|
||||
export class ChoiceChannelClient implements IChoiceService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private channel: IChoiceChannel) { }
|
||||
|
||||
choose(severity: Severity, message: string, options: string[], cancelId: number, modal?: boolean): TPromise<number> {
|
||||
return this.channel.call('choose', [severity, message, options, cancelId, modal]);
|
||||
}
|
||||
}
|
||||
57
src/vs/platform/message/node/messageCli.ts
Normal file
57
src/vs/platform/message/node/messageCli.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as readline from 'readline';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
|
||||
|
||||
export class ChoiceCliService implements IChoiceService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
choose(severity: Severity, message: string, options: string[], cancelId: number): TPromise<number> {
|
||||
const promise = new TPromise<number>((c, e) => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: true
|
||||
});
|
||||
rl.prompt();
|
||||
rl.write(this.toQuestion(message, options));
|
||||
|
||||
rl.prompt();
|
||||
|
||||
rl.once('line', (answer) => {
|
||||
rl.close();
|
||||
c(this.toOption(answer, options));
|
||||
});
|
||||
rl.once('SIGINT', () => {
|
||||
rl.close();
|
||||
promise.cancel();
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
private toQuestion(message: string, options: string[]): string {
|
||||
return options.reduce((previousValue: string, currentValue: string, currentIndex: number) => {
|
||||
return previousValue + currentValue + '(' + currentIndex + ')' + (currentIndex < options.length - 1 ? ' | ' : '\n');
|
||||
}, message + ' ');
|
||||
}
|
||||
|
||||
private toOption(answer: string, options: string[]): number {
|
||||
const value = parseInt(answer);
|
||||
if (!isNaN(value)) {
|
||||
return value;
|
||||
}
|
||||
answer = answer.toLocaleLowerCase();
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
if (options[i].toLocaleLowerCase() === answer) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user