Browse Source

Bottomdrawer for NCTrash

Philippe Weidmann 5 years ago
parent
commit
d03492e5b2
1 changed files with 239 additions and 260 deletions
  1. 239 260
      iOSClient/Trash/NCTrash.swift

+ 239 - 260
iOSClient/Trash/NCTrash.swift

@@ -22,10 +22,9 @@
 //
 
 import Foundation
-import Sheeeeeeeeet
 import NCCommunication
 
-class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDelegate, NCGridCellDelegate, NCTrashSectionHeaderMenuDelegate, DropdownMenuDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate  {
+class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDelegate, NCGridCellDelegate, NCTrashSectionHeaderMenuDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate  {
     
     @IBOutlet fileprivate weak var collectionView: UICollectionView!
 
@@ -49,8 +48,6 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
     private var listLayout: NCListLayout!
     private var gridLayout: NCGridLayout!
     
-    private var actionSheet: ActionSheet?
-
     private let highHeader: CGFloat = 50
     
     private let refreshControl = UIRefreshControl()
@@ -118,7 +115,6 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
         
         coordinator.animate(alongsideTransition: nil) { _ in
             self.collectionView.collectionViewLayout.invalidateLayout()
-            self.actionSheet?.viewDidLayoutSubviews()
         }
     }
     
@@ -154,6 +150,17 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
     func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool {
         return true
     }
+    
+    func reloadSortOrder(){
+        NCUtility.sharedInstance.setLayoutForView(
+            key: k_layout_view_trash,
+            layout: self.typeLayout,
+            sort: self.datasourceSorted,
+            ascending: self.datasourceAscending,
+            groupBy: self.datasourceGroupBy,
+            directoryOnTop: self.datasourceDirectoryOnTop)
+        self.loadDatasource()
+    }
 
     // MARK: TAP EVENT
     
@@ -185,87 +192,131 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
     }
     
     func tapOrderHeaderMenu(sender: Any) {
+        let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
+        
+        var actions = [NCMenuAction]()
+        
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_order_by_name_a_z_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameAZ"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
+                onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameZA"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                selected: datasourceSorted == "fileName",
+                on: datasourceAscending,
+                action: { menuAction in
+                    if(self.datasourceSorted == "fileName"){
+                        self.datasourceAscending = !self.datasourceAscending
+                    } else {
+                        self.datasourceSorted = "fileName"
+                    }
+                    self.reloadSortOrder()
+                }
+            )
+        )
+        
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
+                onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                selected: datasourceSorted == "date",
+                on: datasourceAscending,
+                action: { menuAction in
+                    if(self.datasourceSorted == "date"){
+                        self.datasourceAscending = !self.datasourceAscending
+                    } else {
+                        self.datasourceSorted = "date"
+                    }
+                    self.reloadSortOrder()
+                }
+            )
+        )
+
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
+                onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                selected: datasourceSorted == "size",
+                on: datasourceAscending,
+                action: { menuAction in
+                    if(self.datasourceSorted == "size"){
+                        self.datasourceAscending = !self.datasourceAscending
+                    } else {
+                        self.datasourceSorted = "size"
+                    }
+                    self.reloadSortOrder()
+                }
+            )
+        )
+    
+        mainMenuViewController.actions = actions
         
-        var menuView: DropdownMenu?
-        var selectedRow = 0
-        
-        let item1 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameAZ"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_name_a_z_", comment: ""))
-        let item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameZA"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_name_z_a_", comment: ""))
-        let item3 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateMoreRecent"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_date_more_recent_", comment: ""))
-        let item4 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateLessRecent"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_date_less_recent_", comment: ""))
-        let item5 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortSmallest"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_size_smallest_", comment: ""))
-        let item6 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortLargest"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_order_by_size_largest_", comment: ""))
-        
-        switch datasourceSorted {
-        case "fileName":
-            if datasourceAscending == true { item1.style = .highlight; selectedRow = 0 }
-            if datasourceAscending == false { item2.style = .highlight; selectedRow = 1 }
-        case "date":
-            if datasourceAscending == false { item3.style = .highlight; selectedRow = 2 }
-            if datasourceAscending == true { item4.style = .highlight; selectedRow = 3 }
-        case "size":
-            if datasourceAscending == true { item5.style = .highlight; selectedRow = 4 }
-            if datasourceAscending == false { item6.style = .highlight; selectedRow = 5 }
-        default:
-            print("")
-        }
-        
-        menuView = DropdownMenu(navigationController: self.navigationController!, items: [item1, item2, item3, item4, item5, item6], selectedRow: selectedRow)
-        menuView?.token = "tapOrderHeaderMenu"
-        menuView?.delegate = self
-        menuView?.rowHeight = 45
-        menuView?.highlightColor = NCBrandColor.sharedInstance.brand
-        menuView?.tableView.alwaysBounceVertical = false
-        menuView?.tableViewSeperatorColor = NCBrandColor.sharedInstance.separator
-        menuView?.tableViewBackgroundColor = NCBrandColor.sharedInstance.backgroundForm
-        menuView?.cellBackgroundColor = NCBrandColor.sharedInstance.backgroundForm
-        menuView?.textColor = NCBrandColor.sharedInstance.textView
-
-        let header = (sender as? UIButton)?.superview as! NCTrashSectionHeaderMenu
-        let headerRect = self.collectionView.convert(header.bounds, from: self.view)
-        let menuOffsetY =  headerRect.height - headerRect.origin.y - 2
-        menuView?.topOffsetY = CGFloat(menuOffsetY)
-        
-        menuView?.showMenu()
+        let menuPanelController = NCMenuPanelController()
+        menuPanelController.parentPresenter = self
+        menuPanelController.delegate = mainMenuViewController
+        menuPanelController.set(contentViewController: mainMenuViewController)
+        menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+        self.present(menuPanelController, animated: true, completion: nil)
     }
     
     func tapMoreHeaderMenu(sender: Any) {
+        let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
         
-        var menuView: DropdownMenu?
-        
+        var actions = [NCMenuAction]()
+                
         if isEditMode {
-            
-            //let item0 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedNo"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_cancel_", comment: ""))
-            //let item1 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "restore"), multiplier: 1, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_trash_restore_selected_", comment: ""))
-            let item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_trash_delete_selected_", comment: ""))
-            
-            menuView = DropdownMenu(navigationController: self.navigationController!, items: [item2], selectedRow: -1)
-            menuView?.token = "tapMoreHeaderMenuSelect"
-            
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_trash_delete_selected_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
+                    action: { menuAction in
+                        let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert)
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
+                            for ocId in self.selectocId {
+                                self.deleteItem(with: ocId)
+                            }
+                            self.isEditMode = false
+                            self.selectocId.removeAll()
+                            self.collectionView.reloadData()
+                        }))
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
+                        }))
+                        self.present(alert, animated: true, completion: nil)
+                    }
+                )
+            )
         } else {
-            
-            //let item0 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "select"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_select_", comment: ""))
-            //let item1 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "restore"), multiplier: 1, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_trash_restore_all_", comment: ""))
-            let item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), title:  NSLocalizedString("_trash_delete_all_", comment: ""))
-            
-            menuView = DropdownMenu(navigationController: self.navigationController!, items: [item2], selectedRow: -1)
-            menuView?.token = "tapMoreHeaderMenu"
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_trash_delete_all_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
+                    action: { menuAction in
+                        let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_", comment: ""), message: "", preferredStyle: .alert)
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
+                            self.emptyTrash()
+                        }))
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
+                        }))
+                        self.present(alert, animated: true, completion: nil)
+                    }
+                )
+            )
         }
         
-        menuView?.delegate = self
-        menuView?.rowHeight = 45
-        menuView?.highlightColor = NCBrandColor.sharedInstance.brand
-        menuView?.tableView.alwaysBounceVertical = false
-        menuView?.tableViewBackgroundColor = NCBrandColor.sharedInstance.backgroundForm
-        menuView?.cellBackgroundColor = NCBrandColor.sharedInstance.backgroundForm
-        menuView?.textColor = NCBrandColor.sharedInstance.textView
-        
-        let header = (sender as? UIButton)?.superview as! NCTrashSectionHeaderMenu
-        let headerRect = self.collectionView.convert(header.bounds, from: self.view)
-        let menuOffsetY =  headerRect.height - headerRect.origin.y - 2
-        menuView?.topOffsetY = CGFloat(menuOffsetY)
+        mainMenuViewController.actions = actions
         
-        menuView?.showMenu()
+        let menuPanelController = NCMenuPanelController()
+        menuPanelController.parentPresenter = self
+        menuPanelController.delegate = mainMenuViewController
+        menuPanelController.set(contentViewController: mainMenuViewController)
+        menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+        self.present(menuPanelController, animated: true, completion: nil)
     }
     
     func tapRestoreListItem(with ocId: String, sender: Any) {
@@ -280,214 +331,142 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel
     }
     
     func tapMoreListItem(with objectId: String, sender: Any) {
-
         if !isEditMode {
-            var items = [MenuItem]()
-            
-            ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-            ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
-            ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-            ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
-            
-            items.append(DestructiveButton(title: NSLocalizedString("_delete_", comment: "")))
-            items.append(CancelButton(title: NSLocalizedString("_cancel_", comment: "")))
-            
-            actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
-                if item is DestructiveButton { self.deleteItem(with: objectId) }
-                if item is CancelButton { print("Cancel buttons has the value `true`") }
-            })
-            
+            let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
+
+            var actions = [NCMenuAction]()
+
             guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileId: objectId, account: appDelegate.activeAccount) else {
                 return
             }
-            
-            let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: tableTrash.directory, iconName: tableTrash.iconName, ocId: tableTrash.fileId, fileNameView: tableTrash.fileName, text: tableTrash.trashbinFileName)
-            actionSheet?.headerView = headerView
-            actionSheet?.headerView?.frame.size.height = 50
-            
-            actionSheet?.present(in: self, from: sender as! UIButton)
+
+            var iconHeader: UIImage!
+            if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, fileNameView: tableTrash.fileName)) {
+                iconHeader = icon
+            } else {
+                if(tableTrash.directory) {
+                    iconHeader = CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
+                } else {
+                    iconHeader = UIImage(named: tableTrash.iconName)
+                }
+            }
+
+            actions.append(
+                NCMenuAction(
+                    title: tableTrash.trashbinFileName,
+                    icon: iconHeader,
+                    action: nil
+                )
+            )
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_delete_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
+                    action: { menuAction in
+                        self.deleteItem(with: objectId)
+                    }
+                )
+            )
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_cancel_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "cancel"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    action: { menuAction in }
+                )
+            )
+
+            mainMenuViewController.actions = actions
+
+            let menuPanelController = NCMenuPanelController()
+            menuPanelController.parentPresenter = self
+            menuPanelController.delegate = mainMenuViewController
+            menuPanelController.set(contentViewController: mainMenuViewController)
+            menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+            self.present(menuPanelController, animated: true, completion: nil)
         } else {
-            let buttonPosition:CGPoint = (sender as! UIButton).convert(CGPoint.zero, to:collectionView)
+            let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
             let indexPath = collectionView.indexPathForItem(at: buttonPosition)
             collectionView(self.collectionView, didSelectItemAt: indexPath!)
         }
     }
     
     func tapMoreGridItem(with objectId: String, sender: Any) {
-        
         if !isEditMode {
-            var items = [MenuItem]()
+            let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
+
+            var actions = [NCMenuAction]()
 
-            ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-            ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
-            ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-            ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
-            
-            items.append(MenuItem(title: NSLocalizedString("_restore_", comment: ""), value: 0, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "restore"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
-            items.append(MenuItem(title: NSLocalizedString("_delete_", comment: ""), value: 1, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: UIColor.red)))
-            items.append(CancelButton(title: NSLocalizedString("_cancel_", comment: "")))
-            
-            actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
-                if item.value as? Int == 0 { self.restoreItem(with: objectId) }
-                if item.value as? Int == 1 { self.deleteItem(with: objectId) }
-                if item is CancelButton { print("Cancel buttons has the value `true`") }
-            })
-            
             guard let tableTrash = NCManageDatabase.sharedInstance.getTrashItem(fileId: objectId, account: appDelegate.activeAccount) else {
                 return
             }
-            
-            let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: tableTrash.directory, iconName: tableTrash.iconName, ocId: tableTrash.fileId, fileNameView: tableTrash.fileName, text: tableTrash.trashbinFileName)
-            actionSheet?.headerView = headerView
-            actionSheet?.headerView?.frame.size.height = 50
-            
-            actionSheet?.present(in: self, from: sender as! UIButton)
-        } else {
-            let buttonPosition:CGPoint = (sender as! UIButton).convert(CGPoint.zero, to:collectionView)
-            let indexPath = collectionView.indexPathForItem(at: buttonPosition)
-            collectionView(self.collectionView, didSelectItemAt: indexPath!)
-        }
-    }
-    
-    // MARK: DROP-DOWN-MENU
-
-    func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath) {
-        
-        if dropdownMenu.token == "tapOrderHeaderMenu" {
-            
-            switch indexPath.row {
-                
-            case 0: datasourceSorted = "fileName"; datasourceAscending = true
-            case 1: datasourceSorted = "fileName"; datasourceAscending = false
-                
-            case 2: datasourceSorted = "date"; datasourceAscending = false
-            case 3: datasourceSorted = "date"; datasourceAscending = true
-                
-            case 4: datasourceSorted = "size"; datasourceAscending = true
-            case 5: datasourceSorted = "size"; datasourceAscending = false
-                
-            default: print("")
-            }
-            
-            NCUtility.sharedInstance.setLayoutForView(key: k_layout_view_trash, layout: typeLayout, sort: datasourceSorted, ascending: datasourceAscending, groupBy: datasourceGroupBy, directoryOnTop: datasourceDirectoryOnTop)
 
-            loadDatasource()
-        }
-        
-        if dropdownMenu.token == "tapMoreHeaderMenu" {
-        
-            /*
-            // Select
-            if indexPath.row == 0 {
-                isEditMode = true
-                collectionView.reloadData()
-            }
-            
-            // Restore ALL
-            if indexPath.row == 1 {
-                for record: tableTrash in self.datasource {
-                    restoreItem(with: record.ocId)
+            var iconHeader: UIImage!
+            if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, fileNameView: tableTrash.fileName)) {
+                iconHeader = icon
+            } else {
+                if(tableTrash.directory) {
+                    iconHeader = CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
+                } else {
+                    iconHeader = UIImage(named: tableTrash.iconName)
                 }
             }
-            */
-            
-            // Empty Trash
-            if indexPath.row == 0 {
-                
-                var items = [MenuItem]()
-                
-                ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-                ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
-                ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-                ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
-                
-                items.append(MenuItem(title: NSLocalizedString("_trash_delete_all_", comment: "")))
-                items.append(DestructiveButton(title: NSLocalizedString("_ok_", comment: "")))
-                items.append(CancelButton(title: NSLocalizedString("_cancel_", comment: "")))
-                
-                actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
-                    if item is DestructiveButton {
-                        self.emptyTrash()
-                        //for record: tableTrash in self.datasource {
-                        //    self.deleteItem(with: record.ocId)
-                        //}
+
+            actions.append(
+                NCMenuAction(
+                    title: tableTrash.trashbinFileName,
+                    icon: iconHeader,
+                    action: nil
+                )
+            )
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_restore_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "restore"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    action: { menuAction in
+                        self.restoreItem(with: objectId)
                     }
-                    if item is CancelButton { return }
-                })
-                
-                actionSheet?.present(in: self, from: self.view)
-            }
-        }
-        
-        if dropdownMenu.token == "tapMoreHeaderMenuSelect" {
-            
-            // Cancel
-            if indexPath.row == 0 {
-                isEditMode = false
-                selectocId.removeAll()
-                collectionView.reloadData()
-            }
-            
-            // Restore selected files
-            if indexPath.row == 1 {
-                for ocId in selectocId {
-                    restoreItem(with: ocId)
-                }
-                isEditMode = false
-                selectocId.removeAll()
-                collectionView.reloadData()
-            }
-            
-            // Delete selected files
-            if indexPath.row == 2 {
-                
-                var items = [MenuItem]()
-                
-                ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-                ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
-                ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
-                ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
-                
-                items.append(MenuItem(title: NSLocalizedString("_trash_delete_selected_", comment: "")))
-                items.append(DestructiveButton(title: NSLocalizedString("_delete_", comment: "")))
-                items.append(CancelButton(title: NSLocalizedString("_cancel_", comment: "")))
-                
-                actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
-                    if item is DestructiveButton {
-                        for ocId in self.selectocId {
-                            self.deleteItem(with: ocId)
-                        }
-                        self.isEditMode = false
-                        self.selectocId.removeAll()
-                        self.collectionView.reloadData()
+                )
+            )
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_delete_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
+                    action: { menuAction in
+                        self.deleteItem(with: objectId)
                     }
-                    if item is CancelButton { return }
-                })
-                
-                actionSheet?.present(in: self, from: self.view)
-            }
-            
-        }
-    }
-    
-    /*
-    func dropdownMenuWillDismiss(_ dropdownMenu: DropdownMenu) {
-        if dropdownMenu.token == "tapOrderHeaderMenu" {
-            let trashHeader = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: IndexPath(row: 0, section: 0)) as! NCTrashHeaderMenu
-            let title = String(trashHeader.buttonOrder.title(for: .normal)!.dropLast()) + "▽"
-            trashHeader.buttonOrder.setTitle(title, for: .normal)
+                )
+            )
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_cancel_", comment: ""),
+                    icon: CCGraphics.changeThemingColorImage(UIImage(named: "cancel"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                    action: { menuAction in }
+                )
+            )
+
+            mainMenuViewController.actions = actions
+
+            let menuPanelController = NCMenuPanelController()
+            menuPanelController.parentPresenter = self
+            menuPanelController.delegate = mainMenuViewController
+            menuPanelController.set(contentViewController: mainMenuViewController)
+            menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+            self.present(menuPanelController, animated: true, completion: nil)
+
+        } else {
+            let buttonPosition: CGPoint = (sender as! UIButton).convert(CGPoint.zero, to: collectionView)
+            let indexPath = collectionView.indexPathForItem(at: buttonPosition)
+            collectionView(self.collectionView, didSelectItemAt: indexPath!)
         }
     }
     
-    func dropdownMenuWillShow(_ dropdownMenu: DropdownMenu) {
-        
-        if dropdownMenu.token == "tapOrderHeaderMenu" {
-            let trashHeader = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: IndexPath(row: 0, section: 0)) as! NCTrashHeaderMenu
-            let title = String(trashHeader.buttonOrder.title(for: .normal)!.dropLast()) + "△"
-            trashHeader.buttonOrder.setTitle(title, for: .normal)
-        }
-    }
-    */
 }
 
 // MARK: - Collection View