|
@@ -57,11 +57,13 @@ let KMMarkupColorCircleFillKey: KMPreferenceKey = "KMMarkupColorCircleFillKey"
|
|
let KMMarkupColorCircleBorderKey: KMPreferenceKey = "KMMarkupColorCircleBorderKey"
|
|
let KMMarkupColorCircleBorderKey: KMPreferenceKey = "KMMarkupColorCircleBorderKey"
|
|
let KMMarkupColorLineKey: KMPreferenceKey = "KMMarkupColorLineKey"
|
|
let KMMarkupColorLineKey: KMPreferenceKey = "KMMarkupColorLineKey"
|
|
let KMMarkupFontTextTypeKey: KMPreferenceKey = "KMMarkupFontTextTypeKey"
|
|
let KMMarkupFontTextTypeKey: KMPreferenceKey = "KMMarkupFontTextTypeKey"
|
|
|
|
+let KMMarkupFontTextStringKey: KMPreferenceKey = "KMMarkupFontTextStringKey"
|
|
let KMMarkupFontTextAligmentTypeKey: KMPreferenceKey = "KMMarkupFontTextAligmentTypeKey"
|
|
let KMMarkupFontTextAligmentTypeKey: KMPreferenceKey = "KMMarkupFontTextAligmentTypeKey"
|
|
|
|
+let KMMarkupFontTextAligmentKey: KMPreferenceKey = "KMMarkupFontTextAligmentKey"
|
|
let KMMarkupFontNoteTypeKey: KMPreferenceKey = "KMMarkupFontNoteTypeKey"
|
|
let KMMarkupFontNoteTypeKey: KMPreferenceKey = "KMMarkupFontNoteTypeKey"
|
|
|
|
|
|
/// 偏好设置已改变
|
|
/// 偏好设置已改变
|
|
-let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
|
|
|
|
|
|
+fileprivate let KMPreferenceDidChangeNotificationName = "KMPreferenceDidChangeNotificationName"
|
|
|
|
|
|
class KMPreferenceManager: NSObject {
|
|
class KMPreferenceManager: NSObject {
|
|
static let shared = KMPreferenceManager()
|
|
static let shared = KMPreferenceManager()
|
|
@@ -70,6 +72,8 @@ class KMPreferenceManager: NSObject {
|
|
private var displayGroupKeys: Array<KMPreferenceKey> = []
|
|
private var displayGroupKeys: Array<KMPreferenceKey> = []
|
|
private var markupGroupKeys: Array<KMPreferenceKey> = []
|
|
private var markupGroupKeys: Array<KMPreferenceKey> = []
|
|
|
|
|
|
|
|
+ public static let didChangeNotification = Notification.Name(KMPreferenceDidChangeNotificationName)
|
|
|
|
+
|
|
override init() {
|
|
override init() {
|
|
super.init()
|
|
super.init()
|
|
|
|
|
|
@@ -105,9 +109,7 @@ class KMPreferenceManager: NSObject {
|
|
UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
UserDefaults.standard.synchronize()
|
|
UserDefaults.standard.synchronize()
|
|
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: KMPreferenceDidChangeNotificationName), object: [group], userInfo: [key : data])
|
|
|
|
- }
|
|
|
|
|
|
+ self.postNotification(object: [group], userInfo: [key : data])
|
|
|
|
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -139,16 +141,15 @@ class KMPreferenceManager: NSObject {
|
|
|
|
|
|
public func setMarkData(color:NSColor,forKey key:KMPreferenceKey) {
|
|
public func setMarkData(color:NSColor,forKey key:KMPreferenceKey) {
|
|
UserDefaults.standard.setPDFListViewColor(color, forKey: key)
|
|
UserDefaults.standard.setPDFListViewColor(color, forKey: key)
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: KMPreferenceDidChangeNotificationName), object: [], userInfo: [key : color])
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ self.postNotification(object: [.markup], userInfo: [key : color])
|
|
}
|
|
}
|
|
|
|
|
|
public func setAlignment(alignment:Int,forKey key:KMPreferenceKey) {
|
|
public func setAlignment(alignment:Int,forKey key:KMPreferenceKey) {
|
|
UserDefaults.standard.set(alignment, forKey: key)
|
|
UserDefaults.standard.set(alignment, forKey: key)
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: KMPreferenceDidChangeNotificationName), object: [], userInfo: [key : alignment])
|
|
|
|
- }
|
|
|
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
|
+
|
|
|
|
+ self.postNotification(object: [.markup], userInfo: [key : alignment])
|
|
}
|
|
}
|
|
|
|
|
|
public func getAlignment(for key:KMPreferenceKey) -> Int{
|
|
public func getAlignment(for key:KMPreferenceKey) -> Int{
|
|
@@ -174,6 +175,9 @@ class KMPreferenceManager: NSObject {
|
|
self.markupCircleFillColor = self.dataToColor(colors: self.markupCircleFillColorValues)
|
|
self.markupCircleFillColor = self.dataToColor(colors: self.markupCircleFillColorValues)
|
|
self.markupCircleBorderColor = self.dataToColor(colors: self.markupCircleBorderColorValues)
|
|
self.markupCircleBorderColor = self.dataToColor(colors: self.markupCircleBorderColorValues)
|
|
self.markupLineColor = self.dataToColor(colors: self.markupLineColorValues)
|
|
self.markupLineColor = self.dataToColor(colors: self.markupLineColorValues)
|
|
|
|
+
|
|
|
|
+ self.markupFontTextString = kKMFreeTextDefaultFontName
|
|
|
|
+ self.markupFontTextAligment = .left
|
|
}
|
|
}
|
|
|
|
|
|
public func resetData(_ group: KMPreferenceGroup) {
|
|
public func resetData(_ group: KMPreferenceGroup) {
|
|
@@ -192,13 +196,13 @@ class KMPreferenceManager: NSObject {
|
|
UserDefaults.standard.synchronize()
|
|
UserDefaults.standard.synchronize()
|
|
|
|
|
|
}
|
|
}
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
let info: [String : Any]? = UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]
|
|
let info: [String : Any]? = UserDefaults.standard.value(forKey: KMPreferenceInfoKey) as? [String : Any]
|
|
var groupInfo: [KMPreferenceKey : Any]?
|
|
var groupInfo: [KMPreferenceKey : Any]?
|
|
if (info != nil) {
|
|
if (info != nil) {
|
|
groupInfo = info![group.rawValue] as? [KMPreferenceKey : Any]
|
|
groupInfo = info![group.rawValue] as? [KMPreferenceKey : Any]
|
|
}
|
|
}
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: KMPreferenceDidChangeNotificationName), object: [group], userInfo: groupInfo != nil ? groupInfo : [:])
|
|
|
|
|
|
+ self.postNotification(object: [group], userInfo: groupInfo != nil ? groupInfo : [:])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -207,7 +211,9 @@ class KMPreferenceManager: NSObject {
|
|
UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
UserDefaults.standard.set(info, forKey: KMPreferenceInfoKey)
|
|
UserDefaults.standard.synchronize()
|
|
UserDefaults.standard.synchronize()
|
|
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
|
|
|
+ self.resetMarkUpData()
|
|
|
|
+
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
var groppInfos: [KMPreferenceKey : Any] = [:]
|
|
var groppInfos: [KMPreferenceKey : Any] = [:]
|
|
for groupInfo in info.values {
|
|
for groupInfo in info.values {
|
|
for (key, value) in groupInfo {
|
|
for (key, value) in groupInfo {
|
|
@@ -215,7 +221,7 @@ class KMPreferenceManager: NSObject {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: KMPreferenceDidChangeNotificationName), object: [KMPreferenceGroup.general, KMPreferenceGroup.display, KMPreferenceGroup.markup, KMPreferenceGroup.infomation, KMPreferenceGroup.other], userInfo: groppInfos)
|
|
|
|
|
|
+ self.postNotification(object: [KMPreferenceGroup.general, KMPreferenceGroup.display, KMPreferenceGroup.markup, KMPreferenceGroup.infomation, KMPreferenceGroup.other], userInfo: groppInfos)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -230,6 +236,15 @@ class KMPreferenceManager: NSObject {
|
|
return true
|
|
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: 获取信息
|
|
// MARK: 获取信息
|
|
private func findGroup(forKey key: KMPreferenceKey) -> KMPreferenceGroup {
|
|
private func findGroup(forKey key: KMPreferenceKey) -> KMPreferenceGroup {
|
|
if (self.generalGroupKeys.contains(key)) {
|
|
if (self.generalGroupKeys.contains(key)) {
|
|
@@ -280,8 +295,8 @@ class KMPreferenceManager: NSObject {
|
|
CCircleNoteInteriorColorKey,
|
|
CCircleNoteInteriorColorKey,
|
|
CCircleNoteColorKey,
|
|
CCircleNoteColorKey,
|
|
CAnnotationSelfSignLineColorKey,
|
|
CAnnotationSelfSignLineColorKey,
|
|
- KMMarkupFontTextTypeKey,
|
|
|
|
- CFreeTextNoteAlignmentKey,
|
|
|
|
|
|
+ KMMarkupFontTextTypeKey, KMMarkupFontTextStringKey,
|
|
|
|
+ CFreeTextNoteAlignmentKey, KMMarkupFontTextAligmentKey,
|
|
KMMarkupFontNoteTypeKey]
|
|
KMMarkupFontNoteTypeKey]
|
|
}
|
|
}
|
|
return []
|
|
return []
|
|
@@ -322,8 +337,8 @@ class KMPreferenceManager: NSObject {
|
|
KMMarkupColorCircleFillKey : self.markupCircleFillColorValues,
|
|
KMMarkupColorCircleFillKey : self.markupCircleFillColorValues,
|
|
KMMarkupColorCircleBorderKey : self.markupCircleBorderColorValues,
|
|
KMMarkupColorCircleBorderKey : self.markupCircleBorderColorValues,
|
|
KMMarkupColorLineKey : self.markupLineColorValues,
|
|
KMMarkupColorLineKey : self.markupLineColorValues,
|
|
- KMMarkupFontTextTypeKey : 1,
|
|
|
|
- KMMarkupFontTextAligmentTypeKey : 0,
|
|
|
|
|
|
+ KMMarkupFontTextTypeKey : 1, KMMarkupFontTextStringKey : "",
|
|
|
|
+ KMMarkupFontTextAligmentTypeKey : 0, KMMarkupFontTextAligmentKey : 0,
|
|
KMMarkupFontNoteTypeKey : 1],
|
|
KMMarkupFontNoteTypeKey : 1],
|
|
KMPreferenceGroup.infomation.rawValue : [:],
|
|
KMPreferenceGroup.infomation.rawValue : [:],
|
|
KMPreferenceGroup.other.rawValue : [:]]
|
|
KMPreferenceGroup.other.rawValue : [:]]
|
|
@@ -817,14 +832,14 @@ extension KMPreferenceManager {
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
- var markupFontTextAligmentType: Int {
|
|
|
|
- get {
|
|
|
|
- return self.getAlignment(for: CFreeTextNoteAlignmentKey)
|
|
|
|
- }
|
|
|
|
- set {
|
|
|
|
- let _ = self.setAlignment(alignment: newValue, forKey: CFreeTextNoteAlignmentKey)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// var markupFontTextAligmentType: Int {
|
|
|
|
+// get {
|
|
|
|
+// return self.getAlignment(for: CFreeTextNoteAlignmentKey)
|
|
|
|
+// }
|
|
|
|
+// set {
|
|
|
|
+// let _ = self.setAlignment(alignment: newValue, forKey: CFreeTextNoteAlignmentKey)
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
var markupFontNoteType: Int {
|
|
var markupFontNoteType: Int {
|
|
get {
|
|
get {
|
|
@@ -856,6 +871,29 @@ extension KMPreferenceManager {
|
|
if (KMPreferenceManager.supportFonts.contains(newValue)) {
|
|
if (KMPreferenceManager.supportFonts.contains(newValue)) {
|
|
UserDefaults.standard.set(newValue, forKey: CFreeTextNoteFontNameKey)
|
|
UserDefaults.standard.set(newValue, forKey: CFreeTextNoteFontNameKey)
|
|
UserDefaults.standard.synchronize()
|
|
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])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -901,7 +939,7 @@ extension KMPreferenceManager {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- var viewSetting: [String : Any]? = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any]
|
|
|
|
|
|
+ let viewSetting: [String : Any]? = UserDefaults.standard.value(forKey: kKMViewSettingKey) as? [String : Any]
|
|
var info: [String : Any] = [:]
|
|
var info: [String : Any] = [:]
|
|
if (viewSetting != nil) {
|
|
if (viewSetting != nil) {
|
|
for (key, value) in viewSetting! {
|
|
for (key, value) in viewSetting! {
|