Commit a1dbed62 authored by Ivan Mazhukin's avatar Ivan Mazhukin

simplify inferred app picker

parent 94c34315
...@@ -43,7 +43,7 @@ The same VSIX can be installed from the VS Code command `Extensions: Install fro ...@@ -43,7 +43,7 @@ The same VSIX can be installed from the VS Code command `Extensions: Install fro
- `Rerun last command`: repeats the last generated command. - `Rerun last command`: repeats the last generated command.
- `Open log folder`: opens `${XDG_STATE_HOME:-$HOME/.local/state}/epm-docker-test` or the configured log root. - `Open log folder`: opens `${XDG_STATE_HOME:-$HOME/.local/state}/epm-docker-test` or the configured log root.
When an app name is requested, it is inferred from the active editor if the file is in `play.d`, `pack.d`, or `repack.d`. The extension first checks simple shell variables such as `PRODUCT=rstudio` or `PKGNAME=rstudio`, then falls back to the file name without extension. If an app is inferred, the extension shows clickable `OK`, `Edit`, and `Cancel` choices; `Edit` opens the app input field. When an app name is requested, it is inferred from the active editor if the file is in `play.d`, `pack.d`, or `repack.d`. The extension first checks simple shell variables such as `PRODUCT=rstudio` or `PKGNAME=rstudio`, then falls back to the file name without extension. If an app is inferred, the extension shows clickable `OK` and `Cancel` choices; the app name can be edited in the picker input before pressing `OK`.
## Favorites ## Favorites
......
...@@ -261,32 +261,7 @@ async function promptForApp(options) { ...@@ -261,32 +261,7 @@ async function promptForApp(options) {
const initialValue = inferred?.app || fallback; const initialValue = inferred?.app || fallback;
if (inferred?.app) { if (inferred?.app) {
const choice = await vscode.window.showQuickPick([ return promptForInferredApp(options, inferred);
{
label: `$(check) OK: ${inferred.app}`,
description: inferred.source,
action: 'ok'
},
{
label: '$(edit) Изменить имя...',
description: 'Открыть поле ввода',
action: 'edit'
},
{
label: '$(close) Отмена',
action: 'cancel'
}
], {
title: options.title,
placeHolder: `${options.prompt} (inferred from ${inferred.source})`
});
if (!choice || choice.action === 'cancel') {
return undefined;
}
if (choice.action === 'ok') {
return inferred.app;
}
} }
return vscode.window.showInputBox({ return vscode.window.showInputBox({
...@@ -299,6 +274,55 @@ async function promptForApp(options) { ...@@ -299,6 +274,55 @@ async function promptForApp(options) {
}); });
} }
function promptForInferredApp(options, inferred) {
return new Promise((resolve) => {
const quickPick = vscode.window.createQuickPick();
const okItem = { label: '', description: inferred.source, action: 'ok' };
const cancelItem = { label: '$(close) Отмена', action: 'cancel' };
let settled = false;
const finish = (value) => {
if (settled) {
return;
}
settled = true;
resolve(value);
};
const updateOkItem = (value) => {
const app = value.trim() || inferred.app;
okItem.label = `$(check) OK: ${app}`;
quickPick.items = [okItem, cancelItem];
};
quickPick.title = options.title;
quickPick.placeholder = `${options.prompt} (inferred from ${inferred.source})`;
quickPick.value = inferred.app;
quickPick.matchOnDescription = true;
updateOkItem(quickPick.value);
quickPick.onDidChangeValue(updateOkItem);
quickPick.onDidAccept(() => {
const selected = quickPick.selectedItems[0];
if (selected?.action === 'cancel') {
quickPick.hide();
finish(undefined);
return;
}
const app = quickPick.value.trim() || inferred.app;
quickPick.hide();
finish(app);
});
quickPick.onDidHide(() => {
quickPick.dispose();
finish(undefined);
});
quickPick.show();
});
}
async function rerunLast() { async function rerunLast() {
const command = getWorkspaceState('lastCommand', lastRun); const command = getWorkspaceState('lastCommand', lastRun);
if (!command) { if (!command) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment