|
@@ -8,7 +8,6 @@
|
|
|
import Cocoa
|
|
|
|
|
|
class KMOutlineEditViewController: NSViewController {
|
|
|
-
|
|
|
@IBOutlet var outlineNameTextView: NSTextView!
|
|
|
@IBOutlet weak var outlineNameLabel: NSTextField!
|
|
|
@IBOutlet weak var outlineTargetPageIndexTextField: NSTextField!
|
|
@@ -18,25 +17,29 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
@IBOutlet weak var urlButton: NSButton!
|
|
|
@IBOutlet weak var mailAddressTextField: NSTextField!
|
|
|
@IBOutlet weak var mailButton: NSButton!
|
|
|
- var outline : CPDFOutline!
|
|
|
- var pdfView : CPDFListView!
|
|
|
+
|
|
|
+ weak var outline : CPDFOutline?
|
|
|
+ weak var pdfView : CPDFListView?
|
|
|
var originalURLString : String = ""
|
|
|
- var originalDestination : CPDFDestination?
|
|
|
+ weak var originalDestination : CPDFDestination?
|
|
|
var originalLabel : String = ""
|
|
|
var currentPageIndex : Int = 0
|
|
|
- convenience init(outline:CPDFOutline!,document:CPDFListView!) {
|
|
|
+
|
|
|
+ convenience init(outline: CPDFOutline?, document: CPDFListView?) {
|
|
|
self.init()
|
|
|
+
|
|
|
self.outline = outline
|
|
|
self.pdfView = document
|
|
|
}
|
|
|
|
|
|
-//MARK: Life cycle
|
|
|
override func loadView() {
|
|
|
super.loadView()
|
|
|
+
|
|
|
self.localizedLanguage()
|
|
|
}
|
|
|
|
|
|
- //MARK: Private Methods
|
|
|
+ //MARK: - Private Methods
|
|
|
+
|
|
|
private func localizedLanguage () {
|
|
|
self.outlineNameLabel.stringValue = "\(NSLocalizedString("Label", comment: ""))"
|
|
|
self.pageButton.title = "\(NSLocalizedString("Page", comment: ""))"
|
|
@@ -44,18 +47,26 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
self.outlineURLTextField.placeholderString = "\(NSLocalizedString("https://www.pdfreaderpro.com", comment: ""))"
|
|
|
self.mailButton.title = "Email:"
|
|
|
self.mailAddressTextField.placeholderString = "\(NSLocalizedString("support@pdfreaderpro.com", comment: ""))"
|
|
|
- self.outlineNameTextView.string = self.outline.label
|
|
|
+ self.outlineNameTextView.string = self.outline?.label ?? ""
|
|
|
}
|
|
|
|
|
|
private func adjustUIWithAction(action:CPDFAction!) {
|
|
|
+ guard let doc = self.pdfView?.document else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if action == nil {
|
|
|
- self.totalPageCountLabel.stringValue = " \(self.pdfView.document.pageCount)"
|
|
|
+ self.totalPageCountLabel.stringValue = " \(doc.pageCount)"
|
|
|
self.outlineTargetPageIndexTextField.stringValue = " \(self.currentPageIndex + 1)"
|
|
|
} else {
|
|
|
+ guard let outL = self.outline else {
|
|
|
+ return
|
|
|
+ }
|
|
|
if action.isKind(of: CPDFURLAction.self) {
|
|
|
- var newAction : CPDFURLAction = self.outline.action as! CPDFURLAction
|
|
|
- self.originalURLString = newAction.url()
|
|
|
+ var newAction : CPDFURLAction = self.outline?.action as! CPDFURLAction
|
|
|
var urlString : String = newAction.url()
|
|
|
+ self.originalURLString = urlString
|
|
|
+
|
|
|
if urlString.hasPrefix("mailto:") {
|
|
|
self.setONButton(button: self.mailButton)
|
|
|
self.enableTextField(textField: self.mailAddressTextField)
|
|
@@ -66,15 +77,15 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
self.enableTextField(textField: self.outlineURLTextField)
|
|
|
self.outlineURLTextField.stringValue = urlString
|
|
|
}
|
|
|
- self.currentPageIndex = Int(self.pdfView.document.index(for: self.pdfView.document.page(at: UInt(self.pdfView.currentPageIndex))))
|
|
|
+ self.currentPageIndex = Int(doc.index(for: doc.page(at: UInt(self.pdfView!.currentPageIndex))))
|
|
|
} else {
|
|
|
self.setONButton(button: self.pageButton)
|
|
|
self.enableTextField(textField: self.outlineTargetPageIndexTextField)
|
|
|
- self.currentPageIndex = Int(self.pdfView.document.index(for: self.pdfView.document.page(at: UInt(self.outline.destination.pageIndex))))
|
|
|
- self.originalDestination = self.outline.destination
|
|
|
+ self.currentPageIndex = Int(doc.index(for: doc.page(at: UInt(outL.destination.pageIndex))))
|
|
|
+ self.originalDestination = outL.destination
|
|
|
}
|
|
|
- self.originalLabel = self.outline.label
|
|
|
- self.totalPageCountLabel.stringValue = " /\(self.pdfView.document.pageCount)"
|
|
|
+ self.originalLabel = outL.label
|
|
|
+ self.totalPageCountLabel.stringValue = " /\(doc.pageCount)"
|
|
|
self.outlineTargetPageIndexTextField.stringValue = "\(self.currentPageIndex + 1)"
|
|
|
}
|
|
|
}
|
|
@@ -85,7 +96,7 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
|
|
|
var formatter = NumberFormatter()
|
|
|
formatter.numberStyle = .none
|
|
|
- formatter.maximum = NSNumber(value: self.pdfView.document.pageCount)
|
|
|
+ formatter.maximum = NSNumber(value: self.pdfView?.document?.pageCount ?? 0)
|
|
|
formatter.minimum = NSNumber(value: 1)
|
|
|
self.outlineTargetPageIndexTextField.formatter = formatter
|
|
|
}
|
|
@@ -118,12 +129,14 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
@IBAction func buttonClicked_GotoAction(_ sender: Any) {
|
|
|
self.setONButton(button: self.pageButton)
|
|
|
self.enableTextField(textField: self.outlineTargetPageIndexTextField)
|
|
|
+
|
|
|
self.view.window?.makeFirstResponder(self.outlineTargetPageIndexTextField)
|
|
|
}
|
|
|
|
|
|
@IBAction func buttonClicked_URLAction(_ sender: Any) {
|
|
|
self.setONButton(button: self.urlButton)
|
|
|
self.enableTextField(textField: self.outlineURLTextField)
|
|
|
+
|
|
|
self.view.window?.makeFirstResponder(self.outlineURLTextField)
|
|
|
if (self.outlineTargetPageIndexTextField.stringValue == "0" || self.outlineTargetPageIndexTextField.stringValue.lengthOfBytes(using: String.Encoding(rawValue: String.Encoding.utf16.rawValue)) < 1){
|
|
|
self.outlineTargetPageIndexTextField.stringValue = "\(self.currentPageIndex + 1)"
|
|
@@ -133,6 +146,7 @@ class KMOutlineEditViewController: NSViewController {
|
|
|
@IBAction func buttonClicked_MailAction(_ sender: Any) {
|
|
|
self.setONButton(button: self.mailButton)
|
|
|
self.enableTextField(textField: self.mailAddressTextField)
|
|
|
+
|
|
|
self.view.window?.makeFirstResponder(self.mailAddressTextField)
|
|
|
if (self.outlineTargetPageIndexTextField.stringValue == "0" || self.outlineTargetPageIndexTextField.stringValue.lengthOfBytes(using: String.Encoding(rawValue: String.Encoding.utf16.rawValue)) < 1){
|
|
|
self.outlineTargetPageIndexTextField.stringValue = "\(self.currentPageIndex + 1)"
|