* Handle contextmenu * @param {"file"|"dir"|"root"} type * @param {string} url * @param {string} name * @param {HTMLElement} $target
(type, url, name, $target)
| 324 | * @param {HTMLElement} $target |
| 325 | */ |
| 326 | async function handleContextmenu(type, url, name, $target) { |
| 327 | if (appSettings.value.vibrateOnTap) { |
| 328 | navigator.vibrate(config.VIBRATION_TIME); |
| 329 | } |
| 330 | const { clipBoard, $node } = openFolder.find(url); |
| 331 | const cancel = `${strings.cancel}${clipBoard ? ` (${strings[clipBoard.action]})` : ""}`; |
| 332 | const COPY = ["copy", strings.copy, "copy"]; |
| 333 | const CUT = ["cut", strings.cut, "cut"]; |
| 334 | const COPY_RELATIVE_PATH = [ |
| 335 | "copy-relative-path", |
| 336 | strings["copy relative path"], |
| 337 | "attach_file", |
| 338 | ]; |
| 339 | const REMOVE = ["delete", strings.delete, "delete"]; |
| 340 | const RENAME = ["rename", strings.rename, "edit"]; |
| 341 | const PASTE = ["paste", strings.paste, "paste", !!clipBoard]; |
| 342 | const NEW_FILE = ["new file", strings["new file"], "document-add"]; |
| 343 | const NEW_FOLDER = ["new folder", strings["new folder"], "folder-add"]; |
| 344 | const CANCEL = ["cancel", cancel, "clearclose"]; |
| 345 | const OPEN_FOLDER = ["open-folder", strings["open folder"], "folder"]; |
| 346 | const INSERT_FILE = ["insert-file", strings["insert file"], "file_copy"]; |
| 347 | const CLOSE_FOLDER = ["close", strings["close"], "folder-remove"]; |
| 348 | const INSTALL_PLUGIN = [ |
| 349 | "install-plugin", |
| 350 | strings["install as plugin"] || "Install as Plugin", |
| 351 | "extension", |
| 352 | ]; |
| 353 | |
| 354 | let options; |
| 355 | |
| 356 | if (helpers.isFile(type)) { |
| 357 | options = [COPY, CUT, COPY_RELATIVE_PATH, RENAME, REMOVE]; |
| 358 | if ( |
| 359 | url.toLowerCase().endsWith(".zip") && |
| 360 | (await fsOperation( |
| 361 | Url.dirname(url) + ACODE_PLUGIN_MANIFEST_FILE, |
| 362 | ).exists()) |
| 363 | ) { |
| 364 | options.push(INSTALL_PLUGIN); |
| 365 | } |
| 366 | } else if (helpers.isDir(type)) { |
| 367 | options = [COPY, CUT, COPY_RELATIVE_PATH, REMOVE, RENAME]; |
| 368 | |
| 369 | if (clipBoard.url != null) { |
| 370 | options.push(PASTE); |
| 371 | } |
| 372 | |
| 373 | options.push(NEW_FILE, NEW_FOLDER, OPEN_FOLDER, INSERT_FILE); |
| 374 | |
| 375 | if (isTerminalAccessiblePath(url)) { |
| 376 | const OPEN_IN_TERMINAL = [ |
| 377 | "open-in-terminal", |
| 378 | strings["open in terminal"] || "Open in Terminal", |
| 379 | "terminal", |
| 380 | ]; |
| 381 | options.push(OPEN_IN_TERMINAL); |
| 382 | } |
| 383 | } else if (type === "root") { |
no test coverage detected