diff options
author | Rob Lourens <roblourens@gmail.com> | 2019-10-15 08:11:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-15 08:11:08 +0300 |
commit | 385bf0f0e80a473e862dc27d4aa8127e926c2f13 (patch) | |
tree | 5012b9a36fa48af4f070e67a4f37a0c511145f15 | |
parent | 3f6ed25939b8ef157a7a41e0dc43b517898d4005 (diff) | |
parent | 2f37e87f4c26f3aae404ef189acaee64dfafe13a (diff) |
Merge pull request #80684 from solomatov/disposables-10-09
Replace Disposable[] with DisposableStore
4 files changed, 29 insertions, 28 deletions
diff --git a/src/vs/base/browser/ui/tree/abstractTree.ts b/src/vs/base/browser/ui/tree/abstractTree.ts index b34dd3936a7..1408a017c68 100644 --- a/src/vs/base/browser/ui/tree/abstractTree.ts +++ b/src/vs/base/browser/ui/tree/abstractTree.ts @@ -250,7 +250,7 @@ class TreeRenderer<T, TFilterData, TRef, TTemplateData> implements IListRenderer private activeIndentNodes = new Set<ITreeNode<T, TFilterData>>(); private indentGuidesDisposable: IDisposable = Disposable.None; - private disposables: IDisposable[] = []; + private readonly disposables = new DisposableStore(); constructor( private renderer: ITreeRenderer<T, TFilterData, TTemplateData>, @@ -458,7 +458,7 @@ class TreeRenderer<T, TFilterData, TRef, TTemplateData> implements IListRenderer this.renderedNodes.clear(); this.renderedElements.clear(); this.indentGuidesDisposable.dispose(); - this.disposables = dispose(this.disposables); + dispose(this.disposables); } } @@ -471,7 +471,7 @@ class TypeFilter<T> implements ITreeFilter<T, FuzzyScore>, IDisposable { private _pattern: string = ''; private _lowercasePattern: string = ''; - private disposables: IDisposable[] = []; + private readonly disposables = new DisposableStore(); set pattern(pattern: string) { this._pattern = pattern; @@ -546,7 +546,7 @@ class TypeFilter<T> implements ITreeFilter<T, FuzzyScore>, IDisposable { } dispose(): void { - this.disposables = dispose(this.disposables); + dispose(this.disposables); } } @@ -581,8 +581,8 @@ class TypeFilterController<T, TFilterData> implements IDisposable { private readonly _onDidChangePattern = new Emitter<string>(); readonly onDidChangePattern = this._onDidChangePattern.event; - private enabledDisposables: IDisposable[] = []; - private disposables: IDisposable[] = []; + private readonly enabledDisposables = new DisposableStore(); + private readonly disposables = new DisposableStore(); constructor( private tree: AbstractTree<T, TFilterData, any>, @@ -682,7 +682,7 @@ class TypeFilterController<T, TFilterData> implements IDisposable { } this.domNode.remove(); - this.enabledDisposables = dispose(this.enabledDisposables); + this.enabledDisposables.clear(); this.tree.refilter(); this.render(); this._enabled = false; @@ -744,7 +744,7 @@ class TypeFilterController<T, TFilterData> implements IDisposable { const containerWidth = container.clientWidth; const midContainerWidth = containerWidth / 2; const width = this.domNode.clientWidth; - const disposables: IDisposable[] = []; + const disposables = new DisposableStore(); let positionClassName = this.positionClassName; const updatePosition = () => { @@ -790,13 +790,13 @@ class TypeFilterController<T, TFilterData> implements IDisposable { removeClass(this.domNode, positionClassName); addClass(this.domNode, 'dragging'); - disposables.push(toDisposable(() => removeClass(this.domNode, 'dragging'))); + disposables.add(toDisposable(() => removeClass(this.domNode, 'dragging'))); domEvent(document, 'dragover')(onDragOver, null, disposables); domEvent(this.domNode, 'dragend')(onDragEnd, null, disposables); StaticDND.CurrentDragAndDropData = new DragAndDropData('vscode-ui'); - disposables.push(toDisposable(() => StaticDND.CurrentDragAndDropData = undefined)); + disposables.add(toDisposable(() => StaticDND.CurrentDragAndDropData = undefined)); } private onDidSpliceModel(): void { @@ -857,13 +857,13 @@ class TypeFilterController<T, TFilterData> implements IDisposable { dispose() { if (this._enabled) { this.domNode.remove(); - this.enabledDisposables = dispose(this.enabledDisposables); + this.enabledDisposables.dispose(); this._enabled = false; this.triggered = false; } this._onDidChangePattern.dispose(); - this.disposables = dispose(this.disposables); + dispose(this.disposables); } } @@ -1181,7 +1181,7 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable private typeFilterController?: TypeFilterController<T, TFilterData>; private focusNavigationFilter: ((node: ITreeNode<T, TFilterData>) => boolean) | undefined; private styleElement: HTMLStyleElement; - protected disposables: IDisposable[] = []; + protected readonly disposables = new DisposableStore(); get onDidScroll(): Event<ScrollEvent> { return this.view.onDidScroll; } @@ -1230,16 +1230,17 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable const onDidChangeCollapseStateRelay = new Relay<ICollapseStateChangeEvent<T, TFilterData>>(); const onDidChangeActiveNodes = new Relay<ITreeNode<T, TFilterData>[]>(); const activeNodes = new EventCollection(onDidChangeActiveNodes.event); - this.renderers = renderers.map(r => new TreeRenderer<T, TFilterData, TRef, any>(r, () => this.model, onDidChangeCollapseStateRelay.event, activeNodes, _options)); - this.disposables.push(...this.renderers); + for (let r of this.renderers) { + this.disposables.add(r); + } let filter: TypeFilter<T> | undefined; if (_options.keyboardNavigationLabelProvider) { filter = new TypeFilter(this, _options.keyboardNavigationLabelProvider, _options.filter as any as ITreeFilter<T, FuzzyScore>); _options = { ..._options, filter: filter as ITreeFilter<T, TFilterData> }; // TODO need typescript help here - this.disposables.push(filter); + this.disposables.add(filter); } this.focus = new Trait(_options.identityProvider); @@ -1293,7 +1294,7 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable const delegate = _options.keyboardNavigationDelegate || DefaultKeyboardNavigationDelegate; this.typeFilterController = new TypeFilterController(this, this.model, this.view, filter!, delegate); this.focusNavigationFilter = node => this.typeFilterController!.shouldAllowFocus(node); - this.disposables.push(this.typeFilterController!); + this.disposables.add(this.typeFilterController!); } this.styleElement = createStyleSheet(this.view.getHTMLElement()); @@ -1647,7 +1648,7 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable } dispose(): void { - this.disposables = dispose(this.disposables); + dispose(this.disposables); this.view.dispose(); } } diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index c0a6c5b2c0d..024c3f08d21 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -798,9 +798,9 @@ export class WorkbenchObjectTree<T extends NonNullable<any>, TFilterData = void> ) { const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble(container, options, contextKeyService, themeService, configurationService, keybindingService, accessibilityService); super(user, container, delegate, renderers, treeOptions); - this.disposables.push(disposable); + this.disposables.add(disposable); this.internals = new WorkbenchTreeInternals(this, treeOptions, getAutomaticKeyboardNavigation, contextKeyService, listService, themeService, configurationService, accessibilityService); - this.disposables.push(this.internals); + this.disposables.add(this.internals); } } @@ -825,9 +825,9 @@ export class WorkbenchCompressibleObjectTree<T extends NonNullable<any>, TFilter ) { const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble(container, options, contextKeyService, themeService, configurationService, keybindingService, accessibilityService); super(user, container, delegate, renderers, treeOptions); - this.disposables.push(disposable); + this.disposables.add(disposable); this.internals = new WorkbenchTreeInternals(this, treeOptions, getAutomaticKeyboardNavigation, contextKeyService, listService, themeService, configurationService, accessibilityService); - this.disposables.push(this.internals); + this.disposables.add(this.internals); } } @@ -853,9 +853,9 @@ export class WorkbenchDataTree<TInput, T, TFilterData = void> extends DataTree<T ) { const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble(container, options, contextKeyService, themeService, configurationService, keybindingService, accessibilityService); super(user, container, delegate, renderers, dataSource, treeOptions); - this.disposables.push(disposable); + this.disposables.add(disposable); this.internals = new WorkbenchTreeInternals(this, treeOptions, getAutomaticKeyboardNavigation, contextKeyService, listService, themeService, configurationService, accessibilityService); - this.disposables.push(this.internals); + this.disposables.add(this.internals); } } diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts index 8f9829317ff..5a520357567 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts @@ -1488,8 +1488,8 @@ export class SettingsTree extends ObjectTree<SettingsTreeElement> { filter: instantiationService.createInstance(SettingsTreeFilter, viewState) }); - this.disposables = []; - this.disposables.push(registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { + this.disposables.clear(); + this.disposables.add(registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => { const activeBorderColor = theme.getColor(focusBorder); if (activeBorderColor) { // TODO@rob - why isn't this applied when added to the stylesheet from tocTree.ts? Seems like a chromium glitch. @@ -1539,7 +1539,7 @@ export class SettingsTree extends ObjectTree<SettingsTreeElement> { this.getHTMLElement().classList.add(treeClass); - this.disposables.push(attachStyler(themeService, { + this.disposables.add(attachStyler(themeService, { listActiveSelectionBackground: transparent(Color.white, 0), listActiveSelectionForeground: foreground, listFocusAndSelectionBackground: transparent(Color.white, 0), diff --git a/src/vs/workbench/contrib/preferences/browser/tocTree.ts b/src/vs/workbench/contrib/preferences/browser/tocTree.ts index 0576d491913..845274f20ec 100644 --- a/src/vs/workbench/contrib/preferences/browser/tocTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/tocTree.ts @@ -211,7 +211,7 @@ export class TOCTree extends ObjectTree<SettingsTreeGroupElement> { this.getHTMLElement().classList.add(treeClass); - this.disposables.push(attachStyler(themeService, { + this.disposables.add(attachStyler(themeService, { listActiveSelectionBackground: editorBackground, listActiveSelectionForeground: settingsHeaderForeground, listFocusAndSelectionBackground: editorBackground, |