WIP refactor of integrated terminal part

This commit is contained in:
Daniel Imms
2016-09-09 19:01:16 -07:00
parent f0644a47fc
commit 9981aefa8a
10 changed files with 1390 additions and 892 deletions

View File

@@ -153,7 +153,7 @@ export abstract class MainThreadOutputServiceShape {
}
export abstract class MainThreadTerminalServiceShape {
$createTerminal(name?: string): TPromise<number> { throw ni(); }
$createTerminal(name?: string): number { throw ni(); }
$dispose(terminalId: number): void { throw ni(); }
$hide(terminalId: number): void { throw ni(); }
$sendText(terminalId: number, text: string, addNewLine: boolean): void { throw ni(); }

View File

@@ -15,17 +15,11 @@ export class ExtHostTerminal implements vscode.Terminal {
private _id: number;
private _proxy: MainThreadTerminalServiceShape;
private _disposed: boolean;
private _queuedRequests: ApiRequest[] = [];
constructor(proxy: MainThreadTerminalServiceShape, id: number, name?: string) {
this._name = name;
this._proxy = proxy;
this._proxy.$createTerminal(name).then((terminalId) => {
this._id = terminalId;
this._queuedRequests.forEach((r) => {
r.run(this._proxy, this._id);
});
});
this._id = this._proxy.$createTerminal(name);
}
public get name(): string {
@@ -35,32 +29,17 @@ export class ExtHostTerminal implements vscode.Terminal {
public sendText(text: string, addNewLine: boolean = true): void {
this._checkDisposed();
let request: ApiRequest = new ApiRequest(this._proxy.$sendText, [text, addNewLine]);
if (!this._id) {
this._queuedRequests.push(request);
return;
}
request.run(this._proxy, this._id);
this._proxy.$sendText(this._id, text, addNewLine);
}
public show(preserveFocus: boolean): void {
this._checkDisposed();
let request: ApiRequest = new ApiRequest(this._proxy.$show, [preserveFocus]);
if (!this._id) {
this._queuedRequests.push(request);
return;
}
request.run(this._proxy, this._id);
this._proxy.$show(this._id, preserveFocus);
}
public hide(): void {
this._checkDisposed();
let request: ApiRequest = new ApiRequest(this._proxy.$hide, []);
if (!this._id) {
this._queuedRequests.push(request);
return;
}
request.run(this._proxy, this._id);
this._proxy.$hide(this._id);
}
public dispose(): void {
@@ -89,17 +68,3 @@ export class ExtHostTerminalService {
return new ExtHostTerminal(this._proxy, -1, name);
}
}
class ApiRequest {
private _callback: (...args: any[]) => void;
private _args: any[];
constructor(callback: (...args: any[]) => void, args: any[]) {
this._callback = callback;
this._args = args;
}
public run(proxy: MainThreadTerminalServiceShape, id: number) {
this._callback.apply(proxy, [id].concat(this._args));
}
}

View File

@@ -4,50 +4,53 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import {TPromise} from 'vs/base/common/winjs.base';
import {ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminal';
import {ITerminalService, TERMINAL_PANEL_ID} from 'vs/workbench/parts/terminal/electron-browser/terminal';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {MainThreadTerminalServiceShape} from './extHost.protocol';
export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
private _terminalService: ITerminalService;
constructor(
@ITerminalService terminalService: ITerminalService
@IPanelService private panelService: IPanelService,
@IPartService private partService: IPartService,
@ITerminalService private terminalService: ITerminalService
) {
super();
this._terminalService = terminalService;
}
public $createTerminal(name?: string): TPromise<number> {
return this._terminalService.createNew(name);
public $createTerminal(name?: string): number {
return this.terminalService.createInstance(name).id;
}
public $show(terminalId: number, preserveFocus: boolean): void {
this._terminalService.show(!preserveFocus).then((terminalPanel) => {
this._terminalService.setActiveTerminalById(terminalId);
if (!preserveFocus) {
// If the panel was already showing an explicit focus call is necessary here.
terminalPanel.focus();
}
});
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
this.terminalService.setActiveInstance(terminalInstance);
this.terminalService.showPanel(!preserveFocus);
}
}
public $hide(terminalId: number): void {
this._terminalService.hideTerminalInstance(terminalId);
if (this.terminalService.getActiveInstance().id === terminalId) {
const panel = this.panelService.getActivePanel();
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
this.partService.setPanelHidden(true);
}
}
}
public $dispose(terminalId: number): void {
// TODO: This could be improved by not first showing the terminal to be disposed
this._terminalService.show(false).then((terminalPanel) => {
terminalPanel.closeTerminalById(terminalId);
});;
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
terminalInstance.dispose();
}
}
public $sendText(terminalId: number, text: string, addNewLine: boolean): void {
this._terminalService.show(false).then((terminalPanel) => {
this._terminalService.setActiveTerminalById(terminalId);
terminalPanel.sendTextToActiveTerminal(text, addNewLine);
});
let terminalInstance = this.terminalService.getInstanceFromId(terminalId);
if (terminalInstance) {
terminalInstance.sendText(text, addNewLine);
}
}
}