KMTransitionInfo.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // KMTransitionInfo.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2024/1/17.
  6. //
  7. import Foundation
  8. let SKPasteboardTypeTransition = "net.sourceforge.skim-app.pasteboard.transition"
  9. class KMTransitionInfo: NSObject{
  10. var transitionStyle: SKAnimationTransitionStyle = .noTransition
  11. var duration: Float = 0.0
  12. var shouldRestrict = false {
  13. didSet {
  14. // KMPrint("")
  15. }
  16. }
  17. var thumbnail: KMThumbnail?
  18. var label: String = ""
  19. var title: String {
  20. get {
  21. return NSLocalizedString("Page Transition", comment: "Box title")
  22. }
  23. }
  24. var properties: NSDictionary?{
  25. get{
  26. return [SKStyleNameKey: SKTransitionController.name(for: transitionStyle) ?? "", SKDurationKey: NSNumber(value: duration), SKShouldRestrictKey: NSNumber(value: shouldRestrict)] as [String : Any] as NSDictionary
  27. }
  28. set{
  29. if let value = newValue?[SKStyleNameKey] {
  30. transitionStyle = SKTransitionController.style(forName: value as? String)
  31. }
  32. if let value = newValue?[SKDurationKey] {
  33. duration = value as! Float
  34. }
  35. if let value = newValue?[SKShouldRestrictKey] {
  36. shouldRestrict = value as! Bool
  37. }
  38. }
  39. }
  40. override init() {
  41. super.init()
  42. self.transitionStyle = .noTransition
  43. self.duration = 1.0
  44. self.shouldRestrict = false
  45. self.thumbnail = nil
  46. self.label = ""
  47. }
  48. init(propertyList: NSDictionary, ofType: String) {
  49. super.init()
  50. if ofType == SKPasteboardTypeTransition {
  51. self.properties = propertyList
  52. } else {
  53. }
  54. }
  55. override var description: String {
  56. return "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())> \(properties)"
  57. }
  58. class func readableTypesForPasteboard(pasteboard: NSPasteboard) -> NSArray {
  59. return NSArray(objects: SKPasteboardTypeTransition)
  60. }
  61. class func readingOptionsForType(type: String, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions {
  62. if type == SKPasteboardTypeTransition {
  63. return .asPropertyList
  64. }
  65. return .asData
  66. }
  67. func writableTypesForPasteboard(pasteboard: NSPasteboard) -> NSArray {
  68. return NSArray(objects: SKPasteboardTypeTransition)
  69. }
  70. func pasteboardPropertyListForType(type: String) -> Any? {
  71. if type == SKPasteboardTypeTransition {
  72. return properties
  73. }
  74. return nil
  75. }
  76. }