// // HistoryFilesManager.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/10/10. // import Foundation public enum HistoryFileShowMode : Int { case Thumbnail = 0 case List } class HistoryFilesManager: NSObject { @objc public static let manager = HistoryFilesManager() var showMode: HistoryFileShowMode = .Thumbnail { didSet { UserDefaults.standard.setValue(showMode.rawValue, forKey: "HistoryFileShowModeKey") UserDefaults.standard.synchronize() } }//显示模式 var files: [URL] = [] //列表文件 var selectFiles: [URL] = [] //选中的列表文件 override init() { super.init() self.refreshHistoryFile() if UserDefaults.standard.object(forKey: "SetHistoryFileShowModeKey") == nil { self.showMode = .Thumbnail UserDefaults.standard.setValue("show", forKey: "SetHistoryFileShowModeKey") UserDefaults.standard.synchronize() } else { self.showMode = HistoryFileShowMode(rawValue: UserDefaults.standard.integer(forKey: "HistoryFileShowModeKey"))! } } func refreshHistoryFile() -> Void { files.removeAll() for url in NSDocumentController.shared.recentDocumentURLs { if FileManager.default.fileExists(atPath: url.path) { files.append(url) } } let fileNumber = SettingsManager.sharedInstance.fileListCount if fileNumber <= files.count { let arr1 = files.prefix(fileNumber) files = Array(arr1) } } func historyFileDeleteAction(_ indexPaths: [URL]) -> Void { let urls: Array = NSDocumentController.shared.recentDocumentURLs NSDocumentController.shared.clearRecentDocuments(nil) for (_, url) in urls.enumerated() { if !indexPaths.contains(url) { NSDocumentController.shared.noteNewRecentDocumentURL(url) } } refreshHistoryFile() } }