Browse Source

【综合】页面编辑,页面范围自定义窗口偶发crash修复

tangchao 1 year ago
parent
commit
1e5946a041

+ 10 - 8
PDF Office/PDF Master/Class/PDFTools/PageEdit/Window/KMPDFEditPageRangeWindowController.swift

@@ -18,6 +18,8 @@ class KMPDFEditPageRangeWindowController: NSWindowController {
     @IBOutlet var cancelButton: NSButton!
     @IBOutlet var okButton: NSButton!
     
+    private var fileAttri_: KMFileAttribute?
+    
     override var windowNibName: NSNib.Name? {
         return "KMPDFEditPageRangeWindowController"
     }
@@ -39,6 +41,11 @@ class KMPDFEditPageRangeWindowController: NSWindowController {
         self.okButton.title = KMLocalizedString("OK", nil)
         
         self.window?.title = KMLocalizedString("Page Range", nil)
+        
+        self.fileAttri_ = KMFileAttribute()
+        self.fileAttri_?.filePath = self.pdfDocument?.documentURL.path ?? ""
+        self.fileAttri_?.bAllPage = false
+        self.fileAttri_?.pagesType = .custom
     }
     
     @IBAction func buttonClicked_Cancel(_ sender: AnyObject?) {
@@ -48,14 +55,9 @@ class KMPDFEditPageRangeWindowController: NSWindowController {
     }
 
     @IBAction func buttonClicked_Done(_ sender: AnyObject?) {
-        let fileAttribute = KMFileAttribute()
-        fileAttribute.filePath = self.pdfDocument?.documentURL.path ?? ""
-//        fileAttribute.pdfDocument = self.pdfDocument
-        fileAttribute.bAllPage = false
-        fileAttribute.pagesType = .custom
-        fileAttribute.pagesString = self.pageRangeTextField.stringValue
+        self.fileAttri_?.pagesString = self.pageRangeTextField.stringValue
         
-        if fileAttribute.fetchSelectPages().isEmpty {
+        if self.fileAttri_ == nil || self.fileAttri_!.fetchSelectPages().isEmpty {
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.messageText = String(format: "%@ %@", self.pdfDocument?.documentURL.lastPathComponent.lastPathComponent ?? "", KMLocalizedString("Invalid page range or the page number is out of range. Please try again.", nil))
@@ -64,7 +66,7 @@ class KMPDFEditPageRangeWindowController: NSWindowController {
             return
         } else {
             if (self.pageSelectCallBack != nil) {
-                self.pageSelectCallBack!(fileAttribute.fetchSelectPages());
+                self.pageSelectCallBack!(self.fileAttri_?.fetchSelectPages() ?? [])
             }
         }
     }