NCDetailNavigationController+Menu.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // NCDetailNavigationController+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/02/2020.
  6. // Copyright © 2020 Marino Faggiana All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import FloatingPanel
  24. import NCCommunication
  25. extension NCDetailNavigationController {
  26. private func initMoreMenu(viewController: UIViewController, metadata: tableMetadata) -> [NCMenuAction] {
  27. var actions = [NCMenuAction]()
  28. let fileNameExtension = (metadata.fileNameView as NSString).pathExtension.uppercased()
  29. let directEditingCreators = NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount)
  30. actions.append(
  31. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  32. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  33. action: { menuAction in
  34. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  35. }
  36. )
  37. )
  38. actions.append(
  39. NCMenuAction(title: NSLocalizedString("_share_", comment: ""),
  40. icon: CCGraphics.changeThemingColorImage(UIImage(named: "share"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  41. action: { menuAction in
  42. NCMainCommon.sharedInstance.openShare(ViewController: viewController, metadata: metadata, indexPage: 0)
  43. }
  44. )
  45. )
  46. actions.append(
  47. NCMenuAction(title: NSLocalizedString("_delete_", comment: ""),
  48. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  49. action: { menuAction in
  50. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  51. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  52. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
  53. NCMainCommon.sharedInstance.deleteFile(metadatas: [metadata], e2ee: directory.e2eEncrypted, serverUrl: metadata.serverUrl, folderocId: directory.ocId) { (errorCode, errorMessage) in
  54. if errorCode == 0 {
  55. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: metadata.serverUrl, ocId: metadata.ocId, action: k_action_DEL)
  56. self.appDelegate.activeDetail.viewUnload()
  57. } else {
  58. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  59. }
  60. }
  61. }
  62. })
  63. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
  64. self.present(alertController, animated: true, completion:nil)
  65. }
  66. )
  67. )
  68. if CCUtility.isDocumentModifiableExtension(fileNameExtension) && (directEditingCreators == nil || !appDelegate.reachability.isReachable()) {
  69. actions.append(
  70. NCMenuAction(title: NSLocalizedString("_internal_modify_", comment: ""),
  71. icon: CCGraphics.changeThemingColorImage(UIImage(named: "pencil"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  72. action: { menuAction in
  73. if let navigationController = UIStoryboard(name: "NCText", bundle: nil).instantiateViewController(withIdentifier: "NCText") as? UINavigationController {
  74. navigationController.modalPresentationStyle = .pageSheet
  75. navigationController.modalTransitionStyle = .crossDissolve
  76. if let textViewController = navigationController.topViewController as? NCText {
  77. textViewController.metadata = metadata;
  78. viewController.present(navigationController, animated: true, completion: nil)
  79. }
  80. }
  81. }
  82. )
  83. )
  84. }
  85. return actions
  86. }
  87. @objc func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata) {
  88. if appDelegate.activeDetail.subViewActive() != nil {
  89. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  90. mainMenuViewController.actions = self.initMoreMenu(viewController: viewController, metadata: metadata)
  91. let menuPanelController = NCMenuPanelController()
  92. menuPanelController.parentPresenter = viewController
  93. menuPanelController.delegate = mainMenuViewController
  94. menuPanelController.set(contentViewController: mainMenuViewController)
  95. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  96. viewController.present(menuPanelController, animated: true, completion: nil)
  97. }
  98. }
  99. }