فهرست منبع

【综合】toolbar调整选中区域

tangchao 1 سال پیش
والد
کامیت
62ae42a2d2

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPDFEditToolbar.swift

@@ -506,7 +506,7 @@ extension KMPDFEditToolbar: KMToolbarViewDelegate {
             item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
             item?.target = self
             item?.btnTag = KMPageEditType.insert.rawValue
-            item?.toolTip = NSLocalizedString("Inserting pages into an existing PDF", comment: "")
+//            item?.toolTip = NSLocalizedString("Inserting pages into an existing PDF", comment: "")
             item?.titleName = NSLocalizedString("Insert", comment: "")
             item?.boxImagePosition = .imageExpandLeft
 //            item?.btnAction = #selector(insertMenuAction)
@@ -524,7 +524,7 @@ extension KMPDFEditToolbar: KMToolbarViewDelegate {
             item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
             item?.target = self
             item?.btnTag = KMPageEditType.extract.rawValue
-            item?.toolTip = NSLocalizedString("Exctract selected pages", comment: "")
+//            item?.toolTip = NSLocalizedString("Exctract selected pages", comment: "")
             item?.titleName = NSLocalizedString("Extract", comment: "")
             item?.boxImagePosition = .imageExpandLeft
 //            item?.btnAction = #selector(extractMenuAction)
@@ -554,7 +554,7 @@ extension KMPDFEditToolbar: KMToolbarViewDelegate {
             item?.alternateImage = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
             item?.target = self
             item?.btnTag = KMPageEditType.split.rawValue
-            item?.toolTip = NSLocalizedString("Split and save selected PDF pages as a new separate document", comment: "")
+//            item?.toolTip = NSLocalizedString("Split and save selected PDF pages as a new separate document", comment: "")
             item?.titleName = NSLocalizedString("Split", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true

+ 42 - 14
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarItemView.swift

@@ -7,6 +7,11 @@
 
 import Cocoa
 
+enum KMToolbarItemViewSelectBackgroundType: Int {
+    case none = 0
+    case imageBox
+}
+
 class KMToolbarClickButton: NSButton {
     weak var clickObject: AnyObject?
 }
@@ -43,8 +48,6 @@ extension KMToolbarItemView {
         didSet {
             if self.itemIdentifier != KMToolbarDividerItemIdentifier {
                 if (isSelected) {
-//                    self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
-                    self.imageViewBox.fillColor = self.selectedBackgroundColor
                     if(self.image != nil && self.alternateImage != nil) {
                         if (self.selectedImage != nil) {
                             self.imageViewBtn.image = self.selectedImage!
@@ -59,8 +62,6 @@ extension KMToolbarItemView {
                         self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownSel")
                     }
                 } else {
-//                    self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
-                    self.imageViewBox.fillColor = self.normalBackgroundColor
                     if (self.needExpandAction) {
                         self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
                     }
@@ -71,6 +72,7 @@ extension KMToolbarItemView {
                         self.nameBtn.setTitleColor(color: KMAppearance.titleColor())
                     }
                 }
+                self._updateSelectBackground()
             }
         }
     }
@@ -136,6 +138,7 @@ extension KMToolbarItemView {
   
     var normalBackgroundColor: NSColor = .clear
     var selectedBackgroundColor: NSColor = KMAppearance.Status.selColor()
+    var selectBackgroundType: KMToolbarItemViewSelectBackgroundType = .none
     
     lazy var imageViewBox: NSBox = {
         let view = NSBox()
@@ -181,11 +184,7 @@ extension KMToolbarItemView {
                 if (newValue != nil) {
                     self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
                 } else {
-                    if (self.isSelected) {
-                        self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
-                    }else {
-                        self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
-                    }
+                    self._updateSelectBackground()
                 }
             }
         }
@@ -270,8 +269,12 @@ extension KMToolbarItemView {
             return
         }
         if (!self.isSelected) {
-//            self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
-            self.imageViewBox.fillColor = self.selectedBackgroundColor
+            if self.selectBackgroundType == .none {
+                self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
+            } else {
+                self.imageViewBox.fillColor = self.selectedBackgroundColor
+            }
+            
             if(self.image != nil && self.alternateImage != nil) {
                 self._kNormalImage = self.image
                 self.imageViewBtn.image = self.alternateImage
@@ -293,15 +296,24 @@ extension KMToolbarItemView {
         super.mouseExited(with: event)
         
         if (!self.isSelected && !self.needExpandAction) {
-//            self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
-            self.imageViewBox.fillColor = self.normalBackgroundColor
+            if self.selectBackgroundType == .none {
+                self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
+            } else {
+                self.imageViewBox.fillColor = self.normalBackgroundColor
+            }
+           
             if(self.image != nil && self.alternateImage != nil) {
                 self.imageViewBtn.image = self._kNormalImage ?? self.image!
             }
         }
 
         if(self.needExpandAction && !self.isSelected) {
-            self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
+            if self.selectBackgroundType == .none {
+                self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
+            } else {
+                self.imageViewBox.fillColor = self.normalBackgroundColor
+            }
+            
             if(self.image != nil && self.alternateImage != nil) {
                 self.imageViewBtn.image = self._kNormalImage ?? self.image!
             }
@@ -325,6 +337,22 @@ extension KMToolbarItemView {
             self._closePop()
         }
     }
+    
+    private func _updateSelectBackground() {
+        if self.selectBackgroundType == .none {
+            if self.isSelected {
+                self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
+            } else {
+                self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
+            }
+        } else if self.selectBackgroundType == .imageBox {
+            if self.isSelected {
+                self.imageViewBox.fillColor = self.selectedBackgroundColor
+            } else {
+                self.imageViewBox.fillColor = self.normalBackgroundColor
+            }
+        }
+    }
 }
 
 // MARK: - Private Methods

+ 28 - 11
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -823,6 +823,7 @@ extension KMToolbarViewController {
             item?.target = self
             item?.toolTip = NSLocalizedString("View Settings", comment: "")
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
         } else if identifier == KMDocumentZoomToolbarItemIdentifier {
             item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
@@ -873,6 +874,7 @@ extension KMToolbarViewController {
             item?.target = self
             item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
         } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
             item?.titleName = NSLocalizedString("Tools", comment: "")
@@ -882,6 +884,7 @@ extension KMToolbarViewController {
             item?.btnTag = KMToolbarViewType.Annatiton.rawValue
             item?.btnAction = #selector(leftControllButtonAction)
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
         } else if identifier == KMDocumentPageToolbarItemIdentifier {
             item?.titleName = NSLocalizedString("Page Edit", comment: "")
             item?.target = self
@@ -890,6 +893,7 @@ extension KMToolbarViewController {
             item?.btnTag = KMToolbarViewType.Page.rawValue
             item?.btnAction = #selector(leftControllButtonAction)
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
         } else if identifier == KMDocumentConversonToolbarItemIdentifier {
             item?.titleName = NSLocalizedString("Converter", comment: "")
             item?.target = self
@@ -898,12 +902,14 @@ extension KMToolbarViewController {
             item?.btnTag = KMToolbarViewType.Conversion.rawValue
             item?.btnAction = #selector(leftControllButtonAction)
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
         } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
             item?.titleName = NSLocalizedString("OCR", comment: "")
             item?.target = self
             item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
             item?.boxImagePosition = .imageAbove
             item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_itemAction), target: self)
@@ -916,6 +922,7 @@ extension KMToolbarViewController {
             item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
             item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
             item?.boxImagePosition = .imageLeft
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(scanOCRModelSelect)
         } else if identifier == KMToolbarToolOCRTextIdentifier {
             item?.image = NSImage(named: "KMImageNameMainToolOCRText")
@@ -923,6 +930,7 @@ extension KMToolbarViewController {
             item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
             item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
             item?.boxImagePosition = .imageLeft
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(scanOCRModelSelect)
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR Text Recognition", comment: ""), action: #selector(scanOCRModelSelect), target: self)
@@ -935,6 +943,7 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.btnTag = KMToolbarViewType.editPDF.rawValue
             item?.toolTip = NSLocalizedString("Edit text and image in PDF", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(leftControllButtonAction)
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Edit PDF", comment: ""), action: #selector(leftControllButtonAction), target: self)
@@ -947,6 +956,7 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.btnTag = KMToolbarViewType.Form.rawValue
             item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(leftControllButtonAction)
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Forms", comment: ""), action: #selector(leftControllButtonAction), target: self)
@@ -959,6 +969,7 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.btnTag = KMToolbarViewType.FillSign.rawValue
             item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(leftControllButtonAction)
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Fill & Sign", comment: ""), action: #selector(leftControllButtonAction), target: self)
             menuItem.tag = item!.btnTag
@@ -971,6 +982,7 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.btnTag = KMToolbarViewType.Tool.rawValue
             item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(leftControllButtonAction)
         } else if identifier == KMDocumentRedactToolbarItemIdentifier {
             item?.titleName = NSLocalizedString("Redact Text", comment: "")
@@ -978,6 +990,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
             item?.boxImagePosition = .imageAbove
             item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
         } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
             item?.image = NSImage(named: "ic_function_other_AITranslation")
@@ -999,6 +1012,7 @@ extension KMToolbarViewController {
             item?.target = self
             item?.toolTip = NSLocalizedString("Page Display", comment: "")
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Display", comment: ""), action: #selector(_itemAction), target: self)
             menuItem.tag = item!.btnTag
@@ -1009,6 +1023,7 @@ extension KMToolbarViewController {
             item?.target = self
             item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(shareButtonAction)
             
             let menuItem = NSMenuItem.init(title: item!.titleName ?? "", action: nil, target: self)
@@ -1047,6 +1062,7 @@ extension KMToolbarViewController {
             item?.target = self
             item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
             item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Properties", comment: ""), action: #selector(_itemAction), target: self)
             menuItem.tag = item!.btnTag
@@ -1057,6 +1073,7 @@ extension KMToolbarViewController {
             item?.btnTag = KMToolbarType.redact.rawValue
             item?.toolTip = NSLocalizedString("Redact", comment: "")
             item?.titleName = NSLocalizedString("Redact", comment: "")
+            item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(redactMenuAction)
             
             let menuItem = NSMenuItem.init(title: NSLocalizedString("Redact", comment: ""), action: #selector(redactMenuAction), target: self)
@@ -1319,7 +1336,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertPDFToIMG)
             item?.target = self
             item?.btnTag = KMToolbarType.conversion_image.rawValue
-            item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
+//            item?.toolTip = NSLocalizedString("Convert PDF to JPEG, PNG, TIFF, BMP, GIF or TGA files", comment: "")
             item?.titleName = NSLocalizedString("To Image", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1340,7 +1357,7 @@ extension KMToolbarViewController {
         } else if item?.itemIdentifier == KMToolbarConversionExportImageItemIdentifier {
             item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertExportImage)
             item?.target = self
-            item?.toolTip = NSLocalizedString("The range you can extract images includes current page, odd page, even page, custom page, and all pages.", comment: "")
+//            item?.toolTip = NSLocalizedString("The range you can extract images includes current page, odd page, even page, custom page, and all pages.", comment: "")
             item?.titleName = NSLocalizedString("Extract Images", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1366,7 +1383,7 @@ extension KMToolbarViewController {
         } else if item?.itemIdentifier == KMToolbarConversionCreatePDFItemIdentifier {
             item?.image = NSImage(named: KMImageNameUXIconSubtoolbarConvertCreatPDF)
             item?.target = self
-            item?.toolTip = NSLocalizedString("Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", comment: "")
+//            item?.toolTip = NSLocalizedString("Convert JPEG, JPG, PNG, TIFF, BMP or PSD files to PDFs", comment: "")
             item?.titleName = NSLocalizedString("New PDF Document", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1547,7 +1564,7 @@ extension KMToolbarViewController {
         } else if identifier == KMToolbarToolFormAlignIdentifier {
             item?.image = NSImage(named: KMImageNameUXIconPropertybarAlignLeftToor)
             item?.target = self
-            item?.toolTip = NSLocalizedString("Alignment", comment: "")
+//            item?.toolTip = NSLocalizedString("Alignment", comment: "")
             item?.titleName = NSLocalizedString("Alignment", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1595,7 +1612,7 @@ extension KMToolbarViewController {
         } else if identifier == KMToolbarCropIdentifier {
             item?.image = NSImage(named: KMImageNameUXIconSubtoolbarDisplayTailor)
             item?.target = self
-            item?.toolTip = NSLocalizedString("Note: Cropping a PDF hides some of the PDF’s content without removing it.", comment: "")
+//            item?.toolTip = NSLocalizedString("Note: Cropping a PDF hides some of the PDF’s content without removing it.", comment: "")
             item?.titleName = NSLocalizedString("Crop", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1647,7 +1664,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: KMImageNameUXIconBatchComparison)
             item?.target = self
             item?.btnTag = KMToolbarType.comparison.rawValue
-            item?.toolTip = NSLocalizedString("Compare", comment: "")
+//            item?.toolTip = NSLocalizedString("Compare", comment: "")
             item?.titleName = NSLocalizedString("Compare", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1663,7 +1680,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameUXIconBatchBatesNor")
             item?.target = self
             item?.btnTag = KMToolbarType.bates.rawValue
-            item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
+//            item?.toolTip = NSLocalizedString("Add PDF Bates numbering to your legal, medical, or business documents", comment: "")
             item?.titleName = NSLocalizedString("Bates Number", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1682,7 +1699,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameUXIconBatchHeaderandfooterNor")
             item?.target = self
             item?.btnTag = KMToolbarType.headerAndFooter.rawValue
-            item?.toolTip = NSLocalizedString("Insert header, footer, and page numbers to PDF", comment: "")
+//            item?.toolTip = NSLocalizedString("Insert header, footer, and page numbers to PDF", comment: "")
             item?.titleName = NSLocalizedString("Header & Footer", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1701,7 +1718,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameUXIconBatchBackgroundNor")
             item?.target = self
             item?.btnTag = KMToolbarType.background.rawValue
-            item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
+//            item?.toolTip = NSLocalizedString("Insert PDF page background by color or image", comment: "")
             item?.titleName = NSLocalizedString("Backgroud", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1720,7 +1737,7 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameMainToolsWatermark")
             item?.target = self
             item?.btnTag = KMToolbarType.watermark.rawValue
-            item?.toolTip = NSLocalizedString("Watermark", comment: "")
+//            item?.toolTip = NSLocalizedString("Watermark", comment: "")
             item?.titleName = NSLocalizedString("Watermark", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true
@@ -1746,7 +1763,7 @@ extension KMToolbarViewController {
         } else if identifier == KMToolbarToolSecureItemIdentifier {
             item?.image = NSImage(named: "KMImageNameUXIconBatchSafeNor")
             item?.target = self
-            item?.toolTip = NSLocalizedString("Batch encrypting PDF documents", comment: "")
+//            item?.toolTip = NSLocalizedString("Batch encrypting PDF documents", comment: "")
             item?.titleName = NSLocalizedString("Security", comment: "")
             item?.boxImagePosition = .imageExpandLeft
             item?.needExpandAction = true