1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165 |
- //
- // KMPreferenceManager.swift
- // PDF Master
- //
- // Created by tangchao on 2023/2/3.
- //
- import Cocoa
- enum KMPreferenceGroup: String {
- case general, display, markup, infomation, other
- }
- let KMPreferenceInfoKey: String = "KMPreferenceInfoKey"
- typealias KMPreferenceKey = String
- /// general
- /// files
- private let KMOpenLastUnclosedDocumentWhenAppStartKey: KMPreferenceKey = "KMOpenLastUnclosedDocumentWhenAppStartKey"
- private let KMOpenLastUnlockedDocumentWhenAppStartKey: KMPreferenceKey = "KMOpenLastUnlockedDocumentWhenAppStartKey"
- private let KMDocumentMaximunDisplayNumberKey: KMPreferenceKey = "KMDocumentMaximunDisplayNumberKey"
- private let KMAutoSaveKey: KMPreferenceKey = "KMAutoSaveKey"
- private let KMAutoSavePerNumberMinuteKey: KMPreferenceKey = "KMAutoSavePerNumberMinuteKey"
- private let KMCloseFilePromptTypeKey: KMPreferenceKey = "KMCloseFilePromptTypeKey"
- /// open image file
- private let KMOpenImageFileTypeKey: KMPreferenceKey = "KMOpenImageFileTypeKey"
- private let KMSetDefaultPDFReaderKey: KMPreferenceKey = "KMSetDefaultPDFReaderKey"
- /// save password
- private let KMSavePasswordTypeKey: KMPreferenceKey = "KMSavePasswordTypeKey"
- private let KMGeneralAuthorNameKey: KMPreferenceKey = "KMGeneralAuthorNameKey"
- /// 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"
- /// markup
- private let KMMarkupColorHighlightKey: KMPreferenceKey = "KMMarkupColorHighlightKey"
- private let KMMarkupColorStrikthroughKey: KMPreferenceKey = "KMMarkupColorStrikthroughKey"
- private let KMMarkupColorUnderlineKey: KMPreferenceKey = "KMMarkupColorUnderlineKey"
- private let KMMarkupColorPenKey: KMPreferenceKey = "KMMarkupColorPenKey"
- private let KMMarkupColorTextKey: KMPreferenceKey = "KMMarkupColorTextKey"
- private let KMMarkupColorNoteKey: KMPreferenceKey = "KMMarkupColorNoteKey"
- private let KMMarkupColorRectangleFillKey: KMPreferenceKey = "KMMarkupColorRectangleFillKey"
- private let KMMarkupColorRectangleBorderKey: KMPreferenceKey = "KMMarkupColorRectangleBorderKey"
- private let KMMarkupColorCircleFillKey: KMPreferenceKey = "KMMarkupColorCircleFillKey"
- private let KMMarkupColorCircleBorderKey: KMPreferenceKey = "KMMarkupColorCircleBorderKey"
- private let KMMarkupColorLineKey: KMPreferenceKey = "KMMarkupColorLineKey"
- private let KMMarkupColorArrowKey: KMPreferenceKey = "KMMarkupColorArrowKey"
- private let KMMarkupFontTextStringKey: KMPreferenceKey = "KMMarkupFontTextStringKey"
- private let KMMarkupFontTextAligmentKey: KMPreferenceKey = "KMMarkupFontTextAligmentKey"
- private let KMMarkupFontNoteStringKey: KMPreferenceKey = "KMMarkupFontNoteStringKey"
- /// 偏好设置已改变
- private let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
- private let KMDefaultFontName = "Helvetica-Oblique"
- typealias KMPreference = KMPreferenceManager
- @objcMembers class KMPreferenceManager: NSObject {
- static let shared = KMPreferenceManager()
-
- private var generalGroupKeys: Array<KMPreferenceKey> = []
- private var displayGroupKeys: Array<KMPreferenceKey> = []
- private var markupGroupKeys: Array<KMPreferenceKey> = []
-
- public static let didChangeNotification = Notification.Name(KMPreferenceDidChangeNotificationName)
-
- /// general
- /// files
- public static let openLastUnclosedDocumentWhenAppStartKey = KMOpenLastUnclosedDocumentWhenAppStartKey
- public static let openLastUnlockedDocumentWhenAppStartKey = KMOpenLastUnlockedDocumentWhenAppStartKey
- public static let documentMaximunDisplayNumberKey = KMDocumentMaximunDisplayNumberKey
- public static let autoSaveKey = KMAutoSaveKey
- public static let autoSavePerNumberMinuteKey = KMAutoSavePerNumberMinuteKey
- public static let closeFilePromptTypeKey = KMCloseFilePromptTypeKey
- /// open image file
- public static let openImageFileTypeKey = KMOpenImageFileTypeKey
- public static let setDefaultPDFReaderKey = KMSetDefaultPDFReaderKey
- /// save password
- public static let savePasswordTypeKey = KMSavePasswordTypeKey
- public static let generalAuthorNameKey = KMGeneralAuthorNameKey
-
- /// 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
-
- /// markup
- public static let markupColorHighlightKey = KMMarkupColorHighlightKey
- public static let markupColorStrikthroughKey = KMMarkupColorStrikthroughKey
- public static let markupColorUnderlineKey = KMMarkupColorUnderlineKey
- public static let markupColorPenKey = KMMarkupColorPenKey
- public static let markupColorTextKey = KMMarkupColorTextKey
- public static let markupColorNoteKey = KMMarkupColorNoteKey
- public static let markupColorRectangleFillKey = KMMarkupColorRectangleFillKey
- public static let markupColorRectangleBorderKey = KMMarkupColorRectangleBorderKey
- public static let markupColorCircleFillKey = KMMarkupColorCircleFillKey
- public static let markupColorCircleBorderKey = KMMarkupColorCircleBorderKey
- public static let markupColorLineKey = KMMarkupColorLineKey
- public static let markupColorArrowKey = KMMarkupColorArrowKey
- public static let markupFontTextStringKey = KMMarkupFontTextStringKey
- public static let markupFontTextAligmentKey = KMMarkupFontTextAligmentKey
- public static let markupFontNoteStringKey = KMMarkupFontNoteStringKey
-
- 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: 保存/获取数据
- public func setData(data: Any,forKey key: KMPreferenceKey) -> Bool {
- return self.setData(data: data, forKey: key, in: findGroup(forKey: key))
- }
-
- 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()
-
- 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.resetDataToPDFView()
-
- 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.resetDataToPDFView()
-
- 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) {
- if (self.generalGroupKeys.contains(key)) {
- return false
- }
- self.generalGroupKeys.append(key)
- }
- return true
- }
-
- // MARK: -
- // MARK: 发布通知
-
- private func postNotification(object: [KMPreferenceGroup]?, userInfo: [KMPreferenceKey : Any]?) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
- NotificationCenter.default.post(name: KMPreferenceManager.didChangeNotification, object: object, userInfo: userInfo)
- }
- }
-
- // MARK: 获取信息
- private func findGroup(forKey key: KMPreferenceKey) -> KMPreferenceGroup {
- if (self.generalGroupKeys.contains(key)) {
- return .general
- } else if (self.displayGroupKeys.contains(key)) {
- return .display
- } else if (self.markupGroupKeys.contains(key)) {
- return .markup
- }
- return .other
- }
- private func getDefaultKeys(for group: KMPreferenceGroup) -> Array<KMPreferenceKey> {
- if (group == .general) {
- return [KMOpenLastUnclosedDocumentWhenAppStartKey,
- KMOpenLastUnlockedDocumentWhenAppStartKey,
- KMDocumentMaximunDisplayNumberKey,
- KMAutoSaveKey,
- KMAutoSavePerNumberMinuteKey,
- KMCloseFilePromptTypeKey,
- KMOpenImageFileTypeKey,
- KMSetDefaultPDFReaderKey,
- KMSavePasswordTypeKey,
- KMGeneralAuthorNameKey]
- } else if (group == .display) {
- return [KMViewPageDisplayTypeKey,
- KMViewZoomScaleTypeKey,
- KMLeftSideDisplayTypeKey,
- KMShowOutlineListKey,
- KMLeftSideExpandTypeKey,
- KMPropertyPanelExpandTypeKey,
- KMDisplayBackgroundNormalColorKey,
- KMDisplayBackgroundFullScreenColorKey,
- KMHighlightFormsKey,
- KMDisplayFieldHighlightingColorKey,
- KMDisplayRequiredFieldHighlightingColorKey,
- KMPageIndicatorTypeKey,
- KMHighlightLinksKey]
- } else if (group == .markup) {
- return [KMMarkupColorHighlightKey,
- KMMarkupColorUnderlineKey,
- KMMarkupColorStrikthroughKey,
- KMMarkupColorPenKey,
- KMMarkupColorLineKey,
- KMMarkupColorArrowKey,
- KMMarkupColorNoteKey,
- KMMarkupColorTextKey,
- KMMarkupColorCircleFillKey,
- KMMarkupColorCircleBorderKey,
- KMMarkupColorRectangleFillKey,
- KMMarkupColorRectangleBorderKey,
- KMMarkupFontTextStringKey,
- KMMarkupFontTextAligmentKey,
- KMMarkupFontNoteStringKey]
- }
- 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()],
- KMPreferenceGroup.display.rawValue : [KMViewPageDisplayTypeKey : 1,
- KMViewZoomScaleTypeKey : 0,
- KMLeftSideDisplayTypeKey : 0,
- KMShowOutlineListKey: true,
- KMLeftSideExpandTypeKey : 0,
- KMPropertyPanelExpandTypeKey : 0,
- KMDisplayBackgroundNormalColorKey : self.displayBackgroundNormalColorValues,
- KMDisplayBackgroundFullScreenColorKey : self.displayBackgroundFullScreenColorValues,
- KMHighlightFormsKey : true,
- KMDisplayFieldHighlightingColorKey : self.displayFieldHighlightingColorValues,
- KMDisplayRequiredFieldHighlightingColorKey : self.displayRequiredFieldHighlightingColorValues,
- KMPageIndicatorTypeKey : 0,
- KMHighlightLinksKey : true],
- KMPreferenceGroup.markup.rawValue : [KMMarkupColorHighlightKey : self.markupHighlightColorValues,
- KMMarkupColorStrikthroughKey : self.markupStrikthroughColorValues,
- KMMarkupColorUnderlineKey : self.markupUnderlineColorValues,
- KMMarkupColorPenKey : self.markupPenColorValues,
- KMMarkupColorTextKey : self.markupTextColorValues,
- KMMarkupColorNoteKey : self.markupNoteColorValues,
- KMMarkupColorRectangleFillKey : self.markupRectangleFillColorValues,
- KMMarkupColorRectangleBorderKey : self.markupRectangleBorderColorValues,
- KMMarkupColorCircleFillKey : self.markupCircleFillColorValues,
- KMMarkupColorCircleBorderKey : self.markupCircleBorderColorValues,
- KMMarkupColorLineKey : self.markupLineColorValues,
- KMMarkupColorArrowKey : self.markupArrowColorValues,
- KMMarkupFontTextStringKey : KMDefaultFontName,
- KMMarkupFontTextAligmentKey : 0,
- KMMarkupFontNoteStringKey : KMDefaultFontName],
- KMPreferenceGroup.infomation.rawValue : [:],
- KMPreferenceGroup.other.rawValue : [:]]
- }
-
- }
- //protocol KMPreferenceManagerColorPart: NSObjectProtocol {
- // var markupHighlightColorValues: [Double] { get }
- //}
- // MARK: 扩展 颜色
- extension KMPreferenceManager {
- fileprivate var displayBackgroundNormalColorValues: [Double] {
- get {
- return [206/255.0, 208/255.0, 212/255.0, 1.0]
- }
- }
- fileprivate var displayBackgroundFullScreenColorValues: [Double] {
- get {
- return [54/255.0, 56/255.0, 59/255.0, 1.0]
- }
- }
- fileprivate var displayFieldHighlightingColorValues: [Double] {
- get {
- return [189/255.0, 223/255.0, 253/255.0, 1.0]
- }
- }
- fileprivate var displayRequiredFieldHighlightingColorValues: [Double] {
- get {
- return [23/255.0, 112/255.0, 224/255.0, 1.0]
- }
- }
- fileprivate var markupHighlightColorValues: [Double] {
- get {
- return [255/255.0, 175/255.0, 37/255.0, 1.0]
- }
- }
- fileprivate var markupStrikthroughColorValues: [Double] {
- get {
- return [252/255.0, 31/255.0, 31/255.0, 1.0]
- }
- }
- fileprivate var markupUnderlineColorValues: [Double] {
- get {
- return [30/255.0, 137/255.0, 86/255.0, 1.0]
- }
- }
- fileprivate var markupPenColorValues: [Double] {
- get {
- self.markupStrikthroughColorValues
- }
- }
- fileprivate var markupTextColorValues: [Double] {
- get {
- return [37/255.0, 38/255.0, 41/255.0, 1.0]
- }
- }
- fileprivate var markupNoteColorValues: [Double] {
- get {
- return [255/255.0, 213/255.0, 115/255.0, 1.0]
- }
- }
- fileprivate var markupRectangleFillColorValues: [Double] {
- get {
- return [0/255.0, 0/255.0, 0/255.0, 0.0]
- }
- }
- fileprivate var markupRectangleBorderColorValues: [Double] {
- get {
- self.markupStrikthroughColorValues
- }
- }
- fileprivate var markupCircleFillColorValues: [Double] {
- get {
- self.markupRectangleFillColorValues
- }
- }
- fileprivate var markupCircleBorderColorValues: [Double] {
- get {
- return self.markupRectangleBorderColorValues
- }
- }
- fileprivate var markupLineColorValues: [Double] {
- get {
- self.markupStrikthroughColorValues
- }
- }
- fileprivate var markupArrowColorValues: [Double] {
- get {
- self.markupStrikthroughColorValues
- }
- }
-
- 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 {
- get {
- return self.getData(forKey: KMOpenLastUnclosedDocumentWhenAppStartKey) as! Bool
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMOpenLastUnclosedDocumentWhenAppStartKey)
- }
- }
-
- var openLastUnlockedDocumentWhenAppStart: Bool {
- get {
- return self.getData(forKey: KMOpenLastUnlockedDocumentWhenAppStartKey) as! Bool
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMOpenLastUnlockedDocumentWhenAppStartKey)
- }
- }
-
- var documentMaximunDisplayNumber: Int {
- get {
- return self.getData(forKey: KMDocumentMaximunDisplayNumberKey) as! Int
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMDocumentMaximunDisplayNumberKey)
- }
- }
-
- var autoSave: Bool {
- get {
- return self.getData(forKey: KMAutoSaveKey) as! Bool
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMAutoSaveKey)
- }
- }
-
- var autoSavePerNumberMinute: Int {
- get {
- return self.getData(forKey: KMAutoSavePerNumberMinuteKey) as! Int
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMAutoSavePerNumberMinuteKey)
- }
- }
-
- var closeFilePromptType: KMPreferenceCloseFilePromptType {
- get {
- let type: Int? = self.getData(forKey: KMCloseFilePromptTypeKey) as? Int
- if (type != nil && type! == 1) { // 无提示,直接保存
- return .noPromp
- }
-
- return .promp
- }
- set {
- if (newValue == .promp || newValue == .noPromp) {
- let _ = self.setData(data: newValue.rawValue, forKey: KMCloseFilePromptTypeKey)
- }
- }
- }
-
- var openImageFileType: Int {
- get {
- return self.getData(forKey: KMOpenImageFileTypeKey) as! Int
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMOpenImageFileTypeKey)
- }
- }
-
- var author: String {
- get {
- return self.getData(forKey: KMGeneralAuthorNameKey) as! String
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMGeneralAuthorNameKey)
- }
- }
-
- var setDefaultPDFReader: Bool {
- get {
- return self.getData(forKey: KMSetDefaultPDFReaderKey) as! Bool
- }
- set {
- let result = KMTools.setDefaultPDFReader(newValue)
- if (result) {
- let _ = self.setData(data: newValue, forKey: KMSetDefaultPDFReaderKey)
- }
- }
- }
-
- var savePasswordType: KMPreferenceSavePasswordType {
- get {
- let type: Int? = self.getData(forKey: KMSavePasswordTypeKey) as? Int
- if (type == nil || type! == 2) {
- return .ask
- }
- if (type! == 0) {
- return .always
- } else if (type! == 1) {
- return .never
- }
-
- return .ask
- }
- set {
- if (newValue == .always || newValue == .never || newValue == .ask) {
- let _ = self.setData(data: newValue.rawValue, forKey: KMSavePasswordTypeKey)
- }
- }
- }
- }
- // MARK: 扩展 Display
- extension KMPreferenceManager {
- var viewPageDisplayType: KMPDFDisplayType {
- get {
- let type: Int? = self.getData(forKey: KMViewPageDisplayTypeKey) as? Int
- if (type == nil || type == 1) {
- return .singlePageContinuous
- }
- if (type! == 0) {
- return .singlePage
- } else if (type! == 2) {
- return .twoUp
- } else if (type! == 3) {
- return .twoUpContinuous
- } else if (type! == 4) {
- return .bookMode
- } else if (type! == 5) {
- return .bookContinuous
- }
-
- return .singlePageContinuous
- }
- set {
- if (newValue == .singlePage || newValue == .singlePageContinuous || newValue == .twoUp ||
- newValue == .twoUpContinuous || newValue == .bookMode || newValue == .bookContinuous) {
- let _ = self.setData(data: newValue.rawValue, forKey: KMViewPageDisplayTypeKey)
- }
- }
- }
-
- var viewZoomScaleType: KMPDFZoomType {
- get {
- let type: Int? = self.getData(forKey: KMViewZoomScaleTypeKey) as? Int
- if (type == nil || 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 {
- let type: Int? = self.getData(forKey: KMLeftSideDisplayTypeKey) as? Int
- if (type == nil || 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 showOutlineList: Bool {
- // get {
- // return self.getData(forKey: KMShowOutlineListKey) as! Bool
- // }
- // set {
- // let _ = self.setData(data: newValue, forKey: KMShowOutlineListKey)
- // }
- // }
-
- // var leftSideExpandType: Int {
- // get {
- // return self.getData(forKey: KMLeftSideExpandTypeKey) as! Int
- // }
- // set {
- // let _ = self.setData(data: newValue, forKey: KMLeftSideExpandTypeKey)
- // }
- // }
-
- var propertyPanelExpandType: KMPreferencePropertyPanelExpandType {
- get {
- let type: Int? = self.getData(forKey: KMPropertyPanelExpandTypeKey) as? Int
- if (type == nil || 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
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMHighlightFormsKey)
- }
- }
- var pageIndicatorType: KMPreferencePageIndicatorDisplayType {
- get {
- let type: Int? = self.getData(forKey: KMPageIndicatorTypeKey) as? Int
- if (type == nil || 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
- }
- set {
- let _ = self.setData(data: newValue, forKey: KMHighlightLinksKey)
- }
- }
-
- var displayBackgroundNormalColor: NSColor {
- get {
- return self.getColor(forKey: KMDisplayBackgroundNormalColorKey)
- }
- set {
- let _ = self.setColor(newValue, forKey: KMDisplayBackgroundNormalColorKey)
- }
- }
-
- var displayBackgroundFullScreenColor: NSColor {
- get {
- return self.getColor(forKey: KMDisplayBackgroundFullScreenColorKey)
- }
- set {
- 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)
- }
- }
- }
- // MARK: 扩展 Markup
- extension KMPreferenceManager {
- var markupHighlightColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorHighlightKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorHighlightKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorHighlightKey)
- }
- }
- var markupStrikthroughColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorStrikthroughKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorStrikthroughKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorStrikthroughKey)
- }
- }
- var markupUnderlineColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorUnderlineKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorUnderlineKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorUnderlineKey)
- }
- }
- var markupPenColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorPenKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorPenKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorPenKey)
- }
- }
- var markupTextColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorTextKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorTextKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorTextKey)
- }
- }
- var markupNoteColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorNoteKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorNoteKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorNoteKey)
- }
- }
- var markupRectangleFillColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorRectangleFillKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorRectangleFillKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorRectangleFillKey)
- }
- }
- var markupRectangleBorderColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorRectangleBorderKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorRectangleBorderKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorRectangleBorderKey)
- }
- }
- var markupCircleFillColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorCircleFillKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorCircleFillKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorCircleFillKey)
- }
- }
- var markupCircleBorderColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorCircleBorderKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorCircleBorderKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorCircleBorderKey)
- }
- }
- var markupLineColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorLineKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorLineKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorLineKey)
- }
- }
- var markupArrowColor: NSColor {
- get {
- return self.getColor(forKey: KMPreference.markupColorArrowKey)
- }
- set {
- self.syncDataToPDFView(newValue, forKey: KMPreference.markupColorArrowKey)
-
- let _ = self.setColor(newValue, forKey: KMPreference.markupColorArrowKey)
- }
- }
- }
- // MARK: -
- // MARK: Additions
- extension KMPreferenceManager {
- var markupFontTextString: String {
- get {
- let string: String? = UserDefaults.standard.object(forKey: CFreeTextNoteFontNameKey) as? String
- if (string == nil) {
- return KMDefaultFontName
- }
- if (KMPreferenceManager.supportFonts.contains(string!)) {
- return string!
- }
- return KMDefaultFontName
- }
- set {
- if (KMPreferenceManager.supportFonts.contains(newValue)) {
- UserDefaults.standard.set(newValue, forKey: CFreeTextNoteFontNameKey)
- UserDefaults.standard.synchronize()
-
- self.postNotification(object: [.markup], userInfo: [KMMarkupFontTextStringKey : newValue])
- }
- }
- }
-
- var markupFontTextAligment: NSTextAlignment {
- get {
- let type: Int? = UserDefaults.standard.integer(forKey: CFreeTextNoteAlignmentKey)
- if (type == nil) {
- return .left
- }
- if (type! == 0 || type! == 1 || type == 2) {
- return NSTextAlignment(rawValue: type!)!
- }
- return .left
- }
- set {
- if (newValue == .left || newValue == .center || newValue == .right) {
- UserDefaults.standard.set(newValue.rawValue, forKey: CFreeTextNoteAlignmentKey)
- UserDefaults.standard.synchronize()
-
- self.postNotification(object: [.markup], userInfo: [KMMarkupFontTextAligmentKey : newValue.rawValue])
- }
- }
- }
-
- var markupFontNoteString: String {
- get {
- let fontName: String? = KMPreferenceManager.shared.getData(forKey: KMPreference.markupFontNoteStringKey) as? String
- if (fontName == nil) {
- return KMDefaultFontName
- }
- if (KMPreference.supportFonts.contains(fontName!)) {
- return fontName!
- }
- return KMDefaultFontName
- }
- set {
- if (KMPreferenceManager.supportFonts.contains(newValue)) {
- let _ = KMPreferenceManager.shared.setData(data: newValue, forKey: KMPreference.markupFontNoteStringKey)
- }
- }
- }
-
- class var supportFonts: [String] {
- get {
- var fontNames: Array<String> = []
- for fontInfo in CPDFAnnotationModel.supportFonts() {
- if ((fontInfo is NSDictionary) == false) {
- continue
- }
-
- for (familyString, styleStrings) in (fontInfo as! NSDictionary) {
- if ((styleStrings is NSArray) == false) {
- break
- }
- for styleString in (styleStrings as! NSArray) {
- fontNames.append("\(familyString)-\(styleString)")
- }
- }
- }
- return fontNames
- }
- }
-
- private func syncDataToPDFView(_ data: Any, forKey key: KMPreferenceKey) {
- if (key == KMMarkupColorHighlightKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CHighlightNoteColorKey)
- } else if (key == KMMarkupColorUnderlineKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CUnderlineNoteColorKey)
- } else if (key == KMMarkupColorStrikthroughKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CStrikeOutNoteColorKey)
- } else if (key == KMMarkupColorPenKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CInkNoteColorKey)
- } else if (key == KMMarkupColorNoteKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CAnchoredNoteColorKey)
- } else if (key == KMMarkupColorRectangleFillKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteInteriorColorKey)
- } else if (key == KMMarkupColorRectangleBorderKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CSquareNoteColorKey)
- } else if (key == KMMarkupColorCircleFillKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteInteriorColorKey)
- } else if (key == KMMarkupColorCircleBorderKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CCircleNoteColorKey)
- } else if (key == KMMarkupColorLineKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CLineNoteColorKey)
- } else if (key == KMMarkupColorArrowKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CArrowNoteColorKey)
- } else if (key == KMMarkupColorTextKey) {
- UserDefaults.standard.setPDFListViewColor((data as! NSColor), forKey: CFreeTextNoteColorKey)
- } else if (key == KMMarkupFontTextStringKey) {
- UserDefaults.standard.set(data, forKey: CFreeTextNoteFontNameKey)
- UserDefaults.standard.synchronize()
- } else if (key == KMMarkupFontTextAligmentKey) {
- UserDefaults.standard.set(data, forKey: CFreeTextNoteAlignmentKey)
- UserDefaults.standard.synchronize()
- } else if (key == KMMarkupFontNoteStringKey) {
- // UserDefaults.standard.set(data, forKey: CFreeTextNoteAlignmentKey)
- // UserDefaults.standard.synchronize()
- }
- }
-
- private func getDefaultColors(forKey key: KMPreferenceKey) -> [Double] {
- let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
- for key_i in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
- KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
- KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
- KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
- KMMarkupColorLineKey, KMMarkupColorArrowKey] {
- if (key == key_i) {
- return markupGroupInfo[key] as! [Double]
- }
- }
- 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 resetDataToPDFView() {
- let markupGroupInfo: [KMPreferenceKey : Any] = self.getDefaultInfo()[KMPreferenceGroup.markup.rawValue]!
- for key in [KMMarkupColorHighlightKey, KMMarkupColorUnderlineKey, KMMarkupColorStrikthroughKey,
- KMMarkupColorPenKey, KMMarkupColorNoteKey, KMMarkupColorTextKey,
- KMMarkupColorRectangleFillKey, KMMarkupColorRectangleBorderKey,
- KMMarkupColorCircleFillKey, KMMarkupColorCircleBorderKey,
- KMMarkupColorLineKey, KMMarkupColorArrowKey] {
- self.syncDataToPDFView(self.dataToColor(colors: markupGroupInfo[key] as! [Double]), forKey: key)
- }
-
- self.syncDataToPDFView(KMDefaultFontName, forKey: KMMarkupFontTextStringKey)
- self.syncDataToPDFView(NSTextAlignment.left.rawValue, forKey: KMMarkupFontTextAligmentKey)
- self.syncDataToPDFView(KMDefaultFontName, forKey: KMMarkupFontNoteStringKey)
- }
-
- public func resumeDataToPDFView() {
- self.syncDataToPDFView(KMPreferenceManager.shared.markupHighlightColor, forKey: KMMarkupColorHighlightKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupUnderlineColor, forKey: KMMarkupColorUnderlineKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupStrikthroughColor, forKey: KMMarkupColorStrikthroughKey)
-
- self.syncDataToPDFView(KMPreferenceManager.shared.markupPenColor, forKey: KMMarkupColorPenKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupNoteColor, forKey: KMMarkupColorNoteKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupRectangleFillColor, forKey: KMMarkupColorRectangleFillKey)
-
- self.syncDataToPDFView(KMPreferenceManager.shared.markupRectangleBorderColor, forKey: KMMarkupColorRectangleBorderKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupCircleFillColor, forKey: KMMarkupColorCircleFillKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupCircleBorderColor, forKey: KMMarkupColorCircleBorderKey)
-
- self.syncDataToPDFView(KMPreferenceManager.shared.markupLineColor, forKey: KMMarkupColorLineKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupArrowColor, forKey: KMMarkupColorArrowKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupTextColor, forKey: KMMarkupColorTextKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupFontTextString, forKey: KMMarkupFontTextStringKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupFontTextAligment.rawValue, forKey: KMMarkupFontTextAligmentKey)
- self.syncDataToPDFView(KMPreferenceManager.shared.markupFontNoteString, forKey: KMMarkupFontNoteStringKey)
- }
- }
- // MARK: -
- // MARK: UserDefaults
- internal let kKMLastOpenFilepathKey = "lastOpenFilepath"
- internal let kKMLastOpenFilepathKeys = "lastOpenFilepaths"
- internal let kKMViewSettingKey = "viewSetting"
- internal let kKMPageNumberKey = "pageNumber"
- internal let kKMPageScaleKey = "pageScale"
- extension KMPreferenceManager {
- var lastOpenFilepath: String? {
- get {
- return UserDefaults.standard.value(forKey: kKMLastOpenFilepathKey) as? String
- }
- set {
- UserDefaults.standard.set(newValue, forKey: kKMLastOpenFilepathKey)
- UserDefaults.standard.synchronize()
- }
- }
-
- var lastOpenFilepaths: [String]? {
- get {
- return UserDefaults.standard.value(forKey: kKMLastOpenFilepathKeys) as? [String]
- }
- set {
- UserDefaults.standard.set(newValue, forKey: kKMLastOpenFilepathKeys)
- 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] = [:]
- if (viewSetting != nil) {
- 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()
- }
-
- func getPageNumber(forKey key: String) -> Int? {
- return UserDefaults.standard.value(forKey: "\(key)+\(kKMPageNumberKey)") as? Int
- }
-
- func setPageScale(_ scale: Float, forKey key: String) {
- UserDefaults.standard.set(scale, forKey: "\(key)+\(kKMPageScaleKey)")
- UserDefaults.standard.synchronize()
- }
-
- func getPageScale(forKey key: String) -> Float? {
- return UserDefaults.standard.value(forKey: "\(key)+\(kKMPageScaleKey)") as? Float
- }
- }
- // MARK: -
- // MARK: Qiuck
- 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 {
- var minute = KMPreferenceManager.shared.autoSavePerNumberMinute
- if (minute < 5) {
- minute = 5
- } else if (minute > 99) {
- minute = 99
- }
-
- let interval: TimeInterval = Double(minute) * 60.0
- return interval
- }
- }
- }
|