|
@@ -22,8 +22,16 @@ import KMComponentLibrary
|
|
|
case MultiSelect //Popup弹窗
|
|
|
}
|
|
|
|
|
|
-@objcMembers class KMLinkViewController: NSViewController {
|
|
|
+/**
|
|
|
+ 未选中注释:修改默认添加类型。
|
|
|
+ 选中注释:
|
|
|
+ - 切换类型:判断类型->修改显示信息。
|
|
|
+ - 输入文字:修改跳转内容。
|
|
|
+ */
|
|
|
|
|
|
+//MARK: - KMLinkViewController
|
|
|
+@objcMembers class KMLinkViewController: NSViewController {
|
|
|
+
|
|
|
@IBOutlet var contendBox: NSBox!
|
|
|
@IBOutlet var infoContendView: NSView!
|
|
|
|
|
@@ -32,29 +40,26 @@ import KMComponentLibrary
|
|
|
|
|
|
@IBOutlet var typeContendView: NSView!
|
|
|
@IBOutlet var linkPageView: KMLinkPageView!
|
|
|
-
|
|
|
@IBOutlet var linkEmailView: KMLinkEmailView!
|
|
|
-
|
|
|
@IBOutlet var linkWebView: KMLinkWebView!
|
|
|
-
|
|
|
- private var _annotations: [CPDFLinkAnnotation] = []
|
|
|
+
|
|
|
+ @IBOutlet var emptyContendView: ComponentEmpty!
|
|
|
|
|
|
private weak var _pdfView: CPDFListView? = nil
|
|
|
|
|
|
- private var annotation: CPDFLinkAnnotation? = nil
|
|
|
+ private var annotations: [CPDFLinkAnnotation] = []
|
|
|
+ private var current_Annotation: CPDFLinkAnnotation? = nil
|
|
|
|
|
|
var multiController: KMNAlignmentController = KMNAlignmentController.init() //注释多选界面
|
|
|
|
|
|
let pageProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: NSLocalizedString("Page", comment: ""))
|
|
|
let webProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: NSLocalizedString("Web", comment: ""))
|
|
|
let emailProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: NSLocalizedString("Email", comment: ""))
|
|
|
-
|
|
|
+
|
|
|
public override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
// Do view setup here.
|
|
|
|
|
|
- pdfLinkType = .Page
|
|
|
-
|
|
|
setUpUI()
|
|
|
|
|
|
}
|
|
@@ -63,13 +68,6 @@ import KMComponentLibrary
|
|
|
|
|
|
contendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
|
|
|
|
|
|
- if pdfLinkType == .Page {
|
|
|
- pageProperty.state = .pressed
|
|
|
- } else if pdfLinkType == .Web {
|
|
|
- webProperty.state = .pressed
|
|
|
- } else if pdfLinkType == .Email {
|
|
|
- emailProperty.state = .pressed
|
|
|
- }
|
|
|
|
|
|
tabsView.updateItemProperty([pageProperty, webProperty, emailProperty])
|
|
|
tabsView.delegate = self
|
|
@@ -81,16 +79,17 @@ import KMComponentLibrary
|
|
|
linkEmailView.delegate = self
|
|
|
|
|
|
multiController.delegate = self
|
|
|
+
|
|
|
+ emptyContendView.properties = ComponentEmptyProperty(emptyType: .noLink,
|
|
|
+ text: KMLocalizedString("Add Link"),
|
|
|
+ subText: KMLocalizedString("Select an area or text on the page to add a link."))
|
|
|
}
|
|
|
|
|
|
|
|
|
//MARK: - Setter
|
|
|
var pdfLinkType: PDFLinkType = .Page {
|
|
|
didSet {
|
|
|
-
|
|
|
view.window?.makeFirstResponder(nil)
|
|
|
-
|
|
|
- reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -103,67 +102,128 @@ import KMComponentLibrary
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var annotations: [CPDFLinkAnnotation] {
|
|
|
- get {
|
|
|
- return _annotations
|
|
|
+ //MARK: - func
|
|
|
+ public func reloadData() {
|
|
|
+ guard let pdfView = self.pdfView else {
|
|
|
+ return
|
|
|
}
|
|
|
- set {
|
|
|
- _annotations = newValue
|
|
|
-
|
|
|
- if _annotations.isEmpty == false {
|
|
|
- annotation = _annotations.first
|
|
|
- } else {
|
|
|
- annotation = nil
|
|
|
+
|
|
|
+ typeContendView.isHidden = true
|
|
|
+ emptyContendView.isHidden = true
|
|
|
+ multiController.view.isHidden = true
|
|
|
+
|
|
|
+ tabsBGView.isHidden = false
|
|
|
+
|
|
|
+ let pdfAnnotations: [CPDFAnnotation] = pdfView.activeAnnotations as? [CPDFAnnotation] ?? []
|
|
|
+ var linkAnnotations: [CPDFLinkAnnotation] = []
|
|
|
+ for annotation in pdfAnnotations {
|
|
|
+ if annotation is CPDFLinkAnnotation {
|
|
|
+ linkAnnotations.append((annotation as! CPDFLinkAnnotation))
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //MARK: - func
|
|
|
- public func reloadData() {
|
|
|
- infoContendView.isHidden = false
|
|
|
+ annotations = linkAnnotations
|
|
|
+ current_Annotation = nil
|
|
|
|
|
|
if annotations.count == 0 {
|
|
|
- infoContendView.isHidden = true
|
|
|
- } else if annotations.count > 1 {
|
|
|
- multiController.view.frame = CGRectMake((CGRectGetWidth(infoContendView.frame) - 232)/2, CGRectGetHeight(infoContendView.frame)-112, 232, 112)
|
|
|
- multiController.view.autoresizingMask = [.width, .maxYMargin]
|
|
|
- infoContendView.addSubview(multiController.view)
|
|
|
+ emptyContendView.isHidden = false
|
|
|
|
|
|
- multiController.view.isHidden = false
|
|
|
- tabsBGView.isHidden = true
|
|
|
- typeContendView.isHidden = true
|
|
|
+ } else if annotations.count == 1 {
|
|
|
|
|
|
- if annotations.count > 2 {
|
|
|
- multiController.aligHorizontalXButton.properties.isDisabled = false
|
|
|
- multiController.aligVerticalYButton.properties.isDisabled = false
|
|
|
- } else {
|
|
|
- multiController.aligHorizontalXButton.properties.isDisabled = true
|
|
|
- multiController.aligVerticalYButton.properties.isDisabled = true
|
|
|
- }
|
|
|
- multiController.aligHorizontalXButton.reloadData()
|
|
|
- multiController.aligVerticalYButton.reloadData()
|
|
|
+ current_Annotation = annotations.first
|
|
|
|
|
|
- } else {
|
|
|
multiController.view.isHidden = true
|
|
|
- tabsBGView.isHidden = false
|
|
|
typeContendView.isHidden = false
|
|
|
|
|
|
linkPageView.isHidden = true
|
|
|
linkEmailView.isHidden = true
|
|
|
linkWebView.isHidden = true
|
|
|
|
|
|
+ if let url = current_Annotation?.url() {
|
|
|
+ if url.hasPrefix("mailto:") {
|
|
|
+ pdfLinkType = .Email
|
|
|
+ } else {
|
|
|
+ pdfLinkType = .Web
|
|
|
+ }
|
|
|
+ } else if let _ = current_Annotation?.destination() {
|
|
|
+ pdfLinkType = .Page
|
|
|
+ }
|
|
|
+
|
|
|
if pdfLinkType == .Page {
|
|
|
linkPageView.isHidden = false
|
|
|
linkPageView.pdfView = pdfView
|
|
|
- linkPageView.annotation = annotation
|
|
|
+ linkPageView.annotation = current_Annotation
|
|
|
linkPageView.reloadData()
|
|
|
-
|
|
|
} else if pdfLinkType == .Web {
|
|
|
linkWebView.isHidden = false
|
|
|
-
|
|
|
+ linkWebView.annotation = current_Annotation
|
|
|
} else if pdfLinkType == .Email {
|
|
|
linkEmailView.isHidden = false
|
|
|
-
|
|
|
+ linkEmailView.annotation = current_Annotation
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ multiController.view.frame = CGRectMake((CGRectGetWidth(infoContendView.frame) - 232)/2, CGRectGetHeight(infoContendView.frame)-112, 232, 112)
|
|
|
+ multiController.view.autoresizingMask = [.width, .maxYMargin]
|
|
|
+ infoContendView.addSubview(multiController.view)
|
|
|
+
|
|
|
+ multiController.view.isHidden = false
|
|
|
+ tabsBGView.isHidden = true
|
|
|
+
|
|
|
+ if annotations.count > 2 {
|
|
|
+ multiController.aligHorizontalXButton.properties.isDisabled = false
|
|
|
+ multiController.aligVerticalYButton.properties.isDisabled = false
|
|
|
+ } else {
|
|
|
+ multiController.aligHorizontalXButton.properties.isDisabled = true
|
|
|
+ multiController.aligVerticalYButton.properties.isDisabled = true
|
|
|
+ }
|
|
|
+ multiController.aligHorizontalXButton.reloadData()
|
|
|
+ multiController.aligVerticalYButton.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ pageProperty.state = .normal
|
|
|
+ webProperty.state = .normal
|
|
|
+ emailProperty.state = .normal
|
|
|
+ if pdfLinkType == .Page {
|
|
|
+ pageProperty.state = .pressed
|
|
|
+ } else if pdfLinkType == .Web {
|
|
|
+ webProperty.state = .pressed
|
|
|
+ } else if pdfLinkType == .Email {
|
|
|
+ emailProperty.state = .pressed
|
|
|
+ }
|
|
|
+ tabsView.refreshItems()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func pdfLinkTypeChanged() {
|
|
|
+ guard let _ = current_Annotation else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ linkPageView.isHidden = true
|
|
|
+ linkEmailView.isHidden = true
|
|
|
+ linkWebView.isHidden = true
|
|
|
+
|
|
|
+ if pdfLinkType == .Page {
|
|
|
+ linkPageView.isHidden = false
|
|
|
+ linkPageView.reloadData()
|
|
|
+ } else if pdfLinkType == .Web {
|
|
|
+ linkWebView.isHidden = false
|
|
|
+ linkWebView.annotation = current_Annotation
|
|
|
+
|
|
|
+ if let url = current_Annotation?.url() {
|
|
|
+ if url.hasPrefix("mailto:") == true {
|
|
|
+ linkWebView.inputTextarea.properties.text = ""
|
|
|
+ linkWebView.inputTextarea.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if pdfLinkType == .Email {
|
|
|
+ linkEmailView.isHidden = false
|
|
|
+ linkEmailView.annotation = current_Annotation
|
|
|
+
|
|
|
+ if let url = current_Annotation?.url() {
|
|
|
+ if url.hasPrefix("mailto:") == false {
|
|
|
+ linkEmailView.inputTextarea.properties.text = ""
|
|
|
+ linkEmailView.inputTextarea.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -187,36 +247,37 @@ extension KMLinkViewController: ComponentTabsDelegate {
|
|
|
} else if property == emailProperty {
|
|
|
pdfLinkType = .Email
|
|
|
}
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.reloadData()
|
|
|
+
|
|
|
+ if let annotation = current_Annotation {
|
|
|
+ pdfLinkTypeChanged()
|
|
|
}
|
|
|
|
|
|
+ CPDFLinkAnnotation.updateDefault_AddLinkType(pdfLinkType.rawValue)
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//MARK: - KMLinkPageViewDelegate
|
|
|
extension KMLinkViewController: KMLinkPageViewDelegate {
|
|
|
func kmLinkPageViewDidGoToPage(_ view: KMLinkPageView, _ pageIndex: Int) {
|
|
|
- if let page = pdfView?.document.page(at: UInt(pageIndex-1)) {
|
|
|
+ if let _ = pdfView?.document.page(at: UInt(pageIndex-1)) {
|
|
|
pdfView?.go(toPageIndex: pageIndex-1, animated: false)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func kmLinkPageViewDidChangeDestination(_ view: KMLinkPageView, _ pageIndex: Int) {
|
|
|
- guard let activiteAnno = annotation else {
|
|
|
+ guard let activiteAnno = current_Annotation else {
|
|
|
return
|
|
|
}
|
|
|
activiteAnno.setURL(nil)
|
|
|
-
|
|
|
+
|
|
|
if let page = pdfView?.document.page(at: UInt(pageIndex-1)) {
|
|
|
-
|
|
|
let bounds = page.bounds(for: .cropBox)
|
|
|
let destination = CPDFDestination(page: page, at: NSPoint(x: 0, y: bounds.size.height))
|
|
|
activiteAnno.setDestination(destination)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- if let page = pdfView?.document.page(at: UInt(pageIndex-1)) {
|
|
|
+ if let _ = pdfView?.document.page(at: UInt(pageIndex-1)) {
|
|
|
pdfView?.go(toPageIndex: pageIndex-1, animated: false)
|
|
|
}
|
|
|
}
|
|
@@ -225,14 +286,14 @@ extension KMLinkViewController: KMLinkPageViewDelegate {
|
|
|
//MARK: - KMLinkPageViewDelegate
|
|
|
extension KMLinkViewController: KMLinkWebViewDelegate {
|
|
|
func kmLinkWebViewDidGo(_ view: KMLinkWebView, _ webString: String) {
|
|
|
- guard let activeAnnotation = annotation else {
|
|
|
+ guard let activeAnnotation = current_Annotation else {
|
|
|
return
|
|
|
}
|
|
|
activeAnnotation.setDestination(nil)
|
|
|
-
|
|
|
+
|
|
|
let linkUrlPath = KMNTools.judgeWebURL(webString)
|
|
|
activeAnnotation.setURL(linkUrlPath)
|
|
|
-
|
|
|
+
|
|
|
if let url = activeAnnotation.url() {
|
|
|
if let data = URL(string: url) {
|
|
|
NSWorkspace.shared.open(data)
|
|
@@ -242,10 +303,10 @@ extension KMLinkViewController: KMLinkWebViewDelegate {
|
|
|
|
|
|
}
|
|
|
|
|
|
-//MARK: - KMLinkPageViewDelegate
|
|
|
+//MARK: - KMLinkEmailViewDelegate
|
|
|
extension KMLinkViewController: KMLinkEmailViewDelegate {
|
|
|
func kmLinkEmailViewDidGo(_ view: KMLinkEmailView, _ emailString: String) {
|
|
|
- guard let activeAnnotation = annotation else {
|
|
|
+ guard let activeAnnotation = current_Annotation else {
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -257,10 +318,10 @@ extension KMLinkViewController: KMLinkEmailViewDelegate {
|
|
|
return
|
|
|
}
|
|
|
activeAnnotation.setDestination(nil)
|
|
|
-
|
|
|
+
|
|
|
let linkUrlPath = KMNTools.judgeEmailURL(emailString)
|
|
|
activeAnnotation.setURL(linkUrlPath)
|
|
|
-
|
|
|
+
|
|
|
if let url = activeAnnotation.url() {
|
|
|
NSWorkspace.shared.open(URL(string: url)!)
|
|
|
}
|
|
@@ -271,10 +332,16 @@ extension KMLinkViewController: KMLinkEmailViewDelegate {
|
|
|
//MARK: - KMNAlignmentControllerDelegate
|
|
|
extension KMLinkViewController: KMNAlignmentControllerDelegate {
|
|
|
func alignmentControllerDidClick(_ controller: KMNAlignmentController, _ alignmentType: KMPDFActiveFormsAlignType) {
|
|
|
-
|
|
|
+
|
|
|
pdfView?.change(annotations, alignmentType: alignmentType)
|
|
|
|
|
|
pdfView?.setNeedsDisplayForVisiblePages()
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+//MARK: - KMLinkViewController Class Method
|
|
|
+extension KMLinkViewController {
|
|
|
+
|
|
|
+}
|