NCCollectionViewCommon+Menu.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. //
  2. // NCCollectionViewCommon+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2020 Marino Faggiana All rights reserved.
  8. // Copyright © 2021 Henrik Storch All rights reserved.
  9. //
  10. // Author Philippe Weidmann
  11. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  12. // Author Henrik Storch <henrik.storch@nextcloud.com>
  13. //
  14. // This program is free software: you can redistribute it and/or modify
  15. // it under the terms of the GNU General Public License as published by
  16. // the Free Software Foundation, either version 3 of the License, or
  17. // (at your option) any later version.
  18. //
  19. // This program is distributed in the hope that it will be useful,
  20. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. // GNU General Public License for more details.
  23. //
  24. // You should have received a copy of the GNU General Public License
  25. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. //
  27. import UIKit
  28. import FloatingPanel
  29. import NCCommunication
  30. import Queuer
  31. extension NCCollectionViewCommon {
  32. fileprivate func setAvailableOffline(metadata: tableMetadata, isOffline: Bool) {
  33. if isOffline {
  34. if metadata.directory {
  35. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: false, account: self.appDelegate.account)
  36. } else {
  37. NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: false)
  38. }
  39. } else {
  40. if metadata.directory {
  41. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: self.appDelegate.account)
  42. NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorDownloadAllFile)
  43. } else {
  44. NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { _ in }
  45. if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
  46. NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { _ in }
  47. }
  48. }
  49. }
  50. self.reloadDataSource()
  51. }
  52. func toggleMenu(metadata: tableMetadata, imageIcon: UIImage?) {
  53. var actions = [NCMenuAction]()
  54. guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) else { return }
  55. let serverUrl = metadata.serverUrl + "/" + metadata.fileName
  56. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
  57. let serverUrlHome = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
  58. var isOffline = false
  59. var titleDelete = NSLocalizedString("_delete_", comment: "")
  60. if NCManageDatabase.shared.isMetadataShareOrMounted(metadata: metadata, metadataFolder: metadataFolder) {
  61. titleDelete = NSLocalizedString("_leave_share_", comment: "")
  62. } else if metadata.directory {
  63. titleDelete = NSLocalizedString("_delete_folder_", comment: "")
  64. } else {
  65. titleDelete = NSLocalizedString("_delete_file_", comment: "")
  66. }
  67. if let metadataFolder = metadataFolder {
  68. let isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared)
  69. let isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted)
  70. if isShare || isMounted {
  71. titleDelete = NSLocalizedString("_leave_share_", comment: "")
  72. }
  73. }
  74. if metadata.directory {
  75. if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) {
  76. isOffline = directory.offline
  77. }
  78. } else {
  79. if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  80. isOffline = localFile.offline
  81. }
  82. }
  83. let editors = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType)
  84. let isRichDocument = NCUtility.shared.isRichDocument(metadata)
  85. var iconHeader: UIImage!
  86. if imageIcon != nil {
  87. iconHeader = imageIcon!
  88. } else {
  89. if metadata.directory {
  90. iconHeader = NCBrandColor.cacheImages.folder
  91. } else {
  92. iconHeader = NCBrandColor.cacheImages.file
  93. }
  94. }
  95. actions.append(
  96. NCMenuAction(
  97. title: metadata.fileNameView,
  98. icon: iconHeader,
  99. action: nil
  100. )
  101. )
  102. //
  103. // FAVORITE
  104. //
  105. actions.append(
  106. NCMenuAction(
  107. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  108. icon: NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite),
  109. action: { _ in
  110. NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
  111. if errorCode != 0 {
  112. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  113. }
  114. }
  115. }
  116. )
  117. )
  118. //
  119. // DETAIL
  120. //
  121. if !isFolderEncrypted && !appDelegate.disableSharesView {
  122. actions.append(
  123. NCMenuAction(
  124. title: NSLocalizedString("_details_", comment: ""),
  125. icon: NCUtility.shared.loadImage(named: "info"),
  126. action: { _ in
  127. NCFunctionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .activity)
  128. }
  129. )
  130. )
  131. }
  132. //
  133. // OFFLINE
  134. //
  135. if !isFolderEncrypted {
  136. actions.append(
  137. NCMenuAction(
  138. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  139. icon: NCUtility.shared.loadImage(named: "tray.and.arrow.down"),
  140. action: { _ in
  141. self.setAvailableOffline(metadata: metadata, isOffline: isOffline)
  142. }
  143. )
  144. )
  145. }
  146. //
  147. // OPEN with external editor
  148. //
  149. if metadata.classFile == NCCommunicationCommon.typeClassFile.document.rawValue && editors.contains(NCGlobal.shared.editorText) && ((editors.contains(NCGlobal.shared.editorOnlyoffice) || isRichDocument)) {
  150. var editor = ""
  151. var title = ""
  152. var icon: UIImage?
  153. if editors.contains(NCGlobal.shared.editorOnlyoffice) {
  154. editor = NCGlobal.shared.editorOnlyoffice
  155. title = NSLocalizedString("_open_in_onlyoffice_", comment: "")
  156. icon = NCUtility.shared.loadImage(named: "onlyoffice")
  157. } else if isRichDocument {
  158. editor = NCGlobal.shared.editorCollabora
  159. title = NSLocalizedString("_open_in_collabora_", comment: "")
  160. icon = NCUtility.shared.loadImage(named: "collabora")
  161. }
  162. if editor != "" {
  163. actions.append(
  164. NCMenuAction(
  165. title: title,
  166. icon: icon!,
  167. action: { _ in
  168. NCViewer.shared.view(viewController: self, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon, editor: editor, isRichDocument: isRichDocument)
  169. }
  170. )
  171. )
  172. }
  173. }
  174. //
  175. // OPEN IN
  176. //
  177. if !metadata.directory && !NCBrandOptions.shared.disable_openin_file {
  178. actions.append(
  179. NCMenuAction(
  180. title: NSLocalizedString("_open_in_", comment: ""),
  181. icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
  182. action: { menuAction in
  183. if self is NCFileViewInFolder {
  184. self.dismiss(animated: true) {
  185. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorOpenIn)
  186. }
  187. } else {
  188. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorOpenIn)
  189. }
  190. }
  191. )
  192. )
  193. }
  194. //
  195. // PRINT
  196. //
  197. if (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml") || metadata.contentType == "application/pdf" || metadata.contentType == "com.adobe.pdf" {
  198. actions.append(
  199. NCMenuAction(
  200. title: NSLocalizedString("_print_", comment: ""),
  201. icon: NCUtility.shared.loadImage(named: "printer"),
  202. action: { _ in
  203. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint)
  204. }
  205. )
  206. )
  207. }
  208. //
  209. // SAVE
  210. //
  211. if (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml") || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
  212. var title: String = NSLocalizedString("_save_selected_files_", comment: "")
  213. var icon = NCUtility.shared.loadImage(named: "square.and.arrow.down")
  214. let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
  215. if metadataMOV != nil {
  216. title = NSLocalizedString("_livephoto_save_", comment: "")
  217. icon = NCUtility.shared.loadImage(named: "livephoto")
  218. }
  219. actions.append(
  220. NCMenuAction(
  221. title: title,
  222. icon: icon,
  223. action: { _ in
  224. if metadataMOV != nil {
  225. NCFunctionCenter.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV!)
  226. } else {
  227. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  228. NCFunctionCenter.shared.saveAlbum(metadata: metadata)
  229. } else {
  230. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
  231. }
  232. }
  233. }
  234. )
  235. )
  236. }
  237. //
  238. // SAVE AS SCAN
  239. //
  240. if #available(iOS 13.0, *) {
  241. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && metadata.contentType != "image/svg+xml" {
  242. actions.append(
  243. NCMenuAction(
  244. title: NSLocalizedString("_save_as_scan_", comment: ""),
  245. icon: NCUtility.shared.loadImage(named: "viewfinder.circle"),
  246. action: { _ in
  247. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorSaveAsScan)
  248. }
  249. )
  250. )
  251. }
  252. }
  253. //
  254. // RENAME
  255. //
  256. if !(isFolderEncrypted && metadata.serverUrl == serverUrlHome) {
  257. actions.append(
  258. NCMenuAction(
  259. title: NSLocalizedString("_rename_", comment: ""),
  260. icon: NCUtility.shared.loadImage(named: "pencil"),
  261. action: { _ in
  262. if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
  263. vcRename.metadata = metadata
  264. vcRename.imagePreview = imageIcon
  265. let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
  266. self.present(popup, animated: true)
  267. }
  268. }
  269. )
  270. )
  271. }
  272. //
  273. // COPY - MOVE
  274. //
  275. if !isFolderEncrypted && serverUrl != "" {
  276. actions.append(
  277. NCMenuAction(
  278. title: NSLocalizedString("_move_or_copy_", comment: ""),
  279. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  280. action: { _ in
  281. NCFunctionCenter.shared.openSelectView(items: [metadata], viewController: self)
  282. }
  283. )
  284. )
  285. }
  286. //
  287. // COPY
  288. //
  289. if !metadata.directory {
  290. actions.append(
  291. NCMenuAction(
  292. title: NSLocalizedString("_copy_file_", comment: ""),
  293. icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
  294. action: { _ in
  295. self.appDelegate.pasteboardOcIds = [metadata.ocId]
  296. NCFunctionCenter.shared.copyPasteboard()
  297. }
  298. )
  299. )
  300. }
  301. /*
  302. //
  303. // USE AS BACKGROUND
  304. //
  305. if #available(iOS 13.0, *) {
  306. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && self.layoutKey == NCGlobal.shared.layoutViewFiles && !NCBrandOptions.shared.disable_background_image {
  307. actions.append(
  308. NCMenuAction(
  309. title: NSLocalizedString("_use_as_background_", comment: ""),
  310. icon: NCUtility.shared.loadImage(named: "text.below.photo"),
  311. action: { menuAction in
  312. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  313. NCFunctionCenter.shared.saveBackground(metadata: metadata)
  314. } else {
  315. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveBackground)
  316. }
  317. }
  318. )
  319. )
  320. }
  321. }
  322. */
  323. //
  324. // MODIFY
  325. //
  326. if #available(iOS 13.0, *) {
  327. if !isFolderEncrypted && metadata.contentType != "image/gif" && metadata.contentType != "image/svg+xml" && (metadata.contentType == "com.adobe.pdf" || metadata.contentType == "application/pdf" || metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue) {
  328. actions.append(
  329. NCMenuAction(
  330. title: NSLocalizedString("_modify_", comment: ""),
  331. icon: NCUtility.shared.loadImage(named: "pencil.tip.crop.circle"),
  332. action: { menuAction in
  333. if self is NCFileViewInFolder {
  334. self.dismiss(animated: true) {
  335. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook)
  336. }
  337. } else {
  338. NCFunctionCenter.shared.openDownload(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook)
  339. }
  340. }
  341. )
  342. )
  343. }
  344. }
  345. //
  346. // DELETE
  347. //
  348. actions.append(
  349. NCMenuAction(
  350. title: titleDelete,
  351. icon: NCUtility.shared.loadImage(named: "trash"),
  352. action: { _ in
  353. let alertController = UIAlertController(title: "", message: metadata.fileNameView + "\n\n" + NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  354. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
  355. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: false)
  356. })
  357. alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
  358. NCOperationQueue.shared.delete(metadata: metadata, onlyLocalCache: true)
  359. })
  360. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (_: UIAlertAction) in })
  361. self.present(alertController, animated: true, completion: nil)
  362. }
  363. )
  364. )
  365. //
  366. // SET FOLDER E2EE
  367. //
  368. if !metadata.e2eEncrypted && metadata.directory && CCUtility.isEnd(toEndEnabled: appDelegate.account) && metadata.serverUrl == serverUrlHome {
  369. actions.append(
  370. NCMenuAction(
  371. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  372. icon: NCUtility.shared.loadImage(named: "lock"),
  373. action: { _ in
  374. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: false) { account, errorCode, errorDescription in
  375. if errorCode == 0 {
  376. NCManageDatabase.shared.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, serverUrl))
  377. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
  378. NCManageDatabase.shared.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
  379. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE, userInfo: ["serverUrl": metadata.serverUrl])
  380. } else {
  381. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: .error, errorCode: errorCode)
  382. }
  383. }
  384. }
  385. )
  386. )
  387. }
  388. //
  389. // UNSET FOLDER E2EE
  390. //
  391. if metadata.e2eEncrypted && metadata.directory && CCUtility.isEnd(toEndEnabled: appDelegate.account) && metadata.serverUrl == serverUrlHome {
  392. actions.append(
  393. NCMenuAction(
  394. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  395. icon: NCUtility.shared.loadImage(named: "lock"),
  396. action: { _ in
  397. NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: true) { account, errorCode, errorDescription in
  398. if errorCode == 0 {
  399. NCManageDatabase.shared.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, serverUrl))
  400. NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
  401. NCManageDatabase.shared.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
  402. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE, userInfo: ["serverUrl": metadata.serverUrl])
  403. } else {
  404. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: .error, errorCode: errorCode)
  405. }
  406. }
  407. }
  408. )
  409. )
  410. }
  411. presentMenu(with: actions)
  412. }
  413. func toggleMenuSelect() {
  414. var actions = [NCMenuAction]()
  415. let selectedMetadatas = selectOcId.compactMap(NCManageDatabase.shared.getMetadataFromOcId)
  416. let isAnyOffline = selectedMetadatas.contains(where: { metadata in
  417. if metadata.directory,
  418. let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, metadata.serverUrl + "/" + metadata.fileName)) {
  419. return directory.offline
  420. } else if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) {
  421. return localFile.offline
  422. } else { return false }
  423. })
  424. //
  425. // SELECT ALL
  426. //
  427. actions.append(
  428. NCMenuAction(
  429. title: NSLocalizedString("_select_all_", comment: ""),
  430. icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
  431. action: { _ in
  432. self.collectionViewSelectAll()
  433. }
  434. )
  435. )
  436. //
  437. // Avaliable Offline
  438. //
  439. actions.append(
  440. NCMenuAction(
  441. title: isAnyOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  442. icon: NCUtility.shared.loadImage(named: "tray.and.arrow.down"),
  443. action: { _ in
  444. selectedMetadatas.forEach { metadata in
  445. self.setAvailableOffline(metadata: metadata, isOffline: isAnyOffline)
  446. }
  447. self.tapSelect(sender: self)
  448. }
  449. )
  450. )
  451. //
  452. // OPEN IN
  453. //
  454. actions.append(
  455. NCMenuAction(
  456. title: NSLocalizedString("_open_in_", comment: ""),
  457. icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
  458. action: { _ in
  459. NCFunctionCenter.shared.openActivityViewController(selectOcId: self.selectOcId)
  460. self.tapSelect(sender: self)
  461. }
  462. )
  463. )
  464. //
  465. // SAVE TO PHOTO GALLERY
  466. //
  467. actions.append(
  468. NCMenuAction(
  469. title: NSLocalizedString("_save_selected_files_", comment: ""),
  470. icon: NCUtility.shared.loadImage(named: "square.and.arrow.down"),
  471. action: { _ in
  472. selectedMetadatas.forEach { metadata in
  473. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
  474. if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
  475. NCFunctionCenter.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)
  476. } else if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  477. NCFunctionCenter.shared.saveAlbum(metadata: metadata)
  478. } else {
  479. NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
  480. }
  481. }
  482. }
  483. self.tapSelect(sender: self)
  484. }
  485. )
  486. )
  487. //
  488. // COPY - MOVE
  489. //
  490. actions.append(
  491. NCMenuAction(
  492. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  493. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  494. action: { _ in
  495. guard !selectedMetadatas.isEmpty else { return }
  496. NCFunctionCenter.shared.openSelectView(items: selectedMetadatas, viewController: self)
  497. self.tapSelect(sender: self)
  498. }
  499. )
  500. )
  501. //
  502. // COPY
  503. //
  504. actions.append(
  505. NCMenuAction(
  506. title: NSLocalizedString("_copy_file_", comment: ""),
  507. icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
  508. action: { _ in
  509. self.appDelegate.pasteboardOcIds.removeAll()
  510. for ocId in self.selectOcId {
  511. self.appDelegate.pasteboardOcIds.append(ocId)
  512. }
  513. NCFunctionCenter.shared.copyPasteboard()
  514. self.tapSelect(sender: self)
  515. }
  516. )
  517. )
  518. //
  519. // DELETE
  520. //
  521. actions.append(
  522. NCMenuAction(
  523. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  524. icon: NCUtility.shared.loadImage(named: "trash"),
  525. action: { _ in
  526. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  527. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
  528. selectedMetadatas.forEach {
  529. NCOperationQueue.shared.delete(metadata: $0, onlyLocalCache: false)
  530. }
  531. self.tapSelect(sender: self)
  532. })
  533. alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
  534. selectedMetadatas.forEach {
  535. NCOperationQueue.shared.delete(metadata: $0, onlyLocalCache: true)
  536. }
  537. self.tapSelect(sender: self)
  538. })
  539. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (_: UIAlertAction) in })
  540. self.present(alertController, animated: true, completion: nil)
  541. }
  542. )
  543. )
  544. presentMenu(with: actions)
  545. }
  546. }