提交 30d11145 编写于 作者: M Matt Bierner

Replacing a few instances of IDisposable[]

上级 95924674
......@@ -12,7 +12,7 @@ import { ResolvedKeybinding, KeyCode } from 'vs/base/common/keyCodes';
import { addClass, EventType, EventHelper, EventLike, removeTabIndexAndUpdateFocus, isAncestor, hasClass, addDisposableListener, removeClass, append, $, addClasses, removeClasses } from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Color } from 'vs/base/common/color';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { ScrollbarVisibility, ScrollEvent } from 'vs/base/common/scrollable';
......@@ -71,7 +71,7 @@ interface ISubMenuData {
export class Menu extends ActionBar {
private mnemonics: Map<string, Array<BaseMenuActionViewItem>>;
private menuDisposables: IDisposable[];
private readonly menuDisposables: DisposableStore;
private scrollableElement: DomScrollableElement;
private menuElement: HTMLElement;
private scrollTopHold: number | undefined;
......@@ -79,7 +79,6 @@ export class Menu extends ActionBar {
private readonly _onScroll: Emitter<void>;
constructor(container: HTMLElement, actions: IAction[], options: IMenuOptions = {}) {
addClass(container, 'monaco-menu-container');
container.setAttribute('role', 'presentation');
const menuElement = document.createElement('div');
......@@ -103,7 +102,7 @@ export class Menu extends ActionBar {
this.actionsList.tabIndex = 0;
this.menuDisposables = [];
this.menuDisposables = this._register(new DisposableStore());
addDisposableListener(menuElement, EventType.KEY_DOWN, (e) => {
const event = new StandardKeyboardEvent(e);
......@@ -217,9 +216,9 @@ export class Menu extends ActionBar {
menuElement.style.maxHeight = `${Math.max(10, window.innerHeight - container.getBoundingClientRect().top - 30)}px`;
this.scrollableElement.onScroll(() => {
this.menuDisposables.push(this.scrollableElement.onScroll(() => {
this._onScroll.fire();
}, this, this.menuDisposables);
}, this));
this._register(addDisposableListener(this.menuElement, EventType.SCROLL, (e: ScrollEvent) => {
if (this.scrollTopHold !== undefined) {
......@@ -575,7 +574,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
private mysubmenu: Menu | null;
private submenuContainer: HTMLElement | undefined;
private submenuIndicator: HTMLElement;
private submenuDisposables: IDisposable[] = [];
private readonly submenuDisposables = this._register(new DisposableStore());
private mouseOver: boolean;
private showScheduler: RunOnceScheduler;
private hideScheduler: RunOnceScheduler;
......@@ -675,7 +674,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
this.parentData.submenu = undefined;
if (this.submenuContainer) {
this.submenuDisposables = dispose(this.submenuDisposables);
this.submenuDisposables.clear();
this.submenuContainer = undefined;
}
}
......@@ -720,7 +719,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
this.parentData.submenu = undefined;
}
this.submenuDisposables = dispose(this.submenuDisposables);
this.submenuDisposables.clear();
this.submenuContainer = undefined;
}
}));
......@@ -741,7 +740,7 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
this.parentData.submenu = undefined;
}
this.submenuDisposables = dispose(this.submenuDisposables);
this.submenuDisposables.clear();
this.submenuContainer = undefined;
}));
......@@ -781,7 +780,6 @@ class SubmenuMenuActionViewItem extends BaseMenuActionViewItem {
}
if (this.submenuContainer) {
this.submenuDisposables = dispose(this.submenuDisposables);
this.submenuContainer = undefined;
}
}
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./sash';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { isIPad } from 'vs/base/browser/browser';
import { isMacintosh } from 'vs/base/common/platform';
import * as types from 'vs/base/common/types';
......@@ -95,14 +95,14 @@ export class Sash extends Disposable {
linkedSash: Sash | undefined = undefined;
private orthogonalStartSashDisposables: IDisposable[] = [];
private readonly orthogonalStartSashDisposables = this._register(new DisposableStore());
private _orthogonalStartSash: Sash | undefined;
get orthogonalStartSash(): Sash | undefined { return this._orthogonalStartSash; }
set orthogonalStartSash(sash: Sash | undefined) {
this.orthogonalStartSashDisposables = dispose(this.orthogonalStartSashDisposables);
this.orthogonalStartSashDisposables.clear();
if (sash) {
sash.onDidEnablementChange(this.onOrthogonalStartSashEnablementChange, this, this.orthogonalStartSashDisposables);
this.orthogonalStartSashDisposables.push(sash.onDidEnablementChange(this.onOrthogonalStartSashEnablementChange, this));
this.onOrthogonalStartSashEnablementChange(sash.state);
} else {
this.onOrthogonalStartSashEnablementChange(SashState.Disabled);
......@@ -111,14 +111,14 @@ export class Sash extends Disposable {
this._orthogonalStartSash = sash;
}
private orthogonalEndSashDisposables: IDisposable[] = [];
private readonly orthogonalEndSashDisposables = this._register(new DisposableStore());
private _orthogonalEndSash: Sash | undefined;
get orthogonalEndSash(): Sash | undefined { return this._orthogonalEndSash; }
set orthogonalEndSash(sash: Sash | undefined) {
this.orthogonalEndSashDisposables = dispose(this.orthogonalEndSashDisposables);
this.orthogonalEndSashDisposables.clear();
if (sash) {
sash.onDidEnablementChange(this.onOrthogonalEndSashEnablementChange, this, this.orthogonalEndSashDisposables);
this.orthogonalEndSashDisposables.push(sash.onDidEnablementChange(this.onOrthogonalEndSashEnablementChange, this));
this.onOrthogonalEndSashEnablementChange(sash.state);
} else {
this.onOrthogonalEndSashEnablementChange(SashState.Disabled);
......@@ -384,9 +384,6 @@ export class Sash extends Disposable {
dispose(): void {
super.dispose();
this.orthogonalStartSashDisposables = dispose(this.orthogonalStartSashDisposables);
this.orthogonalEndSashDisposables = dispose(this.orthogonalEndSashDisposables);
if (this.el && this.el.parentElement) {
this.el.parentElement.removeChild(this.el);
}
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { TextModel } from 'vs/editor/common/model/textModel';
......@@ -18,7 +18,7 @@ suite('CodeAction', () => {
let langId = new LanguageIdentifier('fooLang', 17);
let uri = URI.parse('untitled:path');
let model: TextModel;
let disposables: IDisposable[] = [];
const disposables = new DisposableStore();
let testData = {
diagnostics: {
abc: {
......@@ -79,12 +79,13 @@ suite('CodeAction', () => {
};
setup(function () {
disposables.clear();
model = TextModel.createFromString('test1\ntest2\ntest3', undefined, langId, uri);
disposables = [model];
disposables.push(model);
});
teardown(function () {
dispose(disposables);
disposables.clear();
});
test('CodeActions are sorted by type, #38623', async function () {
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Selection } from 'vs/editor/common/core/selection';
......@@ -26,10 +26,10 @@ suite('CodeAction', () => {
let model: TextModel;
let markerService: MarkerService;
let editor: ICodeEditor;
let disposables: IDisposable[];
const disposables = new DisposableStore();
setup(() => {
disposables = [];
disposables.clear();
markerService = new MarkerService();
model = TextModel.createFromString('foobar foo bar\nfarboo far boo', undefined, languageIdentifier, uri);
editor = createTestCodeEditor({ model: model });
......@@ -37,7 +37,7 @@ suite('CodeAction', () => {
});
teardown(() => {
dispose(disposables);
disposables.clear();
editor.dispose();
model.dispose();
markerService.dispose();
......
......@@ -5,7 +5,7 @@
import 'vs/css!./dnd';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { isMacintosh } from 'vs/base/common/platform';
import { KeyCode } from 'vs/base/common/keyCodes';
import { ICodeEditor, IEditorMouseEvent, IMouseTarget, MouseTargetType } from 'vs/editor/browser/editorBrowser';
......@@ -28,12 +28,11 @@ function hasTriggerModifier(e: IKeyboardEvent | IMouseEvent): boolean {
}
}
export class DragAndDropController implements editorCommon.IEditorContribution {
export class DragAndDropController extends Disposable implements editorCommon.IEditorContribution {
private static readonly ID = 'editor.contrib.dragAndDrop';
private readonly _editor: ICodeEditor;
private _toUnhook: IDisposable[];
private _dragSelection: Selection | null;
private _dndDecorationIds: string[];
private _mouseDown: boolean;
......@@ -45,15 +44,15 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
}
constructor(editor: ICodeEditor) {
super();
this._editor = editor;
this._toUnhook = [];
this._toUnhook.push(this._editor.onMouseDown((e: IEditorMouseEvent) => this._onEditorMouseDown(e)));
this._toUnhook.push(this._editor.onMouseUp((e: IEditorMouseEvent) => this._onEditorMouseUp(e)));
this._toUnhook.push(this._editor.onMouseDrag((e: IEditorMouseEvent) => this._onEditorMouseDrag(e)));
this._toUnhook.push(this._editor.onMouseDrop((e: IEditorMouseEvent) => this._onEditorMouseDrop(e)));
this._toUnhook.push(this._editor.onKeyDown((e: IKeyboardEvent) => this.onEditorKeyDown(e)));
this._toUnhook.push(this._editor.onKeyUp((e: IKeyboardEvent) => this.onEditorKeyUp(e)));
this._toUnhook.push(this._editor.onDidBlurEditorWidget(() => this.onEditorBlur()));
this._register(this._editor.onMouseDown((e: IEditorMouseEvent) => this._onEditorMouseDown(e)));
this._register(this._editor.onMouseUp((e: IEditorMouseEvent) => this._onEditorMouseUp(e)));
this._register(this._editor.onMouseDrag((e: IEditorMouseEvent) => this._onEditorMouseDrag(e)));
this._register(this._editor.onMouseDrop((e: IEditorMouseEvent) => this._onEditorMouseDrop(e)));
this._register(this._editor.onKeyDown((e: IKeyboardEvent) => this.onEditorKeyDown(e)));
this._register(this._editor.onKeyUp((e: IKeyboardEvent) => this.onEditorKeyUp(e)));
this._register(this._editor.onDidBlurEditorWidget(() => this.onEditorBlur()));
this._dndDecorationIds = [];
this._mouseDown = false;
this._modifierPressed = false;
......@@ -228,7 +227,7 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
this._dragSelection = null;
this._mouseDown = false;
this._modifierPressed = false;
this._toUnhook = dispose(this._toUnhook);
super.dispose();
}
}
......
......@@ -7,7 +7,7 @@ import * as arrays from 'vs/base/common/arrays';
import { localize } from 'vs/nls';
import { Event } from 'vs/base/common/event';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Disposable } from 'vs/base/common/lifecycle';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IExtensionManagementService, ILocalExtension, IExtensionEnablementService, IExtensionTipsService, IExtensionIdentifier, EnablementState, InstallOperation } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
......@@ -22,9 +22,7 @@ export interface IExtensionStatus {
globallyEnabled: boolean;
}
export class KeymapExtensions implements IWorkbenchContribution {
private disposables: IDisposable[] = [];
export class KeymapExtensions extends Disposable implements IWorkbenchContribution {
constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
......@@ -34,13 +32,12 @@ export class KeymapExtensions implements IWorkbenchContribution {
@INotificationService private readonly notificationService: INotificationService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
) {
this.disposables.push(
lifecycleService.onShutdown(() => this.dispose()),
instantiationService.invokeFunction(onExtensionChanged)((identifiers => {
Promise.all(identifiers.map(identifier => this.checkForOtherKeymaps(identifier)))
.then(undefined, onUnexpectedError);
}))
);
super();
this._register(lifecycleService.onShutdown(() => this.dispose()));
this._register(instantiationService.invokeFunction(onExtensionChanged)((identifiers => {
Promise.all(identifiers.map(identifier => this.checkForOtherKeymaps(identifier)))
.then(undefined, onUnexpectedError);
})));
}
private checkForOtherKeymaps(extensionIdentifier: IExtensionIdentifier): Promise<void> {
......@@ -87,10 +84,6 @@ export class KeymapExtensions implements IWorkbenchContribution {
}]
);
}
dispose(): void {
this.disposables = dispose(this.disposables);
}
}
export function onExtensionChanged(accessor: ServicesAccessor): Event<IExtensionIdentifier[]> {
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Action } from 'vs/base/common/actions';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -164,7 +164,7 @@ export class OpenWorkspaceSettingsAction extends Action {
static readonly ID = 'workbench.action.openWorkspaceSettings';
static readonly LABEL = nls.localize('openWorkspaceSettings', "Open Workspace Settings");
private disposables: IDisposable[] = [];
private readonly disposables = new DisposableStore();
constructor(
id: string,
......@@ -174,7 +174,7 @@ export class OpenWorkspaceSettingsAction extends Action {
) {
super(id, label);
this.update();
this.workspaceContextService.onDidChangeWorkbenchState(() => this.update(), this, this.disposables);
this.disposables.push(this.workspaceContextService.onDidChangeWorkbenchState(() => this.update(), this));
}
private update(): void {
......@@ -186,7 +186,7 @@ export class OpenWorkspaceSettingsAction extends Action {
}
dispose(): void {
this.disposables = dispose(this.disposables);
this.disposables.dispose();
super.dispose();
}
}
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { isLinux } from 'vs/base/common/platform';
import { isEqual } from 'vs/base/common/resources';
import { endsWith } from 'vs/base/common/strings';
......@@ -129,14 +129,14 @@ export class PreferencesContribution implements IWorkbenchContribution {
const modelContent = JSON.stringify(schema);
const languageSelection = this.modeService.create('jsonc');
const model = this.modelService.createModel(modelContent, languageSelection, uri);
const disposables: IDisposable[] = [];
const disposables = new DisposableStore();
disposables.push(schemaRegistry.onDidChangeSchema(schemaUri => {
if (schemaUri === uri.toString()) {
schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()];
model.setValue(JSON.stringify(schema));
}
}));
disposables.push(model.onWillDispose(() => dispose(disposables)));
disposables.push(model.onWillDispose(() => disposables.dispose()));
return model;
}
......
......@@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import * as platform from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/terminalWidgetManager';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -64,7 +64,7 @@ interface IPath {
}
export class TerminalLinkHandler {
private _hoverDisposables: IDisposable[] = [];
private readonly _hoverDisposables = new DisposableStore();
private _mouseMoveDisposable: IDisposable;
private _widgetManager: TerminalWidgetManager;
private _processCwd: string;
......@@ -177,7 +177,8 @@ export class TerminalLinkHandler {
public dispose(): void {
this._xterm = null;
this._hoverDisposables = dispose(this._hoverDisposables);
this._hoverDisposables.dispose();
this._mouseMoveDisposable = dispose(this._mouseMoveDisposable);
}
......
......@@ -17,7 +17,7 @@ import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { Schemas } from 'vs/base/common/network';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { rimraf, RimRafMode, copy, readFile, exists } from 'vs/base/node/pfs';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { FileService } from 'vs/workbench/services/files/common/fileService';
import { NullLogService } from 'vs/platform/log/common/log';
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
......@@ -76,7 +76,7 @@ suite('Files - TextFileService i/o', () => {
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'textfileservice');
let accessor: ServiceAccessor;
let disposables: IDisposable[] = [];
const disposables = new DisposableStore();
let service: ITextFileService;
let testDir: string;
......@@ -108,7 +108,7 @@ suite('Files - TextFileService i/o', () => {
(<TextFileEditorModelManager>accessor.textFileService.models).dispose();
accessor.untitledEditorService.revertAll();
disposables = dispose(disposables);
disposables.clear();
await rimraf(parentDir, RimRafMode.MOVE);
});
......
......@@ -7,7 +7,7 @@ import * as assert from 'assert';
import { mapArrayOrNot } from 'vs/base/common/arrays';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { joinPath } from 'vs/base/common/resources';
import { URI, UriComponents } from 'vs/base/common/uri';
import * as pfs from 'vs/base/node/pfs';
......@@ -21,7 +21,7 @@ import * as vscode from 'vscode';
let rpcProtocol: TestRPCProtocol;
let extHostSearch: ExtHostSearch;
let disposables: vscode.Disposable[] = [];
const disposables = new DisposableStore();
let mockMainThreadSearch: MockMainThreadSearch;
class MockMainThreadSearch implements MainThreadSearchShape {
......@@ -139,7 +139,7 @@ suite('ExtHostSearch', () => {
});
teardown(() => {
dispose(disposables);
disposables.clear();
return rpcProtocol.sync();
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册