|
@@ -42,6 +42,8 @@ class KMExtractImageWindowController: NSWindowController,PDFConvertObjectDelegat
|
|
|
@IBOutlet var pdfViewBG: NSView!
|
|
|
var preViewPDFView: CPDFView!
|
|
|
|
|
|
+ private var fileAttri_: KMFileAttribute?
|
|
|
+
|
|
|
deinit {
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
|
@@ -64,6 +66,9 @@ class KMExtractImageWindowController: NSWindowController,PDFConvertObjectDelegat
|
|
|
self.preViewPDFView.autoScales = true
|
|
|
self.preViewPDFView.layoutDocumentView()
|
|
|
self.preViewPDFView.go(toPageIndex: self.currentPage, animated: true)
|
|
|
+
|
|
|
+ self.fileAttri_ = KMFileAttribute()
|
|
|
+ self.fileAttri_?.filePath = url.path
|
|
|
}
|
|
|
self.allPageButton.title = NSLocalizedString("All Pages", comment: "")
|
|
|
self.singlePageButton.title = NSLocalizedString("Odd Pages Only", comment: "")
|
|
@@ -199,22 +204,26 @@ class KMExtractImageWindowController: NSWindowController,PDFConvertObjectDelegat
|
|
|
indeSet.add(IndexSet(integer: IndexSet.Element(index)))
|
|
|
}
|
|
|
} else {
|
|
|
- let fileAttribute = KMFileAttribute()
|
|
|
- fileAttribute.filePath = self.preViewPDFView.document?.documentURL?.path ?? ""
|
|
|
- fileAttribute.bAllPage = false
|
|
|
+ var fileAttribute = self.fileAttri_
|
|
|
+ if fileAttribute == nil {
|
|
|
+ self.fileAttri_ = KMFileAttribute()
|
|
|
+ self.fileAttri_?.filePath = self.preViewPDFView.document?.documentURL?.path ?? ""
|
|
|
+ fileAttribute = self.fileAttri_
|
|
|
+ }
|
|
|
+ fileAttribute?.bAllPage = false
|
|
|
if (self.customPageButton.state == .on){
|
|
|
- fileAttribute.pagesType = .custom
|
|
|
+ fileAttribute?.pagesType = .custom
|
|
|
}
|
|
|
- fileAttribute.pagesString = self.rangeTextField.stringValue
|
|
|
- if fileAttribute.fetchSelectPages().isEmpty {
|
|
|
+ fileAttribute?.pagesString = self.rangeTextField.stringValue
|
|
|
+ if let data = fileAttribute?.fetchSelectPages().isEmpty, data {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
|
- alert.messageText = "\(fileAttribute.filePath.lastPathComponent) \(NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: ""))"
|
|
|
+ alert.messageText = "\(fileAttribute?.filePath.lastPathComponent ?? "") \(NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: ""))"
|
|
|
alert.runModal()
|
|
|
return indeSet
|
|
|
}
|
|
|
|
|
|
- for num in fileAttribute.fetchSelectPages() {
|
|
|
+ for num in fileAttribute?.fetchSelectPages() ?? [] {
|
|
|
indeSet.add(num-1)
|
|
|
}
|
|
|
}
|
|
@@ -287,11 +296,17 @@ class KMExtractImageWindowController: NSWindowController,PDFConvertObjectDelegat
|
|
|
}
|
|
|
}
|
|
|
func checkPageRangeValidate(_ pageRangeString: String) -> Bool {
|
|
|
- let fileAttribute = KMFileAttribute()
|
|
|
- fileAttribute.filePath = self.preViewPDFView.document?.documentURL?.path ?? ""
|
|
|
- fileAttribute.bAllPage = false
|
|
|
- fileAttribute.pagesString = self.rangeTextField.stringValue
|
|
|
- if fileAttribute.fetchSelectPages().isEmpty || fileAttribute.fetchSelectPages().count < 1{
|
|
|
+ var fileAttribute = self.fileAttri_
|
|
|
+ if fileAttribute == nil {
|
|
|
+ self.fileAttri_ = KMFileAttribute()
|
|
|
+ self.fileAttri_?.filePath = self.preViewPDFView.document?.documentURL?.path ?? ""
|
|
|
+ fileAttribute = self.fileAttri_
|
|
|
+ }
|
|
|
+ fileAttribute?.bAllPage = false
|
|
|
+ fileAttribute?.pagesString = self.rangeTextField.stringValue
|
|
|
+ let isEmpty = fileAttribute?.fetchSelectPages().isEmpty ?? true
|
|
|
+ let cnt = fileAttribute?.fetchSelectPages().count ?? 0
|
|
|
+ if isEmpty || cnt < 1{
|
|
|
return false
|
|
|
}
|
|
|
return true
|