Browse Source

【偏好设置】通用模块,数据梳理和串接

tangchao 1 year ago
parent
commit
f91926ffa5

+ 16 - 0
PDF Office/PDF Master/Class/Preference/Controller/GeneralPreferences.xib

@@ -18,6 +18,9 @@
                 <outlet property="fullScreenButton" destination="13" id="rwP-bT-LWq"/>
                 <outlet property="keepSnapshotOnTopButton" destination="4" id="bht-be-yAj"/>
                 <outlet property="normalButton" destination="14" id="2S5-K4-kkj"/>
+                <outlet property="openFileForDefaultButton" destination="33" id="3xZ-fT-imW"/>
+                <outlet property="openFileForFitButton" destination="31" id="tAU-m9-tFw"/>
+                <outlet property="openFileForMaximButton" destination="32" id="B4z-pC-Eqx"/>
                 <outlet property="openFilesLabelField" destination="16" id="78"/>
                 <outlet property="openFilesMatrix" destination="17" id="77"/>
                 <outlet property="openTabButton" destination="A68-ez-c6M" id="72V-76-LRe"/>
@@ -25,6 +28,9 @@
                 <outlet property="rememberSnapshotButton" destination="18" id="o9x-Lr-Cj5"/>
                 <outlet property="reopenLastOpenFilesButton" destination="2" id="bGZ-Pm-RIH"/>
                 <outlet property="savePasswordsMatrix" destination="21" id="75"/>
+                <outlet property="savePwdForAlwaysButton" destination="27" id="GAB-mq-gLv"/>
+                <outlet property="savePwdForAskButton" destination="25" id="ZSq-bS-eey"/>
+                <outlet property="savePwdForNeverButton" destination="26" id="WRR-tA-ahj"/>
                 <outlet property="showConvertMenuButton" destination="AVa-Al-8gG" id="XPN-Cp-dpt"/>
                 <outlet property="showLeftSideButton" destination="3" id="dqO-V9-G0B"/>
                 <outlet property="updateIntervalLabelField" destination="7" id="76"/>
@@ -175,15 +181,22 @@
                                 <font key="font" metaFont="system"/>
                                 <connections>
                                     <accessibilityConnection property="title" destination="16" id="51"/>
+                                    <action selector="openFileForDefaultAction:" target="-2" id="eTS-vr-ReX"/>
                                 </connections>
                             </buttonCell>
                             <buttonCell type="radio" title="Maximized" imagePosition="leading" alignment="left" tag="1" inset="2" id="32">
                                 <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
                                 <font key="font" metaFont="system"/>
+                                <connections>
+                                    <action selector="openFileForMaximAction:" target="-2" id="KK4-zZ-Go6"/>
+                                </connections>
                             </buttonCell>
                             <buttonCell type="radio" title="Fit" imagePosition="leading" alignment="left" tag="2" inset="2" id="31">
                                 <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
                                 <font key="font" metaFont="system"/>
+                                <connections>
+                                    <action selector="openFileForFitAction:" target="-2" id="HNe-8C-0zd"/>
+                                </connections>
                             </buttonCell>
                         </column>
                     </cells>
@@ -344,6 +357,7 @@
                                 <font key="font" metaFont="system"/>
                                 <connections>
                                     <accessibilityConnection property="title" destination="20" id="54"/>
+                                    <action selector="savePwdForAlwaysAction:" target="-2" id="4xv-FY-2lB"/>
                                 </connections>
                             </buttonCell>
                         </column>
@@ -353,6 +367,7 @@
                                 <font key="font" metaFont="system"/>
                                 <connections>
                                     <accessibilityConnection property="title" destination="20" id="52"/>
+                                    <action selector="savePwdForNeverAction:" target="-2" id="Eoe-Jg-bT6"/>
                                 </connections>
                             </buttonCell>
                         </column>
@@ -362,6 +377,7 @@
                                 <font key="font" metaFont="system"/>
                                 <connections>
                                     <accessibilityConnection property="title" destination="20" id="55"/>
+                                    <action selector="savePwdForAskAction:" target="-2" id="IBr-Rp-Zdj"/>
                                 </connections>
                             </buttonCell>
                         </column>

+ 89 - 29
PDF Office/PDF Master/Class/Preference/Controller/KMGeneralPreferences.swift

@@ -30,6 +30,10 @@ class KMGeneralPreferences: NSViewController {
     
     @IBOutlet weak var openFilesLabelField: NSTextField!
     @IBOutlet weak var openFilesMatrix: NSMatrix!
+    @IBOutlet weak var openFileForDefaultButton: NSButtonCell!
+    @IBOutlet weak var openFileForMaximButton: NSButtonCell!
+    @IBOutlet weak var openFileForFitButton: NSButtonCell!
+    
     @IBOutlet weak var showLeftSideButton: NSButton!
     @IBOutlet weak var rememberSnapshotButton: NSButton!
     @IBOutlet weak var normalButton: NSButton!
@@ -40,6 +44,9 @@ class KMGeneralPreferences: NSViewController {
     @IBOutlet weak var keepSnapshotOnTopButton: NSButton!
     
     @IBOutlet var savePasswordsMatrix: NSMatrix!
+    @IBOutlet weak var savePwdForAlwaysButton: NSButtonCell!
+    @IBOutlet weak var savePwdForNeverButton: NSButtonCell!
+    @IBOutlet weak var savePwdForAskButton: NSButtonCell!
     
     @IBOutlet var updateIntervalPopUpButton: NSPopUpButton!
     @IBOutlet var updateIntervalLabelField: NSTextField!
@@ -136,10 +143,12 @@ class KMGeneralPreferences: NSViewController {
         }
         self.autoSaveLbl.stringValue = String(format: "%.0f %@", AutoSaveManager.manager.timeInterval, KMLocalizedString("minute(s)", nil))
         
+        self._selectOpenFileType(KMPreference.shared.openFileType)
         self.showLeftSideButton.state = KMPreference.shared.showLeftSideBar ? .on : .off
         self.rememberSnapshotButton.state = KMPreference.shared.rememberSnapshot ? .on : .off
         self.autoSaveNotesBackupButton.state = KMPreference.shared.autoSaveNoteBackup ? .on : .off
         self.keepSnapshotOnTopButton.state = KMPreference.shared.keepSnapshotWindowToTop ? .on : .off
+        self._selectSavePasswordType(KMPreference.shared.savePasswordType)
         
         self.authorLabel.sizeToFit()
         var frame = self.authorTextField.frame
@@ -165,16 +174,12 @@ class KMGeneralPreferences: NSViewController {
     
     @IBAction func revertPDFViewSettings(_ sender: AnyObject?) {
 //        [[NSUserDefaultsController sharedUserDefaultsController] revertToInitialValueForKey:SKStringConstants.defaultPDFDisplaySettingsKey];
+        KMPreference.shared.revertInitPDFViewSettingType = .normal
     }
     
     @IBAction func revertFullScreenPDFViewSettings(_ sender: AnyObject?) {
 //        [[NSUserDefaultsController sharedUserDefaultsController] revertToInitialValueForKey:SKStringConstants.defaultFullScreenPDFDisplaySettingsKey];
-    }
-    
-    @IBAction func authorTextFieldAction(_ sender: AnyObject?) {
-//        NSString *userName = self.authorTextField.stringValue.length > 0 ? self.authorTextField.stringValue : @"";
-//        [[NSUserDefaults standardUserDefaults] setObject:userName forKey:@"SKUserName"];
-//        [[NSUserDefaults standardUserDefaults] synchronize];
+        KMPreference.shared.revertInitPDFViewSettingType = .fullScreen
     }
     
     @IBAction func defaultOpenButtonAction(_ sender: AnyObject?) {
@@ -182,28 +187,28 @@ class KMGeneralPreferences: NSViewController {
     }
     
     @IBAction func openTabButtonAction(_ sender: AnyObject?) {
-//        if (@available(macOS 10.12, *)) {
-//            NSWindowTabbingMode tabbingMode = NSWindowTabbingModeAutomatic;
-//            if (self.openTabButton.indexOfSelectedItem == 0) {
-//    #if VERSION_FREE
-//    //            if (![IAPProductsManager defaultManager].isAvailableAllFunction) {
-//    //                [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"KMOpenDocumentInTab"];
-//    //                [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
-//    //                return;
-//    //            }
-//    #endif
-//                tabbingMode = NSWindowTabbingModePreferred;
-//            } else if (self.openTabButton.indexOfSelectedItem == 1) {
-//                tabbingMode = NSWindowTabbingModeDisallowed;
-//            }
-//            for (NSDocument *document in [[NSDocumentController sharedDocumentController] documents]) {
-//    //            if ([document isKindOfClass:[SKMainDocument class]]) {
-//    //                for (NSWindowController *windowController in document.windowControllers) {
-//    //                    windowController.window.tabbingMode = tabbingMode;
-//    //                }
-//    //            }
-//            }
-//        }
+        var tabbingMode = NSWindow.TabbingMode.automatic
+        if (self.openTabButton.indexOfSelectedItem == 0) {
+#if VERSION_FREE
+            if IAPProductsManager.default().isAvailableAllFunction() == false {
+                //    //                [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"KMOpenDocumentInTab"];
+                KMPreference.shared.openDocumentType = .newWindow
+                KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
+                return
+            }
+#endif
+            tabbingMode = .preferred
+        } else if (self.openTabButton.indexOfSelectedItem == 1) {
+            tabbingMode = .disallowed
+        }
+        for document in NSDocumentController.shared.documents {
+            guard let _doc = document as? KMMainDocument else {
+                continue
+            }
+            for windowController in _doc.windowControllers {
+                windowController.window?.tabbingMode = tabbingMode
+            }
+        }
     }
     
     @IBAction func showConvertMenuButtonAction(_ sender: AnyObject?) {
@@ -219,6 +224,18 @@ class KMGeneralPreferences: NSViewController {
         KMPreference.shared.openLastUnclosedDocumentWhenAppStart = sender.state == .on
     }
     
+    
+    @IBAction func openFileForDefaultAction(_ sender: Any) {
+        KMPreference.shared.openFileType = .default
+    }
+    
+    @IBAction func openFileForMaximAction(_ sender: Any) {
+        KMPreference.shared.openFileType = .maxim
+    }
+    @IBAction func openFileForFitAction(_ sender: Any) {
+        KMPreference.shared.openFileType = .fit
+    }
+    
     @IBAction func showLeftSideAction(_ sender: Any) {
         KMPreference.shared.showLeftSideBar = self.showLeftSideButton.state == .on
     }
@@ -252,7 +269,18 @@ class KMGeneralPreferences: NSViewController {
     @objc func autoSaveSliderFinish() {
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: KAutoSaveTimeValueChangedNoti), object: nil)
     }
-
+    
+    @IBAction func savePwdForAlwaysAction(_ sender: Any) {
+        KMPreference.shared.savePasswordType = .always
+    }
+    
+    @IBAction func savePwdForNeverAction(_ sender: Any) {
+        KMPreference.shared.savePasswordType = .never
+    }
+    @IBAction func savePwdForAskAction(_ sender: Any) {
+        KMPreference.shared.savePasswordType = .ask
+    }
+    
     /*
      #pragma mark Accessors
 
@@ -324,6 +352,38 @@ extension KMGeneralPreferences {
             self.fullScreenButton.isEnabled = true
         }
     }
+    
+    private func _selectOpenFileType(_ type: KMPreferenceOpenFileType) {
+        if type == .default {
+            self.openFileForDefaultButton.state = .on
+            self.openFileForMaximButton.state = .off
+            self.openFileForFitButton.state = .off
+        } else if type == .maxim {
+            self.openFileForDefaultButton.state = .off
+            self.openFileForMaximButton.state = .on
+            self.openFileForFitButton.state = .off
+        } else if type == .fit {
+            self.openFileForDefaultButton.state = .off
+            self.openFileForMaximButton.state = .off
+            self.openFileForFitButton.state = .on
+        }
+    }
+    
+    private func _selectSavePasswordType(_ type: KMPreferenceSavePasswordType) {
+        if type == .always {
+            self.savePwdForAlwaysButton.state = .on
+            self.savePwdForNeverButton.state = .off
+            self.savePwdForAskButton.state = .off
+        } else if type == .never {
+            self.savePwdForAlwaysButton.state = .off
+            self.savePwdForNeverButton.state = .on
+            self.savePwdForAskButton.state = .off
+        } else if type == .ask {
+            self.savePwdForAlwaysButton.state = .off
+            self.savePwdForNeverButton.state = .off
+            self.savePwdForAskButton.state = .on
+        }
+    }
 }
 
 extension KMGeneralPreferences: KMPreferencePane {