NCCollectionViewCommon+Menu.swift 27 KB

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