123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // KMAutoFlowOptionsSheetController.swift
- // Cisdem PDFMaster
- //
- // Created by lizhe on 2024/1/16.
- //
- import Cocoa
- class KMAutoFlowOptionsSheetController: NSWindowController {
- @IBOutlet weak var timeIntervalLabel: NSTextField!
- @IBOutlet weak var timeIntervalSlider: NSSlider!
- @IBOutlet weak var timeIntervalTextField: NSTextField!
- @IBOutlet weak var secLabel: NSTextField!
- @IBOutlet weak var jumpSpaceLabel: NSTextField!
- @IBOutlet weak var jumpSpaceSlider: NSSlider!
- @IBOutlet weak var jumpSpaceTextField: NSTextField!
- @IBOutlet weak var pxLabel: NSTextField!
-
- @IBOutlet weak var closeButton: NSButton!
- @IBOutlet weak var okButton: NSButton!
-
- var timeInterval: String?
- var jumpSpace: String?
-
- override init(window: NSWindow?) {
- super.init(window: window)
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.closeButton.title = NSLocalizedString("Cancel", comment: "")
- self.okButton.title = NSLocalizedString("OK", comment: "")
- self.timeIntervalLabel.stringValue = NSLocalizedString("Time Interval", comment: "")
- self.jumpSpaceLabel.stringValue = NSLocalizedString("Jump Space", comment: "")
- self.secLabel.stringValue = NSLocalizedString("sec", comment: "")
- self.pxLabel.stringValue = NSLocalizedString("px", comment: "")
-
- self.timeIntervalTextField.delegate = self
- self.jumpSpaceTextField.delegate = self
-
- let timeInterval = KMAutoFlowOptionsSheetController.timeInterval()
- let jumpSpace = KMAutoFlowOptionsSheetController.jumpSpace()
- self.timeInterval = String(timeInterval)
- self.jumpSpace = String(jumpSpace)
- }
-
- @IBAction func closeButtonAction(_ sender: Any) {
- self.close()
- }
-
- @IBAction func okButtonAction(_ sender: Any) {
- let sec = self.timeIntervalTextField.stringValue.isEmpty ? "0" : self.timeIntervalTextField.stringValue
- var jumpSpaceStr = self.jumpSpaceTextField.stringValue.isEmpty ? "0" : self.jumpSpaceTextField.stringValue
- //替换”,“
- jumpSpaceStr = jumpSpaceStr.replacingOccurrences(of: ",", with: "")
-
- KMAutoFlowOptionsSheetController.setTimeInterval(Float(sec) ?? 0.0)
- KMAutoFlowOptionsSheetController.setJumpSpace(Float(jumpSpaceStr) ?? 0.0)
-
- self.close()
- }
- @IBAction func timeIntervalSliderAction(_ sender: NSSlider) {
- self.timeIntervalTextField.stringValue = sender.stringValue
- }
-
- @IBAction func jumpSpaceSliderAction(_ sender: NSSlider) {
- self.jumpSpaceTextField.stringValue = sender.stringValue
- }
-
-
- class func timeInterval() -> Float {
- if let storedValue = UserDefaults.standard.object(forKey: "km_pdfview_autoflow_timeinterval") as? Float {
- return storedValue
- }
- return 5.0
- }
-
- class func setTimeInterval(_ timeInterval: Float) {
- UserDefaults.standard.set(timeInterval, forKey: "km_pdfview_autoflow_timeinterval")
- UserDefaults.standard.synchronize()
- }
-
- class func jumpSpace() -> Float {
- if let storedValue = UserDefaults.standard.object(forKey: "km_pdfview_autoflow_jumpspace") as? Float {
- return storedValue
- }
- return 40.0
- }
-
- class func setJumpSpace(_ jumpSpace: Float) {
- UserDefaults.standard.set(jumpSpace, forKey: "km_pdfview_autoflow_jumpspace")
- UserDefaults.standard.synchronize()
- }
- }
- extension KMAutoFlowOptionsSheetController: NSTextFieldDelegate {
- func controlTextDidEndEditing(_ obj: Notification) {
- let textField: NSTextField = obj.object as! NSTextField;
- if textField == self.timeIntervalTextField {
- self.timeIntervalSlider.stringValue = self.timeIntervalTextField.stringValue
- print("参数改变了")
- } else if textField == self.jumpSpaceTextField {
- print("参数改变了2")
- self.jumpSpaceSlider.stringValue = self.jumpSpaceTextField.stringValue
- }
- }
- }
|