|
@@ -217,7 +217,7 @@ import Cocoa
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
|
|
self.listView.delegate = nil
|
|
|
- self.listView.document.delegate = nil
|
|
|
+ self.listView.document?.delegate = nil
|
|
|
|
|
|
self.editPDFHanddler.clearData()
|
|
|
self.removeEventMonitor()
|
|
@@ -242,7 +242,7 @@ import Cocoa
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
|
|
|
self.listView.document = self.document
|
|
|
- self.listView.document.delegate = self
|
|
|
+ self.listView.document?.delegate = self
|
|
|
}
|
|
|
|
|
|
let autoScale = listView.autoScales
|
|
@@ -306,7 +306,7 @@ import Cocoa
|
|
|
return
|
|
|
}
|
|
|
if (self.model.password != nil) {
|
|
|
- if self.listView.document.unlock(withPassword: self.model.password) {
|
|
|
+ if let data = self.listView.document?.unlock(withPassword: self.model.password), data {
|
|
|
self.model.isSaveKeyChain = false
|
|
|
if self.model.needConvertNotes && self.tabViewIsDragging() == false {
|
|
|
self.showConvertNotesProgress()
|
|
@@ -395,9 +395,9 @@ import Cocoa
|
|
|
|
|
|
if (KMPreferenceManager.shared.openLastUnlockedDocumentWhenAppStart) {
|
|
|
if (self.listView.document != nil) {
|
|
|
- let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document.documentURL.path)
|
|
|
- let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document.documentURL.path)
|
|
|
- if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < self.listView.document.pageCount) {
|
|
|
+ let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
+ let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
+ if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < (self.listView.document?.pageCount ?? 0)) {
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
if (pageScale != nil) {
|
|
|
self.listView.scaleFactor = CGFloat(pageScale!)
|
|
@@ -673,13 +673,13 @@ import Cocoa
|
|
|
return pageNumber!
|
|
|
}
|
|
|
set {
|
|
|
- let pageCount = listView.document.pageCount
|
|
|
+ let pageCount = listView.document?.pageCount ?? 0
|
|
|
var value = newValue
|
|
|
if value > pageCount {
|
|
|
value = pageCount
|
|
|
}
|
|
|
if value > 0 && listView.currentPage().pageIndex() != value-1 {
|
|
|
- listView.go(to: listView.document.page(at: value-1))
|
|
|
+ listView.go(to: listView.document?.page(at: value-1))
|
|
|
}
|
|
|
if pageNumber != value {
|
|
|
pageNumber = value
|
|
@@ -697,7 +697,7 @@ import Cocoa
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if self.listView.document.allowsPrinting == false || self.listView.document.allowsCopying == false {
|
|
|
+ if self.listView.document?.allowsPrinting == false || self.listView.document?.allowsCopying == false {
|
|
|
Task {
|
|
|
_ = await KMAlertTool.runModel(message: KMLocalizedString("This is a secured document. Editing is not permitted.", nil))
|
|
|
}
|
|
@@ -720,7 +720,7 @@ import Cocoa
|
|
|
|
|
|
|
|
|
let ttsWindowC = KMTTSWindowController.share
|
|
|
- if ttsWindowC.pdfView?.document?.documentURL.path == self.listView.document.documentURL.path {
|
|
|
+ if ttsWindowC.pdfView?.document?.documentURL.path == self.listView.document?.documentURL.path {
|
|
|
if let data = ttsWindowC.window?.isVisible, data {
|
|
|
ttsWindowC.stopSpeaking()
|
|
|
ttsWindowC.close()
|
|
@@ -728,7 +728,7 @@ import Cocoa
|
|
|
}
|
|
|
NSColorPanel.shared.showsAlpha = false
|
|
|
|
|
|
- redactController = KMPDFRedactViewController(url: self.listView.document!.documentURL, password: self.listView.document.password)
|
|
|
+ redactController = KMPDFRedactViewController(url: self.listView.document!.documentURL, password: self.listView.document?.password)
|
|
|
self.addChild(redactController)
|
|
|
self.PDFContendView.addSubview(redactController.view)
|
|
|
redactController.view.frame = self.PDFContendView.bounds
|
|
@@ -752,7 +752,7 @@ import Cocoa
|
|
|
if saveResult {
|
|
|
let newDocument = CPDFDocument(url: saveUrl)
|
|
|
if let data = newDocument?.isLocked, data {
|
|
|
- newDocument?.unlock(withPassword: self?.listView.document.password ?? "")
|
|
|
+ newDocument?.unlock(withPassword: self?.listView.document?.password ?? "")
|
|
|
}
|
|
|
self?.document = newDocument
|
|
|
self?.listView.document = newDocument
|
|
@@ -1223,11 +1223,15 @@ import Cocoa
|
|
|
} else {
|
|
|
if self.needSaveDocument() {
|
|
|
self.saveDocumentWithProgressAlert { [unowned self] params in
|
|
|
- self.showDigitalSignWindow(withFilePathURL: self.listView.document.documentURL)
|
|
|
+ if (self.listView.document != nil) {
|
|
|
+ self.showDigitalSignWindow(withFilePathURL: self.listView.document.documentURL)
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- self.showDigitalSignWindow(withFilePathURL: self.listView.document.documentURL)
|
|
|
+ if (self.listView.document != nil) {
|
|
|
+ self.showDigitalSignWindow(withFilePathURL: self.listView.document.documentURL)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1262,7 +1266,7 @@ import Cocoa
|
|
|
// }
|
|
|
|
|
|
digitalSignController?.currentPageIndex = Int(currentPageIndex)
|
|
|
- digitalSignController?.url = listView.document.documentURL
|
|
|
+ digitalSignController?.url = listView.document?.documentURL
|
|
|
digitalSignController?.password = password
|
|
|
digitalSignController?.scaleFactor = listView.scaleFactor
|
|
|
|
|
@@ -1389,7 +1393,7 @@ import Cocoa
|
|
|
self?.currentWindowController = nil
|
|
|
|
|
|
let panel = NSSavePanel()
|
|
|
- panel.nameFieldStringValue = "[新文件]"+(self?.listView.document.documentURL.lastPathComponent)!
|
|
|
+ panel.nameFieldStringValue = "[新文件]"+((self?.listView.document?.documentURL.lastPathComponent) ?? "")
|
|
|
let button = NSButton.init(checkboxWithTitle: "保存后打开文档", target: nil, action: nil)
|
|
|
button.state = .on
|
|
|
panel.accessoryView = button
|
|
@@ -1409,9 +1413,9 @@ import Cocoa
|
|
|
|
|
|
(anno as! CPDFRedactAnnotation).applyRedaction()
|
|
|
} else if (type == .redactAll) {
|
|
|
- self?.listView.document.applyRedactions()
|
|
|
+ self?.listView.document?.applyRedactions()
|
|
|
} else if (type == .eraserOne) {
|
|
|
- let anno = self!.listView.activeAnnotation
|
|
|
+ let anno = self!.listView?.activeAnnotation
|
|
|
if (anno == nil || (anno?.isKind(of: CPDFRedactAnnotation.self)) == false) {
|
|
|
callback()
|
|
|
return
|
|
@@ -1427,7 +1431,7 @@ import Cocoa
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- self!.listView.document.write(to: panel.url)
|
|
|
+ self!.listView.document?.write(to: panel.url)
|
|
|
if (button.state == .on) {
|
|
|
NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { document, alreadyOpen, error in
|
|
|
|
|
@@ -1480,7 +1484,7 @@ import Cocoa
|
|
|
/// 解密成功
|
|
|
self?.hiddenSecureLimitTip()
|
|
|
self?.model.isSaveKeyChain = false
|
|
|
- self?.listView.document.unlock(withPassword: password)
|
|
|
+ self?.listView.document?.unlock(withPassword: password)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1529,14 +1533,14 @@ import Cocoa
|
|
|
DispatchQueue.main.async {
|
|
|
var documentURL = url
|
|
|
if documentURL == nil {
|
|
|
- documentURL = self.listView.document.documentURL
|
|
|
+ documentURL = self.listView.document?.documentURL
|
|
|
}
|
|
|
|
|
|
guard let _url = documentURL else { return }
|
|
|
guard let document = PDFDocument(url: _url) else { return }
|
|
|
|
|
|
self.mergeWindowController = KMMergeWindowController(document: document, password: password ?? "")
|
|
|
- self.mergeWindowController!.oriDucumentUrl = self.listView.document.documentURL
|
|
|
+ self.mergeWindowController!.oriDucumentUrl = self.listView.document?.documentURL
|
|
|
self.mergeWindowController!.pageIndex = self.listView.currentPageIndex
|
|
|
|
|
|
self.mergeWindowController!.cancelAction = { [unowned self] controller in
|
|
@@ -1558,7 +1562,7 @@ import Cocoa
|
|
|
self.securityWindowController = KMSecurityWindowController(windowNibName: "KMSecurityWindowController")
|
|
|
guard let securityWindowController = securityWindowController else { return }
|
|
|
|
|
|
- securityWindowController.documentURL = self.listView.document.documentURL
|
|
|
+ securityWindowController.documentURL = self.listView.document?.documentURL
|
|
|
securityWindowController.batchAction = { [unowned self] controller, files in
|
|
|
self.view.window?.endSheet((securityWindowController.window)!)
|
|
|
|
|
@@ -1612,7 +1616,7 @@ import Cocoa
|
|
|
}
|
|
|
|
|
|
let document: KMMainDocument? = self.myDocument as? KMMainDocument
|
|
|
- if (document?.isDocumentEdited == nil || document!.isDocumentEdited == false) {
|
|
|
+ if (document?.isDocumentEdited == nil || document?.isDocumentEdited == false) {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
@@ -1630,7 +1634,7 @@ import Cocoa
|
|
|
document?.save(nil)
|
|
|
return
|
|
|
}
|
|
|
- if (document?.isDocumentEdited == nil || document!.isDocumentEdited == false) {
|
|
|
+ if (document?.isDocumentEdited == nil || document?.isDocumentEdited == false) {
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1655,7 +1659,7 @@ import Cocoa
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- if (document?.isDocumentEdited == nil || document!.isDocumentEdited == false) {
|
|
|
+ if (document?.isDocumentEdited == nil || document?.isDocumentEdited == false) {
|
|
|
callback()
|
|
|
return
|
|
|
}
|
|
@@ -2160,12 +2164,12 @@ import Cocoa
|
|
|
if (self._documentFirstLoad) {
|
|
|
self.checkShouldAutoOpenLeftVC()
|
|
|
if (KMPreferenceManager.shared.openLastUnlockedDocumentWhenAppStart) {
|
|
|
- let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document.documentURL.path)
|
|
|
- let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document.documentURL.path)
|
|
|
+ let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
+ let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
if (pageScale != nil) {
|
|
|
self.listView.scaleFactor = CGFloat(pageScale!)
|
|
|
}
|
|
|
- if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < self.listView.document.pageCount) {
|
|
|
+ if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < (self.listView.document?.pageCount ?? 0)) {
|
|
|
self.listView.go(toPageIndex: pageNumber!, animated: false)
|
|
|
} else {
|
|
|
self._goToFirstPageForFristAppear()
|
|
@@ -2258,7 +2262,7 @@ import Cocoa
|
|
|
|
|
|
func CPDFDocumentPageCountChangedNotification(_ sender: Notification) {
|
|
|
if self.isReadMode {
|
|
|
- self.readModelView.totalPagesCount = Int(self.listView.document.pageCount)
|
|
|
+ self.readModelView.totalPagesCount = Int(self.listView.document?.pageCount ?? 0)
|
|
|
}
|
|
|
//刷新前一页后一页按钮
|
|
|
self.updateNextAndPreViousButtonState()
|