123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // KMLinkWebView.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/18.
- //
- import Cocoa
- import KMComponentLibrary
- @objc public protocol KMLinkWebViewDelegate: AnyObject {
-
- @objc optional func kmLinkWebViewDidGo(_ view: KMLinkWebView, _ webString: String)
-
- }
- public class KMLinkWebView: BaseXibView {
- @IBOutlet var contendBox: NSBox!
- @IBOutlet var inputTextarea: ComponentTextarea!
- @IBOutlet var goButton: ComponentButton!
-
- weak open var delegate: KMLinkWebViewDelegate?
-
- //MARK: - func
- public override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
-
- // Drawing code here.
- }
-
- public required init?(coder decoder: NSCoder) {
- super.init(coder: decoder)
-
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
- }
-
- public override func awakeFromNib() {
- super.awakeFromNib()
-
- self.setUpUI()
- }
-
-
-
- func setUpUI() {
-
- inputTextarea.properties = ComponentTextareaProperty(size: .m,
- state: .normal,
- isError: false,
- placeholderString: "http://www.pdfreaderpro.com",
- totalCount: -1,
- text: "",
- isDisabled:false)
- inputTextarea.delegate = self
-
- goButton.properties = ComponentButtonProperty(type: .default_tertiary,
- size: .s,
- buttonText: KMLocalizedString("Go"))
- goButton.setTarget(self, action: #selector(buttonClicked(_:)))
- goButton.isHidden = true
-
- }
-
-
- @objc func buttonClicked(_ sender: NSView) {
- delegate?.kmLinkWebViewDidGo?(self, inputTextarea.properties.text)
- }
-
- //MARK: - MouseEvent
- public override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
-
- self.window?.makeFirstResponder(nil)
- }
-
- }
- //MARK: - ComponentTextareaDelegate
- extension KMLinkWebView: ComponentTextareaDelegate {
- public func componentTextareaTextDidBeginEditing(_ view: ComponentTextarea) {
-
- }
-
- public func componentTextareaTextDidChange(_ view: ComponentTextarea) {
- if view.properties.text.count > 0 {
- goButton.isHidden = false
- } else {
- goButton.isHidden = true
- }
- }
-
- public func componentTextareaTextDidEndEditing(_ view: ComponentTextarea) {
-
- }
- }
|