Browse Source

【综合】内容编辑悬浮框弹出优化

TangChao 7 months ago
parent
commit
e4a573be1e

+ 10 - 2
PDF Office/PDF Master/Class/PDFTools/EditPDF/Controller/KMEditPDFPopToolBarController.swift

@@ -563,7 +563,11 @@ extension KMEditPDFPopToolBarController: KMEditPDFToolbarViewDelegate {
             viewC.borderWidth_hov = 0
             viewC.borderWidth_act = 0
             DispatchQueue.main.async {
-                viewC.state = model.isSelected ? .Act : .Norm
+                if model.isEnabled {
+                    viewC.state = model.isSelected ? .Act : .Norm
+                } else {
+                    viewC.state = .Disabled
+                }
             }
             if KMAppearance.isDarkMode() {
                 viewC.background = NSColor.clear
@@ -581,7 +585,11 @@ extension KMEditPDFPopToolBarController: KMEditPDFToolbarViewDelegate {
             viewC.borderWidth_hov = 0
             viewC.borderWidth_act = 0
             DispatchQueue.main.async {
-                viewC.state = model.isSelected ? .Act : .Norm
+                if model.isEnabled {
+                    viewC.state = model.isSelected ? .Act : .Norm
+                } else {
+                    viewC.state = .Disabled
+                }
             }
             if KMAppearance.isDarkMode() {
                 viewC.background = NSColor.clear

+ 21 - 12
PDF Office/PDF Master/Class/PDFTools/EditPDF/Tools/KMEditPDfHanddler.swift

@@ -19,6 +19,9 @@ class KMEditPDfHanddler: NSObject {
     
     static let kRightSideLastStateKey = "KMRightSideLastStateKey"
     
+    // 正在新增文本块
+    var addTextAreaing = false
+    
     weak var listView: CPDFListView? {
         get {
             return self.viewC?.listView
@@ -1473,19 +1476,21 @@ extension KMEditPDfHanddler: CPDFViewDelegate {
             }
         }
         
-        var flag: CPDFEditArea?
-        for area in areas {
-            if flag == nil {
-                flag = area
-                continue
+        if self.addTextAreaing == false {
+            var flag: CPDFEditArea?
+            for area in areas {
+                if flag == nil {
+                    flag = area
+                    continue
+                }
+                if let data = flag, data.bounds.maxY < area.bounds.maxY {
+                    flag = area
+                }
             }
-            if let data = flag, data.bounds.maxY < area.bounds.maxY {
-                flag = area
+            if let data = flag {
+                self.showPopWindow(positionRect: data.bounds, showGuide: true)
             }
         }
-        if let data = flag {
-            self.showPopWindow(positionRect: data.bounds, showGuide: true)
-        }
     }
     
     func pdfViewEditingCropBoundsDidChanged(_ pdfView: CPDFView!, editing editArea: CPDFEditArea!) {
@@ -1629,7 +1634,9 @@ extension KMEditPDfHanddler: CPDFViewDelegate {
         attri.alignment = fontAlign
         attri.isBold = model.bold
         attri.isItalic = model.italic
+        self.addTextAreaing = true
         self.listView?.createStringBounds(newRect, with: attri, page: page)
+        self.addTextAreaing = false
         
         // self.rightViewC != nil &&
         if self.subViewType == .EditPDFAddText && self.annotationType == .addText {
@@ -1692,8 +1699,10 @@ extension KMEditPDfHanddler: CPDFViewDelegate {
 //            self.rightViewC?.eidtPDFTextProperty.reloadData()
 //            self.rightViewC?.eidtPDFTextProperty.updateTextTextPresuppositionState()
             
-            self.showPopWindow(positionRect: .zero, showGuide: false)
-            self._reloadData_right_text()
+            if self.addTextAreaing == false {
+                self.showPopWindow(positionRect: .zero, showGuide: false)
+                self._reloadData_right_text()
+            }
         }
     }
 }

+ 16 - 4
PDF Office/PDF Master/Class/PDFTools/EditPDF/Window/KMEditPDFPopToolBarWindow.swift

@@ -91,12 +91,12 @@ import Cocoa
                         } else if key == .fontReduce {
                             model.isEnabled = self._fontSizeItemIsEnabled()
                         } else if key == .fontBold {
-//                            model.isEnabled = self.model.editAreasFontBoldIsEqual()
+                            model.isEnabled = self.model.editAreasFontBoldIsEqual()
                             if self.model.editAreasFontBoldIsEqual() {
                                 model.isSelected = self.model.fontBolds.first ?? false
                             }
                         } else if key == .fontItalic {
-//                            model.isEnabled = self.model.editAreasFontItalicIsEqual()
+                            model.isEnabled = self.model.editAreasFontItalicIsEqual()
                             if self.model.editAreasFontItalicIsEqual() {
                                 model.isSelected = self.model.fontItalics.first ?? false
                             }
@@ -132,10 +132,10 @@ import Cocoa
                         } else if key == .fontReduce {
                             model.isEnabled = self._fontSizeItemIsEnabled()
                         } else if key == .fontBold {
-//                            model.isEnabled = self.model.editAreasFontBoldIsEqual()
+                            model.isEnabled = self.model.editAreasFontBoldIsEqual()
                             model.isSelected = self.model.fontBolds.first ?? false
                         } else if key == .fontItalic {
-//                            model.isEnabled = self.model.editAreasFontItalicIsEqual()
+                            model.isEnabled = self.model.editAreasFontItalicIsEqual()
                             model.isSelected = self.model.fontItalics.first ?? false
                         } else if key == .textAlignment {
 //                            model.isEnabled = self.model.editAreasTextAlignmentIsEqual()
@@ -247,6 +247,18 @@ import Cocoa
         }
     }
     
+    func updateFontSizeButtons(enable: Bool) {
+        if self.isVisible {
+            let contentViewC = self.contentViewController as? KMEditPDFPopToolBarController
+            for model in contentViewC?.datas ?? [] {
+                if model.itemKey == .fontAdd || model.itemKey == .fontReduce {
+                    model.isEnabled = enable
+                }
+            }
+            contentViewC?.toolbarView?.reloadData()
+        }
+    }
+    
     // MARK: - Private Methods
     
     private func _fontSizeItemIsEnabled() -> Bool {

+ 12 - 5
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/EditPDF/KMEditPDFTextPropertyViewController.swift

@@ -739,9 +739,9 @@ class KMEditPDFTextPropertyViewController: NSViewController {
 //                }
                 self.updateTextPresupposition(fontName: fontName, style: fontStyle, size: CGFloat(Float(sizeString)!), needChangeListView: false)
                 self.currentColor = color
-                DispatchQueue.main.async {
-                    NSColorPanel.shared.color = color
-                }
+//                DispatchQueue.main.async {
+//                    NSColorPanel.shared.color = color
+//                }
                 self.fontColorButton.image = self.swatchWithColor(color: color, size: NSSize(width: 20, height: 20))
                 self.alignment = alignment
                 self.selectAlignment(alignment: alignment)
@@ -774,11 +774,16 @@ class KMEditPDFTextPropertyViewController: NSViewController {
             
             if let data = self.handdler?.editAreasFontStyleIsEqual(), data {
                 if let area = self.handdler?.editingTextAreas.first {
-                    if let styleName = self.listView.editingSelectionCFont(with: area)?.familyName, styleName.isEmpty == false {
+                    if let styleName = self.listView.editingSelectionCFont(with: area)?.styleName, styleName.isEmpty == false {
 //                    if let styleName = self.listView.editingSelectionCFont(byRangeEdit: area)?.styleName, styleName.isEmpty == false {
                         self.fontStyleVC?.stringValue = styleName
                     } else {
-                        self.fontStyleVC?.stringValue = "--"
+                        let styleNames = CPDFFont.fontNames(forFamilyName: self.listView.editingSelectionCFont(with: area).familyName)
+                        if let styleN = styleNames.first, styleN.isEmpty == false {
+                            self.fontStyleVC?.stringValue = styleN
+                        } else {
+                            self.fontStyleVC?.stringValue = "Regular"
+                        }
                     }
                 }
             } else {
@@ -1189,6 +1194,8 @@ extension KMEditPDFTextPropertyViewController: KMSelectPopButtonDelegate {
             let size = CGFloat(Float((obj.stringValue.replacingOccurrences(of: "pt", with: "")))!)
             self.updateFontSize(size: size)
             self.updatePreviewImage()
+            
+            KMEditPDFPopToolBarWindow.shared.updateFontSizeButtons(enable: true)
         } else if obj == fontStyleVC {
             self.updateFontNameAndStyle(name: fontName, style: obj.stringValue)
             self.updatePreviewImage()