Browse Source

【UI替换】打印 - 底部菜单栏切换

lizhe 1 year ago
parent
commit
e225ba2201

+ 17 - 1
PDF Office/PDF Master/Class/PDFTools/Print/KMPrintWindowController.swift

@@ -24,6 +24,12 @@ class KMPrintWindowController: NSWindowController, NetServiceBrowserDelegate {
     var chooseData: KMPrintModel = KMPrintModel()
     var inputType: DataNavigationViewButtonActionType?
     var presenter: KMPrintPresenter = KMPrintPresenter()
+    var printType: PrintModelType = .size {
+        didSet {
+            self.bottomView.type = printType
+        }
+    }
+    
     var inputPageRange: KMPrintPageRange = KMPrintPageRange() {
         didSet {
             self.chooseView.inputPageRange = inputPageRange
@@ -139,10 +145,11 @@ class KMPrintWindowController: NSWindowController, NetServiceBrowserDelegate {
         KMPrintWindowController.showPrintWindowControll(inputData: nil, inputDocument: inputDocument, inputType: inputType,inputPageRange: inputPageRange)
     }
     
-    static func showNewPrintWindowControll(inputData: URL?, inputDocument: CPDFDocument?, inputType: DataNavigationViewButtonActionType = .Print, inputPageRange: KMPrintPageRange) {
+    static func showNewPrintWindowControll(inputData: URL?, inputDocument: CPDFDocument?, inputType: DataNavigationViewButtonActionType = .Print, inputPageRange: KMPrintPageRange, printType: PrintModelType = .size) {
         if (true) {
             let printWindowController: KMPrintWindowController = KMPrintWindowController.init(windowNibName: "KMPrintWindowController")
             NSApp.mainWindow?.beginCriticalSheet(printWindowController.window!)
+            printWindowController.printType = printType
             if inputDocument != nil {
                 printWindowController.inputDocument = inputDocument
             }
@@ -334,14 +341,23 @@ extension KMPrintWindowController: KMPrintBottomViewDelegate {
     
     func posterAction() {
         self.changeTypeAction?(self, .poster)
+        self.cancelAction()
+        
+        KMPrintWindowController.showNewPrintWindowControll(inputData: self.pdfDocument?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .poster)
     }
 
     func multipageAction() {
         self.changeTypeAction?(self, .multipage)
+        self.cancelAction()
+        
+        KMPrintWindowController.showNewPrintWindowControll(inputData: self.pdfDocument?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .poster)
     }
     
     func bookletAction() {
         self.changeTypeAction?(self, .pamphlet)
+        self.cancelAction()
+        
+        KMPrintWindowController.showNewPrintWindowControll(inputData: self.pdfDocument?.documentURL, inputDocument: nil, inputPageRange: KMPrintPageRange(), printType: .poster)
     }
 }
 

+ 5 - 2
PDF Office/PDF Master/Class/PDFTools/Print/Presenter/KMPrintPresenter.swift

@@ -25,8 +25,11 @@ class KMPrintPresenter: NSObject {
         self.delegate = delegate
         self.document = document
         self.printData = data
-        let pdfDocument = self.updatePrintDocument(documentURL: document.documentURL, data: self.printData)
-        self.printData.url = pdfDocument.documentURL
+        
+//        DispatchQueue.main.async {
+//            let pdfDocument = self.updatePrintDocument(documentURL: document.documentURL, data: self.printData)
+//            self.printData.url = pdfDocument.documentURL
+//        }
     }
     
     /**

+ 33 - 2
PDF Office/PDF Master/Class/PDFTools/Print/View/BottomView/KMPrintBottomView.swift

@@ -14,8 +14,18 @@ class KMPrintBottomView: KMBaseXibView {
     
     @IBOutlet weak var cancelButton: NSButton!
     @IBOutlet weak var printButton: NSButton!
-    var delegate: KMPrintBottomViewDelegate?
+    @IBOutlet weak var posterButton: NSButton!
+    @IBOutlet weak var multipleButton: NSButton!
+    @IBOutlet weak var bookletButton: NSButton!
+    
+    @IBOutlet weak var cancelButtonRightConstraint: NSLayoutConstraint!
     
+    var delegate: KMPrintBottomViewDelegate?
+    var type: PrintModelType = .size {
+        didSet {
+            self.updateButtonState()
+        }
+    }
 //    lazy var presenter: KMImageToPDFChoosePresenter! = KMImageToPDFChoosePresenter()
 //    lazy var OCRPresenter: KMOCRPresenter! = KMOCRPresenter()
 //    lazy var data: KMImageToPDFChooseModel! = KMImageToPDFChooseModel()
@@ -32,7 +42,7 @@ class KMPrintBottomView: KMBaseXibView {
     }
     
     override func setup() {
-        super.setup()
+        self.updateButtonState()
         
 //        self.printerButton.wantsLayer = true
 //        self.printerButton.layer?.borderWidth = 1
@@ -104,6 +114,27 @@ class KMPrintBottomView: KMBaseXibView {
 //
     }
     
+    func updateButtonState() {
+        switch type {
+        case .size:
+            self.cancelButtonRightConstraint.constant = 20
+            
+            self.savePDFButton.isHidden = true
+            self.posterButton.isHidden = false
+            self.multipleButton.isHidden = false
+            self.bookletButton.isHidden = false
+        case .poster, .multipage, .pamphlet:
+            self.cancelButtonRightConstraint.constant = 109
+            
+            self.savePDFButton.isHidden = false
+            self.posterButton.isHidden = true
+            self.multipleButton.isHidden = true
+            self.bookletButton.isHidden = true
+        default:
+            break
+        }
+    }
+    
     
     
     @IBAction func printerAction(_ sender: Any) {

+ 20 - 2
PDF Office/PDF Master/Class/PDFTools/Print/View/BottomView/KMPrintBottomView.xib

@@ -8,8 +8,13 @@
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="KMPrintBottomView">
             <connections>
+                <outlet property="bookletButton" destination="Gke-Bn-OKJ" id="r9E-L4-5yH"/>
                 <outlet property="cancelButton" destination="Ayk-Hy-6Mb" id="HNS-Xh-3aU"/>
+                <outlet property="cancelButtonRightConstraint" destination="hV9-LB-Cse" id="FtJ-LB-AmZ"/>
+                <outlet property="multipleButton" destination="Pvn-3t-pYc" id="sFy-3M-nx5"/>
+                <outlet property="posterButton" destination="XoC-G4-SMT" id="6lg-XF-1fV"/>
                 <outlet property="printButton" destination="hjt-Ec-LG7" id="IUp-w6-Ojd"/>
+                <outlet property="savePDFButton" destination="9yM-DE-RPR" id="XM8-1V-U6f"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
@@ -60,7 +65,7 @@
                     </connections>
                 </button>
                 <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ayk-Hy-6Mb">
-                    <rect key="frame" x="401" y="7" width="83" height="33"/>
+                    <rect key="frame" x="312" y="7" width="83" height="33"/>
                     <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="4uM-k8-JhQ">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
@@ -93,10 +98,22 @@ DQ
                         <action selector="printAction:" target="-2" id="uJS-Vx-1rN"/>
                     </connections>
                 </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9yM-DE-RPR">
+                    <rect key="frame" x="401" y="7" width="83" height="32"/>
+                    <buttonCell key="cell" type="push" title="Save" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="gUE-ob-qQ6">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                    <constraints>
+                        <constraint firstAttribute="width" constant="69" id="Irq-ie-pqA"/>
+                        <constraint firstAttribute="height" constant="20" id="ZNg-OS-SeG"/>
+                    </constraints>
+                </button>
             </subviews>
             <constraints>
                 <constraint firstItem="Gke-Bn-OKJ" firstAttribute="centerY" secondItem="XoC-G4-SMT" secondAttribute="centerY" id="1Ai-AJ-d1m"/>
                 <constraint firstItem="XoC-G4-SMT" firstAttribute="leading" secondItem="zFh-KB-UcZ" secondAttribute="leading" constant="20" id="65s-vm-jnZ"/>
+                <constraint firstItem="9yM-DE-RPR" firstAttribute="centerY" secondItem="hjt-Ec-LG7" secondAttribute="centerY" id="6Fh-X6-Fuu"/>
                 <constraint firstAttribute="trailing" secondItem="hjt-Ec-LG7" secondAttribute="trailing" constant="20" id="7Sr-Qv-kfF"/>
                 <constraint firstItem="Pvn-3t-pYc" firstAttribute="leading" secondItem="XoC-G4-SMT" secondAttribute="trailing" constant="20" id="7pr-9B-fk2"/>
                 <constraint firstItem="Ayk-Hy-6Mb" firstAttribute="centerY" secondItem="XoC-G4-SMT" secondAttribute="centerY" id="Aqg-0R-0Ut"/>
@@ -104,8 +121,9 @@ DQ
                 <constraint firstItem="XoC-G4-SMT" firstAttribute="centerY" secondItem="zFh-KB-UcZ" secondAttribute="centerY" id="W61-pR-Fhf"/>
                 <constraint firstAttribute="height" constant="48" id="Wh7-M9-jtZ"/>
                 <constraint firstItem="Gke-Bn-OKJ" firstAttribute="leading" secondItem="Pvn-3t-pYc" secondAttribute="trailing" constant="20" id="YZz-yh-HBZ"/>
-                <constraint firstItem="hjt-Ec-LG7" firstAttribute="leading" secondItem="Ayk-Hy-6Mb" secondAttribute="trailing" constant="20" id="dWj-cF-qST"/>
+                <constraint firstItem="hjt-Ec-LG7" firstAttribute="leading" secondItem="Ayk-Hy-6Mb" secondAttribute="trailing" constant="109" id="hV9-LB-Cse"/>
                 <constraint firstItem="hjt-Ec-LG7" firstAttribute="centerY" secondItem="XoC-G4-SMT" secondAttribute="centerY" id="mAC-Pm-KCC"/>
+                <constraint firstItem="hjt-Ec-LG7" firstAttribute="leading" secondItem="9yM-DE-RPR" secondAttribute="trailing" constant="20" id="zg9-dC-gQ4"/>
             </constraints>
             <point key="canvasLocation" x="74" y="172"/>
         </customView>