clean up some disposable use (#6832)

This commit is contained in:
Anthony Dresser
2019-08-20 14:34:13 -07:00
committed by GitHub
parent 54cf062737
commit c540e81108
23 changed files with 139 additions and 244 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Action, IActionViewItem, IActionRunner } from 'vs/base/common/actions';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore, Disposable } from 'vs/base/common/lifecycle';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
@@ -150,14 +150,13 @@ export class ChangeMaxRowsAction extends EditDataAction {
* Action item that handles the dropdown (combobox) that lists the avaliable number of row selections
* for an edit data session
*/
export class ChangeMaxRowsActionItem implements IActionViewItem {
export class ChangeMaxRowsActionItem extends Disposable implements IActionViewItem {
public actionRunner: IActionRunner;
public defaultRowCount: number;
private container: HTMLElement;
private start: HTMLElement;
private selectBox: SelectBox;
private toDispose: IDisposable[];
private context: any;
private _options: string[];
private _currentOptionsIndex: number;
@@ -166,15 +165,15 @@ export class ChangeMaxRowsActionItem implements IActionViewItem {
private _editor: EditDataEditor,
@IContextViewService contextViewService: IContextViewService,
@IThemeService private _themeService: IThemeService) {
super();
this._options = ['200', '1000', '10000'];
this._currentOptionsIndex = 0;
this.toDispose = [];
this.selectBox = new SelectBox(this._options, this._options[this._currentOptionsIndex], contextViewService);
this._registerListeners();
this._refreshOptions();
this.defaultRowCount = Number(this._options[this._currentOptionsIndex]);
this.toDispose.push(attachSelectBoxStyler(this.selectBox, _themeService));
this._register(attachSelectBoxStyler(this.selectBox, _themeService));
}
public render(container: HTMLElement): void {
@@ -211,20 +210,16 @@ export class ChangeMaxRowsActionItem implements IActionViewItem {
this.container.blur();
}
public dispose(): void {
this.toDispose = dispose(this.toDispose);
}
private _refreshOptions(databaseIndex?: number): void {
this.selectBox.setOptions(this._options, this._currentOptionsIndex);
}
private _registerListeners(): void {
this.toDispose.push(this.selectBox.onDidSelect(selection => {
this._register(this.selectBox.onDidSelect(selection => {
this._currentOptionsIndex = this._options.findIndex(x => x === selection.selected);
this._editor.editDataInput.onRowDropDownSet(Number(selection.selected));
}));
this.toDispose.push(attachSelectBoxStyler(this.selectBox, this._themeService));
this._register(attachSelectBoxStyler(this.selectBox, this._themeService));
}
}
@@ -263,4 +258,4 @@ export class ShowQueryPaneAction extends EditDataAction {
this.updateLabel(this.editor.queryPaneEnabled());
return Promise.resolve(null);
}
}
}

View File

@@ -25,7 +25,7 @@ import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
@@ -54,7 +54,7 @@ export abstract class GridParentComponent {
protected dataService: DataService;
protected actionProvider: actions.GridActionProvider;
protected toDispose: IDisposable[];
protected toDispose = new DisposableStore();
// Context keys to set when keybindings are available
@@ -97,7 +97,6 @@ export abstract class GridParentComponent {
protected queryEditorService: IQueryEditorService,
protected logService: ILogService
) {
this.toDispose = [];
}
protected baseInit(): void {
@@ -177,7 +176,7 @@ export abstract class GridParentComponent {
*/
protected subscribeWithDispose<T>(subject: Subject<T>, event: (value: any) => void): void {
let sub: Subscription = subject.subscribe(event);
this.toDispose.push(subscriptionToDisposable(sub));
this.toDispose.add(subscriptionToDisposable(sub));
}
private bindKeys(contextKeyService: IContextKeyService): void {
@@ -186,7 +185,7 @@ export abstract class GridParentComponent {
this.queryEditorVisible.set(true);
let gridContextKeyService = this.contextKeyService.createScoped(this._el.nativeElement);
this.toDispose.push(gridContextKeyService);
this.toDispose.add(gridContextKeyService);
this.resultsVisibleContextKey = ResultsVisibleContext.bindTo(gridContextKeyService);
this.resultsVisibleContextKey.set(true);
@@ -196,7 +195,7 @@ export abstract class GridParentComponent {
}
protected baseDestroy(): void {
this.toDispose = dispose(this.toDispose);
this.toDispose.dispose();
}
protected toggleResultPane(): void {