|
@@ -28,45 +28,7 @@ private let KMSetDefaultPDFReaderKey: KMPreferenceKey = "KMSetDefaultPDFReaderKe
|
|
|
/// save password
|
|
|
private let KMSavePasswordTypeKey: KMPreferenceKey = "KMSavePasswordTypeKey"
|
|
|
private let KMGeneralAuthorNameKey: KMPreferenceKey = "KMGeneralAuthorNameKey"
|
|
|
-
|
|
|
-// Tip: 新补充
|
|
|
-
|
|
|
-private let KMOpenDocumentTypeKey: KMPreferenceKey = "KMOpenDocumentTypeKey"
|
|
|
-private let KMGeneralShowInMenuBarKey: KMPreferenceKey = "KMGeneralShowInMenuBarKey"
|
|
|
-private let KMOpenFileTypeKey: KMPreferenceKey = "KMOpenFileTypeKey"
|
|
|
-private let KMShowLeftSideBarKey: KMPreferenceKey = "KMShowLeftSideBarKey"
|
|
|
-private let KMEditPDFPopWindowShowKey: KMPreferenceKey = "KMEditPDFPopWindowShowKey"
|
|
|
-private let KMRememberSnapshotKey: KMPreferenceKey = "KMRememberSnapshotKey"
|
|
|
-private let KMRevertInitPDFViewSettingTypeKey: KMPreferenceKey = "KMRevertInitPDFViewSettingTypeKey"
|
|
|
-private let KMAutoSaveNoteBackupKey: KMPreferenceKey = "KMAutoSaveNoteBackupKey"
|
|
|
-private let KMKeepSnapshotWindowToTopKey: KMPreferenceKey = "KMKeepSnapshotWindowToTopKey"
|
|
|
-
|
|
|
-/// display
|
|
|
-private let KMViewPageDisplayTypeKey: KMPreferenceKey = "KMViewPageDisplayTypeKey"
|
|
|
-private let KMViewZoomScaleTypeKey: KMPreferenceKey = "KMViewZoomScaleTypeKey"
|
|
|
-private let KMLeftSideDisplayTypeKey: KMPreferenceKey = "KMLeftSideDisplayTypeKey"
|
|
|
-private let KMShowOutlineListKey: KMPreferenceKey = "KMShowOutlineListKey"
|
|
|
-private let KMLeftSideExpandTypeKey: KMPreferenceKey = "KMLeftSideExpandTypeKey"
|
|
|
-private let KMPropertyPanelExpandTypeKey: KMPreferenceKey = "KMPropertyPanelExpandTypeKey"
|
|
|
-private let KMDisplayBackgroundNormalColorKey: KMPreferenceKey = "KMDisplayBackgroundNormalColorKey"
|
|
|
-private let KMDisplayBackgroundFullScreenColorKey: KMPreferenceKey = "KMDisplayBackgroundFullScreenColorKey"
|
|
|
-private let KMHighlightFormsKey: KMPreferenceKey = "KMHighlightFormsKey"
|
|
|
-private let KMDisplayFieldHighlightingColorKey: KMPreferenceKey = "KMDisplayFieldHighlightingColorKey"
|
|
|
-private let KMDisplayRequiredFieldHighlightingColorKey: KMPreferenceKey = "KMDisplayRequiredFieldHighlightingColorKey"
|
|
|
-private let KMPageIndicatorTypeKey: KMPreferenceKey = "KMPageIndicatorTypeKey"
|
|
|
-private let KMHighlightLinksKey: KMPreferenceKey = "KMHighlightLinksKey"
|
|
|
-
|
|
|
-// Tip: 新补充
|
|
|
-
|
|
|
-private let KMThumbPageSizeKey: KMPreferenceKey = "KMThumbPageSizeKey"
|
|
|
-private let KMThumbSnapshotSizeKey: KMPreferenceKey = "KMThumbSnapshotSizeKey"
|
|
|
-private let KMDiscreteSizeKey: KMPreferenceKey = "KMDiscreteSizeKey"
|
|
|
-private let KMOutlineFontSizeKey: KMPreferenceKey = "KMOutlineFontSizeKey"
|
|
|
-private let KMGreekThresholdKey: KMPreferenceKey = "KMGreekThresholdKey"
|
|
|
-private let KMAntiAliasTextKey: KMPreferenceKey = "KMAntiAliasTextKey"
|
|
|
-private let KMReadBarColorKey: KMPreferenceKey = "KMReadBarColorKey"
|
|
|
-private let KMInvertBarKey: KMPreferenceKey = "KMInvertBarKey"
|
|
|
-
|
|
|
+
|
|
|
/// 偏好设置已改变
|
|
|
private let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
|
|
|
|
|
@@ -104,59 +66,11 @@ typealias KMPreference = KMPreferenceManager
|
|
|
/// save password
|
|
|
public static let savePasswordTypeKey = KMSavePasswordTypeKey
|
|
|
public static let generalAuthorNameKey = KMGeneralAuthorNameKey
|
|
|
-
|
|
|
- // Tip: 新补充
|
|
|
- public static let openDocumentTypeKey = KMOpenDocumentTypeKey
|
|
|
- public static let showInMenuBarKey = KMGeneralShowInMenuBarKey
|
|
|
- public static let openFileTypeKey = KMOpenFileTypeKey
|
|
|
- public static let showLeftSideBarKey = KMShowLeftSideBarKey
|
|
|
- public static let editPDFPopWindowShowKey = KMEditPDFPopWindowShowKey
|
|
|
- public static let rememberSnapshotKey = KMRememberSnapshotKey
|
|
|
- public static let revertInitPDFViewSettingTypeKey = KMRevertInitPDFViewSettingTypeKey
|
|
|
- public static let autoSaveNoteBackupKey = KMAutoSaveNoteBackupKey
|
|
|
- public static let keepSnapshotWindowToTopKey = KMKeepSnapshotWindowToTopKey
|
|
|
-
|
|
|
- /// display
|
|
|
- public static let viewPageDisplayTypeKey = KMViewPageDisplayTypeKey
|
|
|
- public static let viewZoomScaleTypeKey = KMViewZoomScaleTypeKey
|
|
|
- public static let leftSideDisplayTypeKey = KMLeftSideDisplayTypeKey
|
|
|
- public static let showOutlineListKey = KMShowOutlineListKey
|
|
|
- public static let leftSideExpandTypeKey = KMLeftSideExpandTypeKey
|
|
|
- public static let propertyPanelExpandTypeKey = KMPropertyPanelExpandTypeKey
|
|
|
- public static let displayBackgroundNormalColorKey = KMDisplayBackgroundNormalColorKey
|
|
|
- public static let displayBackgroundFullScreenColorKey = KMDisplayBackgroundFullScreenColorKey
|
|
|
- public static let highlightFormsKey = KMHighlightFormsKey
|
|
|
- public static let displayFieldHighlightingColorKey = KMDisplayFieldHighlightingColorKey
|
|
|
- public static let displayRequiredFieldHighlightingColorKey = KMDisplayRequiredFieldHighlightingColorKey
|
|
|
- public static let pageIndicatorTypeKey = KMPageIndicatorTypeKey
|
|
|
- public static let highlightLinksKey = KMHighlightLinksKey
|
|
|
-
|
|
|
- // Tip: 新补充
|
|
|
- public static let thumbPageSizeKey = KMThumbPageSizeKey
|
|
|
- public static let thumbSnapshotSizeKey = KMThumbSnapshotSizeKey
|
|
|
- public static let discreteSizeKey = KMDiscreteSizeKey
|
|
|
- public static let outlineFontSizeKey = KMOutlineFontSizeKey
|
|
|
- public static let greekThresholdKey = KMGreekThresholdKey
|
|
|
- public static let antiAliasTextKey = KMAntiAliasTextKey
|
|
|
- public static let readBarColorKey = KMReadBarColorKey
|
|
|
- public static let invertBarKey = KMInvertBarKey
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
override init() {
|
|
|
super.init()
|
|
|
-
|
|
|
- /// 初始化
|
|
|
- generalGroupKeys = self.getDefaultKeys(for: .general)
|
|
|
- displayGroupKeys = self.getDefaultKeys(for: .display)
|
|
|
- markupGroupKeys = self.getDefaultKeys(for: .markup)
|
|
|
- let info = UserDefaults.standard.value(forKey: KMPreferenceInfoKey)
|
|
|
- if (info == nil) {
|
|
|
- let info = self.getDefaultInfo()
|
|
|
- UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// MARK: 保存/获取数据
|
|
@@ -165,88 +79,21 @@ typealias KMPreference = KMPreferenceManager
|
|
|
}
|
|
|
|
|
|
public func setData(data: Any,forKey key: KMPreferenceKey, in group: KMPreferenceGroup) -> Bool {
|
|
|
- var info: [String : Any]?
|
|
|
- if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
- info = self.getDefaultInfo()
|
|
|
- } else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
- }
|
|
|
-
|
|
|
- var groupInfo: [String : Any] = info?[group.rawValue] as? [String : Any] ?? [:]
|
|
|
- groupInfo.updateValue(data, forKey: key)
|
|
|
-
|
|
|
- info?.updateValue(groupInfo, forKey: group.rawValue)
|
|
|
- UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
-
|
|
|
- if self._grouping {
|
|
|
- self._grouping_objects.insert(group)
|
|
|
- self._grouping_infos[key] = data
|
|
|
- } else {
|
|
|
- self.postNotification(object: [group], userInfo: [key : data])
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
public func getData(forKey key: KMPreferenceKey) -> Any {
|
|
|
var info: [String : Any]?
|
|
|
- if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
- info = self.getDefaultInfo()
|
|
|
- } else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
- }
|
|
|
|
|
|
let groupInfo: [String : Any] = info?[findGroup(forKey: key).rawValue] as? [String : Any] ?? [:]
|
|
|
return groupInfo[key] as Any
|
|
|
}
|
|
|
|
|
|
public func resetData(_ group: KMPreferenceGroup) {
|
|
|
- var info: [String : Any]?
|
|
|
- if (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) == nil) {
|
|
|
- info = self.getDefaultInfo()
|
|
|
- } else {
|
|
|
- info = (UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]) ?? [:]
|
|
|
- }
|
|
|
-
|
|
|
- let groupInfo = self.getDefaultInfo()[group.rawValue]
|
|
|
- info?.updateValue(groupInfo as Any, forKey: group.rawValue)
|
|
|
- UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
-
|
|
|
- self._resetDataToUserDefault(group: group)
|
|
|
-
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
- let info: [String : Any]? = UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]
|
|
|
- var groupInfo: [KMPreferenceKey : Any]?
|
|
|
- if (info != nil) {
|
|
|
- groupInfo = info![group.rawValue] as? [KMPreferenceKey : Any]
|
|
|
- }
|
|
|
- self.postNotification(object: [group], userInfo: groupInfo != nil ? groupInfo : [:])
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public func resetAllData() {
|
|
|
- let info = self.getDefaultInfo()
|
|
|
- UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
-
|
|
|
- self._resetDataToUserDefault(group: .general)
|
|
|
- self._resetDataToUserDefault(group: .display)
|
|
|
- self._resetDataToUserDefault(group: .markup)
|
|
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
- var groppInfos: [KMPreferenceKey : Any] = [:]
|
|
|
- for groupInfo in info.values {
|
|
|
- for (key, value) in groupInfo {
|
|
|
- groppInfos.updateValue(value, forKey: key)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.postNotification(object: [KMPreferenceGroup.general, KMPreferenceGroup.display, KMPreferenceGroup.markup, KMPreferenceGroup.infomation, KMPreferenceGroup.other], userInfo: groppInfos)
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// MARK: 注册 key
|
|
|
public func register(_ key: KMPreferenceKey, to group: KMPreferenceGroup) -> Bool {
|
|
|
if (group == .general) {
|
|
@@ -278,87 +125,6 @@ typealias KMPreference = KMPreferenceManager
|
|
|
}
|
|
|
return .other
|
|
|
}
|
|
|
-
|
|
|
- private func getDefaultKeys(for group: KMPreferenceGroup) -> Array<KMPreferenceKey> {
|
|
|
- if (group == .general) {
|
|
|
- return [KMOpenLastUnclosedDocumentWhenAppStartKey,
|
|
|
- KMOpenLastUnlockedDocumentWhenAppStartKey,
|
|
|
- KMDocumentMaximunDisplayNumberKey,
|
|
|
- KMAutoSaveKey,
|
|
|
- KMAutoSavePerNumberMinuteKey,
|
|
|
- KMCloseFilePromptTypeKey,
|
|
|
- KMOpenImageFileTypeKey,
|
|
|
- KMSetDefaultPDFReaderKey,
|
|
|
- KMSavePasswordTypeKey,
|
|
|
- KMGeneralAuthorNameKey,
|
|
|
- // Tip: 新补充
|
|
|
- KMOpenDocumentTypeKey, KMGeneralShowInMenuBarKey, KMOpenFileTypeKey, KMShowLeftSideBarKey, KMEditPDFPopWindowShowKey,
|
|
|
- KMRememberSnapshotKey, KMRevertInitPDFViewSettingTypeKey, KMAutoSaveNoteBackupKey, KMKeepSnapshotWindowToTopKey]
|
|
|
- } else if (group == .display) {
|
|
|
- return [KMViewPageDisplayTypeKey,
|
|
|
- KMViewZoomScaleTypeKey,
|
|
|
- KMLeftSideDisplayTypeKey,
|
|
|
- KMShowOutlineListKey,
|
|
|
- KMLeftSideExpandTypeKey,
|
|
|
- KMPropertyPanelExpandTypeKey,
|
|
|
- KMDisplayBackgroundNormalColorKey,
|
|
|
- KMDisplayBackgroundFullScreenColorKey,
|
|
|
- KMHighlightFormsKey,
|
|
|
- KMDisplayFieldHighlightingColorKey,
|
|
|
- KMDisplayRequiredFieldHighlightingColorKey,
|
|
|
- KMPageIndicatorTypeKey,
|
|
|
- KMHighlightLinksKey,
|
|
|
- // Tip: 新补充
|
|
|
- KMThumbPageSizeKey, KMThumbSnapshotSizeKey, KMDiscreteSizeKey, KMOutlineFontSizeKey,
|
|
|
- KMGreekThresholdKey, KMAntiAliasTextKey, KMReadBarColorKey, KMInvertBarKey]
|
|
|
- } else if (group == .markup) {
|
|
|
- return []
|
|
|
- }
|
|
|
- return []
|
|
|
- }
|
|
|
-
|
|
|
- private func getDefaultInfo() -> Dictionary<String, Dictionary<String, Any>> {
|
|
|
- return [KMPreferenceGroup.general.rawValue : [KMOpenLastUnclosedDocumentWhenAppStartKey : false,
|
|
|
- KMOpenLastUnlockedDocumentWhenAppStartKey : true,
|
|
|
- KMDocumentMaximunDisplayNumberKey : 10,
|
|
|
- KMAutoSaveKey : true,
|
|
|
- KMAutoSavePerNumberMinuteKey : 5,
|
|
|
- KMCloseFilePromptTypeKey : 0,
|
|
|
- KMOpenImageFileTypeKey : 0,
|
|
|
- KMSetDefaultPDFReaderKey : true,
|
|
|
- KMSavePasswordTypeKey : 2,
|
|
|
- KMGeneralAuthorNameKey : NSFullUserName(),
|
|
|
- // Tip: 新补充
|
|
|
- KMOpenDocumentTypeKey : self.openDocumentTypeDefaultValue.rawValue,
|
|
|
- KMGeneralShowInMenuBarKey : self.showInMenuBarDefaultValue,
|
|
|
- KMOpenFileTypeKey : self.openFileTypeDefaultValue.rawValue,
|
|
|
- KMShowLeftSideBarKey : self.showLeftSideBarDefaultValue,
|
|
|
- KMEditPDFPopWindowShowKey : self.editPDFPopWindowIsShowDefaultValue,
|
|
|
- KMRememberSnapshotKey : self.rememberSnapshotDefaultValue,
|
|
|
- KMRevertInitPDFViewSettingTypeKey : self.revertInitPDFViewSettingTypeDefaultValue.rawValue,
|
|
|
- KMAutoSaveNoteBackupKey : self.autoSaveNoteBackupDefaultValue,
|
|
|
- KMKeepSnapshotWindowToTopKey : self.keepSnapshotWindowToTopDefaultValue()],
|
|
|
- KMPreferenceGroup.display.rawValue : [KMViewPageDisplayTypeKey : 1,
|
|
|
- KMViewZoomScaleTypeKey : 0,
|
|
|
- KMLeftSideDisplayTypeKey : 0,
|
|
|
- KMShowOutlineListKey: true,
|
|
|
- KMLeftSideExpandTypeKey : 0,
|
|
|
- KMPropertyPanelExpandTypeKey : 0,
|
|
|
- KMDisplayBackgroundFullScreenColorKey : self.displayBackgroundFullScreenColorValues,
|
|
|
- KMHighlightFormsKey : true,
|
|
|
- KMPageIndicatorTypeKey : 0,
|
|
|
- KMHighlightLinksKey : true,
|
|
|
- // Tip: 新补充
|
|
|
- KMThumbPageSizeKey : self.thumbPageSizeDefaultValue(),
|
|
|
- KMThumbSnapshotSizeKey : self.thumbSnapshotSizeDefaultValue(),
|
|
|
- KMDiscreteSizeKey : self.discreteSizeDefaultValue(),
|
|
|
- KMOutlineFontSizeKey : self.outlineFontSizeDefaultValue(),
|
|
|
- KMGreekThresholdKey : self.greekThresholdDefaultValue(),
|
|
|
- KMAntiAliasTextKey : self.antiAliasTextDefaultValue(),
|
|
|
- KMInvertBarKey : self.invertBarDefaultValue()],
|
|
|
- KMPreferenceGroup.infomation.rawValue : [:],
|
|
|
- KMPreferenceGroup.other.rawValue : [:]]
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// MARK: - 默认值
|
|
@@ -371,110 +137,8 @@ extension KMPreferenceManager {
|
|
|
return .inSameWindow
|
|
|
}
|
|
|
}
|
|
|
- var showInMenuBarDefaultValue: Bool {
|
|
|
- get {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
- var openFileTypeDefaultValue: KMPreferenceOpenFileType {
|
|
|
- get {
|
|
|
- return .default
|
|
|
- }
|
|
|
- }
|
|
|
- var showLeftSideBarDefaultValue: Bool {
|
|
|
- get {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- var editPDFPopWindowIsShowDefaultValue: Bool {
|
|
|
- get {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- var rememberSnapshotDefaultValue: Bool {
|
|
|
- get {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- var revertInitPDFViewSettingTypeDefaultValue: KMPreferenceRevertInitSettingType {
|
|
|
- get {
|
|
|
- return .normal
|
|
|
- }
|
|
|
- }
|
|
|
- var autoSaveNoteBackupDefaultValue: Bool {
|
|
|
- get {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 内联函数
|
|
|
- @inline (__always) func keepSnapshotWindowToTopDefaultValue() -> Bool {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- // Display
|
|
|
-
|
|
|
- @inline (__always) func thumbPageSizeDefaultValue() -> Float {
|
|
|
- return 128
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func thumbSnapshotSizeDefaultValue() -> Float {
|
|
|
- return 128
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func discreteSizeDefaultValue() -> Bool {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func outlineFontSizeDefaultValue() -> Float {
|
|
|
- return 12
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func greekThresholdDefaultValue() -> Float {
|
|
|
- return 3
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func antiAliasTextDefaultValue() -> Bool {
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- @inline (__always) func invertBarDefaultValue() -> Bool {
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-// MARK: - 扩展 颜色
|
|
|
-extension KMPreferenceManager {
|
|
|
-
|
|
|
- fileprivate var displayBackgroundFullScreenColorValues: [Double] {
|
|
|
- get {
|
|
|
- return [54/255.0, 56/255.0, 59/255.0, 1.0]
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func setColor(_ color: NSColor, forKey key: KMPreferenceKey) -> Bool {
|
|
|
- var red: CGFloat = 0.0
|
|
|
- var green: CGFloat = 0.0
|
|
|
- var blue: CGFloat = 0.0
|
|
|
- var alpha: CGFloat = 0.0
|
|
|
- color.usingColorSpaceName(.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
- return KMPreferenceManager.shared.setData(data: [red, green, blue, alpha], forKey: key)
|
|
|
- }
|
|
|
-
|
|
|
- private func getColor(forKey key: KMPreferenceKey) -> NSColor {
|
|
|
- var colors: [Double]? = self.getData(forKey: key) as? [Double]
|
|
|
- if (colors == nil) {
|
|
|
- colors = self.getDefaultColors(forKey: key)
|
|
|
- }
|
|
|
- return NSColor(red: colors![0], green: colors![1], blue: colors![2], alpha: colors![3])
|
|
|
- }
|
|
|
-
|
|
|
- private func dataToColor(colors:[Double]) -> NSColor {
|
|
|
- NSColor(red: colors[0], green: colors[1], blue: colors[2], alpha: colors[3])
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
// MARK: 扩展 General
|
|
|
extension KMPreferenceManager {
|
|
|
var openLastUnclosedDocumentWhenAppStart: Bool {
|
|
@@ -483,7 +147,7 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
set {
|
|
|
let pKey = KMPreference.openLastUnclosedDocumentWhenAppStartKey
|
|
|
- self._syncDataToUserDefault(newValue, forKey: pKey)
|
|
|
+
|
|
|
_ = self.setData(data: newValue, forKey: pKey)
|
|
|
}
|
|
|
}
|
|
@@ -555,7 +219,6 @@ extension KMPreferenceManager {
|
|
|
return KMDataManager.ud_string(forKey: KMUserNameKey) ?? NSFullUserName()
|
|
|
}
|
|
|
set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMGeneralAuthorNameKey)
|
|
|
let _ = self.setData(data: newValue, forKey: KMGeneralAuthorNameKey)
|
|
|
}
|
|
|
}
|
|
@@ -590,7 +253,7 @@ extension KMPreferenceManager {
|
|
|
} else if newValue == .ask {
|
|
|
data = -1
|
|
|
}
|
|
|
- self._syncDataToUserDefault(data, forKey: KMSavePasswordTypeKey)
|
|
|
+
|
|
|
let _ = self.setData(data: newValue.rawValue, forKey: KMSavePasswordTypeKey)
|
|
|
}
|
|
|
}
|
|
@@ -608,22 +271,10 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
set {
|
|
|
if (newValue == .inSameWindow || newValue == .newWindow) {
|
|
|
- let pKey = KMOpenDocumentTypeKey
|
|
|
- self._syncDataToUserDefault(NSNumber(value: newValue.rawValue), forKey: pKey)
|
|
|
- _ = self.setData(data: newValue.rawValue, forKey: pKey)
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- var showInMenuBar: Bool {
|
|
|
- get {
|
|
|
- return self.getData(forKey: KMGeneralShowInMenuBarKey) as? Bool ?? self.showInMenuBarDefaultValue
|
|
|
- }
|
|
|
- set {
|
|
|
- _ = self.setData(data: newValue, forKey: KMGeneralShowInMenuBarKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
var openFileType: KMPreferenceOpenFileType {
|
|
|
get {
|
|
|
// 数据兼容
|
|
@@ -637,70 +288,10 @@ extension KMPreferenceManager {
|
|
|
set {
|
|
|
if (newValue == .default || newValue == .maxim || newValue == .fit) {
|
|
|
// 数据兼容
|
|
|
- self._syncDataToUserDefault(newValue.rawValue, forKey: KMOpenFileTypeKey)
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMOpenFileTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var showLeftSideBar: Bool {
|
|
|
- get {
|
|
|
- return KMDataManager.ud_bool(forKey: KMOpenContentsPaneOnlyForTOCKey)
|
|
|
-
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMShowLeftSideBarKey)
|
|
|
- _ = self.setData(data: newValue, forKey: KMShowLeftSideBarKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var editPDFPopWindowIsShow: Bool {
|
|
|
- get {
|
|
|
- return self.getData(forKey: Self.editPDFPopWindowShowKey) as? Bool ?? self.editPDFPopWindowIsShowDefaultValue
|
|
|
- }
|
|
|
- set {
|
|
|
- _ = self.setData(data: newValue, forKey: Self.editPDFPopWindowShowKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var rememberSnapshot: Bool {
|
|
|
- get {
|
|
|
- return KMDataManager.ud_bool(forKey: KMRememberSnapshotsKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- // 数据兼容
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMRememberSnapshotKey)
|
|
|
- _ = self.setData(data: newValue, forKey: KMRememberSnapshotKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var revertInitPDFViewSettingType: KMPreferenceRevertInitSettingType {
|
|
|
- get {
|
|
|
- guard let type = self.getData(forKey: KMRevertInitPDFViewSettingTypeKey) as? Int else {
|
|
|
- return self.revertInitPDFViewSettingTypeDefaultValue
|
|
|
- }
|
|
|
-
|
|
|
- if type == 1 {
|
|
|
- return .fullScreen
|
|
|
- }
|
|
|
- return .normal
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == .normal || newValue == .fullScreen) {
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMRevertInitPDFViewSettingTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var autoSaveNoteBackup: Bool {
|
|
|
- get {
|
|
|
- return KMDataManager.ud_bool(forKey: KMAutoSaveSkimNotesKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMAutoSaveNoteBackupKey)
|
|
|
- _ = self.setData(data: newValue, forKey: KMAutoSaveNoteBackupKey)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
var keepSnapshotWindowToTop: Bool {
|
|
|
get {
|
|
@@ -708,290 +299,11 @@ extension KMPreferenceManager {
|
|
|
}
|
|
|
set {
|
|
|
// 数据兼容
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMKeepSnapshotWindowToTopKey)
|
|
|
- _ = self.setData(data: newValue, forKey: KMKeepSnapshotWindowToTopKey)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// MARK: 扩展 Display
|
|
|
-extension KMPreferenceManager {
|
|
|
-
|
|
|
- var viewZoomScaleType: KMPDFZoomType {
|
|
|
- get {
|
|
|
- if let type = self.getData(forKey: KMViewZoomScaleTypeKey) as? Int {
|
|
|
- if (type == 0) {
|
|
|
- return .width
|
|
|
- } else if (type == 1) {
|
|
|
- return .fit
|
|
|
- } else if (type == 2) {
|
|
|
- return .actualSize
|
|
|
- }
|
|
|
- }
|
|
|
- return .width
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == .width || newValue == .fit || newValue == .actualSize) {
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMViewZoomScaleTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var leftSideDisplayType: KMPreferenceLeftSideDisplayType {
|
|
|
- get {
|
|
|
- if let type = self.getData(forKey: KMLeftSideDisplayTypeKey) as? Int {
|
|
|
- if type == 0 {
|
|
|
- return .closeWhenOpenFile
|
|
|
- } else if (type == 1) {
|
|
|
- return .openAppSaveLastSelect
|
|
|
- } else if (type == 2) {
|
|
|
- return .showOutlineIfHas
|
|
|
- }
|
|
|
- }
|
|
|
- return .closeWhenOpenFile
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == .closeWhenOpenFile || newValue == .openAppSaveLastSelect || newValue == .showOutlineIfHas) {
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMLeftSideDisplayTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var propertyPanelExpandType: KMPreferencePropertyPanelExpandType {
|
|
|
- get {
|
|
|
- if let type = self.getData(forKey: KMPropertyPanelExpandTypeKey) as? Int {
|
|
|
- if (type == 0) {
|
|
|
- return .auto
|
|
|
- } else if (type == 1) {
|
|
|
- return .manual
|
|
|
- }
|
|
|
- }
|
|
|
- return .auto
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == .auto || newValue == .manual) {
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMPropertyPanelExpandTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var highlightForms: Bool {
|
|
|
- get {
|
|
|
- return self.getData(forKey: KMHighlightFormsKey) as? Bool ?? true
|
|
|
- }
|
|
|
- set {
|
|
|
- let _ = self.setData(data: newValue, forKey: KMHighlightFormsKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var pageIndicatorType: KMPreferencePageIndicatorDisplayType {
|
|
|
- get {
|
|
|
- if let type = self.getData(forKey: KMPageIndicatorTypeKey) as? Int {
|
|
|
- if (type == 2) {
|
|
|
- return .never
|
|
|
- } else if (type == 0) {
|
|
|
- return .automatic
|
|
|
- } else if (type == 1) {
|
|
|
- return .always
|
|
|
- }
|
|
|
- }
|
|
|
- return .never
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == .automatic || newValue == .always || newValue == .never) {
|
|
|
- let _ = self.setData(data: newValue.rawValue, forKey: KMPageIndicatorTypeKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var highlightLinks: Bool {
|
|
|
- get {
|
|
|
- return self.getData(forKey: KMHighlightLinksKey) as? Bool ?? true
|
|
|
- }
|
|
|
- set {
|
|
|
- let _ = self.setData(data: newValue, forKey: KMHighlightLinksKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var displayBackgroundNormalColor: NSColor {
|
|
|
- get {
|
|
|
- if let color = UserDefaults.standard.color(forKey: KMBackgroundColorKey) {
|
|
|
- return color
|
|
|
- }
|
|
|
- return self.getColor(forKey: KMDisplayBackgroundNormalColorKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMDisplayBackgroundNormalColorKey)
|
|
|
- let _ = self.setColor(newValue, forKey: KMDisplayBackgroundNormalColorKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var displayBackgroundFullScreenColor: NSColor {
|
|
|
- get {
|
|
|
- if let color = UserDefaults.standard.color(forKey: KMFullScreenBackgroundColorKey) {
|
|
|
- return color
|
|
|
- }
|
|
|
- return self.getColor(forKey: KMDisplayBackgroundFullScreenColorKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMDisplayBackgroundFullScreenColorKey)
|
|
|
- let _ = self.setColor(newValue, forKey: KMDisplayBackgroundFullScreenColorKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var displayFieldHighlightingColor: NSColor {
|
|
|
- get {
|
|
|
- return self.getColor(forKey: KMDisplayFieldHighlightingColorKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- let _ = self.setColor(newValue, forKey: KMDisplayFieldHighlightingColorKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var displayRequiredFieldHighlightingColor: NSColor {
|
|
|
- get {
|
|
|
- return self.getColor(forKey: KMDisplayRequiredFieldHighlightingColorKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- let _ = self.setColor(newValue, forKey: KMDisplayRequiredFieldHighlightingColorKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Tip: 新补充
|
|
|
-
|
|
|
- var thumbPageSize: Float {
|
|
|
- get {
|
|
|
- let num = KMDataManager.ud_object(forKey: KMThumbnailSizeKey) as? NSNumber
|
|
|
- return num?.floatValue ?? self.thumbPageSizeDefaultValue()
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(NSNumber(value: newValue), forKey: KMThumbPageSizeKey)
|
|
|
- let _ = self.setData(data: NSNumber(value: newValue), forKey: KMThumbPageSizeKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var thumbSnapshotSize: Float {
|
|
|
- get {
|
|
|
- let num = KMDataManager.ud_object(forKey: KMSnapshotThumbnailSizeKey) as? NSNumber
|
|
|
- return num?.floatValue ?? self.thumbSnapshotSizeDefaultValue()
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(NSNumber(value: newValue), forKey: KMThumbSnapshotSizeKey)
|
|
|
- let _ = self.setData(data: newValue, forKey: KMThumbSnapshotSizeKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var discreteSize: Bool {
|
|
|
- get {
|
|
|
- return self.getData(forKey: KMDiscreteSizeKey) as? Bool ?? self.discreteSizeDefaultValue()
|
|
|
- }
|
|
|
- set {
|
|
|
- let _ = self.setData(data: newValue, forKey: KMDiscreteSizeKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var outlineFontSize: Float {
|
|
|
- get {
|
|
|
- let num = KMDataManager.ud_object(forKey: KMTableFontSizeKey) as? NSNumber
|
|
|
- return num?.floatValue ?? self.outlineFontSizeDefaultValue()
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(NSNumber(value: newValue), forKey: KMOutlineFontSizeKey)
|
|
|
- let _ = self.setData(data: newValue, forKey: KMOutlineFontSizeKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var greekThreshold: Float {
|
|
|
- get {
|
|
|
- let num = KMDataManager.ud_object(forKey: KMGreekingThresholdKey) as? NSNumber
|
|
|
- return num?.floatValue ?? self.greekThresholdDefaultValue()
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(NSNumber(value: newValue), forKey: KMGreekThresholdKey)
|
|
|
- let _ = self.setData(data: newValue, forKey: KMGreekThresholdKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var antiAliasText: Bool {
|
|
|
- get {
|
|
|
- return KMDataManager.ud_bool(forKey: KMShouldAntiAliasKey)
|
|
|
- }
|
|
|
- set {
|
|
|
- self._syncDataToUserDefault(newValue, forKey: KMAntiAliasTextKey)
|
|
|
- let _ = self.setData(data: newValue, forKey: KMAntiAliasTextKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// MARK: Additions
|
|
|
-extension KMPreferenceManager {
|
|
|
-
|
|
|
- private func _syncDataToUserDefault(_ data: Any, forKey key: KMPreferenceKey) {
|
|
|
- // general
|
|
|
- if let udKey = KMPreferenceKeyToUDKey(pKey: key) {
|
|
|
- if let color = data as? NSColor {
|
|
|
- UserDefaults.standard.setColor(color, forKey: udKey)
|
|
|
- } else {
|
|
|
- KMDataManager.ud_set(data, forKey: udKey)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func getDefaultColors(forKey key: KMPreferenceKey) -> [Double] {
|
|
|
- let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue] ?? [:]
|
|
|
-
|
|
|
-
|
|
|
- let displayGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.display.rawValue] ?? [:]
|
|
|
- for key_i in [KMDisplayBackgroundNormalColorKey, KMDisplayBackgroundFullScreenColorKey,
|
|
|
- KMDisplayFieldHighlightingColorKey, KMDisplayRequiredFieldHighlightingColorKey] {
|
|
|
- if (key == key_i) {
|
|
|
- return displayGroupInfo[key] as? [Double] ?? []
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return [0.0, 0.0, 0.0, 1.0]
|
|
|
- }
|
|
|
-
|
|
|
- private func getDefaultColor(forKey key: KMPreferenceKey) -> NSColor {
|
|
|
- return self.dataToColor(colors: self.getDefaultColors(forKey: key))
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private func _resetDataToUserDefault(group: KMPreferenceGroup) {
|
|
|
- if group == .general {
|
|
|
- KMDataManager.ud_set(nil, forKey: KMUserNameKey)
|
|
|
- KMDataManager.ud_set(NSNumber(value: 0), forKey: KMOpenDocumentInTabKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMReopenLastOpenFilesKey)
|
|
|
- KMDataManager.ud_set(0, forKey: KMInitialWindowSizeOptionKey)
|
|
|
- KMDataManager.ud_set(true, forKey: KMOpenContentsPaneOnlyForTOCKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMRememberSnapshotsKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMAutoSaveSkimNotesKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMSnapshotsOnTopKey)
|
|
|
- KMDataManager.ud_set(-1, forKey: KMSavePasswordOptionKey)
|
|
|
- } else if group == .display {
|
|
|
- KMDataManager.ud_set(NSNumber(value: self.thumbPageSizeDefaultValue()), forKey: KMThumbnailSizeKey)
|
|
|
- KMDataManager.ud_set(NSNumber(value: self.thumbSnapshotSizeDefaultValue()), forKey: KMSnapshotThumbnailSizeKey)
|
|
|
- KMDataManager.ud_set(NSNumber(value: self.outlineFontSizeDefaultValue()), forKey: KMTableFontSizeKey)
|
|
|
- KMDataManager.ud_set(NSNumber(value: self.greekThresholdDefaultValue()), forKey: KMGreekingThresholdKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMShouldAntiAliasKey)
|
|
|
- UserDefaults.standard.setColor(self.getDefaultColor(forKey: KMPreference.displayBackgroundNormalColorKey), forKey: KMBackgroundColorKey)
|
|
|
- UserDefaults.standard.setColor(self.getDefaultColor(forKey: KMPreference.displayBackgroundFullScreenColorKey), forKey: KMFullScreenBackgroundColorKey)
|
|
|
- UserDefaults.standard.setColor(self.getDefaultColor(forKey: KMPreference.readBarColorKey), forKey: KMReadingBarColorKey)
|
|
|
- KMDataManager.ud_set(false, forKey: KMReadingBarInvertKey)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public func initDataForAppLaunch() {
|
|
|
- if (KMPreferenceManager.shared.autoSave) {
|
|
|
-
|
|
|
- KMPreferenceManager.shared.autoSave = false
|
|
|
-
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// MARK: UserDefaults
|
|
|
|
|
|
fileprivate let kKMLastOpenFilepathKey = "lastOpenFilepath"
|
|
@@ -999,6 +311,7 @@ fileprivate let kKMLastOpenFilepathKeys = "lastOpenFilepaths"
|
|
|
fileprivate let kKMViewSettingKey = "viewSetting"
|
|
|
fileprivate let kKMPageNumberKey = "pageNumber"
|
|
|
fileprivate let kKMPageScaleKey = "pageScale"
|
|
|
+
|
|
|
extension KMPreferenceManager {
|
|
|
var lastOpenFilepath: String? {
|
|
|
get {
|
|
@@ -1019,34 +332,7 @@ extension KMPreferenceManager {
|
|
|
UserDefaults.standard.synchronize()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- var viewSetting: [KMPreferenceViewSetting : Any]? {
|
|
|
- get {
|
|
|
- return UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [KMPreferenceViewSetting : Any]
|
|
|
- }
|
|
|
- set {
|
|
|
- if (newValue == nil) {
|
|
|
- UserDefaults.standard.set(newValue, forKey: kKMViewSettingKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let viewSetting: [String : Any] = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any] ?? [:]
|
|
|
- var info: [String : Any] = [:]
|
|
|
- for (key, value) in viewSetting {
|
|
|
- info.updateValue(value, forKey: key)
|
|
|
- }
|
|
|
- for (key, value) in newValue ?? [:] {
|
|
|
- if (key == .pageNumber) { // 只处理 枚举
|
|
|
- info.updateValue(value, forKey: key.rawValue)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- UserDefaults.standard.set(info, forKey: kKMViewSettingKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
func setPageNumber(_ number: Int, forKey key: String) {
|
|
|
UserDefaults.standard.set(number, forKey: "\(key)+\(kKMPageNumberKey)")
|
|
|
UserDefaults.standard.synchronize()
|
|
@@ -1072,17 +358,7 @@ extension KMPreferenceManager {
|
|
|
internal func closeFileIsPrompt() -> Bool {
|
|
|
return self.closeFilePromptType == .promp
|
|
|
}
|
|
|
-
|
|
|
- func leftSideNeedCloseWhenOpenFile() -> Bool {
|
|
|
- return KMPreferenceManager.shared.leftSideDisplayType == .closeWhenOpenFile
|
|
|
- }
|
|
|
-
|
|
|
- var autoExpandPropertyPanel: Bool {
|
|
|
- get {
|
|
|
- return KMPreferenceManager.shared.propertyPanelExpandType == .auto
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// 单位: 秒
|
|
|
var autoSaveTimeInterval: TimeInterval {
|
|
|
get {
|