KMPreferenceCommon.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // KMPreferenceCommon.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/1/16.
  6. //
  7. import Foundation
  8. public let KMUserNameKey = "SKUserName"
  9. public let KMReopenLastOpenFilesKey = "SKReopenLastOpenFilesKey"
  10. public let KMOpenDocumentInTabKey = "KMOpenDocumentInTab"
  11. public let KMInitialWindowSizeOptionKey = "SKInitialWindowSizeOptionKey"
  12. public let KMOpenContentsPaneOnlyForTOCKey = "SKOpenContentsPaneOnlyForTOCKey"
  13. public let KMRememberSnapshotsKey = "SKRememberSnapshotsKey"
  14. public let KMDefaultPDFDisplaySettingsKey = "SKDefaultPDFDisplaySettingsKey"
  15. public let KMDefaultFullScreenPDFDisplaySettingsKey = "SKDefaultFullScreenPDFDisplaySettings"
  16. public let KMAutoSaveSkimNotesKey = "SKAutoSaveSkimNotesKey"
  17. public let KMSnapshotsOnTopKey = "SKSnapshotsOnTopKey"
  18. public let KMSavePasswordOptionKey = "SKSavePasswordOptionKey"
  19. func KMPreferenceKeyToCKey(pKey: KMPreferenceKey) -> String? {
  20. // freeText
  21. if pKey == KMPreference.freeTextNoteLineWidthKey {
  22. return CFreeTextNoteLineWidthKey
  23. } else if pKey == KMPreference.freeTextNoteLineStyleKey {
  24. return CFreeTextNoteLineStyleKey
  25. } else if pKey == KMPreference.freeTextNoteDashPatternKey {
  26. return CFreeTextNoteDashPatternKey
  27. }
  28. // Line
  29. else if pKey == KMPreference.lineNoteLineWidthKey {
  30. return CLineNoteLineWidthKey
  31. } else if pKey == KMPreference.lineNoteLineStyleKey {
  32. return CLineNoteLineStyleKey
  33. } else if pKey == KMPreference.lineNoteDashPatternKey {
  34. return CLineNoteDashPatternKey
  35. } else if pKey == KMPreference.lineNoteStartLineStyleKey {
  36. return CLineNoteStartLineStyleKey
  37. } else if pKey == KMPreference.lineNoteEndLineStyleKey {
  38. return CLineNoteEndLineStyleKey
  39. }
  40. // freehand
  41. else if pKey == KMPreference.inkNoteLineWidthKey {
  42. return CInkNoteLineWidthKey
  43. } else if pKey == KMPreference.inkNoteLineStyleKey {
  44. return CInkNoteLineStyleKey
  45. } else if pKey == KMPreference.inkNoteDashPatternKey {
  46. return CInkNoteDashPatternKey
  47. }
  48. // circle
  49. else if pKey == KMPreference.circleNoteLineWidthKey {
  50. return CCircleNoteLineWidthKey
  51. } else if pKey == KMPreference.circleNoteLineStyleKey {
  52. return CCircleNoteLineStyleKey
  53. } else if pKey == KMPreference.circleNoteDashPatternKey {
  54. return CCircleNoteDashPatternKey
  55. }
  56. // rect
  57. else if pKey == KMPreference.squareNoteLineWidthKey {
  58. return CSquareNoteLineWidthKey
  59. } else if pKey == KMPreference.squareNoteLineStyleKey {
  60. return CSquareNoteLineStyleKey
  61. } else if pKey == KMPreference.squareNoteDashPatternKey {
  62. return CSquareNoteDashPatternKey
  63. }
  64. return nil
  65. }
  66. // MARK: - NSUserDefault key 与 偏好设置 key 相互转换
  67. func KMPreferenceKeyToUDKey(pKey: KMPreferenceKey) -> String? {
  68. // general
  69. if pKey == KMPreference.generalAuthorNameKey {
  70. return KMUserNameKey
  71. } else if pKey == KMPreference.openLastUnclosedDocumentWhenAppStartKey {
  72. return KMReopenLastOpenFilesKey
  73. } else if pKey == KMPreference.openDocumentTypeKey {
  74. return KMOpenDocumentInTabKey
  75. } else if pKey == KMPreference.openFileTypeKey {
  76. return KMInitialWindowSizeOptionKey
  77. } else if pKey == KMPreference.showLeftSideBarKey {
  78. return KMOpenContentsPaneOnlyForTOCKey
  79. } else if pKey == KMPreference.rememberSnapshotKey {
  80. return KMRememberSnapshotsKey
  81. } else if pKey == KMPreference.autoSaveNoteBackupKey {
  82. return KMAutoSaveSkimNotesKey
  83. } else if pKey == KMPreference.keepSnapshotWindowToTopKey {
  84. return KMSnapshotsOnTopKey
  85. } else if pKey == KMPreference.savePasswordTypeKey {
  86. return KMSavePasswordOptionKey
  87. }
  88. return nil
  89. }
  90. func KMPreferenceKeyFromUDKey(udKey: String) -> KMPreferenceKey? {
  91. // general
  92. if udKey == KMUserNameKey {
  93. return KMPreference.generalAuthorNameKey
  94. } else if udKey == KMReopenLastOpenFilesKey {
  95. return KMPreference.openLastUnclosedDocumentWhenAppStartKey
  96. } else if udKey == KMOpenDocumentInTabKey {
  97. return KMPreference.openDocumentTypeKey
  98. } else if udKey == KMInitialWindowSizeOptionKey {
  99. return KMPreference.openFileTypeKey
  100. } else if udKey == KMOpenContentsPaneOnlyForTOCKey {
  101. return KMPreference.showLeftSideBarKey
  102. } else if udKey == KMRememberSnapshotsKey {
  103. return KMPreference.rememberSnapshotKey
  104. } else if udKey == KMAutoSaveSkimNotesKey {
  105. return KMPreference.autoSaveNoteBackupKey
  106. } else if udKey == KMSnapshotsOnTopKey {
  107. return KMPreference.keepSnapshotWindowToTopKey
  108. } else if udKey == KMSavePasswordOptionKey {
  109. return KMPreference.savePasswordTypeKey
  110. }
  111. return nil
  112. }