mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
debt week code cleanup
- avoid public modifier - use Disposable where applicable - fix some event handler leaks - clean up some TODO@ben
This commit is contained in:
@@ -70,8 +70,8 @@ export class Builder implements IDisposable {
|
||||
private offdom: boolean;
|
||||
private container: HTMLElement;
|
||||
private createdElements: HTMLElement[];
|
||||
private toUnbind: { [type: string]: IDisposable[]; };
|
||||
private captureToUnbind: { [type: string]: IDisposable[]; };
|
||||
private toDispose: { [type: string]: IDisposable[]; };
|
||||
private captureToDispose: { [type: string]: IDisposable[]; };
|
||||
|
||||
constructor(element?: HTMLElement, offdom?: boolean) {
|
||||
this.offdom = offdom;
|
||||
@@ -81,27 +81,27 @@ export class Builder implements IDisposable {
|
||||
this.currentElement = element;
|
||||
this.createdElements = [];
|
||||
|
||||
this.toUnbind = {};
|
||||
this.captureToUnbind = {};
|
||||
this.toDispose = {};
|
||||
this.captureToDispose = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new builder that lets the current HTML Element of this builder be the container
|
||||
* for future additions on the builder.
|
||||
*/
|
||||
public asContainer(): Builder {
|
||||
asContainer(): Builder {
|
||||
return withBuilder(this, this.offdom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the builder providing the same properties as this one.
|
||||
*/
|
||||
public clone(): Builder {
|
||||
clone(): Builder {
|
||||
let builder = new Builder(this.container, this.offdom);
|
||||
builder.currentElement = this.currentElement;
|
||||
builder.createdElements = this.createdElements;
|
||||
builder.captureToUnbind = this.captureToUnbind;
|
||||
builder.toUnbind = this.toUnbind;
|
||||
builder.captureToDispose = this.captureToDispose;
|
||||
builder.toDispose = this.toDispose;
|
||||
|
||||
return builder;
|
||||
}
|
||||
@@ -113,9 +113,9 @@ export class Builder implements IDisposable {
|
||||
* at the end.
|
||||
* This method is a no-op unless the builder was created with the offdom option to be true.
|
||||
*/
|
||||
public build(container?: Builder, index?: number): Builder;
|
||||
public build(container?: HTMLElement, index?: number): Builder;
|
||||
public build(container?: any, index?: number): Builder {
|
||||
build(container?: Builder, index?: number): Builder;
|
||||
build(container?: HTMLElement, index?: number): Builder;
|
||||
build(container?: any, index?: number): Builder {
|
||||
assert.ok(this.offdom, 'This builder was not created off-dom, so build() can not be called.');
|
||||
|
||||
// Use builders own container if present
|
||||
@@ -154,9 +154,9 @@ export class Builder implements IDisposable {
|
||||
* attached the current element. If the current element has a parent, it will be
|
||||
* detached from that parent.
|
||||
*/
|
||||
public appendTo(container?: Builder, index?: number): Builder;
|
||||
public appendTo(container?: HTMLElement, index?: number): Builder;
|
||||
public appendTo(container?: any, index?: number): Builder {
|
||||
appendTo(container?: Builder, index?: number): Builder;
|
||||
appendTo(container?: HTMLElement, index?: number): Builder;
|
||||
appendTo(container?: any, index?: number): Builder {
|
||||
|
||||
// Use builders own container if present
|
||||
if (!container) {
|
||||
@@ -194,9 +194,9 @@ export class Builder implements IDisposable {
|
||||
* of the return value being the builder which called the operation (`a` in the
|
||||
* first case; `b` in the second case).
|
||||
*/
|
||||
public append(child: HTMLElement, index?: number): Builder;
|
||||
public append(child: Builder, index?: number): Builder;
|
||||
public append(child: any, index?: number): Builder {
|
||||
append(child: HTMLElement, index?: number): Builder;
|
||||
append(child: Builder, index?: number): Builder;
|
||||
append(child: any, index?: number): Builder {
|
||||
assert.ok(child, 'Need a child to append');
|
||||
|
||||
if (DOM.isHTMLElement(child)) {
|
||||
@@ -213,7 +213,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Removes the current element of this builder from its parent node.
|
||||
*/
|
||||
public offDOM(): Builder {
|
||||
offDOM(): Builder {
|
||||
if (this.currentElement.parentNode) {
|
||||
this.currentElement.parentNode.removeChild(this.currentElement);
|
||||
}
|
||||
@@ -224,14 +224,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Returns the HTML Element the builder is currently active on.
|
||||
*/
|
||||
public getHTMLElement(): HTMLElement {
|
||||
getHTMLElement(): HTMLElement {
|
||||
return this.currentElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML Element the builder is building in.
|
||||
*/
|
||||
public getContainer(): HTMLElement {
|
||||
getContainer(): HTMLElement {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public div(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
div(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('div', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public p(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
p(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('p', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public ul(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
ul(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('ul', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public li(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
li(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('li', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public span(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
span(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('span', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public img(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
img(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('img', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public a(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
a(attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement('a', attributes, fn);
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ export class Builder implements IDisposable {
|
||||
* of the element. The function will be called with a new builder created with the
|
||||
* provided element.
|
||||
*/
|
||||
public element(name: string, attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
element(name: string, attributes?: any, fn?: (builder: Builder) => void): Builder {
|
||||
return this.doElement(name, attributes, fn);
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Calls focus() on the current HTML element;
|
||||
*/
|
||||
public domFocus(): Builder {
|
||||
domFocus(): Builder {
|
||||
this.currentElement.focus();
|
||||
|
||||
return this;
|
||||
@@ -380,7 +380,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Calls blur() on the current HTML element;
|
||||
*/
|
||||
public domBlur(): Builder {
|
||||
domBlur(): Builder {
|
||||
this.currentElement.blur();
|
||||
|
||||
return this;
|
||||
@@ -389,14 +389,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Registers listener on event types on the current element.
|
||||
*/
|
||||
public on<E extends Event = Event>(type: string, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
public on<E extends Event = Event>(typeArray: string[], fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
public on<E extends Event = Event>(arg1: any, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder {
|
||||
on<E extends Event = Event>(type: string, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
on<E extends Event = Event>(typeArray: string[], fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
on<E extends Event = Event>(arg1: any, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder {
|
||||
|
||||
// Event Type Array
|
||||
if (types.isArray(arg1)) {
|
||||
arg1.forEach((type: string) => {
|
||||
this.on(type, fn, listenerToUnbindContainer, useCapture);
|
||||
this.on(type, fn, listenerToDisposeContainer, useCapture);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -411,15 +411,15 @@ export class Builder implements IDisposable {
|
||||
|
||||
// Remember for off() use
|
||||
if (useCapture) {
|
||||
if (!this.captureToUnbind[type]) {
|
||||
this.captureToUnbind[type] = [];
|
||||
if (!this.captureToDispose[type]) {
|
||||
this.captureToDispose[type] = [];
|
||||
}
|
||||
this.captureToUnbind[type].push(unbind);
|
||||
this.captureToDispose[type].push(unbind);
|
||||
} else {
|
||||
if (!this.toUnbind[type]) {
|
||||
this.toUnbind[type] = [];
|
||||
if (!this.toDispose[type]) {
|
||||
this.toDispose[type] = [];
|
||||
}
|
||||
this.toUnbind[type].push(unbind);
|
||||
this.toDispose[type].push(unbind);
|
||||
}
|
||||
|
||||
// Bind to Element
|
||||
@@ -428,8 +428,8 @@ export class Builder implements IDisposable {
|
||||
this.setProperty(LISTENER_BINDING_ID, listenerBinding);
|
||||
|
||||
// Add to Array if passed in
|
||||
if (listenerToUnbindContainer && types.isArray(listenerToUnbindContainer)) {
|
||||
listenerToUnbindContainer.push(unbind);
|
||||
if (listenerToDisposeContainer && types.isArray(listenerToDisposeContainer)) {
|
||||
listenerToDisposeContainer.push(unbind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,9 +439,9 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Removes all listeners from all elements created by the builder for the given event type.
|
||||
*/
|
||||
public off(type: string, useCapture?: boolean): Builder;
|
||||
public off(typeArray: string[], useCapture?: boolean): Builder;
|
||||
public off(arg1: any, useCapture?: boolean): Builder {
|
||||
off(type: string, useCapture?: boolean): Builder;
|
||||
off(typeArray: string[], useCapture?: boolean): Builder;
|
||||
off(arg1: any, useCapture?: boolean): Builder {
|
||||
|
||||
// Event Type Array
|
||||
if (types.isArray(arg1)) {
|
||||
@@ -454,12 +454,12 @@ export class Builder implements IDisposable {
|
||||
else {
|
||||
let type = arg1;
|
||||
if (useCapture) {
|
||||
if (this.captureToUnbind[type]) {
|
||||
this.captureToUnbind[type] = dispose(this.captureToUnbind[type]);
|
||||
if (this.captureToDispose[type]) {
|
||||
this.captureToDispose[type] = dispose(this.captureToDispose[type]);
|
||||
}
|
||||
} else {
|
||||
if (this.toUnbind[type]) {
|
||||
this.toUnbind[type] = dispose(this.toUnbind[type]);
|
||||
if (this.toDispose[type]) {
|
||||
this.toDispose[type] = dispose(this.toDispose[type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -471,9 +471,9 @@ export class Builder implements IDisposable {
|
||||
* Registers listener on event types on the current element and removes
|
||||
* them after first invocation.
|
||||
*/
|
||||
public once<E extends Event = Event>(type: string, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
public once<E extends Event = Event>(typesArray: string[], fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
public once<E extends Event = Event>(arg1: any, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToUnbindContainer?: IDisposable[], useCapture?: boolean): Builder {
|
||||
once<E extends Event = Event>(type: string, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
once<E extends Event = Event>(typesArray: string[], fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder;
|
||||
once<E extends Event = Event>(arg1: any, fn: (e: E, builder: Builder, unbind: IDisposable) => void, listenerToDisposeContainer?: IDisposable[], useCapture?: boolean): Builder {
|
||||
|
||||
// Event Type Array
|
||||
if (types.isArray(arg1)) {
|
||||
@@ -493,8 +493,8 @@ export class Builder implements IDisposable {
|
||||
}, useCapture || false);
|
||||
|
||||
// Add to Array if passed in
|
||||
if (listenerToUnbindContainer && types.isArray(listenerToUnbindContainer)) {
|
||||
listenerToUnbindContainer.push(unbind);
|
||||
if (listenerToDisposeContainer && types.isArray(listenerToDisposeContainer)) {
|
||||
listenerToDisposeContainer.push(unbind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,12 +510,12 @@ export class Builder implements IDisposable {
|
||||
* c) an object literal passed in will apply the properties of the literal as attributes
|
||||
* to the current element of the builder.
|
||||
*/
|
||||
public attr(name: string): string;
|
||||
public attr(name: string, value: string): Builder;
|
||||
public attr(name: string, value: boolean): Builder;
|
||||
public attr(name: string, value: number): Builder;
|
||||
public attr(attributes: any): Builder;
|
||||
public attr(firstP: any, secondP?: any): any {
|
||||
attr(name: string): string;
|
||||
attr(name: string, value: string): Builder;
|
||||
attr(name: string, value: boolean): Builder;
|
||||
attr(name: string, value: number): Builder;
|
||||
attr(attributes: any): Builder;
|
||||
attr(firstP: any, secondP?: any): any {
|
||||
|
||||
// Apply Object Literal to Attributes of Element
|
||||
if (types.isObject(firstP)) {
|
||||
@@ -564,14 +564,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Removes an attribute by the given name.
|
||||
*/
|
||||
public removeAttribute(prop: string): void {
|
||||
removeAttribute(prop: string): void {
|
||||
this.currentElement.removeAttribute(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id attribute to the value provided for the current HTML element of the builder.
|
||||
*/
|
||||
public id(id: string): Builder {
|
||||
id(id: string): Builder {
|
||||
this.currentElement.setAttribute('id', id);
|
||||
|
||||
return this;
|
||||
@@ -580,7 +580,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the title attribute to the value provided for the current HTML element of the builder.
|
||||
*/
|
||||
public title(title: string): Builder {
|
||||
title(title: string): Builder {
|
||||
this.currentElement.setAttribute('title', title);
|
||||
|
||||
return this;
|
||||
@@ -589,7 +589,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the type attribute to the value provided for the current HTML element of the builder.
|
||||
*/
|
||||
public type(type: string): Builder {
|
||||
type(type: string): Builder {
|
||||
this.currentElement.setAttribute('type', type);
|
||||
|
||||
return this;
|
||||
@@ -598,7 +598,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the value attribute to the value provided for the current HTML element of the builder.
|
||||
*/
|
||||
public value(value: string): Builder {
|
||||
value(value: string): Builder {
|
||||
this.currentElement.setAttribute('value', value);
|
||||
|
||||
return this;
|
||||
@@ -607,7 +607,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the tabindex attribute to the value provided for the current HTML element of the builder.
|
||||
*/
|
||||
public tabindex(index: number): Builder {
|
||||
tabindex(index: number): Builder {
|
||||
this.currentElement.setAttribute('tabindex', index.toString());
|
||||
|
||||
return this;
|
||||
@@ -623,10 +623,10 @@ export class Builder implements IDisposable {
|
||||
* c) an object literal passed in will apply the properties of the literal as styles
|
||||
* to the current element of the builder.
|
||||
*/
|
||||
public style(name: string): string;
|
||||
public style(name: string, value: string): Builder;
|
||||
public style(attributes: any): Builder;
|
||||
public style(firstP: any, secondP?: any): any {
|
||||
style(name: string): string;
|
||||
style(name: string, value: string): Builder;
|
||||
style(attributes: any): Builder;
|
||||
style(firstP: any, secondP?: any): any {
|
||||
|
||||
// Apply Object Literal to Styles of Element
|
||||
if (types.isObject(firstP)) {
|
||||
@@ -692,14 +692,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Returns the computed CSS style for the current HTML element of the builder.
|
||||
*/
|
||||
public getComputedStyle(): CSSStyleDeclaration {
|
||||
getComputedStyle(): CSSStyleDeclaration {
|
||||
return DOM.getComputedStyle(this.currentElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the variable list of arguments as class names to the current HTML element of the builder.
|
||||
*/
|
||||
public addClass(...classes: string[]): Builder {
|
||||
addClass(...classes: string[]): Builder {
|
||||
classes.forEach((nameValue: string) => {
|
||||
let names = nameValue.split(' ');
|
||||
names.forEach((name: string) => {
|
||||
@@ -714,7 +714,7 @@ export class Builder implements IDisposable {
|
||||
* Sets the class name of the current HTML element of the builder to the provided className.
|
||||
* If shouldAddClass is provided - for true class is added, for false class is removed.
|
||||
*/
|
||||
public setClass(className: string, shouldAddClass: boolean = null): Builder {
|
||||
setClass(className: string, shouldAddClass: boolean = null): Builder {
|
||||
if (shouldAddClass === null) {
|
||||
this.currentElement.className = className;
|
||||
} else if (shouldAddClass) {
|
||||
@@ -729,14 +729,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Returns whether the current HTML element of the builder has the provided class assigned.
|
||||
*/
|
||||
public hasClass(className: string): boolean {
|
||||
hasClass(className: string): boolean {
|
||||
return DOM.hasClass(this.currentElement, className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the variable list of arguments as class names from the current HTML element of the builder.
|
||||
*/
|
||||
public removeClass(...classes: string[]): Builder {
|
||||
removeClass(...classes: string[]): Builder {
|
||||
classes.forEach((nameValue: string) => {
|
||||
let names = nameValue.split(' ');
|
||||
names.forEach((name: string) => {
|
||||
@@ -750,7 +750,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Adds or removes the provided className for the current HTML element of the builder.
|
||||
*/
|
||||
public toggleClass(className: string): Builder {
|
||||
toggleClass(className: string): Builder {
|
||||
if (this.hasClass(className)) {
|
||||
this.removeClass(className);
|
||||
} else {
|
||||
@@ -763,7 +763,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property color.
|
||||
*/
|
||||
public color(color: string): Builder {
|
||||
color(color: string): Builder {
|
||||
this.currentElement.style.color = color;
|
||||
|
||||
return this;
|
||||
@@ -772,10 +772,10 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property padding.
|
||||
*/
|
||||
public padding(padding: string): Builder;
|
||||
public padding(top: number, right?: number, bottom?: number, left?: number): Builder;
|
||||
public padding(top: string, right?: string, bottom?: string, left?: string): Builder;
|
||||
public padding(top: any, right?: any, bottom?: any, left?: any): Builder {
|
||||
padding(padding: string): Builder;
|
||||
padding(top: number, right?: number, bottom?: number, left?: number): Builder;
|
||||
padding(top: string, right?: string, bottom?: string, left?: string): Builder;
|
||||
padding(top: any, right?: any, bottom?: any, left?: any): Builder {
|
||||
if (types.isString(top) && top.indexOf(' ') >= 0) {
|
||||
return this.padding.apply(this, top.split(' '));
|
||||
}
|
||||
@@ -802,10 +802,10 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property margin.
|
||||
*/
|
||||
public margin(margin: string): Builder;
|
||||
public margin(top: number, right?: number, bottom?: number, left?: number): Builder;
|
||||
public margin(top: string, right?: string, bottom?: string, left?: string): Builder;
|
||||
public margin(top: any, right?: any, bottom?: any, left?: any): Builder {
|
||||
margin(margin: string): Builder;
|
||||
margin(top: number, right?: number, bottom?: number, left?: number): Builder;
|
||||
margin(top: string, right?: string, bottom?: string, left?: string): Builder;
|
||||
margin(top: any, right?: any, bottom?: any, left?: any): Builder {
|
||||
if (types.isString(top) && top.indexOf(' ') >= 0) {
|
||||
return this.margin.apply(this, top.split(' '));
|
||||
}
|
||||
@@ -832,10 +832,10 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property position.
|
||||
*/
|
||||
public position(position: string): Builder;
|
||||
public position(top: number, right?: number, bottom?: number, left?: number, position?: string): Builder;
|
||||
public position(top: string, right?: string, bottom?: string, left?: string, position?: string): Builder;
|
||||
public position(top: any, right?: any, bottom?: any, left?: any, position?: string): Builder {
|
||||
position(position: string): Builder;
|
||||
position(top: number, right?: number, bottom?: number, left?: number, position?: string): Builder;
|
||||
position(top: string, right?: string, bottom?: string, left?: string, position?: string): Builder;
|
||||
position(top: any, right?: any, bottom?: any, left?: any, position?: string): Builder {
|
||||
if (types.isString(top) && top.indexOf(' ') >= 0) {
|
||||
return this.position.apply(this, top.split(' '));
|
||||
}
|
||||
@@ -868,10 +868,10 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property size.
|
||||
*/
|
||||
public size(size: string): Builder;
|
||||
public size(width: number, height?: number): Builder;
|
||||
public size(width: string, height?: string): Builder;
|
||||
public size(width: any, height?: any): Builder {
|
||||
size(size: string): Builder;
|
||||
size(width: number, height?: number): Builder;
|
||||
size(width: string, height?: string): Builder;
|
||||
size(width: any, height?: any): Builder {
|
||||
if (types.isString(width) && width.indexOf(' ') >= 0) {
|
||||
return this.size.apply(this, width.split(' '));
|
||||
}
|
||||
@@ -890,7 +890,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the CSS property display.
|
||||
*/
|
||||
public display(display: string): Builder {
|
||||
display(display: string): Builder {
|
||||
this.currentElement.style.display = display;
|
||||
|
||||
return this;
|
||||
@@ -899,7 +899,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Shows the current element of the builder.
|
||||
*/
|
||||
public show(): Builder {
|
||||
show(): Builder {
|
||||
if (this.hasClass('monaco-builder-hidden')) {
|
||||
this.removeClass('monaco-builder-hidden');
|
||||
}
|
||||
@@ -919,7 +919,7 @@ export class Builder implements IDisposable {
|
||||
* only show the element when a specific delay is reached (e.g. for a long running
|
||||
* operation.
|
||||
*/
|
||||
public showDelayed(delay: number): Builder {
|
||||
showDelayed(delay: number): Builder {
|
||||
|
||||
// Cancel any pending showDelayed() invocation
|
||||
this.cancelVisibilityPromise();
|
||||
@@ -938,7 +938,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Hides the current element of the builder.
|
||||
*/
|
||||
public hide(): Builder {
|
||||
hide(): Builder {
|
||||
if (!this.hasClass('monaco-builder-hidden')) {
|
||||
this.addClass('monaco-builder-hidden');
|
||||
}
|
||||
@@ -953,7 +953,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Returns true if the current element of the builder is hidden.
|
||||
*/
|
||||
public isHidden(): boolean {
|
||||
isHidden(): boolean {
|
||||
return this.hasClass('monaco-builder-hidden') || this.currentElement.style.display === 'none';
|
||||
}
|
||||
|
||||
@@ -976,7 +976,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the innerHTML attribute.
|
||||
*/
|
||||
public innerHtml(html: string, append?: boolean): Builder {
|
||||
innerHtml(html: string, append?: boolean): Builder {
|
||||
if (append) {
|
||||
this.currentElement.innerHTML += html;
|
||||
} else {
|
||||
@@ -990,7 +990,7 @@ export class Builder implements IDisposable {
|
||||
* Sets the textContent property of the element.
|
||||
* All HTML special characters will be escaped.
|
||||
*/
|
||||
public text(text: string, append?: boolean): Builder {
|
||||
text(text: string, append?: boolean): Builder {
|
||||
if (append) {
|
||||
// children is child Elements versus childNodes includes textNodes
|
||||
if (this.currentElement.children.length === 0) {
|
||||
@@ -1011,14 +1011,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Sets the innerHTML attribute in escaped form.
|
||||
*/
|
||||
public safeInnerHtml(html: string, append?: boolean): Builder {
|
||||
safeInnerHtml(html: string, append?: boolean): Builder {
|
||||
return this.innerHtml(strings.escape(html), append);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to store arbritary data into the current element.
|
||||
*/
|
||||
public setProperty(key: string, value: any): Builder {
|
||||
setProperty(key: string, value: any): Builder {
|
||||
setPropertyOnElement(this.currentElement, key, value);
|
||||
|
||||
return this;
|
||||
@@ -1027,14 +1027,14 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Allows to get arbritary data from the current element.
|
||||
*/
|
||||
public getProperty(key: string, fallback?: any): any {
|
||||
getProperty(key: string, fallback?: any): any {
|
||||
return getPropertyFromElement(this.currentElement, key, fallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a property from the current element that is stored under the given key.
|
||||
*/
|
||||
public removeProperty(key: string): Builder {
|
||||
removeProperty(key: string): Builder {
|
||||
if (hasData(this.currentElement)) {
|
||||
delete data(this.currentElement)[key];
|
||||
}
|
||||
@@ -1045,7 +1045,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Returns a new builder with the child at the given index.
|
||||
*/
|
||||
public child(index = 0): Builder {
|
||||
child(index = 0): Builder {
|
||||
let children = this.currentElement.children;
|
||||
|
||||
return withElement(<HTMLElement>children.item(index));
|
||||
@@ -1085,7 +1085,7 @@ export class Builder implements IDisposable {
|
||||
* event listners registered and also clear any data binding and properties stored
|
||||
* to any child element.
|
||||
*/
|
||||
public empty(): Builder {
|
||||
empty(): Builder {
|
||||
this.unbindDescendants(this.currentElement);
|
||||
|
||||
this.clearChildren();
|
||||
@@ -1100,7 +1100,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Removes all HTML elements from the current element of the builder.
|
||||
*/
|
||||
public clearChildren(): Builder {
|
||||
clearChildren(): Builder {
|
||||
|
||||
// Remove Elements
|
||||
if (this.currentElement) {
|
||||
@@ -1114,7 +1114,7 @@ export class Builder implements IDisposable {
|
||||
* Removes the current HTML element and all its children from its parent and unbinds
|
||||
* all listeners and properties set to the data slots.
|
||||
*/
|
||||
public destroy(): void {
|
||||
destroy(): void {
|
||||
|
||||
if (this.currentElement) {
|
||||
|
||||
@@ -1144,15 +1144,15 @@ export class Builder implements IDisposable {
|
||||
|
||||
let type: string;
|
||||
|
||||
for (type in this.toUnbind) {
|
||||
if (this.toUnbind.hasOwnProperty(type) && types.isArray(this.toUnbind[type])) {
|
||||
this.toUnbind[type] = dispose(this.toUnbind[type]);
|
||||
for (type in this.toDispose) {
|
||||
if (this.toDispose.hasOwnProperty(type) && types.isArray(this.toDispose[type])) {
|
||||
this.toDispose[type] = dispose(this.toDispose[type]);
|
||||
}
|
||||
}
|
||||
|
||||
for (type in this.captureToUnbind) {
|
||||
if (this.captureToUnbind.hasOwnProperty(type) && types.isArray(this.captureToUnbind[type])) {
|
||||
this.captureToUnbind[type] = dispose(this.captureToUnbind[type]);
|
||||
for (type in this.captureToDispose) {
|
||||
if (this.captureToDispose.hasOwnProperty(type) && types.isArray(this.captureToDispose[type])) {
|
||||
this.captureToDispose[type] = dispose(this.captureToDispose[type]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1161,22 +1161,22 @@ export class Builder implements IDisposable {
|
||||
this.container = null;
|
||||
this.offdom = null;
|
||||
this.createdElements = null;
|
||||
this.captureToUnbind = null;
|
||||
this.toUnbind = null;
|
||||
this.captureToDispose = null;
|
||||
this.toDispose = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the current HTML element and all its children from its parent and unbinds
|
||||
* all listeners and properties set to the data slots.
|
||||
*/
|
||||
public dispose(): void {
|
||||
dispose(): void {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size (in pixels) of an element, including the margin.
|
||||
*/
|
||||
public getTotalSize(): DOM.Dimension {
|
||||
getTotalSize(): DOM.Dimension {
|
||||
let totalWidth = DOM.getTotalWidth(this.currentElement);
|
||||
let totalHeight = DOM.getTotalHeight(this.currentElement);
|
||||
|
||||
@@ -1186,7 +1186,7 @@ export class Builder implements IDisposable {
|
||||
/**
|
||||
* Another variant of getting the inner dimensions of an element.
|
||||
*/
|
||||
public getClientArea(): DOM.Dimension {
|
||||
getClientArea(): DOM.Dimension {
|
||||
return DOM.getClientArea(this.currentElement);
|
||||
}
|
||||
}
|
||||
@@ -1197,7 +1197,7 @@ export class Builder implements IDisposable {
|
||||
*/
|
||||
export class MultiBuilder extends Builder {
|
||||
|
||||
public length: number;
|
||||
length: number;
|
||||
|
||||
private builders: Builder[];
|
||||
|
||||
@@ -1278,11 +1278,11 @@ export class MultiBuilder extends Builder {
|
||||
}
|
||||
}
|
||||
|
||||
public item(i: number): Builder {
|
||||
item(i: number): Builder {
|
||||
return this.builders[i];
|
||||
}
|
||||
|
||||
public push(...items: Builder[]): void {
|
||||
push(...items: Builder[]): void {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
this.builders.push(items[i]);
|
||||
}
|
||||
@@ -1290,7 +1290,7 @@ export class MultiBuilder extends Builder {
|
||||
this.length = this.builders.length;
|
||||
}
|
||||
|
||||
public clone(): MultiBuilder {
|
||||
clone(): MultiBuilder {
|
||||
return new MultiBuilder(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { addDisposableListener } from 'vs/base/browser/dom';
|
||||
|
||||
/**
|
||||
* A helper that will execute a provided function when the provided HTMLElement receives
|
||||
* dragover event for 800ms. If the drag is aborted before, the callback will not be triggered.
|
||||
*/
|
||||
export class DelayedDragHandler {
|
||||
private toDispose: IDisposable[] = [];
|
||||
export class DelayedDragHandler extends Disposable {
|
||||
private timeout: number;
|
||||
|
||||
constructor(container: HTMLElement, callback: () => void) {
|
||||
this.toDispose.push(addDisposableListener(container, 'dragover', () => {
|
||||
super();
|
||||
|
||||
this._register(addDisposableListener(container, 'dragover', () => {
|
||||
if (!this.timeout) {
|
||||
this.timeout = setTimeout(() => {
|
||||
callback();
|
||||
@@ -28,7 +29,7 @@ export class DelayedDragHandler {
|
||||
}));
|
||||
|
||||
['dragleave', 'drop', 'dragend'].forEach(type => {
|
||||
this.toDispose.push(addDisposableListener(container, type, () => {
|
||||
this._register(addDisposableListener(container, type, () => {
|
||||
this.clearDragTimeout();
|
||||
}));
|
||||
});
|
||||
@@ -41,8 +42,9 @@ export class DelayedDragHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
dispose(): void {
|
||||
super.dispose();
|
||||
|
||||
this.clearDragTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
import { Event as BaseEvent, Emitter } from 'vs/base/common/event';
|
||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Gesture, EventType } from 'vs/base/browser/touch';
|
||||
|
||||
export interface IButtonOptions extends IButtonStyles {
|
||||
@@ -33,7 +33,7 @@ const defaultOptions: IButtonStyles = {
|
||||
buttonForeground: Color.white
|
||||
};
|
||||
|
||||
export class Button {
|
||||
export class Button extends Disposable {
|
||||
|
||||
private $el: Builder;
|
||||
private options: IButtonOptions;
|
||||
@@ -43,12 +43,14 @@ export class Button {
|
||||
private buttonForeground: Color;
|
||||
private buttonBorder: Color;
|
||||
|
||||
private _onDidClick = new Emitter<any>();
|
||||
readonly onDidClick: BaseEvent<Event> = this._onDidClick.event;
|
||||
private _onDidClick = this._register(new Emitter<any>());
|
||||
get onDidClick(): BaseEvent<Event> { return this._onDidClick.event; }
|
||||
|
||||
private focusTracker: DOM.IFocusTracker;
|
||||
|
||||
constructor(container: HTMLElement, options?: IButtonOptions) {
|
||||
super();
|
||||
|
||||
this.options = options || Object.create(null);
|
||||
mixin(this.options, defaultOptions, false);
|
||||
|
||||
@@ -57,10 +59,10 @@ export class Button {
|
||||
this.buttonForeground = this.options.buttonForeground;
|
||||
this.buttonBorder = this.options.buttonBorder;
|
||||
|
||||
this.$el = $('a.monaco-button').attr({
|
||||
this.$el = this._register($('a.monaco-button').attr({
|
||||
'tabIndex': '0',
|
||||
'role': 'button'
|
||||
}).appendTo(container);
|
||||
}).appendTo(container));
|
||||
|
||||
Gesture.addTarget(this.$el.getHTMLElement());
|
||||
|
||||
@@ -74,7 +76,7 @@ export class Button {
|
||||
});
|
||||
|
||||
this.$el.on(DOM.EventType.KEY_DOWN, e => {
|
||||
let event = new StandardKeyboardEvent(e as KeyboardEvent);
|
||||
const event = new StandardKeyboardEvent(e as KeyboardEvent);
|
||||
let eventHandled = false;
|
||||
if (this.enabled && event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
|
||||
this._onDidClick.fire(e);
|
||||
@@ -100,9 +102,9 @@ export class Button {
|
||||
});
|
||||
|
||||
// Also set hover background when button is focused for feedback
|
||||
this.focusTracker = DOM.trackFocus(this.$el.getHTMLElement());
|
||||
this.focusTracker.onDidFocus(() => this.setHoverBackground());
|
||||
this.focusTracker.onDidBlur(() => this.applyStyles()); // restore standard styles
|
||||
this.focusTracker = this._register(DOM.trackFocus(this.$el.getHTMLElement()));
|
||||
this._register(this.focusTracker.onDidFocus(() => this.setHoverBackground()));
|
||||
this._register(this.focusTracker.onDidBlur(() => this.applyStyles())); // restore standard styles
|
||||
|
||||
this.applyStyles();
|
||||
}
|
||||
@@ -177,27 +179,13 @@ export class Button {
|
||||
focus(): void {
|
||||
this.$el.domFocus();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this.$el) {
|
||||
this.$el.dispose();
|
||||
this.$el = null;
|
||||
|
||||
this.focusTracker.dispose();
|
||||
this.focusTracker = null;
|
||||
}
|
||||
|
||||
this._onDidClick.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export class ButtonGroup {
|
||||
private _buttons: Button[];
|
||||
private toDispose: IDisposable[];
|
||||
export class ButtonGroup extends Disposable {
|
||||
private _buttons: Button[] = [];
|
||||
|
||||
constructor(container: HTMLElement, count: number, options?: IButtonOptions) {
|
||||
this._buttons = [];
|
||||
this.toDispose = [];
|
||||
super();
|
||||
|
||||
this.create(container, count, options);
|
||||
}
|
||||
@@ -208,9 +196,8 @@ export class ButtonGroup {
|
||||
|
||||
private create(container: HTMLElement, count: number, options?: IButtonOptions): void {
|
||||
for (let index = 0; index < count; index++) {
|
||||
const button = new Button(container, options);
|
||||
const button = this._register(new Button(container, options));
|
||||
this._buttons.push(button);
|
||||
this.toDispose.push(button);
|
||||
|
||||
// Implement keyboard access in buttons if there are multiple
|
||||
if (count > 1) {
|
||||
@@ -236,8 +223,4 @@ export class ButtonGroup {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import 'vs/css!./checkbox';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { Widget } from 'vs/base/browser/ui/widget';
|
||||
@@ -12,7 +13,6 @@ import { Color } from 'vs/base/common/color';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import 'vs/css!./checkbox';
|
||||
|
||||
export interface ICheckboxOpts extends ICheckboxStyles {
|
||||
readonly actionClassName: string;
|
||||
@@ -31,18 +31,19 @@ const defaultOpts = {
|
||||
export class Checkbox extends Widget {
|
||||
|
||||
private readonly _onChange = this._register(new Emitter<boolean>());
|
||||
public readonly onChange: Event<boolean /* via keyboard */> = this._onChange.event;
|
||||
get onChange(): Event<boolean /* via keyboard */> { return this._onChange.event; }
|
||||
|
||||
private readonly _onKeyDown = this._register(new Emitter<IKeyboardEvent>());
|
||||
public readonly onKeyDown: Event<IKeyboardEvent> = this._onKeyDown.event;
|
||||
get onKeyDown(): Event<IKeyboardEvent> { return this._onKeyDown.event; }
|
||||
|
||||
private readonly _opts: ICheckboxOpts;
|
||||
public readonly domNode: HTMLElement;
|
||||
readonly domNode: HTMLElement;
|
||||
|
||||
private _checked: boolean;
|
||||
|
||||
constructor(opts: ICheckboxOpts) {
|
||||
super();
|
||||
|
||||
this._opts = objects.deepClone(opts);
|
||||
objects.mixin(this._opts, defaultOpts, false);
|
||||
this._checked = this._opts.isChecked;
|
||||
@@ -75,19 +76,19 @@ export class Checkbox extends Widget {
|
||||
});
|
||||
}
|
||||
|
||||
public get enabled(): boolean {
|
||||
get enabled(): boolean {
|
||||
return this.domNode.getAttribute('aria-disabled') !== 'true';
|
||||
}
|
||||
|
||||
public focus(): void {
|
||||
focus(): void {
|
||||
this.domNode.focus();
|
||||
}
|
||||
|
||||
public get checked(): boolean {
|
||||
get checked(): boolean {
|
||||
return this._checked;
|
||||
}
|
||||
|
||||
public set checked(newIsChecked: boolean) {
|
||||
set checked(newIsChecked: boolean) {
|
||||
this._checked = newIsChecked;
|
||||
this.domNode.setAttribute('aria-checked', String(this._checked));
|
||||
if (this._checked) {
|
||||
@@ -99,11 +100,11 @@ export class Checkbox extends Widget {
|
||||
this.applyStyles();
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
width(): number {
|
||||
return 2 /*marginleft*/ + 2 /*border*/ + 2 /*padding*/ + 16 /* icon width */;
|
||||
}
|
||||
|
||||
public style(styles: ICheckboxStyles): void {
|
||||
style(styles: ICheckboxStyles): void {
|
||||
if (styles.inputActiveOptionBorder) {
|
||||
this._opts.inputActiveOptionBorder = styles.inputActiveOptionBorder;
|
||||
}
|
||||
@@ -116,12 +117,12 @@ export class Checkbox extends Widget {
|
||||
}
|
||||
}
|
||||
|
||||
public enable(): void {
|
||||
enable(): void {
|
||||
this.domNode.tabIndex = 0;
|
||||
this.domNode.setAttribute('aria-disabled', String(false));
|
||||
}
|
||||
|
||||
public disable(): void {
|
||||
disable(): void {
|
||||
DOM.removeTabIndexAndUpdateFocus(this.domNode);
|
||||
this.domNode.setAttribute('aria-disabled', String(true));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ export interface IBaseDropdownOptions {
|
||||
}
|
||||
|
||||
export class BaseDropdown extends ActionRunner {
|
||||
private _toDispose: IDisposable[];
|
||||
private _toDispose: IDisposable[] = [];
|
||||
|
||||
private $el: Builder;
|
||||
private $boxContainer: Builder;
|
||||
private $label: Builder;
|
||||
@@ -38,8 +39,6 @@ export class BaseDropdown extends ActionRunner {
|
||||
constructor(container: HTMLElement, options: IBaseDropdownOptions) {
|
||||
super();
|
||||
|
||||
this._toDispose = [];
|
||||
|
||||
this.$el = $('.monaco-dropdown').appendTo(container);
|
||||
|
||||
this.$label = $('.dropdown-label');
|
||||
@@ -66,8 +65,7 @@ export class BaseDropdown extends ActionRunner {
|
||||
}
|
||||
}).appendTo(this.$el);
|
||||
|
||||
let cleanupFn = labelRenderer(this.$label.getHTMLElement());
|
||||
|
||||
const cleanupFn = labelRenderer(this.$label.getHTMLElement());
|
||||
if (cleanupFn) {
|
||||
this._toDispose.push(cleanupFn);
|
||||
}
|
||||
@@ -75,27 +73,27 @@ export class BaseDropdown extends ActionRunner {
|
||||
Gesture.addTarget(this.$label.getHTMLElement());
|
||||
}
|
||||
|
||||
public get toDispose(): IDisposable[] {
|
||||
get toDispose(): IDisposable[] {
|
||||
return this._toDispose;
|
||||
}
|
||||
|
||||
public get element(): HTMLElement {
|
||||
get element(): HTMLElement {
|
||||
return this.$el.getHTMLElement();
|
||||
}
|
||||
|
||||
public get label(): HTMLElement {
|
||||
get label(): HTMLElement {
|
||||
return this.$label.getHTMLElement();
|
||||
}
|
||||
|
||||
public set tooltip(tooltip: string) {
|
||||
set tooltip(tooltip: string) {
|
||||
this.$label.title(tooltip);
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
show(): void {
|
||||
this.visible = true;
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
hide(): void {
|
||||
this.visible = false;
|
||||
}
|
||||
|
||||
@@ -103,7 +101,7 @@ export class BaseDropdown extends ActionRunner {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
dispose(): void {
|
||||
super.dispose();
|
||||
this.hide();
|
||||
|
||||
@@ -139,7 +137,7 @@ export class Dropdown extends BaseDropdown {
|
||||
this.contextViewProvider = options.contextViewProvider;
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
show(): void {
|
||||
super.show();
|
||||
|
||||
addClass(this.element, 'active');
|
||||
@@ -167,7 +165,7 @@ export class Dropdown extends BaseDropdown {
|
||||
removeClass(this.element, 'active');
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
hide(): void {
|
||||
super.hide();
|
||||
|
||||
if (this.contextViewProvider) {
|
||||
@@ -211,11 +209,11 @@ export class DropdownMenu extends BaseDropdown {
|
||||
this.menuClassName = options.menuClassName || '';
|
||||
}
|
||||
|
||||
public set menuOptions(options: IMenuOptions) {
|
||||
set menuOptions(options: IMenuOptions) {
|
||||
this._menuOptions = options;
|
||||
}
|
||||
|
||||
public get menuOptions(): IMenuOptions {
|
||||
get menuOptions(): IMenuOptions {
|
||||
return this._menuOptions;
|
||||
}
|
||||
|
||||
@@ -231,7 +229,7 @@ export class DropdownMenu extends BaseDropdown {
|
||||
this._actions = actions;
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
show(): void {
|
||||
super.show();
|
||||
|
||||
addClass(this.element, 'active');
|
||||
@@ -248,7 +246,7 @@ export class DropdownMenu extends BaseDropdown {
|
||||
});
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
hide(): void {
|
||||
super.hide();
|
||||
}
|
||||
|
||||
@@ -279,8 +277,8 @@ export class DropdownMenuActionItem extends BaseActionItem {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public render(container: HTMLElement): void {
|
||||
let labelRenderer: ILabelRenderer = (el: HTMLElement): IDisposable => {
|
||||
render(container: HTMLElement): void {
|
||||
const labelRenderer: ILabelRenderer = (el: HTMLElement): IDisposable => {
|
||||
this.builder = $('a.action-label').attr({
|
||||
tabIndex: '0',
|
||||
role: 'button',
|
||||
@@ -294,7 +292,7 @@ export class DropdownMenuActionItem extends BaseActionItem {
|
||||
return null;
|
||||
};
|
||||
|
||||
let options: IDropdownMenuOptions = {
|
||||
const options: IDropdownMenuOptions = {
|
||||
contextMenuProvider: this.contextMenuProvider,
|
||||
labelRenderer: labelRenderer
|
||||
};
|
||||
@@ -316,7 +314,7 @@ export class DropdownMenuActionItem extends BaseActionItem {
|
||||
};
|
||||
}
|
||||
|
||||
public setActionContext(newContext: any): void {
|
||||
setActionContext(newContext: any): void {
|
||||
super.setActionContext(newContext);
|
||||
|
||||
if (this.dropdownMenu) {
|
||||
@@ -324,13 +322,13 @@ export class DropdownMenuActionItem extends BaseActionItem {
|
||||
}
|
||||
}
|
||||
|
||||
public show(): void {
|
||||
show(): void {
|
||||
if (this.dropdownMenu) {
|
||||
this.dropdownMenu.show();
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
dispose(): void {
|
||||
this.dropdownMenu.dispose();
|
||||
|
||||
super.dispose();
|
||||
|
||||
@@ -12,7 +12,7 @@ import { IMatch } from 'vs/base/common/filters';
|
||||
import uri from 'vs/base/common/uri';
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import { IWorkspaceFolderProvider, getPathLabel, IUserHomeProvider, getBaseLabel } from 'vs/base/common/labels';
|
||||
import { IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, combinedDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export interface IIconLabelCreationOptions {
|
||||
supportHighlights?: boolean;
|
||||
@@ -38,11 +38,11 @@ class FastLabelNode {
|
||||
constructor(private _element: HTMLElement) {
|
||||
}
|
||||
|
||||
public get element(): HTMLElement {
|
||||
get element(): HTMLElement {
|
||||
return this._element;
|
||||
}
|
||||
|
||||
public set textContent(content: string) {
|
||||
set textContent(content: string) {
|
||||
if (this.disposed || content === this._textContent) {
|
||||
return;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class FastLabelNode {
|
||||
this._element.textContent = content;
|
||||
}
|
||||
|
||||
public set className(className: string) {
|
||||
set className(className: string) {
|
||||
if (this.disposed || className === this._className) {
|
||||
return;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class FastLabelNode {
|
||||
this._element.className = className;
|
||||
}
|
||||
|
||||
public set title(title: string) {
|
||||
set title(title: string) {
|
||||
if (this.disposed || title === this._title) {
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class FastLabelNode {
|
||||
}
|
||||
}
|
||||
|
||||
public set empty(empty: boolean) {
|
||||
set empty(empty: boolean) {
|
||||
if (this.disposed || empty === this._empty) {
|
||||
return;
|
||||
}
|
||||
@@ -82,12 +82,12 @@ class FastLabelNode {
|
||||
this._element.style.marginLeft = empty ? '0' : null;
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
dispose(): void {
|
||||
this.disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
export class IconLabel {
|
||||
export class IconLabel extends Disposable {
|
||||
private domNode: FastLabelNode;
|
||||
private labelDescriptionContainer: FastLabelNode;
|
||||
private labelNode: FastLabelNode | HighlightedLabel;
|
||||
@@ -95,34 +95,36 @@ export class IconLabel {
|
||||
private descriptionNodeFactory: () => FastLabelNode | HighlightedLabel;
|
||||
|
||||
constructor(container: HTMLElement, options?: IIconLabelCreationOptions) {
|
||||
this.domNode = new FastLabelNode(dom.append(container, dom.$('.monaco-icon-label')));
|
||||
super();
|
||||
|
||||
this.labelDescriptionContainer = new FastLabelNode(dom.append(this.domNode.element, dom.$('.monaco-icon-label-description-container')));
|
||||
this.domNode = this._register(new FastLabelNode(dom.append(container, dom.$('.monaco-icon-label'))));
|
||||
|
||||
this.labelDescriptionContainer = this._register(new FastLabelNode(dom.append(this.domNode.element, dom.$('.monaco-icon-label-description-container'))));
|
||||
|
||||
if (options && options.supportHighlights) {
|
||||
this.labelNode = new HighlightedLabel(dom.append(this.labelDescriptionContainer.element, dom.$('a.label-name')));
|
||||
this.labelNode = this._register(new HighlightedLabel(dom.append(this.labelDescriptionContainer.element, dom.$('a.label-name'))));
|
||||
} else {
|
||||
this.labelNode = new FastLabelNode(dom.append(this.labelDescriptionContainer.element, dom.$('a.label-name')));
|
||||
this.labelNode = this._register(new FastLabelNode(dom.append(this.labelDescriptionContainer.element, dom.$('a.label-name'))));
|
||||
}
|
||||
|
||||
if (options && options.supportDescriptionHighlights) {
|
||||
this.descriptionNodeFactory = () => new HighlightedLabel(dom.append(this.labelDescriptionContainer.element, dom.$('span.label-description')));
|
||||
this.descriptionNodeFactory = () => this._register(new HighlightedLabel(dom.append(this.labelDescriptionContainer.element, dom.$('span.label-description'))));
|
||||
} else {
|
||||
this.descriptionNodeFactory = () => new FastLabelNode(dom.append(this.labelDescriptionContainer.element, dom.$('span.label-description')));
|
||||
this.descriptionNodeFactory = () => this._register(new FastLabelNode(dom.append(this.labelDescriptionContainer.element, dom.$('span.label-description'))));
|
||||
}
|
||||
}
|
||||
|
||||
public get element(): HTMLElement {
|
||||
get element(): HTMLElement {
|
||||
return this.domNode.element;
|
||||
}
|
||||
|
||||
public onClick(callback: (event: MouseEvent) => void): IDisposable {
|
||||
onClick(callback: (event: MouseEvent) => void): IDisposable {
|
||||
return combinedDisposable([
|
||||
dom.addDisposableListener(this.labelDescriptionContainer.element, dom.EventType.CLICK, (e: MouseEvent) => callback(e)),
|
||||
]);
|
||||
}
|
||||
|
||||
public setValue(label?: string, description?: string, options?: IIconLabelValueOptions): void {
|
||||
setValue(label?: string, description?: string, options?: IIconLabelValueOptions): void {
|
||||
const classes = ['monaco-icon-label'];
|
||||
if (options) {
|
||||
if (options.extraClasses) {
|
||||
@@ -162,15 +164,6 @@ export class IconLabel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.domNode.dispose();
|
||||
this.labelNode.dispose();
|
||||
|
||||
if (this.descriptionNode) {
|
||||
this.descriptionNode.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class FileLabel extends IconLabel {
|
||||
@@ -181,7 +174,7 @@ export class FileLabel extends IconLabel {
|
||||
this.setFile(file, provider, userHome);
|
||||
}
|
||||
|
||||
public setFile(file: uri, provider: IWorkspaceFolderProvider, userHome: IUserHomeProvider): void {
|
||||
setFile(file: uri, provider: IWorkspaceFolderProvider, userHome: IUserHomeProvider): void {
|
||||
const parent = paths.dirname(file.fsPath);
|
||||
|
||||
this.setValue(getBaseLabel(file), parent && parent !== '.' ? getPathLabel(parent, userHome, provider) : '', { title: file.fsPath });
|
||||
|
||||
@@ -10,7 +10,7 @@ import { TPromise, ValueCallback } from 'vs/base/common/winjs.base';
|
||||
import * as assert from 'vs/base/common/assert';
|
||||
import { Builder, $ } from 'vs/base/browser/builder';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
|
||||
@@ -35,9 +35,8 @@ const defaultOpts = {
|
||||
/**
|
||||
* A progress bar with support for infinite or discrete progress.
|
||||
*/
|
||||
export class ProgressBar {
|
||||
export class ProgressBar extends Disposable {
|
||||
private options: IProgressBarOptions;
|
||||
private toUnbind: IDisposable[];
|
||||
private workedVal: number;
|
||||
private element: Builder;
|
||||
private bit: HTMLElement;
|
||||
@@ -46,10 +45,11 @@ export class ProgressBar {
|
||||
private progressBarBackground: Color;
|
||||
|
||||
constructor(container: HTMLElement, options?: IProgressBarOptions) {
|
||||
super();
|
||||
|
||||
this.options = options || Object.create(null);
|
||||
mixin(this.options, defaultOpts, false);
|
||||
|
||||
this.toUnbind = [];
|
||||
this.workedVal = 0;
|
||||
|
||||
this.progressBarBackground = this.options.progressBarBackground;
|
||||
@@ -70,7 +70,7 @@ export class ProgressBar {
|
||||
break;
|
||||
}
|
||||
|
||||
}, this.toUnbind);
|
||||
}, this.toDispose);
|
||||
|
||||
this.bit = builder.getHTMLElement();
|
||||
});
|
||||
@@ -92,14 +92,14 @@ export class ProgressBar {
|
||||
/**
|
||||
* Indicates to the progress bar that all work is done.
|
||||
*/
|
||||
public done(): ProgressBar {
|
||||
done(): ProgressBar {
|
||||
return this.doDone(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the progressbar from showing any progress instantly without fading out.
|
||||
*/
|
||||
public stop(): ProgressBar {
|
||||
stop(): ProgressBar {
|
||||
return this.doDone(false);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ export class ProgressBar {
|
||||
/**
|
||||
* Use this mode to indicate progress that has no total number of work units.
|
||||
*/
|
||||
public infinite(): ProgressBar {
|
||||
infinite(): ProgressBar {
|
||||
this.bit.style.width = '2%';
|
||||
this.bit.style.opacity = '1';
|
||||
|
||||
@@ -149,7 +149,7 @@ export class ProgressBar {
|
||||
* Tells the progress bar the total number of work. Use in combination with workedVal() to let
|
||||
* the progress bar show the actual progress based on the work that is done.
|
||||
*/
|
||||
public total(value: number): ProgressBar {
|
||||
total(value: number): ProgressBar {
|
||||
this.workedVal = 0;
|
||||
this.totalWork = value;
|
||||
|
||||
@@ -159,14 +159,14 @@ export class ProgressBar {
|
||||
/**
|
||||
* Finds out if this progress bar is configured with total work
|
||||
*/
|
||||
public hasTotal(): boolean {
|
||||
hasTotal(): boolean {
|
||||
return !isNaN(this.totalWork);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the progress bar that an increment of work has been completed.
|
||||
*/
|
||||
public worked(value: number): ProgressBar {
|
||||
worked(value: number): ProgressBar {
|
||||
value = Number(value);
|
||||
assert.ok(!isNaN(value), 'Value is not a number');
|
||||
value = Math.max(1, value);
|
||||
@@ -177,7 +177,7 @@ export class ProgressBar {
|
||||
/**
|
||||
* Tells the progress bar the total amount of work that has been completed.
|
||||
*/
|
||||
public setWorked(value: number): ProgressBar {
|
||||
setWorked(value: number): ProgressBar {
|
||||
value = Number(value);
|
||||
assert.ok(!isNaN(value), 'Value is not a number');
|
||||
value = Math.max(1, value);
|
||||
@@ -212,11 +212,11 @@ export class ProgressBar {
|
||||
return this;
|
||||
}
|
||||
|
||||
public getContainer(): HTMLElement {
|
||||
getContainer(): HTMLElement {
|
||||
return this.element.getHTMLElement();
|
||||
}
|
||||
|
||||
public show(delay?: number): void {
|
||||
show(delay?: number): void {
|
||||
if (typeof delay === 'number') {
|
||||
this.element.showDelayed(delay);
|
||||
} else {
|
||||
@@ -224,11 +224,11 @@ export class ProgressBar {
|
||||
}
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
hide(): void {
|
||||
this.element.hide();
|
||||
}
|
||||
|
||||
public style(styles: IProgressBarStyles): void {
|
||||
style(styles: IProgressBarStyles): void {
|
||||
this.progressBarBackground = styles.progressBarBackground;
|
||||
|
||||
this.applyStyles();
|
||||
@@ -241,8 +241,4 @@ export class ProgressBar {
|
||||
this.bit.style.backgroundColor = background;
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.toUnbind = dispose(this.toUnbind);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import 'vs/css!./selectBox';
|
||||
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { Widget } from 'vs/base/browser/ui/widget';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
@@ -58,15 +57,12 @@ export interface ISelectData {
|
||||
}
|
||||
|
||||
export class SelectBox extends Widget implements ISelectBoxDelegate {
|
||||
private toDispose: IDisposable[];
|
||||
private styles: ISelectBoxStyles;
|
||||
private selectBoxDelegate: ISelectBoxDelegate;
|
||||
|
||||
constructor(options: string[], selected: number, contextViewProvider: IContextViewProvider, styles: ISelectBoxStyles = deepClone(defaultStyles), selectBoxOptions?: ISelectBoxOptions) {
|
||||
super();
|
||||
|
||||
this.toDispose = [];
|
||||
|
||||
mixin(this.styles, defaultStyles, false);
|
||||
|
||||
// Instantiate select implementation based on platform
|
||||
@@ -76,7 +72,7 @@ export class SelectBox extends Widget implements ISelectBoxDelegate {
|
||||
this.selectBoxDelegate = new SelectBoxList(options, selected, contextViewProvider, styles, selectBoxOptions);
|
||||
}
|
||||
|
||||
this.toDispose.push(this.selectBoxDelegate);
|
||||
this._register(this.selectBoxDelegate);
|
||||
}
|
||||
|
||||
// Public SelectBox Methods - routed through delegate interface
|
||||
@@ -114,9 +110,4 @@ export class SelectBox extends Widget implements ISelectBoxDelegate {
|
||||
public applyStyles(): void {
|
||||
this.selectBoxDelegate.applyStyles();
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { Action, IActionRunner, IAction } from 'vs/base/common/actions';
|
||||
import { ActionBar, ActionsOrientation, IActionItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import { IContextMenuProvider, DropdownMenuActionItem } from 'vs/base/browser/ui/dropdown/dropdown';
|
||||
import { ResolvedKeybinding } from 'vs/base/common/keyCodes';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
|
||||
export const CONTEXT = 'context.toolbar';
|
||||
|
||||
@@ -26,7 +27,7 @@ export interface IToolBarOptions {
|
||||
/**
|
||||
* A widget that combines an action bar for primary actions and a dropdown for secondary actions.
|
||||
*/
|
||||
export class ToolBar {
|
||||
export class ToolBar extends Disposable {
|
||||
private options: IToolBarOptions;
|
||||
private actionBar: ActionBar;
|
||||
private toggleMenuAction: ToggleMenuAction;
|
||||
@@ -35,16 +36,18 @@ export class ToolBar {
|
||||
private lookupKeybindings: boolean;
|
||||
|
||||
constructor(container: HTMLElement, contextMenuProvider: IContextMenuProvider, options: IToolBarOptions = { orientation: ActionsOrientation.HORIZONTAL }) {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
this.lookupKeybindings = typeof this.options.getKeyBinding === 'function';
|
||||
|
||||
this.toggleMenuAction = new ToggleMenuAction(() => this.toggleMenuActionItem && this.toggleMenuActionItem.show());
|
||||
this.toggleMenuAction = this._register(new ToggleMenuAction(() => this.toggleMenuActionItem && this.toggleMenuActionItem.show()));
|
||||
|
||||
let element = document.createElement('div');
|
||||
element.className = 'monaco-toolbar';
|
||||
container.appendChild(element);
|
||||
|
||||
this.actionBar = new ActionBar(element, {
|
||||
this.actionBar = this._register(new ActionBar(element, {
|
||||
orientation: options.orientation,
|
||||
ariaLabel: options.ariaLabel,
|
||||
actionRunner: options.actionRunner,
|
||||
@@ -75,29 +78,29 @@ export class ToolBar {
|
||||
|
||||
return options.actionItemProvider ? options.actionItemProvider(action) : null;
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
public set actionRunner(actionRunner: IActionRunner) {
|
||||
set actionRunner(actionRunner: IActionRunner) {
|
||||
this.actionBar.actionRunner = actionRunner;
|
||||
}
|
||||
|
||||
public get actionRunner(): IActionRunner {
|
||||
get actionRunner(): IActionRunner {
|
||||
return this.actionBar.actionRunner;
|
||||
}
|
||||
|
||||
public set context(context: any) {
|
||||
set context(context: any) {
|
||||
this.actionBar.context = context;
|
||||
if (this.toggleMenuActionItem) {
|
||||
this.toggleMenuActionItem.setActionContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
public getContainer(): HTMLElement {
|
||||
getContainer(): HTMLElement {
|
||||
return this.actionBar.getContainer();
|
||||
}
|
||||
|
||||
public getItemsWidth(): number {
|
||||
getItemsWidth(): number {
|
||||
let itemsWidth = 0;
|
||||
for (let i = 0; i < this.actionBar.length(); i++) {
|
||||
itemsWidth += this.actionBar.getWidth(i);
|
||||
@@ -105,11 +108,11 @@ export class ToolBar {
|
||||
return itemsWidth;
|
||||
}
|
||||
|
||||
public setAriaLabel(label: string): void {
|
||||
setAriaLabel(label: string): void {
|
||||
this.actionBar.setAriaLabel(label);
|
||||
}
|
||||
|
||||
public setActions(primaryActions: IAction[], secondaryActions?: IAction[]): () => void {
|
||||
setActions(primaryActions: IAction[], secondaryActions?: IAction[]): () => void {
|
||||
return () => {
|
||||
let primaryActionsToSet = primaryActions ? primaryActions.slice(0) : [];
|
||||
|
||||
@@ -134,7 +137,7 @@ export class ToolBar {
|
||||
return key ? key.getLabel() : void 0;
|
||||
}
|
||||
|
||||
public addPrimaryAction(primaryAction: IAction): () => void {
|
||||
addPrimaryAction(primaryAction: IAction): () => void {
|
||||
return () => {
|
||||
|
||||
// Add after the "..." action if we have secondary actions
|
||||
@@ -150,19 +153,19 @@ export class ToolBar {
|
||||
};
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.actionBar.dispose();
|
||||
this.toggleMenuAction.dispose();
|
||||
|
||||
dispose(): void {
|
||||
if (this.toggleMenuActionItem) {
|
||||
this.toggleMenuActionItem.dispose();
|
||||
this.toggleMenuActionItem = void 0;
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class ToggleMenuAction extends Action {
|
||||
|
||||
public static readonly ID = 'toolbar.toggle.more';
|
||||
static readonly ID = 'toolbar.toggle.more';
|
||||
|
||||
private _menuActions: IAction[];
|
||||
private toggleDropdownMenu: () => void;
|
||||
@@ -173,17 +176,17 @@ class ToggleMenuAction extends Action {
|
||||
this.toggleDropdownMenu = toggleDropdownMenu;
|
||||
}
|
||||
|
||||
public run(): TPromise<any> {
|
||||
run(): TPromise<any> {
|
||||
this.toggleDropdownMenu();
|
||||
|
||||
return TPromise.as(true);
|
||||
}
|
||||
|
||||
public get menuActions() {
|
||||
get menuActions() {
|
||||
return this._menuActions;
|
||||
}
|
||||
|
||||
public set menuActions(actions: IAction[]) {
|
||||
set menuActions(actions: IAction[]) {
|
||||
this._menuActions = actions;
|
||||
}
|
||||
}
|
||||
@@ -57,11 +57,8 @@ export function toDisposable(...fns: (() => void)[]): IDisposable {
|
||||
|
||||
export abstract class Disposable implements IDisposable {
|
||||
|
||||
protected _toDispose: IDisposable[];
|
||||
|
||||
constructor() {
|
||||
this._toDispose = [];
|
||||
}
|
||||
protected _toDispose: IDisposable[] = [];
|
||||
protected get toDispose(): IDisposable[] { return this._toDispose; }
|
||||
|
||||
public dispose(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
@@ -69,6 +66,7 @@ export abstract class Disposable implements IDisposable {
|
||||
|
||||
protected _register<T extends IDisposable>(t: T): T {
|
||||
this._toDispose.push(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,15 +37,15 @@ let IDS = 0;
|
||||
|
||||
export class QuickOpenItemAccessorClass implements IItemAccessor<QuickOpenEntry> {
|
||||
|
||||
public getItemLabel(entry: QuickOpenEntry): string {
|
||||
getItemLabel(entry: QuickOpenEntry): string {
|
||||
return entry.getLabel();
|
||||
}
|
||||
|
||||
public getItemDescription(entry: QuickOpenEntry): string {
|
||||
getItemDescription(entry: QuickOpenEntry): string {
|
||||
return entry.getDescription();
|
||||
}
|
||||
|
||||
public getItemPath(entry: QuickOpenEntry): string {
|
||||
getItemPath(entry: QuickOpenEntry): string {
|
||||
const resource = entry.getResource();
|
||||
|
||||
return resource ? resource.fsPath : void 0;
|
||||
@@ -70,70 +70,70 @@ export class QuickOpenEntry {
|
||||
/**
|
||||
* A unique identifier for the entry
|
||||
*/
|
||||
public getId(): string {
|
||||
getId(): string {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The label of the entry to identify it from others in the list
|
||||
*/
|
||||
public getLabel(): string {
|
||||
getLabel(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for the label to use for this entry
|
||||
*/
|
||||
public getLabelOptions(): IIconLabelValueOptions {
|
||||
getLabelOptions(): IIconLabelValueOptions {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The label of the entry to use when a screen reader wants to read about the entry
|
||||
*/
|
||||
public getAriaLabel(): string {
|
||||
getAriaLabel(): string {
|
||||
return this.getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail information about the entry that is optional and can be shown below the label
|
||||
*/
|
||||
public getDetail(): string {
|
||||
getDetail(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The icon of the entry to identify it from others in the list
|
||||
*/
|
||||
public getIcon(): string {
|
||||
getIcon(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A secondary description that is optional and can be shown right to the label
|
||||
*/
|
||||
public getDescription(): string {
|
||||
getDescription(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tooltip to show when hovering over the entry.
|
||||
*/
|
||||
public getTooltip(): string {
|
||||
getTooltip(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tooltip to show when hovering over the description portion of the entry.
|
||||
*/
|
||||
public getDescriptionTooltip(): string {
|
||||
getDescriptionTooltip(): string {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* An optional keybinding to show for an entry.
|
||||
*/
|
||||
public getKeybinding(): ResolvedKeybinding {
|
||||
getKeybinding(): ResolvedKeybinding {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -141,28 +141,28 @@ export class QuickOpenEntry {
|
||||
* A resource for this entry. Resource URIs can be used to compare different kinds of entries and group
|
||||
* them together.
|
||||
*/
|
||||
public getResource(): URI {
|
||||
getResource(): URI {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to reuse the same model while filtering. Hidden entries will not show up in the viewer.
|
||||
*/
|
||||
public isHidden(): boolean {
|
||||
isHidden(): boolean {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to reuse the same model while filtering. Hidden entries will not show up in the viewer.
|
||||
*/
|
||||
public setHidden(hidden: boolean): void {
|
||||
setHidden(hidden: boolean): void {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to set highlight ranges that should show up for the entry label and optionally description if set.
|
||||
*/
|
||||
public setHighlights(labelHighlights: IHighlight[], descriptionHighlights?: IHighlight[], detailHighlights?: IHighlight[]): void {
|
||||
setHighlights(labelHighlights: IHighlight[], descriptionHighlights?: IHighlight[], detailHighlights?: IHighlight[]): void {
|
||||
this.labelHighlights = labelHighlights;
|
||||
this.descriptionHighlights = descriptionHighlights;
|
||||
this.detailHighlights = detailHighlights;
|
||||
@@ -171,7 +171,7 @@ export class QuickOpenEntry {
|
||||
/**
|
||||
* Allows to return highlight ranges that should show up for the entry label and description.
|
||||
*/
|
||||
public getHighlights(): [IHighlight[] /* Label */, IHighlight[] /* Description */, IHighlight[] /* Detail */] {
|
||||
getHighlights(): [IHighlight[] /* Label */, IHighlight[] /* Description */, IHighlight[] /* Detail */] {
|
||||
return [this.labelHighlights, this.descriptionHighlights, this.detailHighlights];
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ export class QuickOpenEntry {
|
||||
*
|
||||
* The context parameter provides additional context information how the run was triggered.
|
||||
*/
|
||||
public run(mode: Mode, context: IContext): boolean {
|
||||
run(mode: Mode, context: IContext): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ export class QuickOpenEntry {
|
||||
* and the resource of this entry is the same as the resource for an editor history, it will not show up
|
||||
* because it is considered to be a duplicate of an editor history.
|
||||
*/
|
||||
public mergeWithEditorHistory(): boolean {
|
||||
mergeWithEditorHistory(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -211,97 +211,97 @@ export class QuickOpenEntryGroup extends QuickOpenEntry {
|
||||
/**
|
||||
* The label of the group or null if none.
|
||||
*/
|
||||
public getGroupLabel(): string {
|
||||
getGroupLabel(): string {
|
||||
return this.groupLabel;
|
||||
}
|
||||
|
||||
public setGroupLabel(groupLabel: string): void {
|
||||
setGroupLabel(groupLabel: string): void {
|
||||
this.groupLabel = groupLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to show a border on top of the group entry or not.
|
||||
*/
|
||||
public showBorder(): boolean {
|
||||
showBorder(): boolean {
|
||||
return this.withBorder;
|
||||
}
|
||||
|
||||
public setShowBorder(showBorder: boolean): void {
|
||||
setShowBorder(showBorder: boolean): void {
|
||||
this.withBorder = showBorder;
|
||||
}
|
||||
|
||||
public getLabel(): string {
|
||||
getLabel(): string {
|
||||
return this.entry ? this.entry.getLabel() : super.getLabel();
|
||||
}
|
||||
|
||||
public getLabelOptions(): IIconLabelValueOptions {
|
||||
getLabelOptions(): IIconLabelValueOptions {
|
||||
return this.entry ? this.entry.getLabelOptions() : super.getLabelOptions();
|
||||
}
|
||||
|
||||
public getAriaLabel(): string {
|
||||
getAriaLabel(): string {
|
||||
return this.entry ? this.entry.getAriaLabel() : super.getAriaLabel();
|
||||
}
|
||||
|
||||
public getDetail(): string {
|
||||
getDetail(): string {
|
||||
return this.entry ? this.entry.getDetail() : super.getDetail();
|
||||
}
|
||||
|
||||
public getResource(): URI {
|
||||
getResource(): URI {
|
||||
return this.entry ? this.entry.getResource() : super.getResource();
|
||||
}
|
||||
|
||||
public getIcon(): string {
|
||||
getIcon(): string {
|
||||
return this.entry ? this.entry.getIcon() : super.getIcon();
|
||||
}
|
||||
|
||||
public getDescription(): string {
|
||||
getDescription(): string {
|
||||
return this.entry ? this.entry.getDescription() : super.getDescription();
|
||||
}
|
||||
|
||||
public getEntry(): QuickOpenEntry {
|
||||
getEntry(): QuickOpenEntry {
|
||||
return this.entry;
|
||||
}
|
||||
|
||||
public getHighlights(): [IHighlight[], IHighlight[], IHighlight[]] {
|
||||
getHighlights(): [IHighlight[], IHighlight[], IHighlight[]] {
|
||||
return this.entry ? this.entry.getHighlights() : super.getHighlights();
|
||||
}
|
||||
|
||||
public isHidden(): boolean {
|
||||
isHidden(): boolean {
|
||||
return this.entry ? this.entry.isHidden() : super.isHidden();
|
||||
}
|
||||
|
||||
public setHighlights(labelHighlights: IHighlight[], descriptionHighlights?: IHighlight[], detailHighlights?: IHighlight[]): void {
|
||||
setHighlights(labelHighlights: IHighlight[], descriptionHighlights?: IHighlight[], detailHighlights?: IHighlight[]): void {
|
||||
this.entry ? this.entry.setHighlights(labelHighlights, descriptionHighlights, detailHighlights) : super.setHighlights(labelHighlights, descriptionHighlights, detailHighlights);
|
||||
}
|
||||
|
||||
public setHidden(hidden: boolean): void {
|
||||
setHidden(hidden: boolean): void {
|
||||
this.entry ? this.entry.setHidden(hidden) : super.setHidden(hidden);
|
||||
}
|
||||
|
||||
public run(mode: Mode, context: IContext): boolean {
|
||||
run(mode: Mode, context: IContext): boolean {
|
||||
return this.entry ? this.entry.run(mode, context) : super.run(mode, context);
|
||||
}
|
||||
}
|
||||
|
||||
class NoActionProvider implements IActionProvider {
|
||||
|
||||
public hasActions(tree: ITree, element: any): boolean {
|
||||
hasActions(tree: ITree, element: any): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public getActions(tree: ITree, element: any): TPromise<IAction[]> {
|
||||
getActions(tree: ITree, element: any): TPromise<IAction[]> {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
public hasSecondaryActions(tree: ITree, element: any): boolean {
|
||||
hasSecondaryActions(tree: ITree, element: any): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public getSecondaryActions(tree: ITree, element: any): TPromise<IAction[]> {
|
||||
getSecondaryActions(tree: ITree, element: any): TPromise<IAction[]> {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
public getActionItem(tree: ITree, element: any, action: Action): IActionItem {
|
||||
getActionItem(tree: ITree, element: any, action: Action): IActionItem {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ class Renderer implements IRenderer<QuickOpenEntry> {
|
||||
this.actionRunner = actionRunner;
|
||||
}
|
||||
|
||||
public getHeight(entry: QuickOpenEntry): number {
|
||||
getHeight(entry: QuickOpenEntry): number {
|
||||
if (entry.getDetail()) {
|
||||
return 44;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ class Renderer implements IRenderer<QuickOpenEntry> {
|
||||
return 22;
|
||||
}
|
||||
|
||||
public getTemplateId(entry: QuickOpenEntry): string {
|
||||
getTemplateId(entry: QuickOpenEntry): string {
|
||||
if (entry instanceof QuickOpenEntryGroup) {
|
||||
return templateEntryGroup;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ class Renderer implements IRenderer<QuickOpenEntry> {
|
||||
return templateEntry;
|
||||
}
|
||||
|
||||
public renderTemplate(templateId: string, container: HTMLElement, styles: IQuickOpenStyles): IQuickOpenEntryGroupTemplateData {
|
||||
renderTemplate(templateId: string, container: HTMLElement, styles: IQuickOpenStyles): IQuickOpenEntryGroupTemplateData {
|
||||
const entryContainer = document.createElement('div');
|
||||
DOM.addClass(entryContainer, 'sub-content');
|
||||
container.appendChild(entryContainer);
|
||||
@@ -410,7 +410,7 @@ class Renderer implements IRenderer<QuickOpenEntry> {
|
||||
};
|
||||
}
|
||||
|
||||
public renderElement(entry: QuickOpenEntry, templateId: string, data: IQuickOpenEntryGroupTemplateData, styles: IQuickOpenStyles): void {
|
||||
renderElement(entry: QuickOpenEntry, templateId: string, data: IQuickOpenEntryGroupTemplateData, styles: IQuickOpenStyles): void {
|
||||
|
||||
// Action Bar
|
||||
if (this.actionProvider.hasActions(null, entry)) {
|
||||
@@ -480,7 +480,7 @@ class Renderer implements IRenderer<QuickOpenEntry> {
|
||||
}
|
||||
}
|
||||
|
||||
public disposeTemplate(templateId: string, templateData: IQuickOpenEntryGroupTemplateData): void {
|
||||
disposeTemplate(templateId: string, templateData: IQuickOpenEntryGroupTemplateData): void {
|
||||
const data = templateData as IQuickOpenEntryGroupTemplateData;
|
||||
data.actionBar.dispose();
|
||||
data.actionBar = null;
|
||||
@@ -519,21 +519,21 @@ export class QuickOpenModel implements
|
||||
this._accessibilityProvider = this;
|
||||
}
|
||||
|
||||
public get entries() { return this._entries; }
|
||||
public get dataSource() { return this._dataSource; }
|
||||
public get renderer() { return this._renderer; }
|
||||
public get filter() { return this._filter; }
|
||||
public get runner() { return this._runner; }
|
||||
public get accessibilityProvider() { return this._accessibilityProvider; }
|
||||
get entries() { return this._entries; }
|
||||
get dataSource() { return this._dataSource; }
|
||||
get renderer() { return this._renderer; }
|
||||
get filter() { return this._filter; }
|
||||
get runner() { return this._runner; }
|
||||
get accessibilityProvider() { return this._accessibilityProvider; }
|
||||
|
||||
public set entries(entries: QuickOpenEntry[]) {
|
||||
set entries(entries: QuickOpenEntry[]) {
|
||||
this._entries = entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds entries that should show up in the quick open viewer.
|
||||
*/
|
||||
public addEntries(entries: QuickOpenEntry[]): void {
|
||||
addEntries(entries: QuickOpenEntry[]): void {
|
||||
if (types.isArray(entries)) {
|
||||
this._entries = this._entries.concat(entries);
|
||||
}
|
||||
@@ -542,7 +542,7 @@ export class QuickOpenModel implements
|
||||
/**
|
||||
* Set the entries that should show up in the quick open viewer.
|
||||
*/
|
||||
public setEntries(entries: QuickOpenEntry[]): void {
|
||||
setEntries(entries: QuickOpenEntry[]): void {
|
||||
if (types.isArray(entries)) {
|
||||
this._entries = entries;
|
||||
}
|
||||
@@ -553,7 +553,7 @@ export class QuickOpenModel implements
|
||||
*
|
||||
* @visibleOnly optional parameter to only return visible entries
|
||||
*/
|
||||
public getEntries(visibleOnly?: boolean): QuickOpenEntry[] {
|
||||
getEntries(visibleOnly?: boolean): QuickOpenEntry[] {
|
||||
if (visibleOnly) {
|
||||
return this._entries.filter((e) => !e.isHidden());
|
||||
}
|
||||
@@ -561,15 +561,15 @@ export class QuickOpenModel implements
|
||||
return this._entries;
|
||||
}
|
||||
|
||||
public getId(entry: QuickOpenEntry): string {
|
||||
getId(entry: QuickOpenEntry): string {
|
||||
return entry.getId();
|
||||
}
|
||||
|
||||
public getLabel(entry: QuickOpenEntry): string {
|
||||
getLabel(entry: QuickOpenEntry): string {
|
||||
return entry.getLabel();
|
||||
}
|
||||
|
||||
public getAriaLabel(entry: QuickOpenEntry): string {
|
||||
getAriaLabel(entry: QuickOpenEntry): string {
|
||||
const ariaLabel = entry.getAriaLabel();
|
||||
if (ariaLabel) {
|
||||
return nls.localize('quickOpenAriaLabelEntry', "{0}, picker", entry.getAriaLabel());
|
||||
@@ -578,11 +578,11 @@ export class QuickOpenModel implements
|
||||
return nls.localize('quickOpenAriaLabel', "picker");
|
||||
}
|
||||
|
||||
public isVisible(entry: QuickOpenEntry): boolean {
|
||||
isVisible(entry: QuickOpenEntry): boolean {
|
||||
return !entry.isHidden();
|
||||
}
|
||||
|
||||
public run(entry: QuickOpenEntry, mode: Mode, context: IContext): boolean {
|
||||
run(entry: QuickOpenEntry, mode: Mode, context: IContext): boolean {
|
||||
return entry.run(mode, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export class DataSource implements IDataSource {
|
||||
this.modelProvider = isFunction(arg.getModel) ? arg : { getModel: () => arg };
|
||||
}
|
||||
|
||||
public getId(tree: ITree, element: any): string {
|
||||
getId(tree: ITree, element: any): string {
|
||||
if (!element) {
|
||||
return null;
|
||||
}
|
||||
@@ -32,17 +32,17 @@ export class DataSource implements IDataSource {
|
||||
return model === element ? '__root__' : model.dataSource.getId(element);
|
||||
}
|
||||
|
||||
public hasChildren(tree: ITree, element: any): boolean {
|
||||
hasChildren(tree: ITree, element: any): boolean {
|
||||
const model = this.modelProvider.getModel();
|
||||
return model && model === element && model.entries.length > 0;
|
||||
}
|
||||
|
||||
public getChildren(tree: ITree, element: any): TPromise<any[]> {
|
||||
getChildren(tree: ITree, element: any): TPromise<any[]> {
|
||||
const model = this.modelProvider.getModel();
|
||||
return TPromise.as(model === element ? model.entries : []);
|
||||
}
|
||||
|
||||
public getParent(tree: ITree, element: any): TPromise<any> {
|
||||
getParent(tree: ITree, element: any): TPromise<any> {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
}
|
||||
@@ -50,18 +50,18 @@ export class DataSource implements IDataSource {
|
||||
export class AccessibilityProvider implements IAccessibilityProvider {
|
||||
constructor(private modelProvider: IModelProvider) { }
|
||||
|
||||
public getAriaLabel(tree: ITree, element: any): string {
|
||||
getAriaLabel(tree: ITree, element: any): string {
|
||||
const model = this.modelProvider.getModel();
|
||||
|
||||
return model.accessibilityProvider && model.accessibilityProvider.getAriaLabel(element);
|
||||
}
|
||||
|
||||
public getPosInSet(tree: ITree, element: any): string {
|
||||
getPosInSet(tree: ITree, element: any): string {
|
||||
const model = this.modelProvider.getModel();
|
||||
return String(model.entries.indexOf(element) + 1);
|
||||
}
|
||||
|
||||
public getSetSize(): string {
|
||||
getSetSize(): string {
|
||||
const model = this.modelProvider.getModel();
|
||||
return String(model.entries.length);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export class Filter implements IFilter {
|
||||
|
||||
constructor(private modelProvider: IModelProvider) { }
|
||||
|
||||
public isVisible(tree: ITree, element: any): boolean {
|
||||
isVisible(tree: ITree, element: any): boolean {
|
||||
const model = this.modelProvider.getModel();
|
||||
|
||||
if (!model.filter) {
|
||||
@@ -89,31 +89,31 @@ export class Renderer implements IRenderer {
|
||||
this.styles = styles;
|
||||
}
|
||||
|
||||
public updateStyles(styles: IQuickOpenStyles): void {
|
||||
updateStyles(styles: IQuickOpenStyles): void {
|
||||
this.styles = styles;
|
||||
}
|
||||
|
||||
public getHeight(tree: ITree, element: any): number {
|
||||
getHeight(tree: ITree, element: any): number {
|
||||
const model = this.modelProvider.getModel();
|
||||
return model.renderer.getHeight(element);
|
||||
}
|
||||
|
||||
public getTemplateId(tree: ITree, element: any): string {
|
||||
getTemplateId(tree: ITree, element: any): string {
|
||||
const model = this.modelProvider.getModel();
|
||||
return model.renderer.getTemplateId(element);
|
||||
}
|
||||
|
||||
public renderTemplate(tree: ITree, templateId: string, container: HTMLElement): any {
|
||||
renderTemplate(tree: ITree, templateId: string, container: HTMLElement): any {
|
||||
const model = this.modelProvider.getModel();
|
||||
return model.renderer.renderTemplate(templateId, container, this.styles);
|
||||
}
|
||||
|
||||
public renderElement(tree: ITree, element: any, templateId: string, templateData: any): void {
|
||||
renderElement(tree: ITree, element: any, templateId: string, templateData: any): void {
|
||||
const model = this.modelProvider.getModel();
|
||||
model.renderer.renderElement(element, templateId, templateData, this.styles);
|
||||
}
|
||||
|
||||
public disposeTemplate(tree: ITree, templateId: string, templateData: any): void {
|
||||
disposeTemplate(tree: ITree, templateId: string, templateData: any): void {
|
||||
const model = this.modelProvider.getModel();
|
||||
model.renderer.disposeTemplate(templateId, templateData);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||
import { DefaultController, ClickBehavior } from 'vs/base/parts/tree/browser/treeDefaults';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { KeyCode } from 'vs/base/common/keyCodes';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { mixin } from 'vs/base/common/objects';
|
||||
@@ -65,7 +65,7 @@ export interface IShowOptions {
|
||||
|
||||
export class QuickOpenController extends DefaultController {
|
||||
|
||||
public onContextMenu(tree: ITree, element: any, event: ContextMenuEvent): boolean {
|
||||
onContextMenu(tree: ITree, element: any, event: ContextMenuEvent): boolean {
|
||||
if (platform.isMacintosh) {
|
||||
return this.onLeftClick(tree, element, event); // https://github.com/Microsoft/vscode/issues/1011
|
||||
}
|
||||
@@ -91,7 +91,7 @@ const defaultStyles = {
|
||||
|
||||
const DEFAULT_INPUT_ARIA_LABEL = nls.localize('quickOpenAriaLabel', "Quick picker. Type to narrow down results.");
|
||||
|
||||
export class QuickOpenWidget implements IModelProvider {
|
||||
export class QuickOpenWidget extends Disposable implements IModelProvider {
|
||||
|
||||
private static readonly MAX_WIDTH = 600; // Max total width of quick open widget
|
||||
private static readonly MAX_ITEMS_HEIGHT = 20 * 22; // Max height of item list below input field
|
||||
@@ -108,7 +108,6 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
private visible: boolean;
|
||||
private isLoosingFocus: boolean;
|
||||
private callbacks: IQuickOpenCallbacks;
|
||||
private toUnbind: IDisposable[];
|
||||
private quickNavigateConfiguration: IQuickNavigateConfiguration;
|
||||
private container: HTMLElement;
|
||||
private treeElement: HTMLElement;
|
||||
@@ -120,8 +119,9 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
private renderer: Renderer;
|
||||
|
||||
constructor(container: HTMLElement, callbacks: IQuickOpenCallbacks, options: IQuickOpenOptions) {
|
||||
super();
|
||||
|
||||
this.isDisposed = false;
|
||||
this.toUnbind = [];
|
||||
this.container = container;
|
||||
this.callbacks = callbacks;
|
||||
this.options = options;
|
||||
@@ -130,19 +130,19 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
public getElement(): HTMLElement {
|
||||
getElement(): HTMLElement {
|
||||
return $(this.builder).getHTMLElement();
|
||||
}
|
||||
|
||||
public getModel(): IModel<any> {
|
||||
getModel(): IModel<any> {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public setCallbacks(callbacks: IQuickOpenCallbacks): void {
|
||||
setCallbacks(callbacks: IQuickOpenCallbacks): void {
|
||||
this.callbacks = callbacks;
|
||||
}
|
||||
|
||||
public create(): HTMLElement {
|
||||
create(): HTMLElement {
|
||||
this.builder = $().div(div => {
|
||||
|
||||
// Eventing
|
||||
@@ -159,13 +159,13 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
.on(DOM.EventType.BLUR, (e: FocusEvent) => this.loosingFocus(e), null, true);
|
||||
|
||||
// Progress Bar
|
||||
this.progressBar = new ProgressBar(div.clone(), { progressBarBackground: this.styles.progressBarBackground });
|
||||
this.progressBar = this._register(new ProgressBar(div.clone(), { progressBarBackground: this.styles.progressBarBackground }));
|
||||
this.progressBar.hide();
|
||||
|
||||
// Input Field
|
||||
div.div({ 'class': 'quick-open-input' }, inputContainer => {
|
||||
this.inputContainer = inputContainer;
|
||||
this.inputBox = new InputBox(inputContainer.getHTMLElement(), null, {
|
||||
this.inputBox = this._register(new InputBox(inputContainer.getHTMLElement(), null, {
|
||||
placeholder: this.options.inputPlaceHolder || '',
|
||||
ariaLabel: DEFAULT_INPUT_ARIA_LABEL,
|
||||
inputBackground: this.styles.inputBackground,
|
||||
@@ -177,7 +177,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
inputValidationWarningBorder: this.styles.inputValidationWarningBorder,
|
||||
inputValidationErrorBackground: this.styles.inputValidationErrorBackground,
|
||||
inputValidationErrorBorder: this.styles.inputValidationErrorBorder
|
||||
});
|
||||
}));
|
||||
|
||||
// ARIA
|
||||
this.inputElement = this.inputBox.inputElement;
|
||||
@@ -229,7 +229,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}, div => {
|
||||
const createTree = this.options.treeCreator || ((container, config, opts) => new Tree(container, config, opts));
|
||||
|
||||
this.tree = createTree(div.getHTMLElement(), {
|
||||
this.tree = this._register(createTree(div.getHTMLElement(), {
|
||||
dataSource: new DataSource(this),
|
||||
controller: new QuickOpenController({ clickBehavior: ClickBehavior.ON_MOUSE_UP, keyboardSupport: this.options.keyboardSupport }),
|
||||
renderer: (this.renderer = new Renderer(this, this.styles)),
|
||||
@@ -244,16 +244,16 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
ariaLabel: nls.localize('treeAriaLabel', "Quick Picker"),
|
||||
keyboardSupport: this.options.keyboardSupport,
|
||||
preventRootFocus: true
|
||||
});
|
||||
}));
|
||||
|
||||
this.treeElement = this.tree.getHTMLElement();
|
||||
|
||||
// Handle Focus and Selection event
|
||||
this.toUnbind.push(this.tree.onDidChangeFocus(event => {
|
||||
this._register(this.tree.onDidChangeFocus(event => {
|
||||
this.elementFocused(event.focus, event);
|
||||
}));
|
||||
|
||||
this.toUnbind.push(this.tree.onDidChangeSelection(event => {
|
||||
this._register(this.tree.onDidChangeSelection(event => {
|
||||
if (event.selection && event.selection.length > 0) {
|
||||
const mouseEvent: StandardMouseEvent = event.payload && event.payload.originalEvent instanceof StandardMouseEvent ? event.payload.originalEvent : void 0;
|
||||
const shouldOpenInBackground = mouseEvent ? this.shouldOpenInBackground(mouseEvent) : false;
|
||||
@@ -354,7 +354,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
return this.builder.getHTMLElement();
|
||||
}
|
||||
|
||||
public style(styles: IQuickOpenStyles): void {
|
||||
style(styles: IQuickOpenStyles): void {
|
||||
this.styles = styles;
|
||||
|
||||
this.applyStyles();
|
||||
@@ -442,7 +442,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
this.callbacks.onType(value);
|
||||
}
|
||||
|
||||
public navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void {
|
||||
navigate(next: boolean, quickNavigate?: IQuickNavigateConfiguration): void {
|
||||
if (this.isVisible()) {
|
||||
|
||||
// Transition into quick navigate mode if not yet done
|
||||
@@ -548,9 +548,9 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
};
|
||||
}
|
||||
|
||||
public show(prefix: string, options?: IShowOptions): void;
|
||||
public show(input: IModel<any>, options?: IShowOptions): void;
|
||||
public show(param: any, options?: IShowOptions): void {
|
||||
show(prefix: string, options?: IShowOptions): void;
|
||||
show(input: IModel<any>, options?: IShowOptions): void;
|
||||
show(param: any, options?: IShowOptions): void {
|
||||
this.visible = true;
|
||||
this.isLoosingFocus = false;
|
||||
this.quickNavigateConfiguration = options ? options.quickNavigateConfiguration : void 0;
|
||||
@@ -696,7 +696,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(input?: IModel<any>, autoFocus?: IAutoFocus): void {
|
||||
refresh(input?: IModel<any>, autoFocus?: IAutoFocus): void {
|
||||
if (!this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
@@ -760,7 +760,7 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
return height;
|
||||
}
|
||||
|
||||
public hide(reason?: HideReason): void {
|
||||
hide(reason?: HideReason): void {
|
||||
if (!this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
@@ -801,17 +801,17 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public getQuickNavigateConfiguration(): IQuickNavigateConfiguration {
|
||||
getQuickNavigateConfiguration(): IQuickNavigateConfiguration {
|
||||
return this.quickNavigateConfiguration;
|
||||
}
|
||||
|
||||
public setPlaceHolder(placeHolder: string): void {
|
||||
setPlaceHolder(placeHolder: string): void {
|
||||
if (this.inputBox) {
|
||||
this.inputBox.setPlaceHolder(placeHolder);
|
||||
}
|
||||
}
|
||||
|
||||
public setValue(value: string, selectionOrStableHint?: [number, number] | null): void {
|
||||
setValue(value: string, selectionOrStableHint?: [number, number] | null): void {
|
||||
if (this.inputBox) {
|
||||
this.inputBox.value = value;
|
||||
if (selectionOrStableHint === null) {
|
||||
@@ -825,13 +825,13 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public setPassword(isPassword: boolean): void {
|
||||
setPassword(isPassword: boolean): void {
|
||||
if (this.inputBox) {
|
||||
this.inputBox.inputElement.type = isPassword ? 'password' : 'text';
|
||||
}
|
||||
}
|
||||
|
||||
public setInput(input: IModel<any>, autoFocus: IAutoFocus, ariaLabel?: string): void {
|
||||
setInput(input: IModel<any>, autoFocus: IAutoFocus, ariaLabel?: string): void {
|
||||
if (!this.isVisible()) {
|
||||
return;
|
||||
}
|
||||
@@ -864,29 +864,29 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
public getInput(): IModel<any> {
|
||||
getInput(): IModel<any> {
|
||||
return this.tree.getInput();
|
||||
}
|
||||
|
||||
public showInputDecoration(decoration: Severity): void {
|
||||
showInputDecoration(decoration: Severity): void {
|
||||
if (this.inputBox) {
|
||||
this.inputBox.showMessage({ type: decoration === Severity.Info ? MessageType.INFO : decoration === Severity.Warning ? MessageType.WARNING : MessageType.ERROR, content: '' });
|
||||
}
|
||||
}
|
||||
|
||||
public clearInputDecoration(): void {
|
||||
clearInputDecoration(): void {
|
||||
if (this.inputBox) {
|
||||
this.inputBox.hideMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public focus(): void {
|
||||
focus(): void {
|
||||
if (this.isVisible() && this.inputBox) {
|
||||
this.inputBox.focus();
|
||||
}
|
||||
}
|
||||
|
||||
public accept(): void {
|
||||
accept(): void {
|
||||
if (this.isVisible()) {
|
||||
const focus = this.tree.getFocus();
|
||||
if (focus) {
|
||||
@@ -895,15 +895,15 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public getProgressBar(): ProgressBar {
|
||||
getProgressBar(): ProgressBar {
|
||||
return this.progressBar;
|
||||
}
|
||||
|
||||
public getInputBox(): InputBox {
|
||||
getInputBox(): InputBox {
|
||||
return this.inputBox;
|
||||
}
|
||||
|
||||
public setExtraClass(clazz: string): void {
|
||||
setExtraClass(clazz: string): void {
|
||||
const previousClass = this.builder.getProperty('extra-class');
|
||||
if (previousClass) {
|
||||
this.builder.removeClass(previousClass);
|
||||
@@ -917,11 +917,11 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public isVisible(): boolean {
|
||||
isVisible(): boolean {
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
public layout(dimension: DOM.Dimension): void {
|
||||
layout(dimension: DOM.Dimension): void {
|
||||
this.layoutDimensions = dimension;
|
||||
|
||||
// Apply to quick open width (height is dynamic by number of items to show)
|
||||
@@ -971,12 +971,9 @@ export class QuickOpenWidget implements IModelProvider {
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
this.isDisposed = true;
|
||||
this.toUnbind = dispose(this.toUnbind);
|
||||
dispose(): void {
|
||||
super.dispose();
|
||||
|
||||
this.progressBar.dispose();
|
||||
this.inputBox.dispose();
|
||||
this.tree.dispose();
|
||||
this.isDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user