本文整理汇总了TypeScript中vscode.window.createQuickPick方法的典型用法代码示例。如果您正苦于以下问题:TypeScript window.createQuickPick方法的具体用法?TypeScript window.createQuickPick怎么用?TypeScript window.createQuickPick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.window
的用法示例。
在下文中一共展示了window.createQuickPick方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
context.subscriptions.push(commands.registerCommand('extension.rbTools', async () => {
const options: { [key: string]: (context: ExtensionContext) => Promise<void> } = {
createConcinsts,
createFacts,
createFactsFromTable
};
const quickPick = window.createQuickPick();
quickPick.items = Object.keys(options).map(label => ({ label }));
quickPick.onDidChangeSelection(async selection => {
if (selection[0]) {
try {
await options[selection[0].label](context);
quickPick.hide();
} catch (error) {
console.error(error);
}
}
});
quickPick.onDidHide(() => quickPick.dispose());
quickPick.show();
}));
示例2: createQuickPick
function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void) {
const quickPick = window.createQuickPick();
quickPick.onDidChangeActive(items => {
try {
assert.equal('active', expected.events.shift());
const expectedItems = expected.activeItems.shift();
assert.deepEqual(items.map(item => item.label), expectedItems);
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedItems);
} catch (err) {
done(err);
}
});
quickPick.onDidChangeSelection(items => {
try {
assert.equal('selection', expected.events.shift());
const expectedItems = expected.selectionItems.shift();
assert.deepEqual(items.map(item => item.label), expectedItems);
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedItems);
} catch (err) {
done(err);
}
});
quickPick.onDidAccept(() => {
try {
assert.equal('accept', expected.events.shift());
const expectedActive = expected.acceptedItems.active.shift();
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedActive);
const expectedSelection = expected.acceptedItems.selection.shift();
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedSelection);
quickPick.dispose();
} catch (err) {
done(err);
}
});
quickPick.onDidHide(() => {
try {
assert.equal('hide', expected.events.shift());
done();
} catch (err) {
done(err);
}
});
return quickPick;
}
示例3: async
context.subscriptions.push(commands.registerCommand('samples.quickInput', async () => {
const options: { [key: string]: (context: ExtensionContext) => Promise<void> } = {
showQuickPick,
showInputBox,
multiStepInput,
quickOpen,
};
const quickPick = window.createQuickPick();
quickPick.items = Object.keys(options).map(label => ({ label }));
quickPick.onDidChangeSelection(selection => {
if (selection[0]) {
options[selection[0].label](context)
.catch(console.error);
}
});
quickPick.onDidHide(() => quickPick.dispose());
quickPick.show();
}));
示例4: test
test('createQuickPick, hide and dispose', function (_done) {
let done = (err?: any) => {
done = () => {};
_done(err);
};
let hidden = false;
const quickPick = window.createQuickPick();
quickPick.onDidHide(() => {
if (hidden) {
done(new Error('Already hidden'));
} else {
hidden = true;
setTimeout(done, 0);
}
});
quickPick.show();
quickPick.hide();
quickPick.dispose();
});
示例5: RefreshButton
return new Promise<string>((resolve, reject) => {
let quickPick: vscode.QuickPick<AttachItem> = vscode.window.createQuickPick<AttachItem>();
quickPick.title = "Attach to process";
quickPick.canSelectMany = false;
quickPick.matchOnDescription = true;
quickPick.matchOnDetail = true;
quickPick.placeholder = "Select the process to attach to";
quickPick.items = processEntries;
quickPick.buttons = [new RefreshButton()];
let disposables: vscode.Disposable[] = [];
quickPick.onDidTriggerButton(button => {
getAttachItems().then(processEntries => quickPick.items = processEntries);
}, undefined, disposables);
quickPick.onDidAccept(() => {
if (quickPick.selectedItems.length !== 1) {
reject(new Error("Process not selected"));
}
let selectedId: string = quickPick.selectedItems[0].id;
disposables.forEach(item => item.dispose());
quickPick.dispose();
resolve(selectedId);
}, undefined, disposables);
quickPick.onDidHide(() => {
disposables.forEach(item => item.dispose());
quickPick.dispose();
reject(new Error("Process not selected."));
}, undefined, disposables);
quickPick.show();
});
示例6: createQuickPick
function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void, record = false) {
const quickPick = window.createQuickPick();
let eventIndex = -1;
quickPick.onDidChangeActive(items => {
if (record) {
console.log(`active: [${items.map(item => item.label).join(', ')}]`);
return;
}
try {
eventIndex++;
assert.equal('active', expected.events.shift(), `onDidChangeActive (event ${eventIndex})`);
const expectedItems = expected.activeItems.shift();
assert.deepEqual(items.map(item => item.label), expectedItems, `onDidChangeActive event items (event ${eventIndex})`);
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedItems, `onDidChangeActive active items (event ${eventIndex})`);
} catch (err) {
done(err);
}
});
quickPick.onDidChangeSelection(items => {
if (record) {
console.log(`selection: [${items.map(item => item.label).join(', ')}]`);
return;
}
try {
eventIndex++;
assert.equal('selection', expected.events.shift(), `onDidChangeSelection (event ${eventIndex})`);
const expectedItems = expected.selectionItems.shift();
assert.deepEqual(items.map(item => item.label), expectedItems, `onDidChangeSelection event items (event ${eventIndex})`);
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedItems, `onDidChangeSelection selected items (event ${eventIndex})`);
} catch (err) {
done(err);
}
});
quickPick.onDidAccept(() => {
if (record) {
console.log('accept');
return;
}
try {
eventIndex++;
assert.equal('accept', expected.events.shift(), `onDidAccept (event ${eventIndex})`);
const expectedActive = expected.acceptedItems.active.shift();
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedActive, `onDidAccept active items (event ${eventIndex})`);
const expectedSelection = expected.acceptedItems.selection.shift();
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedSelection, `onDidAccept selected items (event ${eventIndex})`);
if (expected.acceptedItems.dispose.shift()) {
quickPick.dispose();
}
} catch (err) {
done(err);
}
});
quickPick.onDidHide(() => {
if (record) {
console.log('hide');
done();
return;
}
try {
assert.equal('hide', expected.events.shift());
done();
} catch (err) {
done(err);
}
});
return quickPick;
}
示例7: show
async show(
placeHolder: string,
options: ReferencesQuickPickOptions = {}
): Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined> {
const cancellation = new CancellationTokenSource();
let scope;
if (options.goBack) {
scope = await Container.keyboard.beginScope({ left: options.goBack });
}
let autoPick;
try {
let items = this.getItems(options, cancellation.token);
if (options.autoPick) {
items = items.then(itms => {
if (itms.length <= 1) {
autoPick = itms[0];
cancellation.cancel();
}
return itms;
});
}
let pick;
if (options.allowEnteringRefs) {
placeHolder += `${GlyphChars.Space.repeat(3)}(select or enter a reference)`;
const quickpick = window.createQuickPick<ReferencesQuickPickItem | CommandQuickPickItem>();
quickpick.busy = true;
quickpick.enabled = false;
quickpick.placeholder = placeHolder;
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut();
quickpick.show();
quickpick.items = await items;
quickpick.busy = false;
quickpick.enabled = true;
pick = await new Promise<ReferencesQuickPickItem | CommandQuickPickItem | undefined>(resolve => {
cancellation.token.onCancellationRequested(() => quickpick.hide());
quickpick.onDidHide(() => resolve(undefined));
quickpick.onDidAccept(async () => {
if (quickpick.selectedItems.length === 0) {
quickpick.busy = true;
quickpick.enabled = false;
const ref = quickpick.value;
if (
this.repoPath === undefined ||
(await Container.git.validateReference(this.repoPath, ref))
) {
resolve(new RefQuickPickItem(ref));
}
else {
quickpick.title = 'You must enter a valid reference';
quickpick.busy = false;
quickpick.enabled = true;
return;
}
}
else {
resolve(quickpick.selectedItems[0]);
}
quickpick.hide();
});
});
quickpick.dispose();
}
else {
pick = await window.showQuickPick(
items,
{
placeHolder: placeHolder,
ignoreFocusOut: getQuickPickIgnoreFocusOut()
},
cancellation.token
);
}
if (pick === undefined && autoPick !== undefined) {
pick = autoPick;
}
if (pick === undefined) {
cancellation.cancel();
}
return pick;
}
finally {
if (scope !== undefined) {
await scope.dispose();
}
cancellation.dispose();
}
//.........这里部分代码省略.........
示例8: activate
export function activate(context: vscode.ExtensionContext) {
let qp = vscode.window.createQuickPick()
let qpVisible = false
let showHidden = false
qp.onDidChangeValue(handleDidChangeValue(qp))
qp.onDidAccept(handleDidAccept(qp))
qp.onDidHide(() => { qpVisible = false })
let disposable = vscode.commands.registerCommand('quick-browser.show', () => {
const { window, workspace } = vscode
const { workspaceFolders } = workspace
let editor = window.activeTextEditor
let dir = home
let initialSelection = []
if (editor && editor.document.uri.scheme === "file") {
const { fsPath } = editor.document.uri
dir = path.dirname(fsPath)
initialSelection.push({ label: editor.document.fileName })
}
else if (workspaceFolders && workspaceFolders.length > 0) {
dir = workspaceFolders[0].uri.fsPath
}
qp.selectedItems = initialSelection
updateQuickPick(qp, dir).then(() => {
qpVisible = true
})
});
let back = vscode.commands.registerCommand('quick-browser.back', () => {
try {
if (qpVisible) {
const parent = path.normalize(qp.placeholder + '/..')
updateQuickPick(qp, parent)
}
} catch (e) {
vscode.window.showErrorMessage(e.message)
}
})
let forward = vscode.commands.registerCommand('quick-browser.forward', () => {
try {
if (qpVisible) {
const selectedLabel = qp.activeItems[0].label
const newPath = path.normalize(qp.placeholder + '/' + selectedLabel)
isDirectory(newPath).then(isDir => {
if (isDir) {
updateQuickPick(qp, newPath, showHidden)
}
else {
const openPath = vscode.Uri.file(newPath)
qp.hide()
vscode.workspace.openTextDocument(openPath).then(doc => {
return vscode.window.showTextDocument(doc)
})
}
}).catch(err => {
vscode.window.showErrorMessage(err)
})
}
} catch (e) {
vscode.window.showErrorMessage(e.message)
}
})
let toggleHidden = vscode.commands.registerCommand('quick-browser.toggleHidden', () => {
try {
if (qpVisible) {
showHidden = !showHidden
updateQuickPick(qp, qp.placeholder || home, showHidden)
}
} catch (e) {
vscode.window.showErrorMessage(e.message)
}
})
context.subscriptions.push(disposable);
context.subscriptions.push(back);
context.subscriptions.push(forward);
context.subscriptions.push(toggleHidden);
}