提交 1ef4a75f 编写于 作者: M Matt Bierner

Replace IDisposable with DisposableStore in a few more simple cases

上级 b61980c3
......@@ -5,7 +5,7 @@
import { RunOnceScheduler, TimeoutTimer } from 'vs/base/common/async';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } from 'vs/editor/common/commands/replaceCommand';
import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
......@@ -71,7 +71,7 @@ export class FindModelBoundToEditorModel {
private readonly _editor: IActiveCodeEditor;
private readonly _state: FindReplaceState;
private _toDispose: IDisposable[];
private readonly _toDispose = new DisposableStore();
private readonly _decorations: FindDecorations;
private _ignoreModelContentChanged: boolean;
private readonly _startSearchingTimer: TimeoutTimer;
......@@ -82,17 +82,16 @@ export class FindModelBoundToEditorModel {
constructor(editor: IActiveCodeEditor, state: FindReplaceState) {
this._editor = editor;
this._state = state;
this._toDispose = [];
this._isDisposed = false;
this._startSearchingTimer = new TimeoutTimer();
this._decorations = new FindDecorations(editor);
this._toDispose.push(this._decorations);
this._toDispose.add(this._decorations);
this._updateDecorationsScheduler = new RunOnceScheduler(() => this.research(false), 100);
this._toDispose.push(this._updateDecorationsScheduler);
this._toDispose.add(this._updateDecorationsScheduler);
this._toDispose.push(this._editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
this._toDispose.add(this._editor.onDidChangeCursorPosition((e: ICursorPositionChangedEvent) => {
if (
e.reason === CursorChangeReason.Explicit
|| e.reason === CursorChangeReason.Undo
......@@ -103,7 +102,7 @@ export class FindModelBoundToEditorModel {
}));
this._ignoreModelContentChanged = false;
this._toDispose.push(this._editor.onDidChangeModelContent((e) => {
this._toDispose.add(this._editor.onDidChangeModelContent((e) => {
if (this._ignoreModelContentChanged) {
return;
}
......@@ -115,7 +114,7 @@ export class FindModelBoundToEditorModel {
this._updateDecorationsScheduler.schedule();
}));
this._toDispose.push(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
this._toDispose.add(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
this.research(false, this._state.searchScope);
}
......@@ -123,7 +122,7 @@ export class FindModelBoundToEditorModel {
public dispose(): void {
this._isDisposed = true;
dispose(this._startSearchingTimer);
this._toDispose = dispose(this._toDispose);
this._toDispose.dispose();
}
private _onStateChanged(e: FindReplaceStateChangedEvent): void {
......
......@@ -6,7 +6,7 @@
import * as nls from 'vs/nls';
import { Emitter } from 'vs/base/common/event';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IDisposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IMarker, IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers';
......@@ -32,7 +32,7 @@ class MarkerModel {
private readonly _editor: ICodeEditor;
private _markers: IMarker[];
private _nextIdx: number;
private _toUnbind: IDisposable[];
private readonly _toUnbind = new DisposableStore();
private _ignoreSelectionChange: boolean;
private readonly _onCurrentMarkerChanged: Emitter<IMarker | undefined>;
private readonly _onMarkerSetChanged: Emitter<MarkerModel>;
......@@ -41,15 +41,14 @@ class MarkerModel {
this._editor = editor;
this._markers = [];
this._nextIdx = -1;
this._toUnbind = [];
this._ignoreSelectionChange = false;
this._onCurrentMarkerChanged = new Emitter<IMarker>();
this._onMarkerSetChanged = new Emitter<MarkerModel>();
this.setMarkers(markers);
// listen on editor
this._toUnbind.push(this._editor.onDidDispose(() => this.dispose()));
this._toUnbind.push(this._editor.onDidChangeCursorPosition(() => {
this._toUnbind.add(this._editor.onDidDispose(() => this.dispose()));
this._toUnbind.add(this._editor.onDidChangeCursorPosition(() => {
if (this._ignoreSelectionChange) {
return;
}
......@@ -190,7 +189,7 @@ class MarkerModel {
}
public dispose(): void {
this._toUnbind = dispose(this._toUnbind);
this._toUnbind.dispose();
}
}
......
......@@ -10,7 +10,7 @@ import { ITelemetryAppender } from 'vs/platform/telemetry/common/telemetryUtils'
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { cloneAndChange, mixin } from 'vs/base/common/objects';
import { Registry } from 'vs/platform/registry/common/platform';
import { ClassifiedEvent, StrictPropertyCheck, GDPRClassification } from 'vs/platform/telemetry/common/gdprTypings';
......@@ -35,7 +35,7 @@ export class TelemetryService implements ITelemetryService {
private _userOptIn: boolean;
private _enabled: boolean;
private _disposables: IDisposable[] = [];
private readonly _disposables = new DisposableStore();
private _cleanupPatterns: RegExp[] = [];
constructor(
......@@ -113,7 +113,7 @@ export class TelemetryService implements ITelemetryService {
}
dispose(): void {
this._disposables = dispose(this._disposables);
this._disposables.dispose();
}
publicLog(eventName: string, data?: ITelemetryData, anonymizeFilePaths?: boolean): Promise<any> {
......
......@@ -6,7 +6,7 @@
import { URI, UriComponents } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
import { dispose, IDisposable, DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { asPromise } from 'vs/base/common/async';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext, ExtHostSCMShape, CommandDto } from './extHost.protocol';
......@@ -263,7 +263,6 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
}
readonly handle = ExtHostSourceControlResourceGroup._handlePool++;
private _disposables: IDisposable[] = [];
constructor(
private _proxy: MainThreadSCMShape,
......@@ -353,7 +352,6 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
dispose(): void {
this._proxy.$unregisterGroup(this._sourceControlHandle, this.handle);
this._disposables = dispose(this._disposables);
this._onDidDispose.fire();
}
}
......
......@@ -5,7 +5,7 @@
import { Event, Emitter } from 'vs/base/common/event';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { IExplorerService, IEditableData, IFilesConfiguration, SortOrder, SortOrderConfiguration } from 'vs/workbench/contrib/files/common/files';
import { ExplorerItem, ExplorerModel } from 'vs/workbench/contrib/files/common/explorerModel';
import { URI } from 'vs/base/common/uri';
......@@ -36,7 +36,7 @@ export class ExplorerService implements IExplorerService {
private _onDidChangeEditable = new Emitter<ExplorerItem>();
private _onDidSelectResource = new Emitter<{ resource?: URI, reveal?: boolean }>();
private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>();
private disposables: IDisposable[] = [];
private readonly disposables = new DisposableStore();
private editable: { stat: ExplorerItem, data: IEditableData } | undefined;
private _sortOrder: SortOrder;
private cutItems: ExplorerItem[] | undefined;
......@@ -88,18 +88,18 @@ export class ExplorerService implements IExplorerService {
(root?: URI) => getFileEventsExcludes(this.configurationService, root),
(event: IConfigurationChangeEvent) => event.affectsConfiguration(FILES_EXCLUDE_CONFIG)
);
this.disposables.push(fileEventsFilter);
this.disposables.add(fileEventsFilter);
return fileEventsFilter;
}
@memoize get model(): ExplorerModel {
const model = new ExplorerModel(this.contextService);
this.disposables.push(model);
this.disposables.push(this.fileService.onAfterOperation(e => this.onFileOperation(e)));
this.disposables.push(this.fileService.onFileChanges(e => this.onFileChanges(e)));
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getValue<IFilesConfiguration>())));
this.disposables.push(this.fileService.onDidChangeFileSystemProviderRegistrations(e => {
this.disposables.add(model);
this.disposables.add(this.fileService.onAfterOperation(e => this.onFileOperation(e)));
this.disposables.add(this.fileService.onFileChanges(e => this.onFileChanges(e)));
this.disposables.add(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationUpdated(this.configurationService.getValue<IFilesConfiguration>())));
this.disposables.add(this.fileService.onDidChangeFileSystemProviderRegistrations(e => {
if (e.added && this.fileSystemProviderSchemes.has(e.scheme)) {
// A file system provider got re-registered, we should update all file stats since they might change (got read-only)
this.model.roots.forEach(r => r.forgetChildren());
......@@ -108,7 +108,7 @@ export class ExplorerService implements IExplorerService {
this.fileSystemProviderSchemes.add(e.scheme);
}
}));
this.disposables.push(model.onDidChangeRoots(() => this._onDidChangeRoots.fire()));
this.disposables.add(model.onDidChangeRoots(() => this._onDidChangeRoots.fire()));
return model;
}
......@@ -380,6 +380,6 @@ export class ExplorerService implements IExplorerService {
}
dispose(): void {
dispose(this.disposables);
this.disposables.dispose();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册