actions.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. /*
  2. actions.js
  3. Everything the user can do to an item, and the menus that offer it:
  4. open / open with, download, move and copy, rename, trash (with undo),
  5. restore, star, compress, extract, clipboard and new items.
  6. */
  7. (function (global) {
  8. "use strict";
  9. var I = DriveUI.I;
  10. var esc = DriveUI.esc;
  11. var API = DriveAPI;
  12. function S() {
  13. return Drive.state;
  14. }
  15. function view() {
  16. return S().view || {};
  17. }
  18. function plural(n, one, many, key) {
  19. return T(n == 1 ? key + "1" : key, n == 1 ? one : many, { n: n });
  20. }
  21. function copyText(text) {
  22. if (navigator.clipboard && window.isSecureContext) {
  23. return navigator.clipboard.writeText(text);
  24. }
  25. return new Promise(function (resolve, reject) {
  26. var ta = document.createElement("textarea");
  27. ta.value = text;
  28. ta.style.position = "fixed";
  29. ta.style.opacity = "0";
  30. document.body.appendChild(ta);
  31. ta.select();
  32. try {
  33. document.execCommand("copy") ? resolve() : reject(new Error("copy failed"));
  34. } catch (e) {
  35. reject(e);
  36. }
  37. ta.remove();
  38. });
  39. }
  40. /* ------------------------------------------------------------------ */
  41. /* Openers */
  42. /* ------------------------------------------------------------------ */
  43. function extOf(item) {
  44. return DriveIcons.getExt(item.name);
  45. }
  46. function launchURL(mod) {
  47. if (mod.SupportEmb && mod.LaunchEmb) {
  48. return mod.LaunchEmb;
  49. }
  50. if (mod.SupportFW && mod.LaunchFWDir) {
  51. return mod.LaunchFWDir;
  52. }
  53. return mod.StartDir;
  54. }
  55. function fileHash(items) {
  56. return "#" + encodeURIComponent(JSON.stringify(items.map(function (i) {
  57. return { filename: i.name, filepath: i.path };
  58. })));
  59. }
  60. //Modules the user may open that registered this extension
  61. function compatibleModules(item) {
  62. var ext = "." + extOf(item);
  63. if (ext == ".") {
  64. return [];
  65. }
  66. return S().modules.filter(function (m) {
  67. if (!m.SupportedExt || m.Group == "Interface Module") {
  68. return false;
  69. }
  70. if (!launchURL(m)) {
  71. return false;
  72. }
  73. return m.SupportedExt.some(function (e) { return String(e).toLowerCase() == ext; });
  74. }).sort(function (a, b) { return a.Name.localeCompare(b.Name); });
  75. }
  76. function defaultModuleFor(item) {
  77. var ext = "." + extOf(item);
  78. return API.defaultOpener(ext).then(function (info) {
  79. if (info && info.Name && Drive.module(info.Name)) {
  80. return Drive.module(info.Name);
  81. }
  82. var list = compatibleModules(item);
  83. return list.length == 1 ? list[0] : null;
  84. });
  85. }
  86. /*
  87. Every app launch for a file comes through here, so the "Open files"
  88. setting applies to the default app, Open with and the chooser alike.
  89. When the browser blocks the new tab, the app opens inside Drive.
  90. */
  91. function openWithModule(item, mod) {
  92. API.recentAdd(item.path);
  93. if (S().settings.openIn == "tab") {
  94. if (window.open(API.ROOT + launchURL(mod) + fileHash([item]), "_blank")) {
  95. return;
  96. }
  97. DriveUI.toast(T("open/tabBlocked", "The browser blocked the new tab, so the app opens here"), { type: "error" });
  98. }
  99. DriveHost.open({
  100. url: launchURL(mod) + fileHash([item]),
  101. title: mod.Name,
  102. icon: mod.IconPath,
  103. appName: mod.Name
  104. });
  105. }
  106. function openShortcut(item) {
  107. API.readText(item.path).then(function (text) {
  108. var lines = String(text).replace(/\r\n/g, "\n").trim().split("\n");
  109. var type = lines[0], name = lines[1], target = lines[2], icon = lines[3];
  110. if (type == "folder") {
  111. location.hash = Drive.folderRoute(target);
  112. } else if (type == "module" && target == "Trash Bin") {
  113. //A shortcut of the old Trash Bin app
  114. location.hash = "#/trash";
  115. } else if (type == "module") {
  116. var m = Drive.module(target);
  117. if (m) {
  118. DriveHost.openModule(m.Name);
  119. } else {
  120. DriveUI.toast(T("err/noModule", "You do not have access to {name}", { name: target }), { type: "error" });
  121. }
  122. } else if (type == "url") {
  123. DriveHost.open({ url: target, title: name, icon: icon });
  124. } else if (type == "app") {
  125. window.open(API.ROOT + "app/" + encodeURIComponent(target) + "/");
  126. } else {
  127. DrivePreview.open(item);
  128. }
  129. }).catch(DriveUI.error);
  130. }
  131. function open(item) {
  132. if (!item) {
  133. return;
  134. }
  135. var v = view();
  136. if (item.trashed) {
  137. if (!item.isDir) {
  138. DrivePreview.open(item);
  139. }
  140. return;
  141. }
  142. if (item.shareOnly) {
  143. DriveHost.open({ url: "/share/" + item.share.UUID, title: item.name, icon: "img/system/favicon.png" });
  144. return;
  145. }
  146. if (item.isDir) {
  147. location.hash = Drive.folderRoute(item.path);
  148. return;
  149. }
  150. if (extOf(item) == "shortcut") {
  151. openShortcut(item);
  152. return;
  153. }
  154. //Drive's own viewers come first for the files they handle, so a user
  155. //without the Photo / Video / ... apps can still open them
  156. if (S().settings.viewer !== false && DriveViewer.canOpen(item)) {
  157. API.recentAdd(item.path);
  158. DriveViewer.open(item);
  159. if (v.kind == "recent") {
  160. item.activity = Math.floor(Date.now() / 1000);
  161. item.openedLast = true;
  162. }
  163. return;
  164. }
  165. defaultModuleFor(item).then(function (mod) {
  166. if (mod) {
  167. openWithModule(item, mod);
  168. } else if (DrivePreview.canPreview(item)) {
  169. API.recentAdd(item.path);
  170. DrivePreview.open(item);
  171. } else {
  172. openWithChooser(item);
  173. }
  174. });
  175. if (v.kind == "recent") {
  176. //Bump the item in the open history without a full reload
  177. item.activity = Math.floor(Date.now() / 1000);
  178. item.openedLast = true;
  179. }
  180. }
  181. function openInNewTab(item) {
  182. if (item.isDir) {
  183. window.open(location.pathname + Drive.folderRoute(item.path), "_blank");
  184. return;
  185. }
  186. if (item.shareOnly) {
  187. window.open("/share/" + item.share.UUID, "_blank");
  188. return;
  189. }
  190. API.recentAdd(item.path);
  191. defaultModuleFor(item).then(function (mod) {
  192. if (mod) {
  193. window.open(API.ROOT + launchURL(mod) + fileHash([item]), "_blank");
  194. } else {
  195. window.open(API.mediaURL(item.path), "_blank");
  196. }
  197. });
  198. }
  199. function openWithItems(item) {
  200. var mods = compatibleModules(item);
  201. var list = mods.map(function (m) {
  202. return { img: API.ROOT + m.IconPath, label: m.Name, action: function () { openWithModule(item, m); } };
  203. });
  204. if (DrivePreview.canPreview(item)) {
  205. list.unshift({ icon: "eye", label: T("open/viewer", "Drive viewer"), action: function () { DrivePreview.open(item); } });
  206. }
  207. list.push("-", { icon: "apps", label: T("open/choose", "Choose another app..."), action: function () { openWithChooser(item); } });
  208. return list;
  209. }
  210. function openWithChooser(item) {
  211. var ext = extOf(item);
  212. var mods = compatibleModules(item);
  213. var all = S().modules.filter(function (m) {
  214. return launchURL(m) && m.Group != "Interface Module" && mods.indexOf(m) < 0 && m.SupportedExt && m.SupportedExt.length;
  215. }).sort(function (a, b) { return a.Name.localeCompare(b.Name); });
  216. var body = DriveUI.el('<div></div>');
  217. function row(m, idx) {
  218. return '<button class="picker-item" data-mod="' + esc(m.Name) + '"><img src="' + esc(API.ROOT + m.IconPath) + '" alt="" style="width:26px;height:26px;object-fit:contain">' +
  219. '<span>' + esc(m.Name) + '<small class="muted" style="display:block;font-size:12px">' + esc(m.Desc || m.Group || "") + '</small></span></button>';
  220. }
  221. var html = "";
  222. if (mods.length) {
  223. html += '<div class="field-label" style="margin-bottom:6px">' + esc(T("open/suggested", "Suggested apps")) + '</div><div class="list-plain" style="margin-bottom:14px">' + mods.map(row).join("") + '</div>';
  224. } else {
  225. html += '<p>' + esc(T("open/noApp", "No installed app registered .{ext} files. You can still preview, download, or try another app.", { ext: ext })) + '</p>';
  226. }
  227. if (all.length) {
  228. html += '<details><summary class="field-label" style="cursor:pointer;margin-bottom:6px">' + esc(T("open/otherApps", "Other apps")) + '</summary><div class="list-plain scroll-y" style="max-height:220px">' + all.map(row).join("") + '</div></details>';
  229. }
  230. if (ext) {
  231. html += '<label class="toggle-row" style="margin:16px 0 0"><span>' + esc(T("open/always", "Always open .{ext} files with the selected app", { ext: ext })) +
  232. '</span><span class="switch"><input type="checkbox" id="openAlways"><span></span></span></label>';
  233. }
  234. body.innerHTML = html;
  235. var ctx = DriveUI.modal({
  236. title: T("open/withTitle", "Open \"{name}\" with", { name: item.name }),
  237. iconHTML: DriveIcons.file(item.name, false),
  238. body: body,
  239. footLeft: DrivePreview.canPreview(item) ? '<button class="btn ghost small" id="owPreview">' + I("eye") + esc(T("open/viewer", "Drive viewer")) + '</button>' : "",
  240. buttons: [
  241. { label: T("toolbar/download", "Download"), action: function () { download([item]); } },
  242. { label: T("common/cancel", "Cancel") }
  243. ]
  244. });
  245. body.querySelectorAll("[data-mod]").forEach(function (b) {
  246. b.addEventListener("click", function () {
  247. var m = Drive.module(b.getAttribute("data-mod"));
  248. var always = body.querySelector("#openAlways");
  249. if (always && always.checked && ext) {
  250. API.setDefaultOpener("." + ext, m.Name).catch(DriveUI.error);
  251. }
  252. ctx.close();
  253. openWithModule(item, m);
  254. });
  255. });
  256. var pv = ctx.node.querySelector("#owPreview");
  257. if (pv) {
  258. pv.addEventListener("click", function () {
  259. ctx.close();
  260. DrivePreview.open(item);
  261. });
  262. }
  263. }
  264. /* ------------------------------------------------------------------ */
  265. /* Download and links */
  266. /* ------------------------------------------------------------------ */
  267. function download(items) {
  268. items = (items || []).filter(function (i) { return i && !i.shareOnly; });
  269. if (!items.length) {
  270. return;
  271. }
  272. if (items.length == 1 && !items[0].isDir) {
  273. DriveTransfers.saveURL(API.downloadURL(items[0].path), items[0].name);
  274. return;
  275. }
  276. if (!API.caps.fm) {
  277. var files = items.filter(function (i) { return !i.isDir; });
  278. if (files.length < items.length) {
  279. DriveUI.toast(T("err/zipNeedFM", "Folders can only be downloaded as a zip with the File Manager permission"), { type: "error" });
  280. }
  281. files.forEach(function (f, idx) {
  282. setTimeout(function () { DriveTransfers.saveURL(API.downloadURL(f.path), f.name); }, idx * 400);
  283. });
  284. return;
  285. }
  286. DriveTransfers.zipDownload(items);
  287. }
  288. function activeShare(info) {
  289. var list = (info && info.Shares) || [];
  290. for (var i = 0; i < list.length; i++) {
  291. if (!list[i].IsExpired) {
  292. return list[i];
  293. }
  294. }
  295. return null;
  296. }
  297. function copyLink(item) {
  298. if (item.share && item.share.UUID) {
  299. copyText(API.shareURL(item.share.UUID)).then(function () {
  300. DriveUI.toast(T("share/copied", "Link copied"), { type: "success" });
  301. }).catch(DriveUI.error);
  302. return;
  303. }
  304. API.shareInfo(item.path).then(function (info) {
  305. var share = activeShare(info);
  306. if (share) {
  307. return share;
  308. }
  309. if (info && info.CanManage === false) {
  310. throw new Error(T("share/notOwnerShort", "This item is shared by someone else"));
  311. }
  312. return API.shareCreate(item.path, { permission: "anyone" });
  313. }).then(function (share) {
  314. var url = API.shareURL(share.UUID || share.uuid);
  315. return copyText(url).then(function () {
  316. DriveUI.toast(T("share/linkCopied", "Link copied. Anyone with the link can view."), {
  317. type: "success",
  318. action: { label: T("share/manage", "Manage"), fn: function () { DriveShare.open(item); } }
  319. });
  320. if (!item.shared) {
  321. item.shared = true;
  322. DriveList.render();
  323. }
  324. });
  325. }).catch(DriveUI.error);
  326. }
  327. function copyPath(item) {
  328. copyText(item.path).then(function () {
  329. DriveUI.toast(T("misc/pathCopied", "Path copied"), { type: "success" });
  330. }).catch(DriveUI.error);
  331. }
  332. /* ------------------------------------------------------------------ */
  333. /* Move and copy */
  334. /* ------------------------------------------------------------------ */
  335. function askConflict(dupes, total) {
  336. return new Promise(function (resolve) {
  337. var answered = false;
  338. var names = dupes.slice(0, 8).map(function (p) {
  339. return '<div>' + DriveIcons.file(API.baseName(p), false) + '<span>' + esc(API.baseName(p)) + '</span></div>';
  340. }).join("") + (dupes.length > 8 ? '<div class="muted">+ ' + (dupes.length - 8) + '</div>' : "");
  341. DriveUI.modal({
  342. title: T("conflict/title", "Some items already exist"),
  343. icon: "alert",
  344. body: '<p>' + esc(T("conflict/text", "{n} of {total} items have the same name as items in the destination.", { n: dupes.length, total: total })) + '</p><div class="name-list">' + names + '</div>',
  345. buttons: [
  346. { label: T("conflict/skip", "Skip"), action: function () { answered = true; resolve("skip"); } },
  347. { label: T("conflict/replace", "Replace"), action: function () { answered = true; resolve("overwrite"); } },
  348. { label: T("conflict/keep", "Keep both"), cls: "primary", action: function () { answered = true; resolve("keep"); } }
  349. ],
  350. onClose: function () {
  351. if (!answered) {
  352. resolve(null);
  353. }
  354. }
  355. });
  356. });
  357. }
  358. function transfer(items, dest, mode) {
  359. dest = Drive.normDir(dest);
  360. items = items.filter(Boolean);
  361. if (mode == "move") {
  362. items = items.filter(function (i) {
  363. return Drive.normDir(API.parentOf(i.path)) != dest;
  364. });
  365. }
  366. if (!items.length) {
  367. return Promise.resolve();
  368. }
  369. for (var i = 0; i < items.length; i++) {
  370. if (items[i].isDir && dest.indexOf(Drive.normDir(items[i].path)) == 0) {
  371. DriveUI.toast(T("err/intoItself", "A folder cannot be moved into itself"), { type: "error" });
  372. return Promise.resolve();
  373. }
  374. }
  375. if (!Drive.isWritable(dest)) {
  376. DriveUI.toast(T("err/readonly", "This location is read only"), { type: "error" });
  377. return Promise.resolve();
  378. }
  379. var paths = items.map(function (i) { return i.path; });
  380. return API.duplicates(paths, dest).catch(function () { return []; }).then(function (dupes) {
  381. if (dupes && dupes.length) {
  382. return askConflict(dupes, items.length);
  383. }
  384. return "keep";
  385. }).then(function (resp) {
  386. if (!resp) {
  387. return;
  388. }
  389. var label = Drive.pathParts(dest);
  390. label = label[label.length - 1].label;
  391. return DriveTransfers.operation(mode, items, dest, resp, {
  392. doneText: mode == "move" ? T("xfer/movedTo", "Moved to {name}", { name: label }) : T("xfer/copiedTo", "Copied to {name}", { name: label })
  393. }).then(function () {
  394. if (mode == "move") {
  395. //Keep stars on the items that moved
  396. var moved = paths.filter(function (p) { return S().starred.has(p); });
  397. if (moved.length) {
  398. var renamed = moved.map(function (p) { return API.joinPath(dest, API.baseName(p)); });
  399. API.star(moved, false).then(function () { return API.star(renamed, true); }).then(function (list) {
  400. S().starred = new Set(list || []);
  401. }).catch(function () { });
  402. }
  403. }
  404. DriveUI.toast(mode == "move" ? plural(items.length, "Moved 1 item to {name}", "Moved {n} items to {name}", "toast/moved").replace("{name}", label) :
  405. plural(items.length, "Copied 1 item to {name}", "Copied {n} items to {name}", "toast/copied").replace("{name}", label), {
  406. type: "success",
  407. action: Drive.normDir(view().path || "") != dest ? { label: T("toast/show", "Show"), fn: function () { location.hash = Drive.folderRoute(dest); } } : null
  408. });
  409. }).catch(function (err) {
  410. DriveUI.error(err);
  411. });
  412. });
  413. }
  414. function startFolder() {
  415. var v = view();
  416. if (v.kind == "drive") {
  417. return v.path;
  418. }
  419. return null;
  420. }
  421. function moveTo(items) {
  422. items = items || Drive.selectedItems();
  423. if (!items.length) {
  424. return;
  425. }
  426. DriveUI.pickFolder({
  427. title: items.length == 1 ? T("move/titleOne", "Move \"{name}\"", { name: items[0].name }) : T("move/title", "Move {n} items", { n: items.length }),
  428. okLabel: T("move/here", "Move here"), icon: "move", start: startFolder(),
  429. sources: items.filter(function (i) { return i.isDir; }).map(function (i) { return i.path; })
  430. }).then(function (dest) {
  431. if (dest) {
  432. transfer(items, dest, "move");
  433. }
  434. });
  435. }
  436. function copyTo(items) {
  437. items = items || Drive.selectedItems();
  438. if (!items.length) {
  439. return;
  440. }
  441. DriveUI.pickFolder({
  442. title: items.length == 1 ? T("copy/titleOne", "Copy \"{name}\"", { name: items[0].name }) : T("copy/title", "Copy {n} items", { n: items.length }),
  443. okLabel: T("copy/here", "Copy here"), icon: "copy", start: startFolder(),
  444. sources: items.filter(function (i) { return i.isDir; }).map(function (i) { return i.path; })
  445. }).then(function (dest) {
  446. if (dest) {
  447. transfer(items, dest, "copy");
  448. }
  449. });
  450. }
  451. function duplicate(items) {
  452. items = items.filter(function (i) { return !i.isDir; });
  453. if (!items.length) {
  454. DriveUI.toast(T("err/copyFolder", "Use Copy to... for folders"), { type: "error" });
  455. return;
  456. }
  457. var parent = API.parentOf(items[0].path);
  458. DriveTransfers.operation("copy", items, parent, "keep", { doneText: T("xfer/copyMade", "Copy created") }).then(function () {
  459. DriveUI.toast(plural(items.length, "Made a copy", "Made {n} copies", "toast/duplicated"), { type: "success" });
  460. }).catch(DriveUI.error);
  461. }
  462. /* Clipboard -------------------------------------------------------------- */
  463. function clipboard(mode, items) {
  464. S().clipboard = { mode: mode, paths: items.map(function (i) { return i.path; }), items: items.slice() };
  465. DriveList.render();
  466. DriveUI.toast(mode == "cut" ? plural(items.length, "1 item cut. Paste it in another folder.", "{n} items cut. Paste them in another folder.", "toast/cut") :
  467. plural(items.length, "1 item copied to the clipboard", "{n} items copied to the clipboard", "toast/clip"));
  468. }
  469. function paste(target) {
  470. var clip = S().clipboard;
  471. var v = view();
  472. target = target || (v.kind == "drive" ? v.path : null);
  473. if (!clip || !target) {
  474. return;
  475. }
  476. var mode = clip.mode == "cut" ? "move" : "copy";
  477. if (mode == "move") {
  478. S().clipboard = null;
  479. }
  480. transfer(clip.items, target, mode);
  481. }
  482. /* ------------------------------------------------------------------ */
  483. /* Rename, trash, delete, restore */
  484. /* ------------------------------------------------------------------ */
  485. function commitRename(item, newName) {
  486. if (/[\/\\]/.test(newName)) {
  487. DriveUI.toast(T("err/badName", "Names cannot contain / or \\"), { type: "error" });
  488. DriveList.render();
  489. return;
  490. }
  491. var oldPath = item.path;
  492. API.rename(oldPath, newName).then(function () {
  493. var newPath = API.joinPath(API.parentOf(oldPath), newName);
  494. if (S().starred.has(oldPath)) {
  495. API.star([oldPath], false).then(function () { return API.star([newPath], true); }).then(function (list) {
  496. S().starred = new Set(list || []);
  497. }).catch(function () { });
  498. }
  499. if (item.isCurrentFolder) {
  500. location.hash = Drive.folderRoute(newPath);
  501. return;
  502. }
  503. Drive.setSelection([newPath], { anchor: newPath, focus: newPath });
  504. Drive.refresh();
  505. DriveUI.toast(T("toast/renamed", "Renamed to {name}", { name: newName }), { type: "success" });
  506. }).catch(function (err) {
  507. DriveUI.error(err);
  508. DriveList.render();
  509. });
  510. }
  511. function rename(item) {
  512. if (!item || item.trashed || item.shareOnly) {
  513. return;
  514. }
  515. if (!Drive.isWritable(item.path)) {
  516. DriveUI.toast(T("err/readonly", "This location is read only"), { type: "error" });
  517. return;
  518. }
  519. if (!item.isCurrentFolder && DriveList.startRename(item, function (v) { commitRename(item, v); })) {
  520. return;
  521. }
  522. DriveUI.prompt({
  523. title: T("menu/rename", "Rename"), label: T("prompt/newName", "New name"), value: item.name,
  524. selectStem: !item.isDir, ok: T("menu/rename", "Rename")
  525. }).then(function (name) {
  526. if (name && name != item.name) {
  527. commitRename(item, name);
  528. }
  529. });
  530. }
  531. function undoTrash(items) {
  532. API.trashList().then(function (list) {
  533. var jobs = items.map(function (it) {
  534. var parent = Drive.normDir(API.parentOf(it.path));
  535. var match = list.filter(function (t) {
  536. return t.name == it.name && Drive.normDir(t.origin || "") == parent;
  537. }).sort(function (a, b) { return b.mtime - a.mtime; })[0];
  538. return match ? API.trashRestore(match.path) : Promise.resolve();
  539. });
  540. return Promise.all(jobs);
  541. }).then(function () {
  542. DriveUI.toast(T("toast/restored", "Restored"), { type: "success" });
  543. Drive.refresh();
  544. }).catch(DriveUI.error);
  545. }
  546. function trash(items) {
  547. items = (items || []).filter(function (i) { return !i.trashed && !i.shareOnly && !i.isRoot; });
  548. if (!items.length || view().kind == "shared") {
  549. return;
  550. }
  551. if (items.some(function (i) { return !Drive.isWritable(i.path); })) {
  552. DriveUI.toast(T("err/readonly", "This location is read only"), { type: "error" });
  553. return;
  554. }
  555. var permanent = !API.caps.fm;
  556. var ask = permanent || S().settings.confirmTrash ? DriveUI.confirm({
  557. title: permanent ? T("delete/title", "Delete forever?") : T("trash/confirmTitle", "Move to trash?"),
  558. message: permanent ? T("delete/reducedText", "Deleted items cannot be restored in limited mode.") :
  559. plural(items.length, "\"{name}\" will be moved to the trash.", "{n} items will be moved to the trash.", "trash/confirmText").replace("{name}", items[0].name),
  560. ok: permanent ? T("delete/ok", "Delete forever") : T("trash/move", "Move to trash"), danger: true
  561. }) : Promise.resolve(true);
  562. ask.then(function (ok) {
  563. if (!ok) {
  564. return;
  565. }
  566. var paths = items.map(function (i) { return i.path; });
  567. API.recycle(paths).then(function () {
  568. Drive.setSelection([]);
  569. Drive.refresh();
  570. Drive.refreshQuota();
  571. if (permanent) {
  572. DriveUI.toast(plural(items.length, "Deleted 1 item", "Deleted {n} items", "toast/deleted"), { type: "success" });
  573. } else {
  574. DriveUI.toast(plural(items.length, "Moved 1 item to the trash", "Moved {n} items to the trash", "toast/trashed"), {
  575. type: "success", timeout: 7000,
  576. action: { label: T("toast/undo", "Undo"), fn: function () { undoTrash(items); } }
  577. });
  578. }
  579. }).catch(function (err) {
  580. if (err.message == "TRASH_QUOTA_EXCEEDED" || /Incompatible File System/i.test(err.message)) {
  581. DriveUI.confirm({
  582. title: T("trash/fullTitle", "Cannot move to trash"),
  583. message: err.message == "TRASH_QUOTA_EXCEEDED" ? T("trash/fullText", "The trash is full. Delete these items forever instead?") :
  584. T("trash/unsupported", "This storage has no trash. Delete these items forever instead?"),
  585. ok: T("delete/ok", "Delete forever"), danger: true
  586. }).then(function (yes) {
  587. if (yes) {
  588. removeNow(items);
  589. }
  590. });
  591. } else {
  592. DriveUI.error(err);
  593. }
  594. });
  595. });
  596. }
  597. function removeNow(items) {
  598. API.remove(items.map(function (i) { return i.path; })).then(function () {
  599. Drive.setSelection([]);
  600. Drive.refresh();
  601. Drive.refreshQuota();
  602. DriveUI.toast(plural(items.length, "Deleted 1 item", "Deleted {n} items", "toast/deleted"), { type: "success" });
  603. }).catch(DriveUI.error);
  604. }
  605. function deleteForever(items) {
  606. items = (items || []).filter(function (i) { return !i.shareOnly && !i.isRoot; });
  607. if (!items.length || view().kind == "shared") {
  608. return;
  609. }
  610. DriveUI.confirm({
  611. title: T("delete/title", "Delete forever?"),
  612. message: plural(items.length, "\"{name}\" will be deleted forever. This cannot be undone.", "{n} items will be deleted forever. This cannot be undone.", "delete/text").replace("{name}", items[0].name),
  613. ok: T("delete/ok", "Delete forever"), danger: true
  614. }).then(function (ok) {
  615. if (ok) {
  616. removeNow(items);
  617. }
  618. });
  619. }
  620. function restore(items) {
  621. items = (items || []).filter(function (i) { return i.trashed; });
  622. if (!items.length) {
  623. return;
  624. }
  625. items.reduce(function (p, it) {
  626. return p.then(function () { return API.trashRestore(it.path); });
  627. }, Promise.resolve()).then(function () {
  628. Drive.setSelection([]);
  629. Drive.refresh();
  630. DriveUI.toast(plural(items.length, "Restored 1 item", "Restored {n} items", "toast/restoredN"), {
  631. type: "success",
  632. action: items.length == 1 && items[0].origin ? { label: T("toast/show", "Show"), fn: function () { location.hash = Drive.folderRoute(items[0].origin); } } : null
  633. });
  634. }).catch(DriveUI.error);
  635. }
  636. function emptyTrash() {
  637. DriveUI.confirm({
  638. title: T("trash/emptyTitle", "Empty trash?"),
  639. message: T("trash/emptyText", "All items in the trash will be deleted forever. This cannot be undone."),
  640. ok: T("trash/empty", "Empty trash"), danger: true
  641. }).then(function (ok) {
  642. if (!ok) {
  643. return;
  644. }
  645. API.trashClear().then(function () {
  646. Drive.refresh();
  647. Drive.refreshQuota();
  648. DriveUI.toast(T("toast/trashEmptied", "Trash emptied"), { type: "success" });
  649. }).catch(DriveUI.error);
  650. });
  651. }
  652. /* ------------------------------------------------------------------ */
  653. /* Star, compress, extract */
  654. /* ------------------------------------------------------------------ */
  655. function star(items, on) {
  656. var paths = items.map(function (i) { return i.path; });
  657. API.star(paths, on).then(function (list) {
  658. S().starred = new Set(list || []);
  659. if (view().kind == "starred" && !on) {
  660. Drive.refresh();
  661. } else {
  662. DriveList.render();
  663. DriveDetails.refresh();
  664. }
  665. DriveUI.toast(on ? plural(items.length, "Added to Starred", "Added {n} items to Starred", "toast/starred") :
  666. plural(items.length, "Removed from Starred", "Removed {n} items from Starred", "toast/unstarred"));
  667. }).catch(DriveUI.error);
  668. }
  669. function allStarred(items) {
  670. return items.length > 0 && items.every(function (i) { return S().starred.has(i.path); });
  671. }
  672. function zip(items) {
  673. if (!API.caps.fm) {
  674. DriveUI.toast(T("err/needFM", "This action needs the File Manager permission"), { type: "error" });
  675. return;
  676. }
  677. var dest = API.parentOf(items[0].path);
  678. DriveTransfers.operation("zip", items, dest, "keep", { doneText: T("xfer/zipped", "Archive created") }).catch(function () { });
  679. }
  680. function isArchive(item) {
  681. return !item.isDir && ["zip"].indexOf(DriveIcons.getExt(item.name)) >= 0;
  682. }
  683. function unzip(item) {
  684. if (!API.caps.fm) {
  685. DriveUI.toast(T("err/needFM", "This action needs the File Manager permission"), { type: "error" });
  686. return;
  687. }
  688. var dest = API.parentOf(item.path);
  689. DriveTransfers.operation("unzip", [item], dest, "keep", { doneText: T("xfer/extracted", "Extracted") }).catch(function () { });
  690. }
  691. /* ------------------------------------------------------------------ */
  692. /* New items and uploads */
  693. /* ------------------------------------------------------------------ */
  694. function freeName(base, ext) {
  695. var names = {};
  696. S().items.forEach(function (i) { names[i.name.toLowerCase()] = true; });
  697. var candidate = base + (ext ? "." + ext : "");
  698. var n = 2;
  699. while (names[candidate.toLowerCase()]) {
  700. candidate = base + " (" + n + ")" + (ext ? "." + ext : "");
  701. n++;
  702. }
  703. return candidate;
  704. }
  705. function targetFolder() {
  706. var v = view();
  707. return v.kind == "drive" && v.writable ? v.path : null;
  708. }
  709. function newFolder() {
  710. var dir = targetFolder();
  711. if (!dir) {
  712. return;
  713. }
  714. DriveUI.prompt({
  715. title: T("toolbar/newFolder", "New folder"), label: T("prompt/folderName", "Folder name"),
  716. value: freeName(T("prompt/untitledFolder", "Untitled folder")), icon: "folderPlus", ok: T("common/create", "Create")
  717. }).then(function (name) {
  718. if (!name) {
  719. return;
  720. }
  721. API.mkdir(dir, name).then(function () {
  722. var p = API.joinPath(dir, name);
  723. Drive.setSelection([p], { anchor: p, focus: p });
  724. Drive.refresh();
  725. }).catch(DriveUI.error);
  726. });
  727. }
  728. function newFile(tpl) {
  729. var dir = targetFolder();
  730. if (!dir) {
  731. return;
  732. }
  733. DriveUI.prompt({
  734. title: T("new/fileTitle", "New {type}", { type: tpl.Desc }), label: T("prompt/fileName", "File name"),
  735. value: freeName(T("new/untitled", "Untitled"), tpl.Ext), selectStem: true, icon: "filePlus", ok: T("common/create", "Create")
  736. }).then(function (name) {
  737. if (!name) {
  738. return;
  739. }
  740. if (tpl.Ext && name.toLowerCase().lastIndexOf("." + tpl.Ext.toLowerCase()) != name.length - tpl.Ext.length - 1) {
  741. name += "." + tpl.Ext;
  742. }
  743. API.newFile(dir, name).then(function () {
  744. var p = API.joinPath(dir, name);
  745. Drive.setSelection([p], { anchor: p, focus: p });
  746. Drive.refresh();
  747. DriveUI.toast(T("toast/created", "Created {name}", { name: name }), {
  748. type: "success", action: { label: T("toast/open", "Open"), fn: function () { open({ name: name, path: p, isDir: false, size: 0, mtime: 0 }); } }
  749. });
  750. }).catch(DriveUI.error);
  751. });
  752. }
  753. var templateCache = null;
  754. function templateItems() {
  755. var p = templateCache ? Promise.resolve(templateCache) : API.templates().then(function (list) {
  756. templateCache = list || [];
  757. return templateCache;
  758. });
  759. return p.then(function (list) {
  760. return list.map(function (tpl) {
  761. return { img: "data:image/svg+xml;charset=utf-8," + encodeURIComponent(DriveIcons.file("x." + tpl.Ext, false).replace("<svg ", '<svg xmlns="http://www.w3.org/2000/svg" ')), label: tpl.Desc, hint: "." + tpl.Ext, action: function () { newFile(tpl); } };
  762. });
  763. }).catch(function () { return []; });
  764. }
  765. function upload() {
  766. var dir = targetFolder();
  767. if (dir) {
  768. DriveTransfers.pick(dir, false);
  769. }
  770. }
  771. function uploadFolder() {
  772. var dir = targetFolder();
  773. if (dir) {
  774. DriveTransfers.pick(dir, true);
  775. }
  776. }
  777. /* ------------------------------------------------------------------ */
  778. /* Menus */
  779. /* ------------------------------------------------------------------ */
  780. function newMenuItems() {
  781. return [
  782. { icon: "folderPlus", label: T("toolbar/newFolder", "New folder"), hint: "Shift+F", action: newFolder },
  783. "-",
  784. { icon: "fileUp", label: T("toolbar/uploadFiles", "File upload"), hint: "Shift+U", action: upload },
  785. { icon: "folderUp", label: T("toolbar/uploadFolder", "Folder upload"), action: uploadFolder },
  786. "-",
  787. { icon: "filePlus", label: T("toolbar/newFile", "New file"), submenu: templateItems }
  788. ];
  789. }
  790. function newMenu(pos) {
  791. DriveUI.menu(pos, newMenuItems());
  792. }
  793. function pasteItem() {
  794. var clip = S().clipboard;
  795. if (!clip || !targetFolder()) {
  796. return null;
  797. }
  798. return { icon: "paste", label: T("menu/paste", "Paste") + " (" + clip.paths.length + ")", hint: "Ctrl+V", action: function () { paste(); } };
  799. }
  800. function folderMenu(pos) {
  801. var folder = Drive.currentFolderItem();
  802. var w = view().writable;
  803. DriveUI.menu(pos, [
  804. w ? { icon: "folderPlus", label: T("toolbar/newFolder", "New folder"), action: newFolder } : null,
  805. w ? { icon: "fileUp", label: T("toolbar/uploadFiles", "File upload"), action: upload } : null,
  806. w ? { icon: "folderUp", label: T("toolbar/uploadFolder", "Folder upload"), action: uploadFolder } : null,
  807. w ? { icon: "filePlus", label: T("toolbar/newFile", "New file"), submenu: templateItems } : null,
  808. pasteItem(),
  809. "-",
  810. !folder.isRoot ? { icon: "link", label: T("toolbar/share", "Share"), action: function () { DriveShare.open(folder); } } : null,
  811. !folder.isRoot ? { icon: "link", label: T("menu/copyLink", "Copy link"), action: function () { copyLink(folder); } } : null,
  812. { icon: "download", label: T("menu/downloadFolder", "Download as zip"), action: function () { download([folder]); } },
  813. !folder.isRoot && w ? { icon: "pencil", label: T("menu/rename", "Rename"), action: function () { rename(folder); } } : null,
  814. !folder.isRoot ? { icon: S().starred.has(folder.path) ? "starFill" : "star", label: S().starred.has(folder.path) ? T("menu/unstar", "Remove from Starred") : T("menu/star", "Add to Starred"), action: function () { star([folder], !S().starred.has(folder.path)); } } : null,
  815. "-",
  816. { icon: "info", label: T("menu/details", "View details"), action: function () { Drive.setSelection([]); Drive.toggleDetails(true); } },
  817. { icon: "refresh", label: T("menu/refresh", "Refresh"), action: function () { Drive.refresh(); } }
  818. ]);
  819. }
  820. function moreMenu(pos) {
  821. var items = Drive.selectedItems();
  822. var v = view();
  823. if (!items.length) {
  824. DriveUI.menu(pos, [
  825. { icon: "checkSquare", label: T("menu/selectAll", "Select all"), hint: "Ctrl+A", action: function () { DriveList.selectAll(); } },
  826. pasteItem(),
  827. { icon: "refresh", label: T("menu/refresh", "Refresh"), action: function () { Drive.refresh(); } },
  828. "-",
  829. { checkable: true, checked: S().settings.showHidden, label: T("menu/showHidden", "Show hidden files"), action: function () { Drive.saveSettings({ showHidden: !S().settings.showHidden }); Drive.refresh(); } },
  830. v.kind == "drive" ? { icon: "info", label: T("menu/details", "View details"), action: function () { Drive.toggleDetails(true); } } : null,
  831. v.kind == "recent" ? { icon: "x", label: T("recent/clear", "Clear open history"), action: function () { API.recentClear().then(function () { Drive.refresh(); }); } } : null
  832. ]);
  833. return;
  834. }
  835. DriveUI.menu(pos, selectionMenu(items, true));
  836. }
  837. //The full set of actions for the selected items, shared by More and right click
  838. function selectionMenu(items, fromToolbar) {
  839. var v = view();
  840. var one = items.length == 1 ? items[0] : null;
  841. var writable = items.every(function (i) { return Drive.isWritable(i.path); }) && v.kind != "shared";
  842. var starredAll = allStarred(items);
  843. if (v.kind == "trash") {
  844. return [
  845. one && DrivePreview.canPreview(one) ? { icon: "eye", label: T("menu/preview", "Preview"), action: function () { DrivePreview.open(one); } } : null,
  846. { icon: "restore", label: T("trash/restore", "Restore"), action: function () { restore(items); } },
  847. { icon: "trash", label: T("trash/deleteForever", "Delete forever"), danger: true, hint: "Del", action: function () { deleteForever(items); } },
  848. "-",
  849. { icon: "info", label: T("menu/details", "View details"), action: function () { Drive.toggleDetails(true); } }
  850. ];
  851. }
  852. var moreSub = function () {
  853. return [
  854. one && DrivePreview.canPreview(one) ? { icon: "eye", label: T("menu/preview", "Preview"), hint: "Space", action: function () { DrivePreview.open(one); } } : null,
  855. one && !one.isDir && !one.shareOnly ? { icon: "apps", label: T("menu/openWith", "Open with"), submenu: function () { return openWithItems(one); } } : null,
  856. writable ? { icon: "cut", label: T("menu/cut", "Cut"), hint: "Ctrl+X", action: function () { clipboard("cut", items); } } : null,
  857. !fromToolbar ? null : { icon: "copy", label: T("menu/copyTo", "Copy to..."), action: function () { copyTo(items); } },
  858. writable && items.every(function (i) { return !i.isDir; }) ? { icon: "copy", label: T("menu/duplicate", "Make a copy"), action: function () { duplicate(items); } } : null,
  859. writable && API.caps.fm ? { icon: "archive", label: T("menu/compress", "Compress to ZIP"), action: function () { zip(items); } } : null,
  860. one && isArchive(one) && writable && API.caps.fm ? { icon: "extract", label: T("menu/extract", "Extract here"), action: function () { unzip(one); } } : null,
  861. v.kind != "shared" ? { icon: starredAll ? "starFill" : "star", label: starredAll ? T("menu/unstar", "Remove from Starred") : T("menu/star", "Add to Starred"), action: function () { star(items, !starredAll); } } : null,
  862. one ? { icon: "code", label: T("menu/copyPath", "Copy path"), action: function () { copyPath(one); } } : null,
  863. one && v.kind != "drive" && !one.shareOnly ? { icon: "folderOpen", label: T("menu/showLocation", "Show file location"), action: function () { location.hash = Drive.folderRoute(API.parentOf(one.path)); } } : null,
  864. one && !one.isDir && API.caps.fm && !one.shareOnly ? { icon: "history", label: T("menu/versions", "Version history"), action: function () { Drive.setSelection([one.path]); DriveDetails.open("versions"); Drive.toggleDetails(true); } } : null
  865. ];
  866. };
  867. if (fromToolbar) {
  868. return [
  869. one && !one.isDir && !one.shareOnly ? { icon: "apps", label: T("menu/openWith", "Open with"), submenu: function () { return openWithItems(one); } } : null,
  870. { icon: "download", label: T("toolbar/download", "Download"), hint: "Ctrl+S", action: function () { download(items); } },
  871. one ? { icon: "link", label: T("menu/copyLink", "Copy link"), action: function () { copyLink(one); } } : null,
  872. writable && one ? { icon: "pencil", label: T("menu/rename", "Rename"), hint: "F2", action: function () { rename(one); } } : null,
  873. "-"
  874. ].concat(moreSub()).concat([
  875. "-",
  876. writable ? { icon: "trash", label: T("menu/trash", "Move to trash"), danger: true, hint: "Del", action: function () { trash(items); } } : null
  877. ]);
  878. }
  879. if (v.kind == "shared") {
  880. var s = one && one.share;
  881. return [
  882. one ? { icon: "open", label: T("menu/open", "Open"), hint: "Enter", action: function () { open(one); } } : null,
  883. one ? { icon: "newTab", label: T("menu/openNewTab", "Open in new tab"), action: function () { openInNewTab(one); } } : null,
  884. one && s ? { icon: "link", label: T("menu/copyLink", "Copy link"), action: function () { copyLink(one); } } : null,
  885. one && s && v.key == "shared:byme" ? { icon: "users", label: T("share/manageSharing", "Manage sharing"), action: function () { DriveShare.open(one); } } : null,
  886. items.some(function (i) { return !i.shareOnly; }) ? { icon: "download", label: T("toolbar/download", "Download"), action: function () { download(items); } } : null,
  887. "-",
  888. { icon: "info", label: T("menu/details", "View details"), action: function () { Drive.toggleDetails(true); } },
  889. v.key == "shared:byme" ? {
  890. icon: "x", label: T("share/stop", "Stop sharing"), danger: true, action: function () {
  891. Promise.all(items.map(function (i) { return API.shareDelete(i.share.UUID, i.path); })).then(function () {
  892. Drive.refresh();
  893. DriveUI.toast(T("share/stopped", "Sharing stopped"), { type: "success" });
  894. }).catch(DriveUI.error);
  895. }
  896. } : null
  897. ];
  898. }
  899. return [
  900. one ? { icon: "open", label: T("menu/open", "Open"), hint: "Enter", action: function () { open(one); } } : null,
  901. one ? { icon: "newTab", label: T("menu/openNewTab", "Open in new tab"), action: function () { openInNewTab(one); } } : null,
  902. "-",
  903. one ? { icon: "share", label: T("toolbar/share", "Share"), action: function () { DriveShare.open(one); } } : null,
  904. one ? { icon: "link", label: T("menu/copyLink", "Copy link"), action: function () { copyLink(one); } } : null,
  905. "-",
  906. { icon: "download", label: T("toolbar/download", "Download"), hint: "Ctrl+S", action: function () { download(items); } },
  907. writable ? { icon: "move", label: T("toolbar/move", "Move"), action: function () { moveTo(items); } } : null,
  908. { icon: "copy", label: T("menu/copy", "Copy"), hint: "Ctrl+C", action: function () { clipboard("copy", items); } },
  909. { icon: "folder", label: T("menu/copyTo", "Copy to..."), action: function () { copyTo(items); } },
  910. writable && one ? { icon: "pencil", label: T("menu/rename", "Rename"), hint: "F2", action: function () { rename(one); } } : null,
  911. one && one.isDir && S().clipboard && writable ? { icon: "paste", label: T("menu/pasteInto", "Paste into folder"), action: function () { paste(Drive.normDir(one.path)); } } : null,
  912. "-",
  913. writable ? { icon: "trash", label: T("menu/delete", "Delete"), danger: true, hint: "Del", action: function () { trash(items); } } : null,
  914. "-",
  915. { icon: "info", label: T("menu/details", "View details"), action: function () { Drive.toggleDetails(true); } },
  916. { icon: "moreH", label: T("toolbar/more", "More"), submenu: moreSub }
  917. ];
  918. }
  919. function contextMenu(pos, item) {
  920. DriveUI.menu(pos, selectionMenu(Drive.selectedItems().length ? Drive.selectedItems() : [item], false));
  921. }
  922. function backgroundMenu(pos) {
  923. var v = view();
  924. var items = [];
  925. if (v.kind == "drive" && v.writable) {
  926. items = items.concat(newMenuItems(), ["-"]);
  927. }
  928. items.push(pasteItem());
  929. items.push({ icon: "checkSquare", label: T("menu/selectAll", "Select all"), hint: "Ctrl+A", action: function () { DriveList.selectAll(); } });
  930. items.push({ icon: "refresh", label: T("menu/refresh", "Refresh"), action: function () { Drive.refresh(); } });
  931. items.push("-");
  932. var grid = Drive.currentViewMode() == "grid";
  933. items.push({ icon: grid ? "list" : "grid", label: grid ? T("view/list", "List view") : T("view/grid", "Grid view"), action: function () { document.querySelector('[data-mode="' + (grid ? "list" : "grid") + '"]').click(); } });
  934. if (v.kind == "drive") {
  935. items.push({ icon: "info", label: T("menu/folderDetails", "Folder details"), action: function () { Drive.setSelection([]); Drive.toggleDetails(true); } });
  936. }
  937. if (v.kind == "trash" && S().items.length) {
  938. items.push("-", { icon: "x", label: T("trash/empty", "Empty trash"), danger: true, action: emptyTrash });
  939. }
  940. DriveUI.menu(pos, items);
  941. }
  942. global.DriveActions = {
  943. open: open,
  944. openInNewTab: openInNewTab,
  945. openWithModule: openWithModule,
  946. openWithChooser: openWithChooser,
  947. openWithItems: openWithItems,
  948. compatibleModules: compatibleModules,
  949. defaultModuleFor: defaultModuleFor,
  950. download: download,
  951. copyLink: copyLink,
  952. copyText: copyText,
  953. copyPath: copyPath,
  954. moveTo: moveTo,
  955. copyTo: copyTo,
  956. transfer: transfer,
  957. duplicate: duplicate,
  958. clipboard: clipboard,
  959. paste: paste,
  960. rename: rename,
  961. trash: trash,
  962. deleteForever: deleteForever,
  963. restore: restore,
  964. emptyTrash: emptyTrash,
  965. star: star,
  966. zip: zip,
  967. unzip: unzip,
  968. isArchive: isArchive,
  969. newFolder: newFolder,
  970. newFile: newFile,
  971. upload: upload,
  972. uploadFolder: uploadFolder,
  973. newMenu: newMenu,
  974. folderMenu: folderMenu,
  975. moreMenu: moreMenu,
  976. contextMenu: contextMenu,
  977. backgroundMenu: backgroundMenu,
  978. launchURL: launchURL,
  979. fileHash: fileHash
  980. };
  981. })(window);