|
@@ -37,6 +37,8 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
|
|
|
var pageCount = 0
|
|
|
|
|
|
+ var itemClick: KMCommonClickBlock?
|
|
|
+
|
|
|
private lazy var inputView_: ComponentTextarea = {
|
|
|
let view = ComponentTextarea()
|
|
|
view.properties = ComponentTextareaProperty(size: .m, state: .pressed, isError: false, placeholderString: "", totalCount: -1, text: "", isDisabled: false)
|
|
@@ -49,9 +51,20 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
- private lazy var pageInput_: ComponentInputAddon = {
|
|
|
- let view = ComponentInputAddon()
|
|
|
- view.properties = ComponentInputAddonProperty(size: .s, state: .normal, isDisabled: false, addOnBefore: false, onlyRead: true, addonType: .textWithColor, iconImage: nil, text: KMLocalizedString("11"))
|
|
|
+ private lazy var pageInput_: ComponentInput = {
|
|
|
+ let view = ComponentInput()
|
|
|
+// view.properties = ComponentInputAddonProperty(size: .s, state: .normal, isDisabled: false, addOnBefore: false, onlyRead: true, addonType: .textWithColor, iconImage: nil, text: KMLocalizedString("11"))
|
|
|
+ let inputWithAddonProperty = ComponentInputProperty(size: .s,
|
|
|
+ state: .normal,
|
|
|
+ isError: false,
|
|
|
+ showPrefix: false,
|
|
|
+ showSuffix: false,
|
|
|
+ showClear: false,
|
|
|
+ isDisabled: true,
|
|
|
+ placeholder: "",
|
|
|
+ text: "",
|
|
|
+ creatable: true)
|
|
|
+ view.properties = inputWithAddonProperty
|
|
|
return view
|
|
|
}()
|
|
|
|
|
@@ -96,6 +109,42 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
+ var pageRadio: ComponentRadio {
|
|
|
+ get {
|
|
|
+ return pageRadio_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var pageInput: ComponentInput {
|
|
|
+ get {
|
|
|
+ return pageInput_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var webRaido: ComponentRadio {
|
|
|
+ get {
|
|
|
+ return webRadio_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var webInput: ComponentInput {
|
|
|
+ get {
|
|
|
+ return webInput_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var emailRadio: ComponentRadio {
|
|
|
+ get {
|
|
|
+ return emailRadio_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var emailInput: ComponentInput {
|
|
|
+ get {
|
|
|
+ return emailInput_
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
convenience init(outline: CPDFOutline?, document: CPDFView?) {
|
|
|
self.init()
|
|
|
|
|
@@ -109,6 +158,8 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
inputView_.frame = inputScrollView.contentView.bounds
|
|
|
inputView_.autoresizingMask = [.width, .height]
|
|
|
inputScrollView.documentView = inputView_
|
|
|
+ inputView_.properties.text = outline?.label ?? ""
|
|
|
+ inputView_.reloadData()
|
|
|
|
|
|
pageButton.isHidden = true
|
|
|
totalPageCountLabel.isHidden = true
|
|
@@ -123,12 +174,13 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
pageInput_.km_add_leading_constraint(equalTo: pageRadio_, attribute: .trailing, constant: 0)
|
|
|
pageInput_.km_add_centerY_constraint()
|
|
|
pageInput_.km_add_height_constraint(constant: 32)
|
|
|
- pageInput_.km_add_width_constraint(constant: 165)
|
|
|
+ pageInput_.km_add_width_constraint(constant: 80)
|
|
|
pageLabel.km_add_leading_constraint(equalTo: pageInput_, attribute: .trailing, constant: 8)
|
|
|
pageLabel.km_add_centerY_constraint()
|
|
|
pageLabel.stringValue = "/\(pageCount)"
|
|
|
pageInput_.properties.text = "11"
|
|
|
pageInput_.reloadData()
|
|
|
+ pageRadio_.setTarget(self, action: #selector(buttonClicked_GotoAction))
|
|
|
|
|
|
urlButton.isHidden = true
|
|
|
outlineURLTextField.isHidden = true
|
|
@@ -143,6 +195,7 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
webInput_.km_add_centerY_constraint()
|
|
|
webInput_.km_add_height_constraint(constant: 32)
|
|
|
webInput_.km_add_trailing_constraint()
|
|
|
+ webRadio_.setTarget(self, action: #selector(buttonClicked_URLAction))
|
|
|
|
|
|
mailButton.isHidden = true
|
|
|
mailAddressTextField.isHidden = true
|
|
@@ -157,24 +210,25 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
emailInput_.km_add_centerY_constraint()
|
|
|
emailInput_.km_add_height_constraint(constant: 32)
|
|
|
emailInput_.km_add_trailing_constraint()
|
|
|
+ emailRadio_.setTarget(self, action: #selector(buttonClicked_MailAction))
|
|
|
|
|
|
bottomBox.borderWidth = 0
|
|
|
leftButtonBox.borderWidth = 0
|
|
|
leftButtonBox.contentView = cancelButton_
|
|
|
rightButtonBox.borderWidth = 0
|
|
|
rightButtonBox.contentView = okButton_
|
|
|
-
|
|
|
+ cancelButton_.setTarget(self, action: #selector(_cancelAction))
|
|
|
+ okButton_.setTarget(self, action: #selector(_okAction))
|
|
|
+
|
|
|
outlineNameLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
|
|
|
pageLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
|
|
|
|
|
|
- self.localizedLanguage()
|
|
|
-
|
|
|
- self.setONButton(button: self.pageButton)
|
|
|
- self.enableTextField(textField: self.outlineTargetPageIndexTextField)
|
|
|
+ setONButton(button: pageRadio_)
|
|
|
+ enableTextField(textField: pageInput_)
|
|
|
|
|
|
- self.setDelegateAndFormatter()
|
|
|
- if let action = self.outline?.action {
|
|
|
- self.adjustUIWithAction(action: action)
|
|
|
+ setDelegateAndFormatter()
|
|
|
+ if let action = outline?.action {
|
|
|
+ adjustUIWithAction(action: action)
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -200,54 +254,48 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
|
|
|
//MARK: - Private Methods
|
|
|
|
|
|
- private func localizedLanguage () {
|
|
|
-
|
|
|
- self.pageButton.title = "\(NSLocalizedString("Page", comment: ""))"
|
|
|
- self.urlButton.title = "\(NSLocalizedString("URL:", comment: ""))"
|
|
|
- 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 ?? ""
|
|
|
- }
|
|
|
-
|
|
|
private func adjustUIWithAction(action:CPDFAction!) {
|
|
|
guard let doc = self.pdfView?.document else {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if action == nil {
|
|
|
- self.totalPageCountLabel.stringValue = " \(doc.pageCount)"
|
|
|
- self.outlineTargetPageIndexTextField.stringValue = " \(self.currentPageIndex + 1)"
|
|
|
+ pageLabel.stringValue = " \(doc.pageCount)"
|
|
|
+ pageInput_.properties.text = " \(currentPageIndex + 1)"
|
|
|
+ pageInput_.reloadData()
|
|
|
} else {
|
|
|
- guard let outL = self.outline else {
|
|
|
+ guard let outL = outline else {
|
|
|
return
|
|
|
}
|
|
|
if action.isKind(of: CPDFURLAction.self) {
|
|
|
- var newAction : CPDFURLAction = self.outline?.action as! CPDFURLAction
|
|
|
+ var newAction : CPDFURLAction = outline?.action as! CPDFURLAction
|
|
|
var urlString = newAction.url() ?? ""
|
|
|
- self.originalURLString = urlString
|
|
|
+ originalURLString = urlString
|
|
|
|
|
|
if urlString.hasPrefix("mailto:") {
|
|
|
- self.setONButton(button: self.mailButton)
|
|
|
- self.enableTextField(textField: self.mailAddressTextField)
|
|
|
+ setONButton(button: emailRadio_)
|
|
|
+ enableTextField(textField: emailInput_)
|
|
|
urlString = String(urlString.suffix(from: "mailto:".endIndex))
|
|
|
- self.mailAddressTextField.stringValue = urlString
|
|
|
+ emailInput_.properties.text = urlString
|
|
|
+ emailInput_.reloadData()
|
|
|
} else {
|
|
|
- self.setONButton(button: self.urlButton)
|
|
|
- self.enableTextField(textField: self.outlineURLTextField)
|
|
|
- self.outlineURLTextField.stringValue = urlString
|
|
|
+ setONButton(button: webRadio_)
|
|
|
+ enableTextField(textField: webInput_)
|
|
|
+ webInput_.properties.text = urlString
|
|
|
+ webInput_.reloadData()
|
|
|
}
|
|
|
- self.currentPageIndex = Int(doc.index(for: doc.page(at: UInt(self.pdfView!.currentPageIndex))))
|
|
|
+ currentPageIndex = Int(doc.index(for: doc.page(at: UInt(pdfView?.currentPageIndex ?? 0))))
|
|
|
} else {
|
|
|
- self.setONButton(button: self.pageButton)
|
|
|
- self.enableTextField(textField: self.outlineTargetPageIndexTextField)
|
|
|
- self.currentPageIndex = Int(doc.index(for: doc.page(at: UInt(outL.destination.pageIndex))))
|
|
|
- self.originalDestination = outL.destination
|
|
|
- self.originalPageIndex = self.originalDestination?.pageIndex ?? -1
|
|
|
+ setONButton(button: pageRadio_)
|
|
|
+ enableTextField(textField: pageInput_)
|
|
|
+ currentPageIndex = Int(doc.index(for: doc.page(at: UInt(outL.destination.pageIndex))))
|
|
|
+ originalDestination = outL.destination
|
|
|
+ originalPageIndex = originalDestination?.pageIndex ?? -1
|
|
|
}
|
|
|
- self.originalLabel = outL.label ?? ""
|
|
|
- self.totalPageCountLabel.stringValue = " /\(doc.pageCount)"
|
|
|
- self.outlineTargetPageIndexTextField.stringValue = "\(self.currentPageIndex + 1)"
|
|
|
+ originalLabel = outL.label ?? ""
|
|
|
+ pageLabel.stringValue = " /\(doc.pageCount)"
|
|
|
+ pageInput_.properties.text = "\(self.currentPageIndex + 1)"
|
|
|
+ pageInput_.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -262,59 +310,68 @@ class KMOutlineEditViewController: KMNBaseViewController {
|
|
|
self.outlineTargetPageIndexTextField.formatter = formatter
|
|
|
}
|
|
|
|
|
|
- private func setONButton(button:NSButton) {
|
|
|
- self.pageButton.state = NSControl.StateValue.off
|
|
|
- self.urlButton.state = NSControl.StateValue.off
|
|
|
- self.mailButton.state = NSControl.StateValue.off
|
|
|
-
|
|
|
- button.state = NSControl.StateValue.on
|
|
|
+ private func setONButton(button sender: ComponentRadio) {
|
|
|
+ for radio in [pageRadio_, webRadio_, emailRadio_] {
|
|
|
+ if radio.isEqual(to: sender) {
|
|
|
+ radio.properties.checkboxType = .selected
|
|
|
+ } else {
|
|
|
+ radio.properties.checkboxType = .normal
|
|
|
+ }
|
|
|
+ radio.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private func enableTextField(textField:NSTextField) {
|
|
|
- self.outlineTargetPageIndexTextField.isEditable = false
|
|
|
- self.outlineTargetPageIndexTextField.isSelectable = false
|
|
|
- self.outlineURLTextField.isEditable = false
|
|
|
- self.outlineURLTextField.isSelectable = false
|
|
|
- self.mailAddressTextField.isEditable = false
|
|
|
- self.mailAddressTextField.isSelectable = false
|
|
|
-
|
|
|
- self.outlineTargetPageIndexTextField.textColor = KMAppearance.Layout.h0Color()
|
|
|
- self.outlineURLTextField.textColor = KMAppearance.Layout.h0Color()
|
|
|
- self.mailAddressTextField.textColor = KMAppearance.Layout.h0Color()
|
|
|
-
|
|
|
- textField.isEditable = true
|
|
|
- textField.isSelectable = true
|
|
|
- textField.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ private func enableTextField(textField sender: ComponentInput) {
|
|
|
+ for input in [pageInput_, webInput_, emailInput_] {
|
|
|
+ if sender.isEqual(to: input) {
|
|
|
+ input.properties.isDisabled = false
|
|
|
+ input.properties.creatable = true
|
|
|
+ } else {
|
|
|
+ input.properties.isDisabled = true
|
|
|
+ input.properties.creatable = false
|
|
|
+ }
|
|
|
+
|
|
|
+ input.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//MARK: Button Action
|
|
|
+
|
|
|
@IBAction func buttonClicked_GotoAction(_ sender: Any) {
|
|
|
- self.setONButton(button: self.pageButton)
|
|
|
- self.enableTextField(textField: self.outlineTargetPageIndexTextField)
|
|
|
+ self.setONButton(button: pageRadio_)
|
|
|
+ self.enableTextField(textField: pageInput_)
|
|
|
+// self.view.window?.makeFirstResponder(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.setONButton(button: self.webRadio_)
|
|
|
+ self.enableTextField(textField: webInput_)
|
|
|
+// self.view.window?.makeFirstResponder(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)"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@IBAction func buttonClicked_MailAction(_ sender: Any) {
|
|
|
- self.setONButton(button: self.mailButton)
|
|
|
- self.enableTextField(textField: self.mailAddressTextField)
|
|
|
+ self.setONButton(button: self.emailRadio_)
|
|
|
+ self.enableTextField(textField: emailInput_)
|
|
|
+// self.view.window?.makeFirstResponder(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)"
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @objc private func _cancelAction() {
|
|
|
+ itemClick?(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func _okAction() {
|
|
|
+ itemClick?(2, self)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMOutlineEditViewController : NSTextFieldDelegate,NSTextViewDelegate {
|