NCCollectionViewCommon+Menu.swift 27 KB

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