NCCollectionViewCommon+Menu.swift 29 KB

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