提交 7e55f101 编写于 作者: J Johannes Rieken

proposal for knowning when an item in pick quick pick was selected

上级 7731ac97
......@@ -1082,6 +1082,11 @@ declare namespace vscode {
* An optional string to show as place holder in the input box to guide the user what to pick on.
*/
placeHolder?: string;
/**
* An optional function that is invoked whenever an item is selected.
*/
onDidSelectItem?: <T extends QuickPickItem>(item: T | string) => any;
}
/**
......
......@@ -134,7 +134,7 @@ export class ExtHostAPIImplementation {
const pluginHostCommands = this._threadService.getRemotable(ExtHostCommands);
const pluginHostEditors = this._threadService.getRemotable(ExtHostEditors);
const pluginHostMessageService = new ExtHostMessageService(this._threadService, this.commands);
const pluginHostQuickOpen = new ExtHostQuickOpen(this._threadService);
const pluginHostQuickOpen = this._threadService.getRemotable(ExtHostQuickOpen);
const pluginHostStatusBar = new ExtHostStatusBar(this._threadService);
const extHostOutputService = new ExtHostOutputService(this._threadService);
......
......@@ -15,9 +15,11 @@ export interface MyQuickPickItems extends IPickOpenEntryItem {
export type Item = string | QuickPickItem;
@Remotable.PluginHostContext('ExtHostQuickOpen')
export class ExtHostQuickOpen {
private _proxy: MainThreadQuickOpen;
private _onDidSelectItem: (handle: number) => void;
constructor(@IThreadService threadService: IThreadService) {
this._proxy = threadService.getRemotable(MainThreadQuickOpen);
......@@ -25,6 +27,9 @@ export class ExtHostQuickOpen {
show(itemsOrItemsPromise: Item[] | Thenable<Item[]>, options?: QuickPickOptions): Thenable<Item> {
// clear state from last invocation
this._onDidSelectItem = undefined;
let itemsPromise: Thenable<Item[]>;
if (!Array.isArray(itemsOrItemsPromise)) {
itemsPromise = itemsOrItemsPromise;
......@@ -60,6 +65,14 @@ export class ExtHostQuickOpen {
});
}
// handle selection changes
if (options && typeof options.onDidSelectItem === 'function') {
this._onDidSelectItem = (handle) => {
options.onDidSelectItem(items[handle]);
}
}
// show items
this._proxy.$setItems(pickItems);
return quickPickWidget.then(handle => {
......@@ -74,6 +87,12 @@ export class ExtHostQuickOpen {
});
}
$onItemSelected(handle: number): void {
if (this._onDidSelectItem) {
this._onDidSelectItem(handle);
}
}
input(options?: InputBoxOptions): Thenable<string> {
return this._proxy.$input(options);
}
......@@ -82,13 +101,15 @@ export class ExtHostQuickOpen {
@Remotable.MainContext('MainThreadQuickOpen')
export class MainThreadQuickOpen {
private _proxy: ExtHostQuickOpen;
private _quickOpenService: IQuickOpenService;
private _doSetItems: (items: MyQuickPickItems[]) => any;
private _doSetError: (error: Error) => any;
private _contents: TPromise<MyQuickPickItems[]>;
private _token: number = 0;
constructor(@IQuickOpenService quickOpenService: IQuickOpenService) {
constructor( @IThreadService threadService: IThreadService, @IQuickOpenService quickOpenService: IQuickOpenService) {
this._proxy = threadService.getRemotable(ExtHostQuickOpen);
this._quickOpenService = quickOpenService;
}
......@@ -114,6 +135,10 @@ export class MainThreadQuickOpen {
if (item) {
return item.handle;
}
}, undefined, progress => {
if (progress) {
this._proxy.$onItemSelected((<MyQuickPickItems>progress).handle);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册