Parcourir la source

【fix】【导航栏】文件-新建空白PDF,叉掉空白PDF-取消,应停留在当前空白PDF页面

tangchao il y a 6 mois
Parent
commit
8983403e10

+ 25 - 0
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -665,6 +665,31 @@ extension NSApplication {
             }
         })
     }
+    
+    // 新建空白文档
+    
+    public static func newBlankDocument() {
+        let panel = NSSavePanel()
+        panel.allowedFileTypes = ["pdf"]
+        let resp = panel.runModal()
+        if resp != .OK {
+            return
+        }
+//        panel.beginSheetModal(for: self.view.window!) { resp in
+//
+//        }
+        let saveUrl = panel.url!
+        let pdfDocument = CPDFDocument()
+        pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
+        pdfDocument?.write(to: saveUrl)
+        NSDocumentController.shared.km_safe_openDocument(withContentsOf: saveUrl, display: true) { document, documentWasAlreadyOpen, error in
+            guard let mainD = document as? KMMainDocument else {
+                return
+            }
+            // 新建空白文档 不需要注释转换
+            mainD.mainViewController?.model.needConvertNotes = false
+        }
+    }
 }
 
 @objc protocol KMInterfaceThemeChangedProtocol: NSObjectProtocol {

+ 27 - 26
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -761,32 +761,33 @@ extension KMHomeViewController {
     }
     
     func openBlankPage() {
-        let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
-        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
-        let filePath = savePath.deletingLastPathComponent
-        if FileManager.default.fileExists(atPath: filePath) == false {
-            try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
-        }
-        
-        let pdfDocument = CPDFDocument()
-        pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
-        pdfDocument?.write(to: URL(fileURLWithPath: savePath))
-        let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
-        if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
-            self.reopenDocument(forPaths: URL(fileURLWithPath: savePath))
-        }else {
-            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
-                if error != nil {
-                    NSApp.presentError(error!)
-                } else {
-                    if document is KMMainDocument {
-                        let newDocument = document
-                        (newDocument as! KMMainDocument).isNewCreated = true
-                    }
-                }
-    //            self.homeContentView?.reloadData()
-            }
-        }
+//        let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
+//        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
+//        let filePath = savePath.deletingLastPathComponent
+//        if FileManager.default.fileExists(atPath: filePath) == false {
+//            try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
+//        }
+//
+//        let pdfDocument = CPDFDocument()
+//        pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
+//        pdfDocument?.write(to: URL(fileURLWithPath: savePath))
+//        let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
+//        if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
+//            self.reopenDocument(forPaths: URL(fileURLWithPath: savePath))
+//        }else {
+//            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
+//                if error != nil {
+//                    NSApp.presentError(error!)
+//                } else {
+//                    if document is KMMainDocument {
+//                        let newDocument = document
+//                        (newDocument as! KMMainDocument).isNewCreated = true
+//                    }
+//                }
+//    //            self.homeContentView?.reloadData()
+//            }
+//        }
+        NSApplication.newBlankDocument()
     }
     
     func importFromWebPage() {