Skip to content

Commit

Permalink
Use register from dispose class
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Oct 5, 2016
1 parent b9513f5 commit 20a4136
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import DOM = require('vs/base/browser/dom');
import lifecycle = require('vs/base/common/lifecycle');
import nls = require('vs/nls');
import platform = require('vs/base/common/platform');
import { Action, IAction } from 'vs/base/common/actions';
Expand Down Expand Up @@ -35,7 +34,6 @@ export class TerminalPanel extends Panel {
private _parentDomElement: HTMLElement;
private _terminalContainer: HTMLElement;
private _themeStyleElement: HTMLElement;
private _toDispose: lifecycle.IDisposable[];

constructor(
@IConfigurationService private _configurationService: IConfigurationService,
Expand All @@ -47,8 +45,6 @@ export class TerminalPanel extends Panel {
@ITelemetryService telemetryService: ITelemetryService
) {
super(TERMINAL_PANEL_ID, telemetryService);

this._toDispose = [];
}

public create(parent: Builder): TPromise<any> {
Expand All @@ -68,8 +64,8 @@ export class TerminalPanel extends Panel {

this._terminalService.setContainers(this.getContainer(), this._terminalContainer);

this._toDispose.push(this._themeService.onDidColorThemeChange(this._updateTheme.bind(this)));
this._toDispose.push(this._configurationService.onDidUpdateConfiguration(this._updateConfig.bind(this)));
this._register(this._themeService.onDidColorThemeChange(this._updateTheme.bind(this)));
this._register(this._configurationService.onDidUpdateConfiguration(this._updateConfig.bind(this)));
this._updateTheme();
this._updateConfig();

Expand Down Expand Up @@ -111,7 +107,7 @@ export class TerminalPanel extends Panel {
this._instantiationService.createInstance(KillTerminalAction, KillTerminalAction.ID, KillTerminalAction.PANEL_LABEL)
];
this._actions.forEach(a => {
this._toDispose.push(a);
this._register(a);
});
}
return this._actions;
Expand All @@ -126,7 +122,7 @@ export class TerminalPanel extends Panel {
this._instantiationService.createInstance(TerminalPasteAction, TerminalPasteAction.ID, nls.localize('paste', "Paste"))
];
this._contextMenuActions.forEach(a => {
this._toDispose.push(a);
this._register(a);
});
}
return this._contextMenuActions;
Expand All @@ -145,7 +141,7 @@ export class TerminalPanel extends Panel {
}

private _attachEventListeners(): void {
this._toDispose.push(DOM.addDisposableListener(this._parentDomElement, 'mousedown', (event: MouseEvent) => {
this._register(DOM.addDisposableListener(this._parentDomElement, 'mousedown', (event: MouseEvent) => {
if (this._terminalService.terminalInstances.length === 0) {
return;
}
Expand Down Expand Up @@ -176,7 +172,7 @@ export class TerminalPanel extends Panel {
});
}
}));
this._toDispose.push(DOM.addDisposableListener(this._parentDomElement, 'click', (event) => {
this._register(DOM.addDisposableListener(this._parentDomElement, 'click', (event) => {
if (this._terminalService.terminalInstances.length === 0) {
return;
}
Expand All @@ -185,7 +181,7 @@ export class TerminalPanel extends Panel {
this._terminalService.getActiveInstance().focus();
}
}));
this._toDispose.push(DOM.addDisposableListener(this._parentDomElement, 'keyup', (event: KeyboardEvent) => {
this._register(DOM.addDisposableListener(this._parentDomElement, 'keyup', (event: KeyboardEvent) => {
if (event.keyCode === 27) {
// Keep terminal open on escape
event.stopPropagation();
Expand Down

2 comments on commit 20a4136

@sandy081
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tyriar I made root class of Panel - WorkbenchComponent to extend Dispose which has nice _register method and disposes registered disposables on dispose. This needed adoption in terminal panel.

Hope it is fine for you. Thanks

@Tyriar
Copy link
Member

@Tyriar Tyriar commented on 20a4136 Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandy081 thanks, I actually tried to use register at some point and found it wasn't there 😛

Please sign in to comment.