Просмотр исходного кода

【2025】【Edit】Crop完善

niehaoyu 2 месяцев назад
Родитель
Сommit
4a1fad9980

+ 17 - 17
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Crop/Views/KMCropPropertyController.swift

@@ -85,9 +85,9 @@ class KMCropPropertyController: NSViewController {
         }
         set {
             _cropSeparateOn = newValue
-          
+            
             UserDefaults.standard.setValue(_cropSeparateOn, forKey: "CropSeparateOnKey")
-         }
+        }
     }
     
     public var cropAutoOn : Bool {
@@ -96,9 +96,9 @@ class KMCropPropertyController: NSViewController {
         }
         set {
             _cropAutoOn = newValue
-          
+            
             UserDefaults.standard.setValue(_cropAutoOn, forKey: "CropAutoOnKey")
-         }
+        }
     }
     
     public var syncChangeBounds : Bool {
@@ -107,9 +107,9 @@ class KMCropPropertyController: NSViewController {
         }
         set {
             _syncChangeBounds = newValue
-          
+            
             UserDefaults.standard.setValue(_syncChangeBounds, forKey: "CropSyncChangeBoundsKey")
-         }
+        }
     }
     
     func setupProperty() {
@@ -210,6 +210,13 @@ class KMCropPropertyController: NSViewController {
     }
     
     func reloadData() {
+        //White Margin
+        separateSwitch.properties.open = cropSeparateOn
+        separateSwitch.reloadData()
+        
+        autoSwitch.properties.open = cropAutoOn
+        autoSwitch.reloadData()
+        
         guard let pdfView = self.pdfView else {
             return
         }
@@ -220,13 +227,6 @@ class KMCropPropertyController: NSViewController {
         let pageBounds = page.bounds
         let selectionRect = pdfView.selectionRect
         
-        //White Margin
-        separateSwitch.properties.open = cropSeparateOn
-        separateSwitch.reloadData()
-        
-        autoSwitch.properties.open = cropAutoOn
-        autoSwitch.reloadData()
-        
         //PageSize
         sizeWidthInput.properties.maxSize = Int(pageBounds.size.width)
         sizeWidthInput.properties.text = String(format: "%.0f", selectionRect.size.width)
@@ -255,7 +255,7 @@ class KMCropPropertyController: NSViewController {
         pageTopInput.properties.maxSize = Int(pageBounds.size.height)
         pageTopInput.properties.text = String(format: "%.0f", pageBounds.size.height - CGRectGetMaxY(selectionRect))
         pageTopInput.reloadData()
-         
+        
         pageBottomInput.properties.maxSize = Int(pageBounds.size.height)
         pageBottomInput.properties.text = String(format: "%.0f", selectionRect.origin.y)
         pageBottomInput.reloadData()
@@ -334,7 +334,7 @@ extension KMCropPropertyController: ComponentInputNumberDelegate {
         if let text = inputNumber?.properties.text {
             value = text.stringToCGFloat()
         }
-  
+        
         var rect = pdfView.selectionRect
         if inputNumber == sizeWidthInput {
             if syncChangeBounds {
@@ -352,7 +352,7 @@ extension KMCropPropertyController: ComponentInputNumberDelegate {
                     scale = value / rect.size.height
                 }
                 rect.size.width *= scale
-             }
+            }
             rect.size.height = value
         } else if inputNumber == pageLeftInput {
             rect.origin.x = value
@@ -368,7 +368,7 @@ extension KMCropPropertyController: ComponentInputNumberDelegate {
         
         cropAutoOn = false
         cropSeparateOn = false
-
+        
         reloadData()
     }
 }

+ 20 - 6
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -1381,12 +1381,7 @@ struct KMNMWCFlags {
             cropController?.view.removeFromSuperview()
             cropController = nil
             
-            if viewManager.subToolMode == .None {
-                viewManager.showRightSide = false
-                pdfToolbarController?.reloadRightToolsView()
-                
-                toggleCloseRightSide()
-            }
+            toolbarManager.edit_crop_Property.state = .normal
         }
         
     }
@@ -3218,6 +3213,12 @@ extension KMMainViewController: KMCropControllerDelegate {
         }
         cropPages(atIndexs: uIndexs, to: [cropRect])
         removeCropController()
+        
+        viewManager.subToolMode = .None
+        if let toolbarVC = self.pdfToolbarController {
+            toolbarVC.refreshSecondToolbarItemsState()
+            self.kmPDFToolbarControllerDidToolbarItemClicked(toolbarVC, KMPDFToolbar_edit_crop_Identifier)
+        }
     }
     
     func kmCropControllerDidCropSeparate(_ controller: KMCropController, _ view: KMPageRangeSelectView) {
@@ -3240,6 +3241,12 @@ extension KMMainViewController: KMCropControllerDelegate {
         }
         cropPages(atIndexs: uIndexs, to: rectArray)
         removeCropController()
+        
+        viewManager.subToolMode = .None
+        if let toolbarVC = self.pdfToolbarController {
+            toolbarVC.refreshSecondToolbarItemsState()
+            self.kmPDFToolbarControllerDidToolbarItemClicked(toolbarVC, KMPDFToolbar_edit_crop_Identifier)
+        }
     }
     
     func kmCropControllerDidCropAuto(_ controller: KMCropController, _ view: KMPageRangeSelectView) {
@@ -3256,6 +3263,13 @@ extension KMMainViewController: KMCropControllerDelegate {
             uIndexs = [UInt(listView.currentPageIndex)]
         }
         auto_cropPagesWhiteMargin(uIndexs)
+        removeCropController()
+        
+        viewManager.subToolMode = .None
+        if let toolbarVC = self.pdfToolbarController {
+            toolbarVC.refreshSecondToolbarItemsState()
+            self.kmPDFToolbarControllerDidToolbarItemClicked(toolbarVC, KMPDFToolbar_edit_crop_Identifier)
+        }
     }
     
     func kmCropControllerDidChangedSelectionOrMagnification(_ controller: KMCropController) {