123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // KMCompressContentView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/11/18.
- //
- import Cocoa
- import KMComponentLibrary
- typealias KMBatchOperateCompressViewSelectTypeBlcok = (_ view: KMCompressContentView, _ model: KMCompressSettingModel) -> Void
- typealias KMBatchOperateCompressViewCompressAction = (_ view: KMCompressContentView, _ model: KMCompressSettingModel, _ showView: NSView) -> Void
- class KMCompressContentView: BaseXibView {
-
- @IBOutlet weak var standardButton: ComponentRadio!
- @IBOutlet weak var mobileButton: ComponentRadio!
- @IBOutlet weak var customButton: ComponentRadio!
- @IBOutlet weak var tipButton: ComponentToolTipsHelp!
- @IBOutlet weak var settingButton: NSButton!
-
- @IBOutlet weak var mobileWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var customButtonWidthConstraint: NSLayoutConstraint!
-
- var isDisable: Bool = false {
- didSet {
- self.reloadData()
- }
- }
-
- var compressSettingViewWindow: NSWindow?
- var faterWindow: NSWindow?
-
- var compressSettingViewController: KMCompressSettingViewController?
- var compressAction: KMBatchOperateCompressViewCompressAction?
-
- var popOver: NSPopover!
-
- var selectTypeAction: KMBatchOperateCompressViewSelectTypeBlcok?
-
- var model: KMCompressSettingModel = KMCompressSettingModel(modelsType: .standard) {
- didSet {
- self.reloadData()
- }
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- updateUI()
- updateUILanguage()
- reloadData()
- }
-
- override func updateUILanguage() {
- standardButton.properties.text = KMLocalizedString("Standard (Recommend)", comment: "")
- mobileButton.properties.text = KMLocalizedString("Mobile", comment: "")
- customButton.properties.text = KMLocalizedString("Custom", comment: "")
- settingButton.stringValue = KMLocalizedString("Setting", comment: "")
- tipButton.toolTip = KMLocalizedString("This mode is specifically tuned for mobile devices to improve compression quality and ensure clear viewing on mobile devices.", comment: "")
- }
-
- override func updateUIThemeColor() {
- settingButton.setTitleColor(NSColor(hex: "#1EB3F9"))
- }
-
- func updateUI() {
- standardButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Standard (Recommend)", comment: ""), checkboxType: .normal)
- standardButton.setTarget(self, action: #selector(standardButtonAction(_:)))
-
- mobileButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Mobile", comment: ""), checkboxType: .normal)
- mobileButton.setTarget(self, action: #selector(mobileButtonAction(_:)))
- mobileWidthConstraint.constant = mobileButton.properties.propertyInfo.viewWidth
-
- customButton.properties = ComponentCheckBoxProperty(size: .s, text: KMLocalizedString("Custom", comment: ""), checkboxType: .normal)
-
- customButton.setTarget(self, action: #selector(customButtonAction(_:)))
- customButtonWidthConstraint.constant = mobileButton.properties.propertyInfo.viewWidth
- }
-
- func reloadData() {
- self.updateType(type: model.modelsType)
-
- self.standardButton.properties.isDisabled = self.isDisable
- self.standardButton.reloadData()
- self.mobileButton.properties.isDisabled = self.isDisable
- self.mobileButton.reloadData()
- self.customButton.properties.isDisabled = self.isDisable
- self.customButton.reloadData()
- self.settingButton.isEnabled = !self.isDisable
- }
-
- func updateType(type: KMCompressModelsType) {
- self.standardButton.properties.checkboxType = .normal
- self.mobileButton.properties.checkboxType = .normal
- self.customButton.properties.checkboxType = .normal
-
-
- switch type {
- case .standard:
- self.standardButton.properties.checkboxType = .selected
- case .custom:
- self.customButton.properties.checkboxType = .selected
- case .mobile:
- self.mobileButton.properties.checkboxType = .selected
- }
-
- self.standardButton.reloadData()
- self.mobileButton.reloadData()
- self.customButton.reloadData()
- }
- }
- extension KMCompressContentView {
- func standardButtonAction(_ sender: Any) {
- self.updateType(type: .standard)
- self.model = KMCompressSettingModel(modelsType: .standard)
-
- guard let callBack = selectTypeAction else { return }
-
- callBack(self, model)
- }
-
- func mobileButtonAction(_ sender: Any) {
- self.updateType(type: .mobile)
- self.model = KMCompressSettingModel(modelsType: .mobile)
-
- guard let callBack = selectTypeAction else { return }
-
- callBack(self, model)
- }
-
- func customButtonAction(_ sender: Any) {
- self.updateType(type: .custom)
- self.model = KMCompressSettingModel(modelsType: .custom)
-
- if !KMCompressSettingModel.isSaveCustomData() {
- self.settingButtonAction(self.settingButton)
- }
-
- guard let callBack = selectTypeAction else { return }
-
- callBack(self, model)
- }
-
- @IBAction func settingButtonAction(_ sender: Any) {
- compressSettingViewController = KMCompressSettingViewController(nibName: "KMCompressSettingViewController", bundle: nil)
- let window = NSWindow(contentViewController: compressSettingViewController!)
- window.minSize = CGSizeMake(584, 640)
- window.maxSize = CGSizeMake(584, 640)
- window.styleMask.remove(.resizable)
- compressSettingViewWindow = window
-
- let currentWindow = NSWindow.currentWindow()
- faterWindow = currentWindow
- currentWindow.beginSheet(window)
-
- compressSettingViewController?.model = self.model
-
- compressSettingViewController?.cancelAction = { resultControler in
- currentWindow.endSheet(window)
- }
-
- compressSettingViewController?.doneAction = { [unowned self] resultControler in
- guard let callBack = compressAction else { return }
-
- callBack(self, self.model, resultControler.view)
- }
-
- compressSettingViewController?.modelChangeAction = { [unowned self] resultControler, tModel in
- self.updateType(type: tModel.modelsType)
-
- guard let callBack = selectTypeAction else { return }
-
- callBack(self, tModel)
- }
-
- }
-
- func closeSettingWindow() {
- guard let window = compressSettingViewWindow else { return }
- guard let faterWindow = faterWindow else { return }
-
- faterWindow.endSheet(window)
- }
- }
|