Browse Source

Home - 修复最近文件列表,单选、多选文件注释后,右键删除,未弹出二次确认按钮

wanjun 1 year ago
parent
commit
d9dd29d1e4

+ 96 - 77
PDF Office/PDF Master/Class/Home/ViewController/KMHomeHistoryFileViewController.swift

@@ -28,7 +28,8 @@ class KMHomeHistoryFileTableviewCell: NSTableCellView {
     var file: URL?
     var selectUrls: [URL] = []
     var isSelect: Bool = false
-    
+    var currentWindowController: NSWindowController?
+
     // MARK: Init
     
     override func awakeFromNib() {
@@ -201,19 +202,37 @@ class KMHomeHistoryFileTableviewCell: NSTableCellView {
     }
     
     @IBAction func buttonItemClick_ClosePath(_ sender: Any) {
-        var selects: [String] = []
+        var selects: [URL] = []
         if selectUrls.count > 0 {
             for selecturl in self.selectUrls {
-                selects.append(selecturl.path)
+                selects.append(selecturl)
             }
         } else {
-            selects.append(file!.path)
+            selects.append(file!)
+        }
+        
+        if UserDefaults.standard.bool(forKey: "kHistoryDeleteNOReminderKey") {
+            historyFileDeleteAction(selects)
+        } else {
+            let historyFileDeleteVC: KMHistoryFileDeleteWindowController = KMHistoryFileDeleteWindowController.init(windowNibName: NSNib.Name("KMHistoryFileDeleteWindowController"))
+            historyFileDeleteVC.indexPaths = selects
+            self.currentWindowController = historyFileDeleteVC
+            historyFileDeleteVC.deleteCallback = { [weak self](indexPaths: [URL], windowController: KMHistoryFileDeleteWindowController) -> Void in
+                if self != nil {
+                    self?.currentWindowController = nil
+                    self!.historyFileDeleteAction(indexPaths)
+                }
+            }
+            self.window?.beginSheet(historyFileDeleteVC.window!)
         }
+    }
+    
+    func historyFileDeleteAction(_ indexPaths: [URL]) -> Void {
         let urls: Array<URL> = NSDocumentController.shared.recentDocumentURLs
         NSDocumentController.shared.clearRecentDocuments(nil)
         DispatchQueue.main.asyncAfter(deadline: .now()) { [self] in
             for (_, url) in urls.enumerated() {
-                if !selects.contains(url.path) {
+                if !indexPaths.contains(url) {
                     NSDocumentController.shared.noteNewRecentDocumentURL(url)
                 }
             }
@@ -563,70 +582,70 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
 
             item.selectUrls = selectFiles
             item.refreshUI(url)
-            item.mainBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
+            item.mainBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
                 if self != nil {
                     if downEntered {
-                        if self!.allowMultipleChoices_shift {
-                            if self!.selectFiles_shift.count == 0 {
-                                self!.selectFiles.append(url)
-                                self!.selectFiles_shift.append(i)
-                            } else if self!.selectFiles_shift.count == 1 {
-                                let first = self!.selectFiles_shift[0] as Int
-                                self!.selectFiles.removeAll()
+                        if self.allowMultipleChoices_shift {
+                            if self.selectFiles_shift.count == 0 {
+                                self.selectFiles.append(url)
+                                self.selectFiles_shift.append(i)
+                            } else if self.selectFiles_shift.count == 1 {
+                                let first = self.selectFiles_shift[0] as Int
+                                self.selectFiles.removeAll()
                                 if first > i {
-                                    for path in self!.files[i...first] {
-                                        self!.selectFiles.append(path as! URL)
+                                    for path in self.files[i...first] {
+                                        self.selectFiles.append(path as! URL)
                                     }
                                 } else {
-                                    for path in self!.files[first...i] {
-                                        self!.selectFiles.append(path as! URL)
+                                    for path in self.files[first...i] {
+                                        self.selectFiles.append(path as! URL)
                                     }
                                 }
-                                self!.selectFiles_shift.append(i)
-                            } else if self!.selectFiles_shift.count == 2 {
-                                let first = self!.selectFiles_shift[0] as Int
-                                self!.selectFiles.removeAll()
+                                self.selectFiles_shift.append(i)
+                            } else if self.selectFiles_shift.count == 2 {
+                                let first = self.selectFiles_shift[0] as Int
+                                self.selectFiles.removeAll()
                                 if first > i {
-                                    for path in self!.files[i...first] {
-                                        self!.selectFiles.append(path as! URL)
+                                    for path in self.files[i...first] {
+                                        self.selectFiles.append(path as! URL)
                                     }
                                 } else {
-                                    for path in self!.files[first...i] {
-                                        self!.selectFiles.append(path as! URL)
+                                    for path in self.files[first...i] {
+                                        self.selectFiles.append(path as! URL)
                                     }
                                 }
-                                self!.selectFiles_shift[1] = i
+                                self.selectFiles_shift[1] = i
                             }
-                        } else if self!.allowMultipleChoices_cmd {
-                            if self!.selectFiles.contains(url) {
-                                self!.selectFiles.removeObject(url)
+                        } else if self.allowMultipleChoices_cmd {
+                            if self.selectFiles.contains(url) {
+                                self.selectFiles.removeObject(url)
                             } else {
-                                self!.selectFiles.append(url)
+                                self.selectFiles.append(url)
                             }
-                            if self!.selectFiles_shift.contains(i) {
-                                self!.selectFiles_shift.removeObject(i)
+                            if self.selectFiles_shift.contains(i) {
+                                self.selectFiles_shift.removeObject(i)
                             } else {
-                                self!.selectFiles_shift.append(i)
+                                self.selectFiles_shift.append(i)
                             }
                         } else {
-                            self!.selectFiles.removeAll()
-                            self!.selectFiles_shift.removeAll()
-                            self!.selectFiles.append(url)
-                            self!.selectFiles_shift.append(i)
+                            self.selectFiles.removeAll()
+                            self.selectFiles_shift.removeAll()
+                            self.selectFiles.append(url)
+                            self.selectFiles_shift.append(i)
                         }
                         collectionView.reloadData()
                     }
                 }
             }
-            item.mainBox.doubleCallback = { [weak self](downEntered: Bool, mouseBox: KMBox) -> Void in
+            item.mainBox.doubleCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox) -> Void in
                 if self != nil {
                     if downEntered {
-                        self!.selectFiles.removeAll()
+                        self.selectFiles.removeAll()
                         
                         var indexs: [URL] = []
-                        let index: URL = self!.files[i] as! URL
+                        let index: URL = self.files[i] as! URL
                         indexs.append(index)
-                        self!.delete?.historyFileViewController!(self!, didSelectItemsAt: indexs)
+                        self.delete?.historyFileViewController!(self, didSelectItemsAt: indexs)
                     }
                 }
             }
@@ -669,71 +688,71 @@ class KMHomeHistoryFileViewController: NSViewController, NSCollectionViewDelegat
         cellView.selectUrls = selectFiles
         cellView.initializeUI(url)
         cellView.highlightCell(multipleChoicesInts, row)
-        cellView.mainBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
+        cellView.mainBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
             if self != nil {
                 if downEntered {
-                    if self!.allowMultipleChoices_shift {
-                        if self!.selectFiles_shift.count == 0 {
-                            self!.selectFiles.append(url)
-                            self!.selectFiles_shift.append(row)
-                        } else if self!.selectFiles_shift.count == 1 {
-                            let first = self!.selectFiles_shift[0] as Int
-                            self!.selectFiles.removeAll()
+                    if self.allowMultipleChoices_shift {
+                        if self.selectFiles_shift.count == 0 {
+                            self.selectFiles.append(url)
+                            self.selectFiles_shift.append(row)
+                        } else if self.selectFiles_shift.count == 1 {
+                            let first = self.selectFiles_shift[0] as Int
+                            self.selectFiles.removeAll()
                             if first > row {
-                                for path in self!.files[row...first] {
-                                    self!.selectFiles.append(path as! URL)
+                                for path in self.files[row...first] {
+                                    self.selectFiles.append(path as! URL)
                                 }
                             } else {
-                                for path in self!.files[first...row] {
-                                    self!.selectFiles.append(path as! URL)
+                                for path in self.files[first...row] {
+                                    self.selectFiles.append(path as! URL)
                                 }
                             }
-                            self!.selectFiles_shift.append(row)
-                        } else if self!.selectFiles_shift.count == 2 {
-                            let first = self!.selectFiles_shift[0] as Int
-                            self!.selectFiles.removeAll()
+                            self.selectFiles_shift.append(row)
+                        } else if self.selectFiles_shift.count == 2 {
+                            let first = self.selectFiles_shift[0] as Int
+                            self.selectFiles.removeAll()
                             if first > row {
-                                for path in self!.files[row...first] {
-                                    self!.selectFiles.append(path as! URL)
+                                for path in self.files[row...first] {
+                                    self.selectFiles.append(path as! URL)
                                 }
                             } else {
-                                for path in self!.files[first...row] {
-                                    self!.selectFiles.append(path as! URL)
+                                for path in self.files[first...row] {
+                                    self.selectFiles.append(path as! URL)
                                 }
                             }
-                            self!.selectFiles_shift[1] = row
+                            self.selectFiles_shift[1] = row
                         }
-                    } else if self!.allowMultipleChoices_cmd {
-                        if self!.selectFiles.contains(url) {
-                            self!.selectFiles.removeObject(url)
+                    } else if self.allowMultipleChoices_cmd {
+                        if self.selectFiles.contains(url) {
+                            self.selectFiles.removeObject(url)
                         } else {
-                            self!.selectFiles.append(url)
+                            self.selectFiles.append(url)
                         }
-                        if self!.selectFiles_shift.contains(row) {
-                            self!.selectFiles_shift.removeObject(row)
+                        if self.selectFiles_shift.contains(row) {
+                            self.selectFiles_shift.removeObject(row)
                         } else {
-                            self!.selectFiles_shift.append(row)
+                            self.selectFiles_shift.append(row)
                         }
                     } else {
-                        self!.selectFiles.removeAll()
-                        self!.selectFiles_shift.removeAll()
-                        self!.selectFiles.append(url)
-                        self!.selectFiles_shift.append(row)
+                        self.selectFiles.removeAll()
+                        self.selectFiles_shift.removeAll()
+                        self.selectFiles.append(url)
+                        self.selectFiles_shift.append(row)
                     }
                     tableView.reloadData()
                 }
             }
         }
         
-        cellView.mainBox.doubleCallback = { [weak self](downEntered: Bool, mouseBox: KMBox) -> Void in
+        cellView.mainBox.doubleCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox) -> Void in
             if self != nil {
                 if downEntered {
-                    self!.selectFiles.removeAll()
+                    self.selectFiles.removeAll()
 
                     var indexs: [URL] = []
-                    let index: URL = self!.files[row] as! URL
+                    let index: URL = self.files[row] as! URL
                     indexs.append(index)
-                    self!.delete?.historyFileViewController!(self!, didSelectItemsAt: indexs)
+                    self.delete?.historyFileViewController!(self, didSelectItemsAt: indexs)
                 }
             }
         }

+ 14 - 1
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -339,7 +339,16 @@ extension KMHomeViewController {
     }
     
     func historyFileDeleteAction(_ indexPaths: [URL]) -> Void {
+//        NSDocumentController.shared.clearRecentDocuments(nil)
+        let urls: Array<URL> = NSDocumentController.shared.recentDocumentURLs
         NSDocumentController.shared.clearRecentDocuments(nil)
+        DispatchQueue.main.asyncAfter(deadline: .now()) { [self] in
+            for (_, url) in urls.enumerated() {
+                if !indexPaths.contains(url) {
+                    NSDocumentController.shared.noteNewRecentDocumentURL(url)
+                }
+            }
+        }
         historyFileViewController.reloadData()
     }
     
@@ -595,10 +604,13 @@ extension KMHomeViewController {
             if x >= 0 {
                 let point = NSPoint(x: x, y: eventPoint.y)
                 if historyFileViewController.historyFileCollectionView.frame.contains(point) ||
-                    historyFileViewController.historyFileTableView.frame.contains(point) {
+                    historyFileViewController.historyFileTableView.frame.contains(point) ||
+                    historyFileViewController.deleteBox.frame.contains(point) ||
+                    historyFileViewController.modeBox.frame.contains(point) {
                     
                 } else {
                     self.historyFileViewController.selectFiles.removeAll()
+                    self.historyFileViewController.selectFiles_shift.removeAll()
                     if self.historyFileViewController.showMode == .Thumbnail {
                         self.historyFileViewController.historyFileCollectionView.reloadData()
                     } else {
@@ -607,6 +619,7 @@ extension KMHomeViewController {
                 }
             } else {
                 self.historyFileViewController.selectFiles.removeAll()
+                self.historyFileViewController.selectFiles_shift.removeAll()
                 if self.historyFileViewController.showMode == .Thumbnail {
                     self.historyFileViewController.historyFileCollectionView.reloadData()
                 } else {