Clean up some more disposable usage (#7190)

* clean up some more disposable usage

* fix a bug

* add more to register
This commit is contained in:
Anthony Dresser
2019-09-13 12:28:33 -07:00
committed by GitHub
parent c9128d56c0
commit d9c5b7ea9e
12 changed files with 86 additions and 144 deletions

View File

@@ -19,25 +19,24 @@ import { TASKS_PANEL_ID } from 'sql/workbench/parts/tasks/common/tasks';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ToggleTasksAction } from 'sql/workbench/parts/tasks/browser/tasksActions';
export class StatusUpdater implements ext.IWorkbenchContribution {
export class StatusUpdater extends lifecycle.Disposable implements ext.IWorkbenchContribution {
static ID = 'data.taskhistory.statusUpdater';
private badgeHandle: lifecycle.IDisposable;
private toDispose: lifecycle.IDisposable[];
constructor(
@IActivityService private readonly activityBarService: IActivityService,
@ITaskService private readonly taskService: ITaskService,
@IPanelService private readonly panelService: IPanelService
) {
this.toDispose = [];
super();
this.toDispose.push(this.taskService.onAddNewTask(args => {
this._register(this.taskService.onAddNewTask(args => {
this.panelService.openPanel(TASKS_PANEL_ID, true);
this.onServiceChange();
}));
this.toDispose.push(this.taskService.onTaskComplete(task => {
this._register(this.taskService.onTaskComplete(task => {
this.onServiceChange();
}));
@@ -55,8 +54,8 @@ export class StatusUpdater implements ext.IWorkbenchContribution {
}
public dispose(): void {
this.toDispose = lifecycle.dispose(this.toDispose);
lifecycle.dispose(this.badgeHandle);
super.dispose();
}
}

View File

@@ -10,7 +10,7 @@ import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { dispose, Disposable } from 'vs/base/common/lifecycle';
import { DefaultFilter, DefaultDragAndDrop, DefaultAccessibilityProvider } from 'vs/base/parts/tree/browser/treeDefaults';
import { localize } from 'vs/nls';
import { hide, $, append } from 'vs/base/browser/dom';
@@ -27,10 +27,9 @@ import { IExpandableTree } from 'sql/workbench/parts/objectExplorer/browser/tree
/**
* TaskHistoryView implements the dynamic tree view.
*/
export class TaskHistoryView {
export class TaskHistoryView extends Disposable {
private _messages: HTMLElement;
private _tree: ITree;
private _toDispose: IDisposable[] = [];
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@@ -38,6 +37,7 @@ export class TaskHistoryView {
@IErrorMessageService private _errorMessageService: IErrorMessageService,
@IThemeService private _themeService: IThemeService
) {
super();
}
/**
@@ -56,17 +56,17 @@ export class TaskHistoryView {
let noTaskMessage = localize('noTaskMessage', "No task history to display.");
append(this._messages, $('span')).innerText = noTaskMessage;
this._tree = this.createTaskHistoryTree(container, this._instantiationService);
this._toDispose.push(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
this._tree = this._register(this.createTaskHistoryTree(container, this._instantiationService));
this._register(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
// Theme styler
this._toDispose.push(attachListStyler(this._tree, this._themeService));
this._register(attachListStyler(this._tree, this._themeService));
this._toDispose.push(this._taskService.onAddNewTask(args => {
this._register(this._taskService.onAddNewTask(args => {
hide(this._messages);
this.refreshTree();
}));
this._toDispose.push(this._taskService.onTaskComplete(task => {
this._register(this._taskService.onTaskComplete(task => {
this.updateTask(task);
}));
@@ -166,12 +166,4 @@ export class TaskHistoryView {
this._tree.onHidden();
}
}
/**
* dispose the server tree view
*/
public dispose(): void {
this._tree.dispose();
this._toDispose = dispose(this._toDispose);
}
}