Skip to content

Commit

Permalink
onDidSelectItem (#45589)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Mar 26, 2018
1 parent 1c0aa2e commit ecce88d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
46 changes: 23 additions & 23 deletions src/vs/workbench/api/electron-browser/mainThreadQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
11 changes: 10 additions & 1 deletion src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit ecce88d

Please sign in to comment.