Browse Source

偏好设置-文本居中新增交互

tangchao 1 year ago
parent
commit
edd384f7b2

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 2
PDF Office/PDF Office.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -398,8 +398,8 @@
             filePath = "PDF Office/Class/Preference/Controller/KMPreferenceMarkupController.swift"
             filePath = "PDF Office/Class/Preference/Controller/KMPreferenceMarkupController.swift"
             startingColumnNumber = "9223372036854775807"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "146"
-            endingLineNumber = "146"
+            startingLineNumber = "152"
+            endingLineNumber = "152"
             landmarkName = "initData()"
             landmarkName = "initData()"
             landmarkType = "7">
             landmarkType = "7">
          </BreakpointContent>
          </BreakpointContent>

+ 1 - 0
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/AppKitCategories/NSUserDefaults+PDFListView.m

@@ -41,6 +41,7 @@
 - (void)setPDFListViewColor:(NSColor *)color forKey:(NSString *)key {
 - (void)setPDFListViewColor:(NSColor *)color forKey:(NSString *)key {
     NSData *data = color ? [NSArchiver archivedDataWithRootObject:color] : [NSArchiver archivedDataWithRootObject:[NSColor clearColor]];
     NSData *data = color ? [NSArchiver archivedDataWithRootObject:color] : [NSArchiver archivedDataWithRootObject:[NSColor clearColor]];
     [self setObject:data forKey:key];
     [self setObject:data forKey:key];
+    [self synchronize];
 }
 }
 
 
 @end
 @end

+ 1 - 1
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -193,7 +193,7 @@ import Cocoa
 
 
         NotificationCenter.default.addObserver(self, selector: #selector(rename(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerRename"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(rename(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerRename"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(showInFinder(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerShowInFinder"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(showInFinder(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerShowInFinder"), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: Notification.Name(KMPreferenceDidChangeNotificationName), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: KMPreferenceManager.didChangeNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(documentDidUnlockNotification), name: Notification.Name("CPDFDocumentDidUnlockNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(documentDidUnlockNotification), name: Notification.Name("CPDFDocumentDidUnlockNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminateNotification), name: NSApplication.willTerminateNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminateNotification), name: NSApplication.willTerminateNotification, object: nil)
     }
     }

+ 12 - 6
PDF Office/PDF Office/Class/Preference/Controller/KMPreferenceMarkupController.swift

@@ -85,7 +85,13 @@ class KMPreferenceMarkupController: NSViewController {
         }
         }
         
         
         self.aligementView.itemClick = { index in
         self.aligementView.itemClick = { index in
-            KMPreferenceManager.shared.markupFontTextAligmentType = index
+            if (index == 0) {
+                KMPreferenceManager.shared.markupFontTextAligment = .left
+            } else if (index == 1) {
+                KMPreferenceManager.shared.markupFontTextAligment = .center
+            } else if (index == 2) {
+                KMPreferenceManager.shared.markupFontTextAligment = .right
+            }
         }
         }
         
         
         self.initUIProperty()
         self.initUIProperty()
@@ -154,17 +160,17 @@ class KMPreferenceMarkupController: NSViewController {
         
         
         self.textComboBox.stringValue = KMPreferenceManager.shared.markupFontTextString
         self.textComboBox.stringValue = KMPreferenceManager.shared.markupFontTextString
         
         
-        var value = KMPreferenceManager.shared.markupFontTextAligmentType
-        if (value == 0) {
+        let aliigment = KMPreferenceManager.shared.markupFontTextAligment
+        if (aliigment == .left) {
             self.aligementView.selectIndex(index: 0)
             self.aligementView.selectIndex(index: 0)
-        } else if (value == 1) {
+        } else if (aliigment == .center) {
             self.aligementView.selectIndex(index: 1)
             self.aligementView.selectIndex(index: 1)
-        } else if (value == 2) {
+        } else if (aliigment == .right) {
             self.aligementView.selectIndex(index: 2)
             self.aligementView.selectIndex(index: 2)
         }
         }
         
         
         let fontNames = self.fontNames
         let fontNames = self.fontNames
-        value = KMPreferenceManager.shared.markupFontNoteType
+        let value = KMPreferenceManager.shared.markupFontNoteType
         if (value == 0) {
         if (value == 0) {
             self.noteComboBox.stringValue = fontNames[0]
             self.noteComboBox.stringValue = fontNames[0]
         } else if (value == 1) {
         } else if (value == 1) {

+ 65 - 27
PDF Office/PDF Office/Class/Preference/Tools/KMPreferenceManager.swift

@@ -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! {

+ 1 - 1
PDF Office/PDF Office/Class/Preference/Window/KMPreferenceWindowController.swift

@@ -85,7 +85,7 @@ class KMPreferenceWindowController: NSWindowController {
         resetAllButton.target = self
         resetAllButton.target = self
         resetAllButton.action = #selector(resetAllAction)
         resetAllButton.action = #selector(resetAllAction)
         
         
-        NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: Notification.Name(KMPreferenceDidChangeNotificationName), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: KMPreferenceManager.didChangeNotification, object: nil)
     }
     }
     
     
     @objc func resetAction() {
     @objc func resetAction() {