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