Browse Source

【工具栏】自定义工具栏补充显示区域内部拖拽

tangchao 9 months ago
parent
commit
3a99500852

+ 208 - 9
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Controller/KMToolbarConfigViewController.swift

@@ -10,8 +10,11 @@ import Cocoa
 typealias KMToolbarConfigViewControllerCallback = (NSApplication.ModalResponse) -> Void
 class KMToolbarConfigViewController: NSViewController {
     
+    @IBOutlet weak var showLabel: NSTextField!
     @IBOutlet weak var collectionView: NSCollectionView!
+    @IBOutlet weak var removedLabel: NSTextField!
     @IBOutlet weak var removedCollectionView: NSCollectionView!
+    @IBOutlet weak var tipLabel: NSTextField!
     @IBOutlet weak var cancelButton: NSButton!
     @IBOutlet weak var confirmButton: NSButton!
     
@@ -39,11 +42,28 @@ class KMToolbarConfigViewController: NSViewController {
     }
     
     func initDefalutValue() {
+        self.showLabel.stringValue = NSLocalizedString("Show", comment: "")
         self.collectionView.delegate = self
         self.collectionView.dataSource = self
         
         self.collectionView.register(KMToolbarConfigViewItem.self, forItemWithIdentifier: self.cellIdentifier_)
         (self.collectionView.collectionViewLayout as? NSCollectionViewFlowLayout)?.scrollDirection = .horizontal
+//        self.collectionView.registerForDraggedTypes([kKMLocalForDraggedTypes, .fileURL, .string])
+        collectionView.registerForDraggedTypes([NSPasteboard.PasteboardType.string, kKMLocalForDraggedTypes, .fileURL, .pdf])
+        collectionView.setDraggingSourceOperationMask(.every, forLocal: false)
+        collectionView.setDraggingSourceOperationMask(.every, forLocal: true)
+        
+        self.collectionView.allowsMultipleSelection = false
+//        self.collectionView.enclosingScrollView?.drawsBackground = false
+        self.collectionView.enclosingScrollView?.backgroundColor = .gridColor
+        self.collectionView.enclosingScrollView?.wantsLayer = true
+        self.collectionView.enclosingScrollView?.layer?.backgroundColor = NSColor.red.cgColor
+//        self.collectionView.wantsLayer = true
+//        self.collectionView.layer?.backgroundColor = NSColor.red.cgColor
+        
+        self.removedLabel.stringValue = NSLocalizedString("Hide", comment: "")
+        
+        self.tipLabel.stringValue = NSLocalizedString("Drag and drop to add, remove and reorder the tools.", comment: "")
         
         self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
         self.cancelButton.target = self
@@ -72,6 +92,10 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
     }
     
     func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
+        if self.removedCollectionView.isEqual(to: collectionView) {
+            return 0
+        }
+        
         if let cnt = self.model.allowedCellIdentifiers?.count {
             return cnt + 2
         }
@@ -79,21 +103,25 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
     }
     
     func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
+        if self.removedCollectionView.isEqual(to: collectionView) {
+            return NSCollectionViewItem()
+        }
+        
         let cell = collectionView.makeItem(withIdentifier: self.cellIdentifier_, for: indexPath) as! KMToolbarConfigViewItem
-        if indexPath.item == self.model.leftCount {
+        if self.model.isFirstSegI(at: indexPath.item) {
             cell.itemView = nil
-        } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
+        } else if self.model.isSecondSegI(at: indexPath.item) {
             cell.itemView = nil
         } else {
             var idx = indexPath.item
-            if idx > (self.model.leftCount + self.model.centerCount) {
+            if self.model.isRight(at: idx) {
                 idx = idx - 2
-            } else if idx > self.model.leftCount {
+            } else if self.model.isCenter(at: idx) {
                 idx = idx - 1
             }
             
             let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
-            let item = KMToolbarItemView(itemIdentifier: itemId)
+            let item = KMToolbarConfigTBItemView(itemIdentifier: itemId)
             self.model.setupMainItem(item)
             cell.itemView = item
         }
@@ -104,16 +132,20 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
     // Layout
     
     func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
-        if indexPath.item == self.model.leftCount {
+        if self.removedCollectionView.isEqual(to: collectionView) {
+            return NSSize(width: 48, height: 48)
+        }
+        
+        if self.model.isFirstSegI(at: indexPath.item) {
             return NSSize(width: self.model.segItemWidth, height: 48)
-        } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
+        } else if self.model.isSecondSegI(at: indexPath.item) {
             return NSSize(width: self.model.segItemWidth, height: 48)
         }
         
         var idx = indexPath.item
-        if idx > (self.model.leftCount + self.model.centerCount) {
+        if self.model.isRight(at: idx) {
             idx = idx - 2
-        } else if idx > self.model.leftCount {
+        } else if self.model.isCenter(at: idx) {
             idx = idx - 1
         }
         let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
@@ -136,5 +168,172 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
         return .init(top: 6, left: 10, bottom: 6, right: 10)
     }
     
+    func collectionView(_ collectionView: NSCollectionView, shouldSelectItemsAt indexPaths: Set<IndexPath>) -> Set<IndexPath> {
+        return indexPaths
+    }
+    
+    // Drag & Drop
+    
+//    func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set<IndexPath>, to pasteboard: NSPasteboard) -> Bool {
+//        if let data = try? NSKeyedArchiver.archivedData(withRootObject: indexPaths, requiringSecureCoding: true) {
+//            pasteboard.declareTypes([kKMLocalForDraggedTypes], owner: self)
+//            pasteboard.setData(data, forType: kKMLocalForDraggedTypes)
+//
+////            self.dragedIndexPaths.removeAll()
+////            for indexPath in indexPaths {
+////                self.dragedIndexPaths.append(indexPath)
+////            }
+//        }
+//        return true
+//    }
+    
+//    func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexes: IndexSet, to pasteboard: NSPasteboard) -> Bool {
+//        if let data = try? NSKeyedArchiver.archivedData(withRootObject: indexes, requiringSecureCoding: true) {
+//            pasteboard.declareTypes([kKMLocalForDraggedTypes], owner: self)
+//            pasteboard.setData(data, forType: kKMLocalForDraggedTypes)
+//
+////            self.dragedIndexPaths.removeAll()
+////            for indexPath in indexPaths {
+////                self.dragedIndexPaths.append(indexPath)
+////            }
+//        }
+//        return true
+//    }
+//
+//    func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath proposedDropIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation {
+//        return .every
+//    }
+//
+//    func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> Bool {
+//        return true
+//    }
+    
+    func collectionView(_ collectionView: NSCollectionView, canDragItemsAt indexPaths: Set<IndexPath>, with event: NSEvent) -> Bool {
+        if self.removedCollectionView.isEqual(to: collectionView) {
+            return true
+        }
+        return true
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting? {
+        return String(indexPath.item) as NSPasteboardWriting
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItemsAt indexPaths: Set<IndexPath>) {
+//        if collectionView.isEqual(showCollectionView) {
+//            indexPathsOfItemsBeingShowItemDragged = indexPaths
+//        } else if collectionView.isEqual(hideCollectionView) {
+//            indexPathsOfItemsBeingHideItemDragged = indexPaths
+//        }
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath proposedDropIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation {
+        if collectionView.isEqual(self.removedCollectionView) {
+            return .move
+        }
+        
+        
+        if collectionView.isEqual(self.collectionView) {
+//            if indexPathsOfItemsBeingShowItemDragged.count != 0 {
+                return .move
+//            } else {
+//                return .copy
+//            }
+        }
+//        else  {
+//            if indexPathsOfItemsBeingHideItemDragged.count != 0 {
+//                return .move
+//            } else {
+//                return .copy
+//            }
+//        }
+        return []
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> Bool {
+        var result = false
+//        if collectionView.isEqual(showCollectionView) {
+//            if indexPathsOfItemsBeingShowItemDragged.count != 0 {
+//                var toItemIndex = indexPath.item
+//                for fromIndexPath in indexPathsOfItemsBeingShowItemDragged {
+//                    let fromItemIndex = fromIndexPath.item
+//                    if fromItemIndex > toItemIndex {
+//                        moveCell(fromIndex: fromItemIndex, toIndex: toItemIndex, collectionView: collectionView)
+//                        collectionView.animator().moveItem(at: fromIndexPath, to: IndexPath(item: toItemIndex, section: indexPath.section))
+//                        toItemIndex += 1
+//                    }
+//                }
+//                var adjustedToItemIndex = indexPath.item
+//                for fromIndexPath in indexPathsOfItemsBeingShowItemDragged.reversed() {
+//                    let fromItemIndex = fromIndexPath.item
+//                    if fromItemIndex < adjustedToItemIndex {
+//                        if adjustedToItemIndex >= showArray.count {
+//                            adjustedToItemIndex = showArray.count - 1
+//                        }
+//                        moveCell(fromIndex: fromItemIndex, toIndex: adjustedToItemIndex, collectionView: collectionView)
+//                        let adjustedToIndexPath = IndexPath(item: adjustedToItemIndex, section: indexPath.section)
+//                        collectionView.animator().moveItem(at: fromIndexPath, to: adjustedToIndexPath)
+//                        adjustedToItemIndex -= 1
+//                    }
+//                }
+//                result = true
+//            } else if indexPathsOfItemsBeingHideItemDragged.count != 0 {
+//                let toItemIndex = indexPathsOfItemsBeingHideItemDragged.first!.item
+//                showArray.insert((hideArray[toItemIndex] as! Int) as NSNumber, at: indexPath.item)
+//                hideArray.remove(at: toItemIndex)
+//                result = true
+//
+//                self.dataChange?(self, showArray)
+//            }
+//        } else if collectionView.isEqual(hideCollectionView) {
+//            if indexPathsOfItemsBeingHideItemDragged.count != 0 {
+//                var toItemIndex = indexPath.item
+//                for fromIndexPath in indexPathsOfItemsBeingHideItemDragged {
+//                    let fromItemIndex = fromIndexPath.item
+//                    if fromItemIndex > toItemIndex {
+//                        moveCell(fromIndex: fromItemIndex, toIndex: toItemIndex, collectionView: collectionView)
+//                        collectionView.animator().moveItem(at: fromIndexPath, to: IndexPath(item: toItemIndex, section: indexPath.section))
+//                        toItemIndex += 1
+//                    }
+//                }
+//                var adjustedToItemIndex = indexPath.item - 1
+//                for fromIndexPath in indexPathsOfItemsBeingHideItemDragged.reversed() {
+//                    let fromItemIndex = fromIndexPath.item
+//                    if fromItemIndex < adjustedToItemIndex {
+//                        if adjustedToItemIndex >= showArray.count {
+//                            adjustedToItemIndex = showArray.count - 1
+//                        }
+//                        moveCell(fromIndex: fromItemIndex, toIndex: adjustedToItemIndex, collectionView: collectionView)
+//                        let adjustedToIndexPath = IndexPath(item: adjustedToItemIndex, section: indexPath.section)
+//                        collectionView.animator().moveItem(at: fromIndexPath, to: adjustedToIndexPath)
+//                        adjustedToItemIndex -= 1
+//                    }
+//                }
+//                result = true
+//            } else if indexPathsOfItemsBeingShowItemDragged.count != 0 {
+//                let toItemIndex = indexPathsOfItemsBeingShowItemDragged.first!.item
+//                hideArray.insert((showArray[toItemIndex] as! Int) as NSNumber, at: indexPath.item)
+//                showArray.remove(at: toItemIndex)
+//                result = true
+//
+//                self.dataChange?(self, showArray)
+//            }
+//        }
+        return result
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, dragOperation operation: NSDragOperation) {
+//        if collectionView.isEqual(showCollectionView) {
+//            indexPathsOfItemsBeingShowItemDragged.removeAll()
+//            removeBox.borderColor = KMAppearance.Layout.h2Color()
+//            removeButton.isEnabled = false
+//        } else if collectionView.isEqual(hideCollectionView) {
+//            indexPathsOfItemsBeingHideItemDragged.removeAll()
+//            addBox.borderColor = KMAppearance.Layout.h2Color()
+//            addButton.isEnabled = false
+//        }
+//        showCollectionView.reloadSections(IndexSet(integer: 0))
+//        hideCollectionView.reloadSections(IndexSet(integer: 0))
+    }
     
 }

+ 61 - 22
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Controller/KMToolbarConfigViewController.xib

@@ -3,6 +3,7 @@
     <dependencies>
         <deployment identifier="macosx"/>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <capability name="Named colors" minToolsVersion="9.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -12,33 +13,36 @@
                 <outlet property="collectionView" destination="C4M-vA-SRV" id="hm4-3W-khn"/>
                 <outlet property="confirmButton" destination="5tz-eV-Ytt" id="VHK-be-N1N"/>
                 <outlet property="removedCollectionView" destination="rXf-Pu-nKA" id="HNv-2K-uW0"/>
+                <outlet property="removedLabel" destination="HMG-Nh-uYe" id="hDR-dF-V0G"/>
+                <outlet property="showLabel" destination="DrL-JR-pL6" id="mt6-YN-BDc"/>
+                <outlet property="tipLabel" destination="WdD-cf-Oez" id="rT6-G5-o2g"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="1480" height="280"/>
+            <rect key="frame" x="0.0" y="0.0" width="1480" height="360"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <scrollView wantsLayer="YES" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pVa-qa-L5j">
-                    <rect key="frame" x="0.0" y="200" width="1480" height="60"/>
-                    <clipView key="contentView" id="hQo-vN-bfQ">
-                        <rect key="frame" x="1" y="1" width="1478" height="58"/>
+                <scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pVa-qa-L5j">
+                    <rect key="frame" x="26" y="230" width="1428" height="90"/>
+                    <clipView key="contentView" drawsBackground="NO" id="hQo-vN-bfQ">
+                        <rect key="frame" x="0.0" y="0.0" width="1428" height="90"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <collectionView id="C4M-vA-SRV">
-                                <rect key="frame" x="0.0" y="0.0" width="1478" height="58"/>
+                            <collectionView selectable="YES" allowsMultipleSelection="YES" id="C4M-vA-SRV">
+                                <rect key="frame" x="0.0" y="0.0" width="1428" height="90"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="Ut1-FD-oCR">
                                     <size key="itemSize" width="50" height="50"/>
                                 </collectionViewFlowLayout>
-                                <color key="primaryBackgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                <color key="primaryBackgroundColor" name="KM_DBDBDB_Color"/>
                             </collectionView>
                         </subviews>
                     </clipView>
                     <constraints>
-                        <constraint firstAttribute="height" constant="60" id="GDp-1c-eHI"/>
+                        <constraint firstAttribute="height" constant="90" id="GDp-1c-eHI"/>
                     </constraints>
                     <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="4yz-zP-zak">
                         <rect key="frame" x="-100" y="-100" width="233" height="15"/>
@@ -49,14 +53,14 @@
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
                 </scrollView>
-                <scrollView wantsLayer="YES" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y3L-cT-yu5">
-                    <rect key="frame" x="0.0" y="100" width="1480" height="60"/>
+                <scrollView wantsLayer="YES" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="y3L-cT-yu5">
+                    <rect key="frame" x="26" y="100" width="1428" height="90"/>
                     <clipView key="contentView" id="rRg-x2-XJs">
-                        <rect key="frame" x="1" y="1" width="1478" height="58"/>
+                        <rect key="frame" x="1" y="1" width="1426" height="88"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <collectionView id="rXf-Pu-nKA">
-                                <rect key="frame" x="0.0" y="0.0" width="1478" height="158"/>
+                                <rect key="frame" x="0.0" y="0.0" width="1426" height="88"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="QkZ-GP-Y7n">
                                     <size key="itemSize" width="50" height="50"/>
@@ -66,14 +70,14 @@
                         </subviews>
                     </clipView>
                     <constraints>
-                        <constraint firstAttribute="height" constant="60" id="kAQ-n6-yZN"/>
+                        <constraint firstAttribute="height" constant="90" id="kAQ-n6-yZN"/>
                     </constraints>
                     <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="kmJ-Fg-BXZ">
-                        <rect key="frame" x="1" y="144" width="233" height="15"/>
+                        <rect key="frame" x="-100" y="-100" width="233" height="15"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
-                    <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="pNf-CQ-3JS">
-                        <rect key="frame" x="1463" y="1" width="16" height="58"/>
+                    <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="pNf-CQ-3JS">
+                        <rect key="frame" x="1463" y="1" width="16" height="88"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
                 </scrollView>
@@ -94,20 +98,55 @@ DQ
 </string>
                     </buttonCell>
                 </button>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="DrL-JR-pL6">
+                    <rect key="frame" x="24" y="324" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="YE2-rQ-Luf">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HMG-Nh-uYe">
+                    <rect key="frame" x="24" y="194" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="Bb7-lA-01B">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WdD-cf-Oez">
+                    <rect key="frame" x="24" y="40" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="7P9-RR-cRl">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
             </subviews>
             <constraints>
+                <constraint firstItem="pVa-qa-L5j" firstAttribute="top" secondItem="DrL-JR-pL6" secondAttribute="bottom" constant="4" id="7Q6-wg-elB"/>
+                <constraint firstItem="HMG-Nh-uYe" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="26" id="9Do-Er-hG7"/>
                 <constraint firstAttribute="trailing" secondItem="5tz-eV-Ytt" secondAttribute="trailing" constant="40" id="Ago-US-e8k"/>
-                <constraint firstAttribute="trailing" secondItem="pVa-qa-L5j" secondAttribute="trailing" id="PQD-Wn-jYz"/>
+                <constraint firstItem="DrL-JR-pL6" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="26" id="CmI-7Z-7Ge"/>
+                <constraint firstItem="y3L-cT-yu5" firstAttribute="top" secondItem="HMG-Nh-uYe" secondAttribute="bottom" constant="4" id="JLJ-pA-RgP"/>
+                <constraint firstAttribute="trailing" secondItem="pVa-qa-L5j" secondAttribute="trailing" constant="26" id="PQD-Wn-jYz"/>
                 <constraint firstItem="y3L-cT-yu5" firstAttribute="top" secondItem="pVa-qa-L5j" secondAttribute="bottom" constant="40" id="QCF-ho-vh9"/>
+                <constraint firstItem="WdD-cf-Oez" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="26" id="SUv-FS-xin"/>
                 <constraint firstAttribute="bottom" secondItem="Jrq-XK-HyQ" secondAttribute="bottom" constant="26" id="a6L-Qa-wSh"/>
-                <constraint firstItem="pVa-qa-L5j" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="i2X-DD-H49"/>
-                <constraint firstItem="y3L-cT-yu5" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="l3e-Dt-Y32"/>
-                <constraint firstItem="pVa-qa-L5j" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="r1p-CD-TUo"/>
-                <constraint firstAttribute="trailing" secondItem="y3L-cT-yu5" secondAttribute="trailing" id="tes-fY-UP2"/>
+                <constraint firstAttribute="bottom" secondItem="WdD-cf-Oez" secondAttribute="bottom" constant="40" id="b9w-qB-piR"/>
+                <constraint firstItem="pVa-qa-L5j" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="40" id="i2X-DD-H49"/>
+                <constraint firstItem="y3L-cT-yu5" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="26" id="l3e-Dt-Y32"/>
+                <constraint firstItem="pVa-qa-L5j" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="26" id="r1p-CD-TUo"/>
+                <constraint firstAttribute="trailing" secondItem="y3L-cT-yu5" secondAttribute="trailing" constant="26" id="tes-fY-UP2"/>
                 <constraint firstAttribute="bottom" secondItem="5tz-eV-Ytt" secondAttribute="bottom" constant="26" id="xfN-Ys-ZAb"/>
                 <constraint firstItem="5tz-eV-Ytt" firstAttribute="leading" secondItem="Jrq-XK-HyQ" secondAttribute="trailing" constant="29" id="zfT-aO-rPp"/>
             </constraints>
             <point key="canvasLocation" x="44" y="154"/>
         </customView>
     </objects>
+    <resources>
+        <namedColor name="KM_DBDBDB_Color">
+            <color red="0.85900002717971802" green="0.85900002717971802" blue="0.85900002717971802" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+        </namedColor>
+    </resources>
 </document>

+ 45 - 1
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Model/KMToolbarConfigModel.swift

@@ -101,9 +101,53 @@ class KMToolbarConfigModel: NSObject {
     
     var segItemWidth: CGFloat {
         get {
-            return (self.windowWidth - self.contentWidth) * 0.5
+            return (self.windowWidth - self.contentWidth - 26 * 2) * 0.5
         }
     }
+    
+    func isLeft(at idx: Int) -> Bool {
+        if self.leftCount <= 0 {
+            return false
+        }
+        let stardIdx = 0
+        let endIdx = self.leftCount
+        if idx >= stardIdx && idx < endIdx {
+            return true
+        }
+        return false
+    }
+    
+    func isCenter(at idx: Int) -> Bool {
+        if self.centerCount <= 0 {
+            return false
+        }
+        let stardIdx = self.leftCount+1
+        let endIdx = stardIdx+self.centerCount
+        if idx >= stardIdx && idx < endIdx {
+            return true
+        }
+        return false
+    }
+    
+    func isRight(at idx: Int) -> Bool {
+        if self.rightCount <= 0 {
+            return false
+        }
+        let stardIdx = self.leftCount+self.centerCount+2
+        let endIdx = stardIdx+self.rightCount
+        if idx >= stardIdx && idx < endIdx {
+            return true
+        }
+        return false
+    }
+    
+    func isFirstSegI(at idx: Int) -> Bool {
+        return idx == self.leftCount
+    }
+    
+    func isSecondSegI(at idx: Int) -> Bool {
+        return idx == (self.leftCount+self.centerCount+1)
+    }
 }
 
 extension KMToolbarConfigModel {

+ 26 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/View/KMToolbarConfigTBItemView.swift

@@ -0,0 +1,26 @@
+//
+//  KMToolbarConfigTBItemView.swift
+//  PDF Reader Pro
+//
+//  Created by tangchao on 2024/5/29.
+//
+
+import Cocoa
+
+class KMToolbarConfigTBItemView: KMToolbarItemView {
+
+    override func draw(_ dirtyRect: NSRect) {
+        super.draw(dirtyRect)
+
+        // Drawing code here.
+    }
+    
+    override func hitTest(_ point: NSPoint) -> NSView? {
+        return self
+    }
+    
+    override func updateTrackingAreas() {
+        /// ...
+    }
+    
+}

+ 8 - 0
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -3692,6 +3692,9 @@
 		BB65A0822AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB65A0812AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib */; };
 		BB65A0832AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB65A0812AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib */; };
 		BB65A0842AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB65A0812AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib */; };
+		BB66472B2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB66472A2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift */; };
+		BB66472C2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB66472A2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift */; };
+		BB66472D2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB66472A2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift */; };
 		BB6710612BC672260018CE54 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB67105E2BC672230018CE54 /* KMSignatureWindowController.xib */; };
 		BB6710622BC672260018CE54 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB67105E2BC672230018CE54 /* KMSignatureWindowController.xib */; };
 		BB6710632BC672260018CE54 /* KMSignatureWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB67105E2BC672230018CE54 /* KMSignatureWindowController.xib */; };
@@ -6756,6 +6759,7 @@
 		BB65A07B2AF8E5A4003A27A0 /* KMLineWell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMLineWell.swift; sourceTree = "<group>"; };
 		BB65A07F2AF8FE7A003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBatchOperateRemoveHeaderFooterViewController.swift; sourceTree = "<group>"; };
 		BB65A0812AF8FEA1003A27A0 /* KMBatchOperateRemoveHeaderFooterViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMBatchOperateRemoveHeaderFooterViewController.xib; sourceTree = "<group>"; };
+		BB66472A2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMToolbarConfigTBItemView.swift; sourceTree = "<group>"; };
 		BB67105E2BC672230018CE54 /* KMSignatureWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMSignatureWindowController.xib; sourceTree = "<group>"; };
 		BB67105F2BC672240018CE54 /* KMSignatureWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMSignatureWindowController.h; sourceTree = "<group>"; };
 		BB6710602BC672250018CE54 /* KMSignatureWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMSignatureWindowController.m; sourceTree = "<group>"; };
@@ -12727,6 +12731,7 @@
 				BBD3C8B52B2C438F00EB0867 /* KMToolbarPreviousNextItemView.swift */,
 				BBDE52BA2BF3676C000545B2 /* KMPresentTableViewCell.swift */,
 				BB072D5C2C05AC8F00779B45 /* KMToolbarConfigViewItem.swift */,
+				BB66472A2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift */,
 				BB072D5D2C05AC8F00779B45 /* KMToolbarConfigViewItem.xib */,
 			);
 			path = View;
@@ -16513,6 +16518,7 @@
 				BBB9B32B299A5D6D004F3235 /* GTMOAuth2KeychainCompatibility.m in Sources */,
 				AD3AAD752B0DCEAA00DE5FE7 /* KMCompareSaveView.swift in Sources */,
 				9FAAA32A290BD01D0046FFCE /* KMHomeHistoryFileViewController.swift in Sources */,
+				BB66472B2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */,
 				BB146FB7299DC0D100784A6A /* GTLRRuntimeCommon.m in Sources */,
 				BB3A429E2B4BF03A006D0642 /* KMSystemPDFMenu.swift in Sources */,
 				9FF0D0602B6A5DCF0018A732 /* KMPDFAnnotationTextWidgetSub.swift in Sources */,
@@ -16892,6 +16898,7 @@
 				BB003036298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */,
 				ADDF838A2B391A5D00A81A4E /* DSignatureFileListCellView.swift in Sources */,
 				AD1FE83F2BD7C98300AA4A9B /* KMPageRangeRecordTool.m in Sources */,
+				BB66472C2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */,
 				BB8810BF2B4F872500AFA63E /* KMVerificationWindowController.m in Sources */,
 				ADE614AD29779C5200F62ED7 /* KMImageTitleButton.swift in Sources */,
 				9FF94F0A29A62B5000B1EF69 /* KMDesignSelect.swift in Sources */,
@@ -18915,6 +18922,7 @@
 				9F72D20A2994BDAF00DCACF1 /* KMNotificationVC.swift in Sources */,
 				BB8F456F295AC1220037EA22 /* KMHeaderFooterAdjectiveModel.swift in Sources */,
 				BB3D970C2B2FEAC8007094C8 /* KMPDFRedactViewController.swift in Sources */,
+				BB66472D2C06DD9C00924EE0 /* KMToolbarConfigTBItemView.swift in Sources */,
 				BBB7B48F2A0384E100B58A5A /* NSCollectionViewItem+KMExtension.swift in Sources */,
 				BB146FFE299DC0D100784A6A /* OIDAuthState+Mac.m in Sources */,
 				AD88108F29A760D100178CA1 /* KMRegisterPresenter.swift in Sources */,