marinofaggiana 3 жил өмнө
parent
commit
e6344f5b22

+ 36 - 38
Share/NCShareExtension.swift

@@ -458,43 +458,6 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
     }
     
-    @objc func moreButtonPressed(sender: NCShareExtensionButtonWithIndexPath) {
-        
-        if let fileName = sender.fileName {
-            let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
-            
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .default) { (action:UIAlertAction) in
-                if let index = self.filesName.firstIndex(of: fileName) {
-                    
-                    self.filesName.remove(at: index)
-                    if self.filesName.count == 0 {
-                        self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
-                    } else {
-                        self.setCommandView()
-                    }
-                }
-            })
-            
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { (action:UIAlertAction) in
-                
-                if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
-                
-                    vcRename.delegate = self
-                    vcRename.fileName = fileName
-                    vcRename.imagePreview = sender.image
-
-                    let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
-                                            
-                    self.present(popup, animated: true)
-                }
-            })
-            
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (action:UIAlertAction) in })
-            
-            self.present(alertController, animated: true, completion:nil)
-        }
-    }
-    
     func accountRequestChangeAccount(account: String) {
         setAccount(account: account)
     }
@@ -701,8 +664,43 @@ extension NCShareExtension: UITableViewDataSource {
         moreButton?.indexPath = indexPath
         moreButton?.fileName = fileName
         moreButton?.image = imageCell?.image
-        moreButton?.addTarget(self, action:#selector(moreButtonPressed(sender:)), for: .touchUpInside)
+        moreButton?.action(for: .touchUpInside, { sender in
+            
+            if let fileName = (sender as! NCShareExtensionButtonWithIndexPath).fileName {
+                let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
+                
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .default) { (action:UIAlertAction) in
+                    if let index = self.filesName.firstIndex(of: fileName) {
+                        
+                        self.filesName.remove(at: index)
+                        if self.filesName.count == 0 {
+                            self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
+                        } else {
+                            self.setCommandView()
+                        }
+                    }
+                })
+                
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { (action:UIAlertAction) in
+                    
+                    if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {
+                    
+                        vcRename.delegate = self
+                        vcRename.fileName = fileName
+                        vcRename.imagePreview = (sender as! NCShareExtensionButtonWithIndexPath).image
 
+                        let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
+                                                
+                        self.present(popup, animated: true)
+                    }
+                })
+                
+                alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (action:UIAlertAction) in })
+                
+                self.present(alertController, animated: true, completion:nil)
+            }
+        })
+        
         return cell
     }
 }

+ 41 - 44
iOSClient/ScanDocument/ScanCollectionView.swift

@@ -409,7 +409,18 @@ extension DragDropViewController : UICollectionViewDataSource {
             }
             
             cell.customImageView?.image = image
-            cell.delete.addTarget(self, action: #selector(deleteSource(_:)), for: .touchUpInside)
+            cell.delete.action(for: .touchUpInside) { sender in
+                
+                let buttonPosition:CGPoint = (sender as! UIButton).convert(.zero, to: self.collectionViewSource)
+                if let indexPath = self.collectionViewSource.indexPathForItem(at: buttonPosition) {
+                
+                    let fileNameAtPath = CCUtility.getDirectoryScan() + "/" + self.itemsSource[indexPath.row]
+                    CCUtility.removeFile(atPath: fileNameAtPath)
+                    self.itemsSource.remove(at: indexPath.row)
+                    
+                    self.collectionViewSource.reloadData()
+                }
+            }
 
             return cell
             
@@ -429,53 +440,39 @@ extension DragDropViewController : UICollectionViewDataSource {
             
             cell.customImageView?.image = self.filter(image: image)
             cell.customLabel.text = NSLocalizedString("_scan_document_pdf_page_", comment: "") + " " + "\(indexPath.row+1)"
-            cell.delete.addTarget(self, action: #selector(deleteDestination(_:)), for: .touchUpInside)
-            cell.rotate.addTarget(self, action: #selector(rotateDestination(_:)), for: .touchUpInside)
+            cell.delete.action(for: .touchUpInside) { sender in
+                
+                let buttonPosition:CGPoint = (sender as! UIButton).convert(.zero, to: self.collectionViewDestination)
+                if let indexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition) {
+                
+                    self.imagesDestination.remove(at: indexPath.row)
+                    self.itemsDestination.remove(at: indexPath.row)
+                    
+                    self.collectionViewDestination.reloadData()
+                    
+                    // Save button
+                    if self.imagesDestination.count == 0 {
+                        self.save.isEnabled = false
+                    } else {
+                        self.save.isEnabled = true
+                    }
+                }
+            }
+            cell.rotate.action(for: .touchUpInside) { sender in
+                
+                let buttonPosition:CGPoint = (sender as! UIButton).convert(.zero, to: self.collectionViewDestination)
+                if let indexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition) {
+                
+                    let image = self.imagesDestination[indexPath.row]
+                    self.imagesDestination[indexPath.row] = image.rotate(radians: .pi/2)!
+                    
+                    self.collectionViewDestination.reloadData()
+                }
+            }
             
             return cell
         }
     }
-    
-    @objc func deleteSource(_ sender: UIButton) {
-        
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewSource)
-        let indexPath:IndexPath = collectionViewSource.indexPathForItem(at: buttonPosition)!
-        
-        let fileNameAtPath = CCUtility.getDirectoryScan() + "/" + itemsSource[indexPath.row]
-        CCUtility.removeFile(atPath: fileNameAtPath)
-        itemsSource.remove(at: indexPath.row)
-        
-        collectionViewSource.reloadData()
-    }
-    
-    @objc func deleteDestination(_ sender:UIButton) {
-        
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewDestination)
-        let indexPath:IndexPath = collectionViewDestination.indexPathForItem(at: buttonPosition)!
-        
-        imagesDestination.remove(at: indexPath.row)
-        itemsDestination.remove(at: indexPath.row)
-        
-        collectionViewDestination.reloadData()
-        
-        // Save button
-        if imagesDestination.count == 0 {
-            save.isEnabled = false
-        } else {
-            save.isEnabled = true
-        }
-    }
-    
-    @objc func rotateDestination(_ sender:UIButton) {
-        
-        let buttonPosition:CGPoint =  sender.convert(.zero, to: collectionViewDestination)
-        let indexPath:IndexPath = collectionViewDestination.indexPathForItem(at: buttonPosition)!
-        
-        let image = imagesDestination[indexPath.row]
-        imagesDestination[indexPath.row] = image.rotate(radians: .pi/2)!
-        
-        collectionViewDestination.reloadData()
-    }
 }
 
 extension UIImage {