提交 ecce88d7 编写于 作者: C Christof Marti

onDidSelectItem (#45589)

上级 1c0aa2e8
......@@ -1569,7 +1569,6 @@ declare module 'vscode' {
/**
* An optional function that is invoked whenever an item is selected.
* (Only honored when the picker does not allow multiple selections.)
*/
onDidSelectItem?(item: QuickPickItem | string): any;
}
......
......@@ -54,29 +54,29 @@ export class MainThreadQuickOpen implements MainThreadQuickOpenShape {
};
});
return asWinJsPromise<number | number[]>(token => {
if (options.canSelectMany) {
return this._quickInputService.pick(this._contents, options, token)
.then(items => {
if (items) {
return items.map(item => item.handle);
}
return undefined;
});
} else {
return this._quickOpenService.pick(this._contents, options, token)
.then(item => {
if (item) {
return item.handle;
}
return undefined;
});
}
}).then(undefined, undefined, progress => {
if (progress) {
this._proxy.$onItemSelected((<MyQuickPickItems>progress).handle);
}
});
if (options.canSelectMany) {
return asWinJsPromise(token => this._quickInputService.pick(this._contents, options, token)).then(items => {
if (items) {
return items.map(item => item.handle);
}
return undefined;
}, undefined, progress => {
if (progress) {
this._proxy.$onItemSelected((<MyQuickPickItems>progress).handle);
}
});
} else {
return asWinJsPromise(token => this._quickOpenService.pick(this._contents, options, token)).then(item => {
if (item) {
return item.handle;
}
return undefined;
}, undefined, progress => {
if (progress) {
this._proxy.$onItemSelected((<MyQuickPickItems>progress).handle);
}
});
}
}
$setItems(items: MyQuickPickItems[]): TPromise<any> {
......
......@@ -50,6 +50,7 @@ export class QuickInputService extends Component implements IQuickInputService {
private ignoreFocusLost = false;
private resolve: (value?: IPickOpenEntry[] | Thenable<IPickOpenEntry[]>) => void;
private progress: (value: IPickOpenEntry) => void;
constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
......@@ -126,6 +127,11 @@ export class QuickInputService extends Component implements IQuickInputService {
this.inputBox.setFocus();
}, 0);
}));
this.toUnbind.push(this.checkboxList.onFocusChange(e => {
if (this.progress && e.length) {
this.progress(e[0]);
}
}));
this.toUnbind.push(dom.addDisposableListener(this.container, 'focusout', (e: FocusEvent) => {
for (let element = <Element>e.relatedTarget; element; element = element.parentElement) {
......@@ -187,7 +193,10 @@ export class QuickInputService extends Component implements IQuickInputService {
this.updateLayout();
this.inputBox.setFocus();
const result = new TPromise<T[]>(resolve => this.resolve = resolve);
const result = new TPromise<T[]>((resolve, reject, progress) => {
this.resolve = resolve;
this.progress = progress;
});
const d = token.onCancellationRequested(() => this.close());
result.then(() => d.dispose(), () => d.dispose());
......
......@@ -15,7 +15,7 @@ import { IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IMatch } from 'vs/base/common/filters';
import { matchesFuzzyOcticonAware, parseOcticons } from 'vs/base/common/octicon';
import { compareAnything } from 'vs/base/common/comparers';
import { Emitter, Event } from 'vs/base/common/event';
import { Emitter, Event, mapEvent } from 'vs/base/common/event';
import { assign } from 'vs/base/common/objects';
import { KeyCode } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
......@@ -181,6 +181,10 @@ export class QuickInputCheckboxList {
}));
}
get onFocusChange() {
return mapEvent(this.list.onFocusChange, e => e.elements.map(e => e.item));
}
getAllVisibleSelected() {
return !this.elements.some(element => !element.hidden && !element.selected);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册