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

@@ -66,7 +66,7 @@ export class CmsConnectionWidget extends ConnectionWidget {
protected registerListeners(): void {
super.registerListeners();
if (this._serverDescriptionInputBox) {
this._toDispose.push(styler.attachInputBoxStyler(this._serverDescriptionInputBox, this._themeService));
this._register(styler.attachInputBoxStyler(this._serverDescriptionInputBox, this._themeService));
}
}

View File

@@ -35,7 +35,7 @@ import { endsWith, startsWith } from 'vs/base/common/strings';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
export class ConnectionWidget {
export class ConnectionWidget extends lifecycle.Disposable {
private _previousGroupOption: string;
private _serverGroupOptions: IConnectionProfileGroup[];
private _serverNameInputBox: InputBox;
@@ -60,7 +60,6 @@ export class ConnectionWidget {
protected _container: HTMLElement;
protected _serverGroupSelectBox: SelectBox;
protected _authTypeSelectBox: SelectBox;
protected _toDispose: lifecycle.IDisposable[];
protected _optionsMaps: { [optionType: number]: azdata.ConnectionOption };
protected _tableContainer: HTMLElement;
protected _providerName: string;
@@ -103,8 +102,8 @@ export class ConnectionWidget {
@IConfigurationService private _configurationService: IConfigurationService,
@IAccountManagementService private _accountManagementService: IAccountManagementService
) {
super();
this._callbacks = callbacks;
this._toDispose = [];
this._optionsMaps = {};
for (let i = 0; i < options.length; i++) {
let option = options[i];
@@ -313,22 +312,22 @@ export class ConnectionWidget {
protected registerListeners(): void {
// Theme styler
this._toDispose.push(styler.attachInputBoxStyler(this._serverNameInputBox, this._themeService));
this._toDispose.push(styler.attachInputBoxStyler(this._connectionNameInputBox, this._themeService));
this._toDispose.push(styler.attachInputBoxStyler(this._userNameInputBox, this._themeService));
this._toDispose.push(styler.attachInputBoxStyler(this._passwordInputBox, this._themeService));
this._toDispose.push(styler.attachButtonStyler(this._advancedButton, this._themeService));
this._toDispose.push(styler.attachCheckboxStyler(this._rememberPasswordCheckBox, this._themeService));
this._toDispose.push(styler.attachSelectBoxStyler(this._azureAccountDropdown, this._themeService));
this._register(styler.attachInputBoxStyler(this._serverNameInputBox, this._themeService));
this._register(styler.attachInputBoxStyler(this._connectionNameInputBox, this._themeService));
this._register(styler.attachInputBoxStyler(this._userNameInputBox, this._themeService));
this._register(styler.attachInputBoxStyler(this._passwordInputBox, this._themeService));
this._register(styler.attachButtonStyler(this._advancedButton, this._themeService));
this._register(styler.attachCheckboxStyler(this._rememberPasswordCheckBox, this._themeService));
this._register(styler.attachSelectBoxStyler(this._azureAccountDropdown, this._themeService));
if (this._serverGroupSelectBox) {
this._toDispose.push(styler.attachSelectBoxStyler(this._serverGroupSelectBox, this._themeService));
this._toDispose.push(this._serverGroupSelectBox.onDidSelect(selectedGroup => {
this._register(styler.attachSelectBoxStyler(this._serverGroupSelectBox, this._themeService));
this._register(this._serverGroupSelectBox.onDidSelect(selectedGroup => {
this.onGroupSelected(selectedGroup.selected);
}));
}
if (this._databaseNameInputBox) {
this._toDispose.push(styler.attachEditableDropdownStyler(this._databaseNameInputBox, this._themeService));
this._toDispose.push(this._databaseNameInputBox.onFocus(() => {
this._register(styler.attachEditableDropdownStyler(this._databaseNameInputBox, this._themeService));
this._register(this._databaseNameInputBox.onFocus(() => {
this._databaseDropdownExpanded = true;
if (this.serverName) {
this._databaseNameInputBox.values = [this._loadingDatabaseName];
@@ -346,7 +345,7 @@ export class ConnectionWidget {
}
}));
this._toDispose.push(this._databaseNameInputBox.onValueChange(s => {
this._register(this._databaseNameInputBox.onValueChange(s => {
if (s === this._defaultDatabaseName || s === this._loadingDatabaseName) {
this._databaseNameInputBox.value = '';
} else {
@@ -357,29 +356,29 @@ export class ConnectionWidget {
if (this._authTypeSelectBox) {
// Theme styler
this._toDispose.push(styler.attachSelectBoxStyler(this._authTypeSelectBox, this._themeService));
this._toDispose.push(this._authTypeSelectBox.onDidSelect(selectedAuthType => {
this._register(styler.attachSelectBoxStyler(this._authTypeSelectBox, this._themeService));
this._register(this._authTypeSelectBox.onDidSelect(selectedAuthType => {
this.onAuthTypeSelected(selectedAuthType.selected);
this.setConnectButton();
}));
}
if (this._azureAccountDropdown) {
this._toDispose.push(styler.attachSelectBoxStyler(this._azureAccountDropdown, this._themeService));
this._toDispose.push(this._azureAccountDropdown.onDidSelect(() => {
this._register(styler.attachSelectBoxStyler(this._azureAccountDropdown, this._themeService));
this._register(this._azureAccountDropdown.onDidSelect(() => {
this.onAzureAccountSelected();
}));
}
if (this._azureTenantDropdown) {
this._toDispose.push(styler.attachSelectBoxStyler(this._azureTenantDropdown, this._themeService));
this._toDispose.push(this._azureTenantDropdown.onDidSelect((selectInfo) => {
this._register(styler.attachSelectBoxStyler(this._azureTenantDropdown, this._themeService));
this._register(this._azureTenantDropdown.onDidSelect((selectInfo) => {
this.onAzureTenantSelected(selectInfo.index);
}));
}
if (this._refreshCredentialsLink) {
this._toDispose.push(DOM.addDisposableListener(this._refreshCredentialsLink, DOM.EventType.CLICK, async () => {
this._register(DOM.addDisposableListener(this._refreshCredentialsLink, DOM.EventType.CLICK, async () => {
let account = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
if (account) {
await this._accountManagementService.refreshAccount(account);
@@ -388,15 +387,15 @@ export class ConnectionWidget {
}));
}
this._toDispose.push(this._serverNameInputBox.onDidChange(serverName => {
this._register(this._serverNameInputBox.onDidChange(serverName => {
this.serverNameChanged(serverName);
}));
this._toDispose.push(this._userNameInputBox.onDidChange(userName => {
this._register(this._userNameInputBox.onDidChange(userName => {
this.setConnectButton();
}));
this._toDispose.push(this._passwordInputBox.onDidChange(passwordInput => {
this._register(this._passwordInputBox.onDidChange(passwordInput => {
this._password = passwordInput;
}));
}
@@ -835,10 +834,6 @@ export class ConnectionWidget {
return group ? group.id : undefined;
}
public dispose(): void {
this._toDispose = lifecycle.dispose(this._toDispose);
}
private getMatchingAuthType(displayName: string): AuthenticationType {
const authType = this._authTypeMap[this._providerName];
return authType ? authType.find(authType => this.getAuthTypeDisplayName(authType) === displayName) : undefined;

View File

@@ -9,7 +9,7 @@ import { FileBrowserRenderer } from 'sql/workbench/services/fileBrowser/browser/
import { IFileBrowserService } from 'sql/platform/fileBrowser/common/interfaces';
import { FileNode } from 'sql/workbench/services/fileBrowser/common/fileNode';
import errors = require('vs/base/common/errors');
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import * as DOM from 'vs/base/browser/dom';
import nls = require('vs/nls');
import { DefaultFilter, DefaultAccessibilityProvider, DefaultDragAndDrop } from 'vs/base/parts/tree/browser/treeDefaults';
@@ -23,15 +23,15 @@ import { IExpandableTree } from 'sql/workbench/parts/objectExplorer/browser/tree
/**
* Implements tree view for file browser
*/
export class FileBrowserTreeView implements IDisposable {
export class FileBrowserTreeView extends Disposable implements IDisposable {
private _tree: ITree;
private _toDispose: IDisposable[] = [];
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@IFileBrowserService private _fileBrowserService: IFileBrowserService,
@IThemeService private _themeService: IThemeService
) {
super();
}
/**
@@ -40,10 +40,10 @@ export class FileBrowserTreeView implements IDisposable {
public renderBody(container: HTMLElement, rootNode: FileNode, selectedNode: FileNode, expandedNodes: FileNode[]): void {
if (!this._tree) {
DOM.addClass(container, 'show-file-icons');
this._tree = this.createFileBrowserTree(container, this._instantiationService);
this._toDispose.push(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
this._toDispose.push(this._fileBrowserService.onExpandFolder(fileNode => this._tree.refresh(fileNode)));
this._toDispose.push(attachListStyler(this._tree, this._themeService));
this._tree = this._register(this.createFileBrowserTree(container, this._instantiationService));
this._register(this._tree.onDidChangeSelection((event) => this.onSelected(event)));
this._register(this._fileBrowserService.onExpandFolder(fileNode => this._tree.refresh(fileNode)));
this._register(attachListStyler(this._tree, this._themeService));
this._tree.domFocus();
}
@@ -159,14 +159,4 @@ export class FileBrowserTreeView implements IDisposable {
this._tree.onHidden();
}
}
/**
* dispose the file browser tree view
*/
public dispose(): void {
if (this._tree) {
this._tree.dispose();
}
this._toDispose = dispose(this._toDispose);
}
}
}

View File

@@ -6,7 +6,6 @@
import { NodeType } from 'sql/workbench/parts/objectExplorer/common/nodeType';
import { TreeNode, TreeItemCollapsibleState } from 'sql/workbench/parts/objectExplorer/common/treeNode';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
@@ -130,8 +129,6 @@ export class ObjectExplorerService implements IObjectExplorerService {
public _serviceBrand: any;
private _disposables: IDisposable[] = [];
private _providers: { [handle: string]: azdata.ObjectExplorerProvider; } = Object.create(null);
private _nodeProviders: { [handle: string]: azdata.ObjectExplorerNodeProvider[]; } = Object.create(null);
@@ -541,10 +538,6 @@ export class ObjectExplorerService implements IObjectExplorerService {
this._nodeProviders[nodeProvider.supportedProviderId] = nodeProviders;
}
public dispose(): void {
this._disposables = dispose(this._disposables);
}
public resolveTreeNodeChildren(session: azdata.ObjectExplorerSession, parentTree: TreeNode): Thenable<TreeNode[]> {
// Always refresh the node if it has an error, otherwise expand it normally
let needsRefresh = !!parentTree.errorStateMessage;