mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
WIP refactor of integrated terminal part
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user