NCCollectionViewCommon+Menu.swift 28 KB

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