* @param {"dir"|"file"|"root"} type * @param {"copy"|"cut"|"delete"|"rename"|"paste"|"new file"|"new folder"|"cancel"|"open-folder"|"install-plugin"} action * @param {string} url target url * @param {HTMLElement} $target target element * @param {string} name Name of file or folder
(type, action, url, $target, name)
| 422 | * @param {string} name Name of file or folder |
| 423 | */ |
| 424 | function execOperation(type, action, url, $target, name) { |
| 425 | const { clipBoard, $node, remove, url: rootUrl } = openFolder.find(url); |
| 426 | const startLoading = () => $node.$title.classList.add("loading"); |
| 427 | const stopLoading = () => $node.$title.classList.remove("loading"); |
| 428 | |
| 429 | switch (action) { |
| 430 | case "copy": |
| 431 | case "cut": |
| 432 | return clipBoardAction(); |
| 433 | |
| 434 | case "delete": |
| 435 | return deleteFile(); |
| 436 | |
| 437 | case "rename": |
| 438 | return renameFile(); |
| 439 | |
| 440 | case "paste": |
| 441 | return paste(); |
| 442 | |
| 443 | case "new file": |
| 444 | case "new folder": |
| 445 | return createNew(); |
| 446 | |
| 447 | case "cancel": |
| 448 | return cancelAction(); |
| 449 | |
| 450 | case "open-folder": |
| 451 | return open(); |
| 452 | |
| 453 | case "insert-file": |
| 454 | return insertFile(); |
| 455 | |
| 456 | case "close": |
| 457 | return remove(); |
| 458 | |
| 459 | case "install-plugin": |
| 460 | return installPlugin(); |
| 461 | |
| 462 | case "open-in-terminal": |
| 463 | return openInTerminal(); |
| 464 | |
| 465 | case "copy-relative-path": |
| 466 | return copyRelativePath(); |
| 467 | } |
| 468 | |
| 469 | async function installPlugin() { |
| 470 | try { |
| 471 | const manifest = JSON.parse( |
| 472 | await fsOperation( |
| 473 | Url.dirname(url) + ACODE_PLUGIN_MANIFEST_FILE, |
| 474 | ).readFile("utf8"), |
| 475 | ); |
| 476 | const { default: installPlugin } = await import("lib/installPlugin"); |
| 477 | await installPlugin(url, manifest.name); |
| 478 | toast(strings["success"], 3000); |
| 479 | } catch (error) { |
| 480 | helpers.error(error); |
| 481 | console.error(error); |
no test coverage detected