NCTrash+Menu.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NCTrash+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. // Copyright © 2022 Henrik Storch. All rights reserved.
  8. //
  9. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  10. // Author Henrik Storch <henrik.storch@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 NextcloudKit
  28. extension NCTrash {
  29. func toggleMenuMore(with objectId: String, image: UIImage?, isGridCell: Bool) {
  30. guard let resultTableTrash = self.database.getResultTrashItem(fileId: objectId, account: session.account) else { return }
  31. guard isGridCell else {
  32. let alert = UIAlertController(title: NSLocalizedString("_want_delete_", comment: ""), message: resultTableTrash.trashbinFileName, preferredStyle: .alert)
  33. alert.addAction(UIAlertAction(title: NSLocalizedString("_delete_", comment: ""), style: .destructive, handler: { _ in
  34. self.deleteItem(with: objectId)
  35. }))
  36. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel))
  37. self.present(alert, animated: true, completion: nil)
  38. return
  39. }
  40. var actions: [NCMenuAction] = []
  41. var iconHeader: UIImage!
  42. if let icon = utility.getImage(ocId: resultTableTrash.fileId, etag: resultTableTrash.fileName, ext: NCGlobal.shared.previewExt512) {
  43. iconHeader = icon
  44. } else {
  45. if resultTableTrash.directory {
  46. iconHeader = NCImageCache.shared.getFolder(account: resultTableTrash.account)
  47. } else {
  48. iconHeader = NCImageCache.shared.getImageFile()
  49. }
  50. }
  51. actions.append(
  52. NCMenuAction(
  53. title: resultTableTrash.trashbinFileName,
  54. icon: iconHeader,
  55. action: nil
  56. )
  57. )
  58. actions.append(
  59. NCMenuAction(
  60. title: NSLocalizedString("_restore_", comment: ""),
  61. icon: utility.loadImage(named: "arrow.circlepath", colors: [NCBrandColor.shared.iconImageColor]),
  62. action: { _ in
  63. self.restoreItem(with: objectId)
  64. }
  65. )
  66. )
  67. actions.append(
  68. NCMenuAction(
  69. title: NSLocalizedString("_delete_", comment: ""),
  70. destructive: true,
  71. icon: utility.loadImage(named: "trash", colors: [.red]),
  72. action: { _ in
  73. self.deleteItem(with: objectId)
  74. }
  75. )
  76. )
  77. presentMenu(with: actions)
  78. }
  79. }