Skip to content

Commit

Permalink
Add terminal hide by ID and fix show bug
Browse files Browse the repository at this point in the history
Part of #9957
  • Loading branch information
Tyriar committed Aug 25, 2016
1 parent d0fb17d commit c647ac9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/vs/workbench/api/node/mainThreadTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {

public $show(terminalId: number, preserveFocus: boolean): void {
this._terminalService.show(!preserveFocus).then((terminalPanel) => {
terminalPanel.setActiveTerminalById(terminalId);
this._terminalService.setActiveTerminalById(terminalId);
});
}

public $hide(terminalId: number): void {
// TODO: Use terminalId to hide it
this._terminalService.hide();
this._terminalService.hideTerminalInstance(terminalId);
}

public $dispose(terminalId: number): void {
Expand All @@ -43,7 +42,7 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {

public $sendText(terminalId: number, text: string, addNewLine: boolean): void {
this._terminalService.show(false).then((terminalPanel) => {
terminalPanel.setActiveTerminalById(terminalId);
this._terminalService.setActiveTerminalById(terminalId);
terminalPanel.sendTextToActiveTerminal(text, addNewLine);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
protected runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments): TPromise<void> {
return this.terminalService.createNew(args.title || nls.localize('debuggee', "debuggee")).then(id => {
return this.terminalService.show(false).then(terminalPanel => {
terminalPanel.setActiveTerminalById(id);
this.terminalService.setActiveTerminalById(id);
terminalPanel.sendTextToActiveTerminal(args.args.join(' '), true);
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/terminal/electron-browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ export interface ITerminalService {
focusNext(): TPromise<any>;
focusPrevious(): TPromise<any>;
hide(): TPromise<any>;
hideTerminalInstance(terminalId: number): TPromise<any>;
paste(): TPromise<any>;
runSelectedText(): TPromise<any>;
scrollDown(): TPromise<any>;
scrollUp(): TPromise<any>;
show(focus: boolean): TPromise<ITerminalPanel>;
setActiveTerminal(index: number): TPromise<any>;
setActiveTerminalById(terminalId: number): void;
toggle(): TPromise<any>;

getActiveTerminalIndex(): number;
Expand All @@ -87,5 +89,4 @@ export interface ITerminalService {
export interface ITerminalPanel {
closeTerminalById(terminalId: number): TPromise<void>;
sendTextToActiveTerminal(text: string, addNewLine: boolean): void;
setActiveTerminalById(terminalId: number): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ export class SwitchTerminalInstanceAction extends Action {

public run(item?: string): TPromise<any> {
let selectedTerminalIndex = parseInt(item.split(':')[0], 10) - 1;
return this.terminalService.setActiveTerminal(selectedTerminalIndex);
return this.terminalService.show(true).then(() => {
this.terminalService.setActiveTerminal(selectedTerminalIndex);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ export class TerminalPanel extends Panel implements ITerminalPanel {
return terminalIndex;
}

public setActiveTerminalById(terminalId: number): void {
this.setActiveTerminal(this.getTerminalIndexFromId(terminalId));
}

private onTerminalInstanceExit(terminalInstance: TerminalInstance): void {
let index = this.terminalInstances.indexOf(terminalInstance);
if (index !== -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,31 @@ export class TerminalService implements ITerminalService {
}

public setActiveTerminal(index: number): TPromise<any> {
return this.focus().then((terminalPanel) => {
return this.show(false).then((terminalPanel) => {
this.activeTerminalIndex = index;
terminalPanel.setActiveTerminal(this.activeTerminalIndex);
terminalPanel.focus();
this._onActiveInstanceChanged.fire();
});
}

public setActiveTerminalById(terminalId: number): void {
this.setActiveTerminal(this.getTerminalIndexFromId(terminalId));
}

private getTerminalIndexFromId(terminalId: number): number {
let terminalIndex = -1;
this.terminalProcesses.forEach((terminalProcess, i) => {
if (terminalProcess.process.pid === terminalId) {
terminalIndex = i;
}
});
if (terminalIndex === -1) {
throw new Error(`Terminal with ID ${terminalId} does not exist (has it already been disposed?)`);
}
return terminalIndex;
}

public focusNext(): TPromise<any> {
return this.focus().then((terminalPanel) => {
if (this.terminalProcesses.length <= 1) {
Expand Down Expand Up @@ -142,7 +159,17 @@ export class TerminalService implements ITerminalService {
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
this.partService.setPanelHidden(true);
}
return TPromise.as(null);
return TPromise.as(void 0);
}

public hideTerminalInstance(terminalId: number): TPromise<any> {
const panel = this.panelService.getActivePanel();
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
if (this.terminalProcesses[this.getActiveTerminalIndex()].process.pid === terminalId) {
this.partService.setPanelHidden(true);
}
}
return TPromise.as(void 0);
}

public toggle(): TPromise<any> {
Expand Down

0 comments on commit c647ac9

Please sign in to comment.