KMTransitionInfo.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. var thumbnail: KMThumbnail?
  14. var label: String = ""
  15. var title: String {
  16. get {
  17. return NSLocalizedString("Page Transition", comment: "Box title")
  18. }
  19. }
  20. var properties: NSDictionary?{
  21. get{
  22. return [SKStyleNameKey: SKTransitionController.name(for: transitionStyle) ?? "", SKDurationKey: NSNumber(value: duration), SKShouldRestrictKey: NSNumber(value: shouldRestrict)] as [String : Any] as NSDictionary
  23. }
  24. set{
  25. if let value = newValue?[SKStyleNameKey] {
  26. transitionStyle = SKTransitionController.style(forName: value as? String)
  27. }
  28. if let value = newValue?[SKDurationKey] {
  29. duration = value as! Float
  30. }
  31. if let value = newValue?[SKShouldRestrictKey] {
  32. shouldRestrict = value as! Bool
  33. }
  34. }
  35. }
  36. override init() {
  37. super.init()
  38. self.transitionStyle = .noTransition
  39. self.duration = 1.0
  40. self.shouldRestrict = false
  41. self.thumbnail = nil
  42. self.label = ""
  43. }
  44. init(propertyList: NSDictionary, ofType: String) {
  45. super.init()
  46. if ofType == SKPasteboardTypeTransition {
  47. self.properties = propertyList
  48. } else {
  49. }
  50. }
  51. override var description: String {
  52. return "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())> \(properties)"
  53. }
  54. class func readableTypesForPasteboard(pasteboard: NSPasteboard) -> NSArray {
  55. return NSArray(objects: SKPasteboardTypeTransition)
  56. }
  57. class func readingOptionsForType(type: String, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions {
  58. if type == SKPasteboardTypeTransition {
  59. return .asPropertyList
  60. }
  61. return .asData
  62. }
  63. func writableTypesForPasteboard(pasteboard: NSPasteboard) -> NSArray {
  64. return NSArray(objects: SKPasteboardTypeTransition)
  65. }
  66. func pasteboardPropertyListForType(type: String) -> Any? {
  67. if type == SKPasteboardTypeTransition {
  68. return properties
  69. }
  70. return nil
  71. }
  72. }