|
| 1 | +import * as vscode from "vscode"; |
| 2 | +import { AtelierAPI } from "../api"; |
| 3 | +import { FILESYSTEM_SCHEMA } from "../extension"; |
| 4 | +import { outputChannel } from "../utils"; |
| 5 | + |
| 6 | +interface StudioAction extends vscode.QuickPickItem { |
| 7 | + name: string; |
| 8 | + id: string; |
| 9 | +} |
| 10 | + |
| 11 | +function doMenuAction(uri: vscode.Uri, menuType: string): Promise<any> { |
| 12 | + uri = uri || vscode.window.activeTextEditor.document.uri; |
| 13 | + if (uri.scheme !== FILESYSTEM_SCHEMA) { |
| 14 | + return; |
| 15 | + } |
| 16 | + const query = "select * from %Atelier_v1_Utils.Extension_GetMenus(?,?,?)"; |
| 17 | + const name = uri.path.slice(1).replace(/\//g, "."); |
| 18 | + const api = new AtelierAPI(uri.authority); |
| 19 | + const parameters = [menuType, name, ""]; |
| 20 | + return api |
| 21 | + .actionQuery(query, parameters) |
| 22 | + .then(data => data.result.content) |
| 23 | + .then(menu => |
| 24 | + menu.reduce( |
| 25 | + (list, sub) => |
| 26 | + list.concat( |
| 27 | + sub.items |
| 28 | + .filter(el => el.id !== "" && el.separator == 0 && el.enabled == 1) |
| 29 | + .map(el => ({ ...el, id: `${sub.id},${el.id}`, label: el.name })) |
| 30 | + ), |
| 31 | + [] |
| 32 | + ) |
| 33 | + ) |
| 34 | + .then(menuItems => { |
| 35 | + return vscode.window.showQuickPick<StudioAction>(menuItems, { canPickMany: false }); |
| 36 | + }) |
| 37 | + .then(({ id, label }) => ({ |
| 38 | + id: id, |
| 39 | + label, |
| 40 | + name, |
| 41 | + })) |
| 42 | + .then(action => { |
| 43 | + if (action) { |
| 44 | + const query = "select * from %Atelier_v1_Utils.Extension_UserAction(?, ?, ?, ?)"; |
| 45 | + const parameters = ["0", action.id, name, ""]; |
| 46 | + return vscode.window.withProgress( |
| 47 | + { |
| 48 | + cancellable: false, |
| 49 | + location: vscode.ProgressLocation.Notification, |
| 50 | + title: `Executing user action: ${action.label}`, |
| 51 | + }, |
| 52 | + () => |
| 53 | + api |
| 54 | + .actionQuery(query, parameters) |
| 55 | + .then(data => data.result.content.pop()) |
| 56 | + .then(userAction => { |
| 57 | + if (userAction && userAction.action != "0") { |
| 58 | + outputChannel.appendLine(`Studio Action "${action.label}" not supported`); |
| 59 | + outputChannel.show(); |
| 60 | + } |
| 61 | + }) |
| 62 | + ); |
| 63 | + } |
| 64 | + }); |
| 65 | +} |
| 66 | + |
| 67 | +// export function contextMenu(uri: vscode.Uri): Promise<void> { |
| 68 | +// return doMenuAction(uri, "context"); |
| 69 | +// } |
| 70 | + |
| 71 | +export function mainMenu(uri: vscode.Uri) { |
| 72 | + return doMenuAction(uri, ""); |
| 73 | +} |
0 commit comments