소스 검색

【多页签】打开3个页签,拖拽其中一个到新窗口时,崩溃一次(概率性出现) -- 优化数据结构

lizhe 6 달 전
부모
커밋
44d9b7c8da

+ 1 - 2
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/KMHomeHistoryListView.swift

@@ -60,8 +60,7 @@ class KMHomeHistoryListView: KMBaseXibView {
         self.data.removeAll()
         for url in NSDocumentController.shared.recentDocumentURLs {
             if FileManager.default.fileExists(atPath: url.path) {
-                let file = KMFile()
-                file.filePath = url.path
+                let file = KMFileManager.manager.fetchFile(filePath: url.path)
                 self.data.append(file)
             }
         }

+ 16 - 1
PDF Office/PDF Master/Class/KMFileManager/KMFileManager.swift

@@ -8,5 +8,20 @@
 import Cocoa
 
 class KMFileManager: NSObject {
-
+    static let manager = KMFileManager()
+    
+    var files: [KMFile] = []
+    
+    func fetchFile(filePath: String) -> KMFile {
+        for file in files {
+            if file.filePath == filePath {
+                return file
+            }
+        }
+        
+        let file = KMFile()
+        file.filePath = filePath
+        self.files.append(file)
+        return file
+    }
 }