提交 29475925 编写于 作者: M Matt Bierner

Extend disposable

上级 d34324f8
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'vs/css!./selectBoxCustom'; import 'vs/css!./selectBoxCustom';
import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { KeyCode, KeyCodeUtils } from 'vs/base/common/keyCodes'; import { KeyCode, KeyCodeUtils } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
...@@ -80,7 +80,7 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList ...@@ -80,7 +80,7 @@ class SelectListRenderer implements IListRenderer<ISelectOptionItem, ISelectList
} }
} }
export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<ISelectOptionItem> { export class SelectBoxList extends Disposable implements ISelectBoxDelegate, IListVirtualDelegate<ISelectOptionItem> {
private static readonly DEFAULT_DROPDOWN_MINIMUM_BOTTOM_MARGIN = 32; private static readonly DEFAULT_DROPDOWN_MINIMUM_BOTTOM_MARGIN = 32;
private static readonly DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN = 2; private static readonly DEFAULT_DROPDOWN_MINIMUM_TOP_MARGIN = 2;
...@@ -92,7 +92,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -92,7 +92,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
private options: ISelectOptionItem[]; private options: ISelectOptionItem[];
private selected: number; private selected: number;
private readonly _onDidSelect: Emitter<ISelectData>; private readonly _onDidSelect: Emitter<ISelectData>;
private toDispose: IDisposable[];
private styles: ISelectBoxStyles; private styles: ISelectBoxStyles;
private listRenderer: SelectListRenderer; private listRenderer: SelectListRenderer;
private contextViewProvider: IContextViewProvider; private contextViewProvider: IContextViewProvider;
...@@ -111,7 +110,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -111,7 +110,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
constructor(options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, styles: ISelectBoxStyles, selectBoxOptions?: ISelectBoxOptions) { constructor(options: ISelectOptionItem[], selected: number, contextViewProvider: IContextViewProvider, styles: ISelectBoxStyles, selectBoxOptions?: ISelectBoxOptions) {
this.toDispose = []; super();
this._isVisible = false; this._isVisible = false;
this.selectBoxOptions = selectBoxOptions || Object.create(null); this.selectBoxOptions = selectBoxOptions || Object.create(null);
...@@ -131,7 +130,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -131,7 +130,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
} }
this._onDidSelect = new Emitter<ISelectData>(); this._onDidSelect = new Emitter<ISelectData>();
this.toDispose.push(this._onDidSelect); this._register(this._onDidSelect);
this.styles = styles; this.styles = styles;
...@@ -185,7 +184,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -185,7 +184,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
// Parent native select keyboard listeners // Parent native select keyboard listeners
this.toDispose.push(dom.addStandardDisposableListener(this.selectElement, 'change', (e) => { this._register(dom.addStandardDisposableListener(this.selectElement, 'change', (e) => {
this.selected = e.target.selectedIndex; this.selected = e.target.selectedIndex;
this._onDidSelect.fire({ this._onDidSelect.fire({
index: e.target.selectedIndex, index: e.target.selectedIndex,
...@@ -199,7 +198,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -199,7 +198,7 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
// Have to implement both keyboard and mouse controllers to handle disabled options // Have to implement both keyboard and mouse controllers to handle disabled options
// Intercept mouse events to override normal select actions on parents // Intercept mouse events to override normal select actions on parents
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.CLICK, (e) => { this._register(dom.addDisposableListener(this.selectElement, dom.EventType.CLICK, (e) => {
dom.EventHelper.stop(e); dom.EventHelper.stop(e);
if (this._isVisible) { if (this._isVisible) {
...@@ -209,13 +208,13 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -209,13 +208,13 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
} }
})); }));
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.MOUSE_DOWN, (e) => { this._register(dom.addDisposableListener(this.selectElement, dom.EventType.MOUSE_DOWN, (e) => {
dom.EventHelper.stop(e); dom.EventHelper.stop(e);
})); }));
// Intercept keyboard handling // Intercept keyboard handling
this.toDispose.push(dom.addDisposableListener(this.selectElement, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => { this._register(dom.addDisposableListener(this.selectElement, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
const event = new StandardKeyboardEvent(e); const event = new StandardKeyboardEvent(e);
let showDropDown = false; let showDropDown = false;
...@@ -735,27 +734,26 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -735,27 +734,26 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
.filter(() => this.selectList.length > 0) .filter(() => this.selectList.length > 0)
.map(e => new StandardKeyboardEvent(e)); .map(e => new StandardKeyboardEvent(e));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(e => this.onEnter(e), this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(e => this.onEnter(e), this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(e => this.onEscape(e), this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(e => this.onEscape(e), this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDown, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDown, this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUp, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUp, this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Home).on(this.onHome, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.Home).on(this.onHome, this));
onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.End).on(this.onEnd, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => e.keyCode === KeyCode.End).on(this.onEnd, this));
onSelectDropDownKeyDown.filter(e => (e.keyCode >= KeyCode.KEY_0 && e.keyCode <= KeyCode.KEY_Z) || (e.keyCode >= KeyCode.US_SEMICOLON && e.keyCode <= KeyCode.NUMPAD_DIVIDE)).on(this.onCharacter, this, this.toDispose); this._register(onSelectDropDownKeyDown.filter(e => (e.keyCode >= KeyCode.KEY_0 && e.keyCode <= KeyCode.KEY_Z) || (e.keyCode >= KeyCode.US_SEMICOLON && e.keyCode <= KeyCode.NUMPAD_DIVIDE)).on(this.onCharacter, this));
// SetUp list mouse controller - control navigation, disabled items, focus // SetUp list mouse controller - control navigation, disabled items, focus
Event.chain(domEvent(this.selectList.getHTMLElement(), 'mouseup')) this._register(Event.chain(domEvent(this.selectList.getHTMLElement(), 'mouseup'))
.filter(() => this.selectList.length > 0) .filter(() => this.selectList.length > 0)
.on(e => this.onMouseUp(e), this, this.toDispose); .on(e => this.onMouseUp(e), this));
this.toDispose.push(
this.selectList.onDidBlur(_ => this.onListBlur()), this._register(this.selectList.onDidBlur(_ => this.onListBlur()));
this.selectList.onMouseOver(e => typeof e.index !== 'undefined' && this.selectList.setFocus([e.index])), this._register(this.selectList.onMouseOver(e => typeof e.index !== 'undefined' && this.selectList.setFocus([e.index])));
this.selectList.onFocusChange(e => this.onListFocus(e)) this._register(this.selectList.onFocusChange(e => this.onListFocus(e)));
);
this.selectList.getHTMLElement().setAttribute('aria-label', this.selectBoxOptions.ariaLabel || ''); this.selectList.getHTMLElement().setAttribute('aria-label', this.selectBoxOptions.ariaLabel || '');
this.selectList.getHTMLElement().setAttribute('aria-expanded', 'true'); this.selectList.getHTMLElement().setAttribute('aria-expanded', 'true');
...@@ -1034,6 +1032,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I ...@@ -1034,6 +1032,6 @@ export class SelectBoxList implements ISelectBoxDelegate, IListVirtualDelegate<I
public dispose(): void { public dispose(): void {
this.hideSelectDropDown(false); this.hideSelectDropDown(false);
this.toDispose = dispose(this.toDispose); super.dispose();
} }
} }
...@@ -34,8 +34,7 @@ export class SelectBoxNative extends Disposable implements ISelectBoxDelegate { ...@@ -34,8 +34,7 @@ export class SelectBoxNative extends Disposable implements ISelectBoxDelegate {
this.selectElement.setAttribute('aria-label', this.selectBoxOptions.ariaLabel); this.selectElement.setAttribute('aria-label', this.selectBoxOptions.ariaLabel);
} }
this._onDidSelect = new Emitter<ISelectData>(); this._onDidSelect = this._register(new Emitter<ISelectData>());
this._register(this._onDidSelect);
this.styles = styles; this.styles = styles;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import * as fs from 'fs'; import * as fs from 'fs';
import { dirname } from 'vs/base/common/path'; import { dirname } from 'vs/base/common/path';
import * as objects from 'vs/base/common/objects'; import * as objects from 'vs/base/common/objects';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Disposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import * as json from 'vs/base/common/json'; import * as json from 'vs/base/common/json';
import { statLink } from 'vs/base/node/pfs'; import { statLink } from 'vs/base/node/pfs';
...@@ -41,18 +41,17 @@ export interface IConfigOptions<T> { ...@@ -41,18 +41,17 @@ export interface IConfigOptions<T> {
* - delayed processing of changes to accomodate for lots of changes * - delayed processing of changes to accomodate for lots of changes
* - configurable defaults * - configurable defaults
*/ */
export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable { export class ConfigWatcher<T> extends Disposable implements IConfigWatcher<T> {
private cache: T; private cache: T;
private parseErrors: json.ParseError[]; private parseErrors: json.ParseError[];
private disposed: boolean; private disposed: boolean;
private loaded: boolean; private loaded: boolean;
private timeoutHandle: NodeJS.Timer | null; private timeoutHandle: NodeJS.Timer | null;
private readonly disposables = new DisposableStore();
private readonly _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>; private readonly _onDidUpdateConfiguration: Emitter<IConfigurationChangeEvent<T>>;
constructor(private _path: string, private options: IConfigOptions<T> = { defaultConfig: Object.create(null), onError: error => console.error(error) }) { constructor(private _path: string, private options: IConfigOptions<T> = { defaultConfig: Object.create(null), onError: error => console.error(error) }) {
this._onDidUpdateConfiguration = new Emitter<IConfigurationChangeEvent<T>>(); super();
this.disposables.add(this._onDidUpdateConfiguration); this._onDidUpdateConfiguration = this._register(new Emitter<IConfigurationChangeEvent<T>>());
this.registerWatcher(); this.registerWatcher();
this.initAsync(); this.initAsync();
...@@ -123,7 +122,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable { ...@@ -123,7 +122,7 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
this.watch(parentFolder, true); this.watch(parentFolder, true);
// Check if the path is a symlink and watch its target if so // Check if the path is a symlink and watch its target if so
this.handleSymbolicLink().then(undefined, error => { /* ignore error */ }); this.handleSymbolicLink().then(undefined, () => { /* ignore error */ });
} }
private async handleSymbolicLink(): Promise<void> { private async handleSymbolicLink(): Promise<void> {
...@@ -141,9 +140,9 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable { ...@@ -141,9 +140,9 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
} }
if (isFolder) { if (isFolder) {
this.disposables.add(watchFolder(path, (type, path) => path === this._path ? this.onConfigFileChange() : undefined, error => this.options.onError(error))); this._register(watchFolder(path, (type, path) => path === this._path ? this.onConfigFileChange() : undefined, error => this.options.onError(error)));
} else { } else {
this.disposables.add(watchFile(path, (type, path) => this.onConfigFileChange(), error => this.options.onError(error))); this._register(watchFile(path, () => this.onConfigFileChange(), error => this.options.onError(error)));
} }
} }
...@@ -185,6 +184,6 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable { ...@@ -185,6 +184,6 @@ export class ConfigWatcher<T> implements IConfigWatcher<T>, IDisposable {
dispose(): void { dispose(): void {
this.disposed = true; this.disposed = true;
this.disposables.dispose(); super.dispose();
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册