Skip to content

Commit

Permalink
This partially reverts "extends Disposable" changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 6, 2019
1 parent a1041f7 commit 078da2b
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 179 deletions.
25 changes: 15 additions & 10 deletions src/vs/base/browser/ui/list/listWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import 'vs/css!./list';
import { localize } from 'vs/nls';
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { isNumber } from 'vs/base/common/types';
import { range, firstIndex, binarySearch } from 'vs/base/common/arrays';
import { memoize } from 'vs/base/common/decorators';
Expand Down Expand Up @@ -226,33 +226,34 @@ function isInputElement(e: HTMLElement): boolean {
return e.tagName === 'INPUT' || e.tagName === 'TEXTAREA';
}

class KeyboardController<T> extends Disposable {
class KeyboardController<T> implements IDisposable {

private disposables: IDisposable[];
private openController: IOpenController;

constructor(
private list: List<T>,
private view: ListView<T>,
options: IListOptions<T>
) {
super();
const multipleSelectionSupport = !(options.multipleSelectionSupport === false);
this.disposables = [];

this.openController = options.openController || DefaultOpenController;

const onKeyDown = Event.chain(domEvent(view.domNode, 'keydown'))
.filter(e => !isInputElement(e.target as HTMLElement))
.map(e => new StandardKeyboardEvent(e));

this._register(onKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(this.onEnter, this));
this._register(onKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this));
this._register(onKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this));
this._register(onKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUpArrow, this));
this._register(onKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDownArrow, this));
this._register(onKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(this.onEscape, this));
onKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(this.onEnter, this, this.disposables);
onKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this, this.disposables);
onKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this, this.disposables);
onKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUpArrow, this, this.disposables);
onKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDownArrow, this, this.disposables);
onKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(this.onEscape, this, this.disposables);

if (multipleSelectionSupport) {
this._register(onKeyDown.filter(e => (platform.isMacintosh ? e.metaKey : e.ctrlKey) && e.keyCode === KeyCode.KEY_A).on(this.onCtrlA, this));
onKeyDown.filter(e => (platform.isMacintosh ? e.metaKey : e.ctrlKey) && e.keyCode === KeyCode.KEY_A).on(this.onCtrlA, this, this.disposables);
}
}

Expand Down Expand Up @@ -311,6 +312,10 @@ class KeyboardController<T> extends Disposable {
this.list.setSelection([], e.browserEvent);
this.view.domNode.focus();
}

dispose() {
this.disposables = dispose(this.disposables);
}
}

enum TypeLabelControllerState {
Expand Down
12 changes: 8 additions & 4 deletions src/vs/code/electron-main/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
import { Event } from 'vs/base/common/event';
import { BrowserWindow, app } from 'electron';
Expand All @@ -22,18 +22,18 @@ type Credentials = {
password: string;
};

export class ProxyAuthHandler extends Disposable {
export class ProxyAuthHandler {

_serviceBrand: any;

private retryCount = 0;
private disposables: IDisposable[] = [];

constructor(
@IWindowsMainService private readonly windowsMainService: IWindowsMainService
) {
super();
const onLogin = Event.fromNodeEventEmitter<LoginEvent>(app, 'login', (event, webContents, req, authInfo, cb) => ({ event, webContents, req, authInfo, cb }));
this._register(onLogin(this.onLogin, this));
onLogin(this.onLogin, this, this.disposables);
}

private onLogin({ event, authInfo, cb }: LoginEvent): void {
Expand Down Expand Up @@ -85,4 +85,8 @@ export class ProxyAuthHandler extends Disposable {
win.close();
});
}

dispose(): void {
this.disposables = dispose(this.disposables);
}
}
16 changes: 10 additions & 6 deletions src/vs/editor/contrib/gotoError/gotoErrorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./media/gotoErrorWidget';
import * as nls from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IDisposable, dispose, DisposableStore } from 'vs/base/common/lifecycle';
import { IMarker, MarkerSeverity, IRelatedInformation } from 'vs/platform/markers/common/markers';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
Expand All @@ -28,7 +28,7 @@ import { peekViewTitleForeground, peekViewTitleInfoForeground } from 'vs/editor/
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { SeverityIcon } from 'vs/platform/severityIcon/common/severityIcon';

class MessageWidget extends Disposable {
class MessageWidget {

private _lines: number = 0;
private _longestLineLength: number = 0;
Expand All @@ -38,9 +38,9 @@ class MessageWidget extends Disposable {
private readonly _relatedBlock: HTMLDivElement;
private readonly _scrollable: ScrollableElement;
private readonly _relatedDiagnostics = new WeakMap<HTMLElement, IRelatedInformation>();
private readonly _disposables: IDisposable[] = [];

constructor(parent: HTMLElement, editor: ICodeEditor, onRelatedInformation: (related: IRelatedInformation) => void) {
super();
this._editor = editor;

const domNode = document.createElement('div');
Expand All @@ -54,7 +54,7 @@ class MessageWidget extends Disposable {

this._relatedBlock = document.createElement('div');
domNode.appendChild(this._relatedBlock);
this._register(dom.addStandardDisposableListener(this._relatedBlock, 'click', event => {
this._disposables.push(dom.addStandardDisposableListener(this._relatedBlock, 'click', event => {
event.preventDefault();
const related = this._relatedDiagnostics.get(event.target);
if (related) {
Expand All @@ -70,11 +70,15 @@ class MessageWidget extends Disposable {
verticalScrollbarSize: 3
});
parent.appendChild(this._scrollable.getDomNode());
this._register(this._scrollable.onScroll(e => {
this._disposables.push(this._scrollable.onScroll(e => {
domNode.style.left = `-${e.scrollLeft}px`;
domNode.style.top = `-${e.scrollTop}px`;
}));
this._register(this._scrollable);
this._disposables.push(this._scrollable);
}

dispose(): void {
dispose(this._disposables);
}

update({ source, message, relatedInformation, code }: IMarker): void {
Expand Down
20 changes: 10 additions & 10 deletions src/vs/editor/contrib/rename/renameInputField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import 'vs/css!./renameInputField';
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
Expand All @@ -16,14 +16,15 @@ import { ITheme, IThemeService } from 'vs/platform/theme/common/themeService';

export const CONTEXT_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('renameInputVisible', false);

export class RenameInputField extends Disposable implements IContentWidget {
export class RenameInputField implements IContentWidget, IDisposable {

private _editor: ICodeEditor;
private _position: Position;
private _domNode: HTMLElement;
private _inputField: HTMLInputElement;
private _visible: boolean;
private readonly _visibleContextKey: IContextKey<boolean>;
private _disposables: IDisposable[] = [];

// Editor.IContentWidget.allowEditorOverflow
public allowEditorOverflow: boolean = true;
Expand All @@ -33,27 +34,26 @@ export class RenameInputField extends Disposable implements IContentWidget {
private readonly themeService: IThemeService,
contextKeyService: IContextKeyService,
) {
super();
this._visibleContextKey = CONTEXT_RENAME_INPUT_VISIBLE.bindTo(contextKeyService);

this._editor = editor;
this._editor.addContentWidget(this);

this._register(editor.onDidChangeConfiguration(e => {
this._disposables.push(editor.onDidChangeConfiguration(e => {
if (e.fontInfo) {
this.updateFont();
}
}));

this._register(themeService.onThemeChange(theme => this.onThemeChange(theme)));
this._disposables.push(themeService.onThemeChange(theme => this.onThemeChange(theme)));
}

private onThemeChange(theme: ITheme): void {
this.updateStyles(theme);
}

public dispose(): void {
super.dispose();
this._disposables = dispose(this._disposables);
this._editor.removeContentWidget(this);
}

Expand Down Expand Up @@ -138,9 +138,9 @@ export class RenameInputField extends Disposable implements IContentWidget {
this._inputField.setAttribute('selectionEnd', selectionEnd.toString());
this._inputField.size = Math.max((where.endColumn - where.startColumn) * 1.1, 20);

const disposeOnDone = new DisposableStore();
const disposeOnDone: IDisposable[] = [];
const always = () => {
disposeOnDone.dispose();
dispose(disposeOnDone);
this._hide();
};

Expand Down Expand Up @@ -172,8 +172,8 @@ export class RenameInputField extends Disposable implements IContentWidget {
}
};

disposeOnDone.add(this._editor.onDidChangeCursorSelection(onCursorChanged));
disposeOnDone.add(this._editor.onDidBlurEditorWidget(() => this.cancelInput(false)));
disposeOnDone.push(this._editor.onDidChangeCursorSelection(onCursorChanged));
disposeOnDone.push(this._editor.onDidBlurEditorWidget(() => this.cancelInput(false)));

this._show();

Expand Down
19 changes: 12 additions & 7 deletions src/vs/editor/contrib/suggest/suggestCommitCharacters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
*--------------------------------------------------------------------------------------------*/

import { isNonEmptyArray } from 'vs/base/common/arrays';
import { Disposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ISelectedSuggestion, SuggestWidget } from './suggestWidget';
import { CharacterSet } from 'vs/editor/common/core/characterClassifier';

export class CommitCharacterController extends Disposable {
export class CommitCharacterController {

private _disposables: IDisposable[] = [];

private _active?: {
readonly acceptCharacters: CharacterSet;
readonly item: ISelectedSuggestion;
};

constructor(editor: ICodeEditor, widget: SuggestWidget, accept: (selected: ISelectedSuggestion) => any) {
super();

this._register(widget.onDidShow(() => this._onItem(widget.getFocusedItem())));
this._register(widget.onDidFocus(this._onItem, this));
this._register(widget.onDidHide(this.reset, this));
this._disposables.push(widget.onDidShow(() => this._onItem(widget.getFocusedItem())));
this._disposables.push(widget.onDidFocus(this._onItem, this));
this._disposables.push(widget.onDidHide(this.reset, this));

this._register(editor.onWillType(text => {
this._disposables.push(editor.onWillType(text => {
if (this._active) {
const ch = text.charCodeAt(text.length - 1);
if (this._active.acceptCharacters.has(ch) && editor.getConfiguration().contribInfo.acceptSuggestionOnCommitCharacter) {
Expand Down Expand Up @@ -51,4 +52,8 @@ export class CommitCharacterController extends Disposable {
reset(): void {
this._active = undefined;
}

dispose() {
dispose(this._disposables);
}
}

0 comments on commit 078da2b

Please sign in to comment.