Browse Source

【偏好设置】快照窗口置顶设置项调式

tangchao 1 year ago
parent
commit
a43e54be8b

+ 19 - 2
PDF Office/PDF Master/Class/PDFTools/Snapshot/Window/KMSnapshotWindowController.swift

@@ -14,7 +14,7 @@ import Cocoa
     @objc optional func snapshotController(_ controller: KMSnapshotWindowController, miniaturizedRect isMiniaturize: Bool) -> NSRect
 }
 
-class KMSnapshotWindowController: NSWindowController {
+class KMSnapshotWindowController: KMBaseWindowController {
     
     @IBOutlet var pdfView: KMSnapshotPDFView!
     
@@ -92,6 +92,12 @@ class KMSnapshotWindowController: NSWindowController {
         self.hasWindow = true
     }
     
+    override func initNotification() {
+        super.initNotification()
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(preferenceInfoDidChange), name: KMPreferenceManager.didChangeNotification, object: nil)
+    }
+    
     /*
      + (NSSet *)keyPathsForValuesAffectingPageAndWindow {
          return [NSSet setWithObjects:PAGELABEL_KEY, HASWINDOW_KEY, nil];
@@ -611,13 +617,24 @@ class KMSnapshotWindowController: NSWindowController {
         self.perform(#selector(goToRect), with: NSValue(rect: rect), afterDelay: SMALL_DELAY)
     }
 
+    // MARK: - Noti Actions
+    
+    @objc func preferenceInfoDidChange(sender: Notification) {
+        let info : [AnyHashable : Any] = sender.userInfo ?? [:]
+        if info.keys.contains(KMPreferenceManager.keepSnapshotWindowToTopKey) {
+            let data = KMPreferenceManager.shared.keepSnapshotWindowToTop
+            if let data = self.window?.isVisible, data {
+                self._updateWindowLevel()
+            }
+        }
+    }
+    
 }
 
 // MARK: - Private Methods
 
 extension KMSnapshotWindowController {
     private func _updateWindowLevel() {
-        
         let onTop = self.forceOnTop || UserDefaults.standard.bool(forKey: SKSnapshotsOnTopKey)
         self.window?.level = onTop ? .floating : .normal
         self.window?.hidesOnDeactivate = onTop

+ 8 - 2
PDF Office/PDF Master/Class/Preference/Tools/KMPreferenceManager.swift

@@ -944,7 +944,7 @@ extension KMPreferenceManager {
 //            return self.getData(forKey: KMRememberSnapshotKey) as? Bool ?? self.rememberSnapshotDefaultValue
         }
         set {
-//            _ = self.setData(data: newValue, forKey: KMRememberSnapshotKey)
+            _ = self.setData(data: newValue, forKey: KMRememberSnapshotKey)
             // 数据兼容
             self._syncDataToUserDefault(newValue, forKey: KMRememberSnapshotKey)
         }
@@ -979,10 +979,14 @@ extension KMPreferenceManager {
     
     var keepSnapshotWindowToTop: Bool {
         get {
-            return self.getData(forKey: KMKeepSnapshotWindowToTopKey) as? Bool ?? self.keepSnapshotWindowToTopDefaultValue()
+            return KMDataManager.ud_bool(forKey: SKSnapshotsOnTopKey)
+//            return self.getData(forKey: KMKeepSnapshotWindowToTopKey) as? Bool ?? self.keepSnapshotWindowToTopDefaultValue()
         }
         set {
             _ = self.setData(data: newValue, forKey: KMKeepSnapshotWindowToTopKey)
+            
+            // 数据兼容
+            self._syncDataToUserDefault(newValue, forKey: KMKeepSnapshotWindowToTopKey)
         }
     }
 }
@@ -1709,6 +1713,8 @@ extension KMPreferenceManager {
             KMDataManager.ud_set(data, forKey: SKInitialWindowSizeOptionKey)
         } else if key == KMRememberSnapshotKey {
             KMDataManager.ud_set(data, forKey: SKRememberSnapshotsKey)
+        } else if key == KMKeepSnapshotWindowToTopKey {
+            KMDataManager.ud_set(data, forKey: SKSnapshotsOnTopKey)
         }
     }