KMTransitionInfo.swift 2.4 KB

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