// // KMHomeFilesHeaderView.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/10/10. // import Cocoa import KMComponentLibrary @objc public protocol KMHomeFilesHeaderViewDelegate: AnyObject { @objc optional func homeFilesShowModeDidUpdate(_ view: KMHomeFilesHeaderView) @objc optional func homeFilesHeaderViewDeleteButtonClicked(_ view: KMHomeFilesHeaderView) } public class KMHomeFilesHeaderView: BaseXibView { @IBOutlet var contendBox: NSBox! @IBOutlet var titleLabel: NSTextField! @IBOutlet var typeSegmented: ComponentSegmented! @IBOutlet var deleteButton: ComponentButton! let thumbProperty = ComponentSegmentedProperty(size: .s, active: false, iconImage: NSImage(named: "file_thumb"), iconImage_active: NSImage(named: "file_thumb_active")) let listProperty = ComponentSegmentedProperty(size: .s, active: false, iconImage: NSImage(named: "file_list"), iconImage_active: NSImage(named: "file_list_active")) weak open var delegate: KMHomeFilesHeaderViewDelegate? 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() titleLabel.stringValue = KMLocalizedString("Recent") titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1") titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold") setUpProperty() reloadData() updateDeleteButtonState() } func setUpProperty() { if true { var itemArr: [ComponentSegmentedProperty] = [] itemArr.append(thumbProperty) itemArr.append(listProperty) typeSegmented.updateItemProperty(itemArr) } typeSegmented.delegate = self deleteButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .xxs, state: .normal, onlyIcon: true, keepPressState: false) deleteButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "file_delete") deleteButton.properties.propertyInfo.leftIcon_dis = NSImage(named: "file_delete_dis") deleteButton.reloadData() deleteButton.setTarget(self, action: #selector(deleteButtonClicked(_:))) } private func reloadData() { if HistoryFilesManager.manager.showMode == .Thumbnail { thumbProperty.active = true listProperty.active = false } else if HistoryFilesManager.manager.showMode == .List { thumbProperty.active = false listProperty.active = true } typeSegmented.reloadData() } func updateDeleteButtonState() { deleteButton.properties.isDisabled = false deleteButton.reloadData() } @objc func deleteButtonClicked(_ sender: NSView) { delegate?.homeFilesHeaderViewDeleteButtonClicked?(self) } //MARK: - MouseEvent } extension KMHomeFilesHeaderView: ComponentSegmentedDelegate { public func componentSegmentedDidSelected(_ view: ComponentSegmented, item: ComponentSegmentedItem) { if item.properties == thumbProperty { HistoryFilesManager.manager.showMode = .Thumbnail } else if item.properties == listProperty { HistoryFilesManager.manager.showMode = .List } self.reloadData() self.delegate?.homeFilesShowModeDidUpdate?(self) } }