mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
proposal for knowning when an item in pick quick pick was selected
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user