NCTrash+Menu.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 NCCommunication
  28. extension NCTrash {
  29. func toggleMenuMore(with objectId: String, image: UIImage?, isGridCell: Bool) {
  30. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  31. return
  32. }
  33. var actions: [NCMenuAction] = []
  34. var iconHeader: UIImage!
  35. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  36. iconHeader = icon
  37. } else {
  38. if tableTrash.directory {
  39. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  40. } else {
  41. iconHeader = UIImage(named: tableTrash.iconName)
  42. }
  43. }
  44. actions.append(
  45. NCMenuAction(
  46. title: tableTrash.trashbinFileName,
  47. icon: iconHeader,
  48. action: nil
  49. )
  50. )
  51. actions.append(
  52. NCMenuAction(
  53. title: NSLocalizedString("_restore_", comment: ""),
  54. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  55. action: { _ in
  56. self.restoreItem(with: objectId)
  57. }
  58. )
  59. )
  60. actions.append(
  61. NCMenuAction(
  62. title: NSLocalizedString("_trash_delete_permanently_", comment: ""),
  63. icon: NCUtility.shared.loadImage(named: "trash"),
  64. action: { _ in
  65. self.deleteItem(with: objectId)
  66. }
  67. )
  68. )
  69. presentMenu(with: actions)
  70. }
  71. }