Browse Source

【工具栏】自定义工具栏UI补充

tangchao 9 months ago
parent
commit
78fdc70802

+ 63 - 251
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Controller/KMToolbarConfigViewController.swift

@@ -7,14 +7,20 @@
 
 import Cocoa
 
+typealias KMToolbarConfigViewControllerCallback = (NSApplication.ModalResponse) -> Void
 class KMToolbarConfigViewController: NSViewController {
     
     @IBOutlet weak var collectionView: NSCollectionView!
+    @IBOutlet weak var removedCollectionView: NSCollectionView!
+    @IBOutlet weak var cancelButton: NSButton!
+    @IBOutlet weak var confirmButton: NSButton!
     
     private let cellIdentifier_ = NSUserInterfaceItemIdentifier(rawValue: "ToolbarConfigCellIdentifier")
     
     var model = KMToolbarConfigModel()
     
+    var callback: KMToolbarConfigViewControllerCallback?
+    
     deinit {
         Swift.debugPrint("KMToolbarConfigViewController deinit.")
     }
@@ -26,8 +32,8 @@ class KMToolbarConfigViewController: NSViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        self.view.wantsLayer = true
-        self.view.layer?.backgroundColor = NSColor.red.cgColor
+//        self.view.wantsLayer = true
+//        self.view.layer?.backgroundColor = NSColor.red.cgColor
         
         self.initDefalutValue()
     }
@@ -36,252 +42,28 @@ class KMToolbarConfigViewController: NSViewController {
         self.collectionView.delegate = self
         self.collectionView.dataSource = self
         
-//        let layout = NSCollectionViewFlowLayout()
-//        layout.sectionInset = NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
-//        layout.minimumInteritemSpacing = 20
-//        layout.minimumLineSpacing = 30
-//        layout.itemSize = NSSize(width: 60, height: 44)
-//        self.collectionView.collectionViewLayout = layout
-        
         self.collectionView.register(KMToolbarConfigViewItem.self, forItemWithIdentifier: self.cellIdentifier_)
+        (self.collectionView.collectionViewLayout as? NSCollectionViewFlowLayout)?.scrollDirection = .horizontal
+        
+        self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
+        self.cancelButton.target = self
+        self.cancelButton.action = #selector(buttonClick)
+        self.confirmButton.title = NSLocalizedString("Confirm", comment: "")
+        self.confirmButton.target = self
+        self.confirmButton.action = #selector(buttonClick)
     }
     
-    private func _setupMainItem(_ item: KMToolbarItemView?) {
-        let identifier = item?.itemIdentifier
-        if identifier == KMLeftControlToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
-            item?.titleName = NSLocalizedString("Panel", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("View Settings", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMDocumentZoomToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
-            item?.titleName = NSLocalizedString("", comment: "")
-            item?.target = self
-            item?.btnTag = 1
-            item?.toolTip = NSLocalizedString("Zoom In", comment: "")
-            item?.boxImagePosition = .imageAbove
-        } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
-            item?.titleName = NSLocalizedString("", comment: "")
-            item?.target = self
-            item?.btnTag = 0
-            item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
-            item?.boxImagePosition = .imageAbove
-        } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
-            item?.titleName = NSLocalizedString("Zoom", comment: "")
-            item?.target = self
-
-            let view = KMToolbarZoomItemView(zoomView: nil)
-            item?.customizeView = view
-        } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
-            item?.titleName = NSLocalizedString("Next", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
-            item?.boxImagePosition = .imageAbove
-        } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Zoom", comment: "")
-            item?.target = self
-
-            let view = KMToolbarPreviousNextItemView()
-            item?.customizeView = view
-        } else if identifier == KMDocumentHomeToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
-            item?.titleName = NSLocalizedString("Home", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Tools", comment: "")
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
-            item?.target = self
-            item?.toolTip = String(format: "%@: %@, %@, %@, %@",  KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
-            item?.btnTag = KMToolbarViewType.Annatiton.rawValue
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMDocumentPageToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Page Edit", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
-            item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
-            item?.btnTag = KMToolbarViewType.Page.rawValue
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMDocumentConversonToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Converter", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
-            item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
-            item?.btnTag = KMToolbarViewType.Conversion.rawValue
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-
-        } 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?.promptIdentifier = identifier
-        } else if identifier == KMToolbarToolEnhancedScanIdentifier {
-            item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
-            item?.target = self
-            item?.btnTag = 0
-            item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
-            item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
-            item?.boxImagePosition = .imageLeft
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMToolbarToolOCRTextIdentifier {
-            item?.image = NSImage(named: "KMImageNameMainToolOCRText")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
-            item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
-            item?.boxImagePosition = .imageLeft
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-
-        } else if identifier == KMDocumentEditToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Edit PDF", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
-            item?.boxImagePosition = .imageAbove
-            item?.btnTag = KMToolbarViewType.editPDF.rawValue
-            item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-
-        } else if identifier == KMDocumentFormToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Forms", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
-            item?.boxImagePosition = .imageAbove
-            item?.btnTag = KMToolbarViewType.Form.rawValue
-            item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
+    @objc func buttonClick(_ sender: NSButton) {
+        var resp: NSApplication.ModalResponse = .cancel
+        if self.confirmButton.isEqual(to: sender) {
+            resp = .OK
         }
         
-        else if identifier == KMDocumentFillSginToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
-            item?.boxImagePosition = .imageAbove
-            item?.btnTag = KMToolbarViewType.FillSign.rawValue
-            item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentToolToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Editor", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
-            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?.promptIdentifier = identifier
-        } else if identifier == KMDocumentRedactToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Redact Text", comment: "")
-            item?.target = self
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
-            item?.boxImagePosition = .imageAbove
-            item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
-            item?.image = NSImage(named: "ic_function_other_AITranslation")
-            item?.titleName = "AI Translation"
-            item?.target = self
-            item?.toolTip = NSLocalizedString("AI Translation", comment: "")
-            item?.boxImagePosition = .imageOnly
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentPrintToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
-            item?.titleName = "Print"
-            item?.target = self
-            item?.toolTip = NSLocalizedString("Print", comment: "")
-            item?.boxImagePosition = .imageOnly
-        } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
-            item?.titleName = NSLocalizedString("Page Display", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("Page Display", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconAINor")
-            item?.titleName = NSLocalizedString("AI Tools", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("AI Tools", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentShareToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
-            item?.titleName = NSLocalizedString("Share", comment: "")
-            item?.target = self
-//            item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMDocumentSearchToolbarItemIdentifier {
-            item?.titleName = NSLocalizedString("Search", comment: "")
-            item?.target = self
-            let view = NSView()
-            view.frame = NSMakeRect(0, 0, 150, 40)
-            let boxView = NSView()
-            boxView.frame = NSMakeRect(0, 16, 150, 22)
-            view.addSubview(boxView)
-            let searchView = NSSearchField()
-            searchView.frame = NSMakeRect(0, 0, 150, 22)
-            searchView.placeholderString = NSLocalizedString("Search", comment: "")
-            searchView.sendsWholeSearchString = true
-            searchView.sendsSearchStringImmediately = true
-            searchView.drawsBackground = false
-//            searchView.delegate = self
-//            self.searchField = searchView
-
-//            self.refreshSearchBarMenu()
-
-            boxView.addSubview(searchView)
-            let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
-            view.addSubview(titleLabel)
-            titleLabel.frame = NSMakeRect(0, 0, 130, 14)
-            titleLabel.alignment = .center
-            titleLabel.textColor = KMAppearance.subtitleColor()
-            titleLabel.font = KMToolbarMainItemView.textFont
-
-            item?.customizeView = view
-        } else if identifier == KMRightControlToolbarItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
-            item?.titleName = NSLocalizedString("Properties", comment: "")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
-            item?.boxImagePosition = .imageAbove
-            item?.selectBackgroundType = .imageBox
-        } else if identifier == KMToolbarToolRedactItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameMainToolsRedact")
-            item?.target = self
-            item?.btnTag = KMToolbarType.redact.rawValue
-            item?.toolTip = NSLocalizedString("Redact", comment: "")
-            item?.titleName = NSLocalizedString("Redact", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.promptIdentifier = identifier
-        } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
-            item?.image = NSImage(named: "DigitalSign_icon")
-            item?.target = self
-            item?.toolTip = NSLocalizedString("Digital signature ensures the authenticity and integrity of digital files. Click and drag the cursor to create a signature field on the page.", comment: "")
-            item?.titleName = NSLocalizedString("Digital Sign", comment: "")
-            item?.selectBackgroundType = .imageBox
-            item?.boxImagePosition = .imageAbove
-            item?.promptIdentifier = identifier
+        guard let block = self.callback else {
+            return
         }
+        block(resp)
     }
-    
 }
 
 extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
@@ -290,15 +72,31 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
     }
     
     func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
-        return self.model.cellIdentifiers?.count ?? 0
+        if let cnt = self.model.allowedCellIdentifiers?.count {
+            return cnt + 2
+        }
+        return 0
     }
     
     func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
         let cell = collectionView.makeItem(withIdentifier: self.cellIdentifier_, for: indexPath) as! KMToolbarConfigViewItem
-        let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
-        let item = KMToolbarItemView(itemIdentifier: itemId)
-        self._setupMainItem(item)
-        cell.itemView = item
+        if indexPath.item == self.model.leftCount {
+            cell.itemView = nil
+        } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
+            cell.itemView = nil
+        } else {
+            var idx = indexPath.item
+            if idx > (self.model.leftCount + self.model.centerCount) {
+                idx = idx - 2
+            } else if idx > self.model.leftCount {
+                idx = idx - 1
+            }
+            
+            let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
+            let item = KMToolbarItemView(itemIdentifier: itemId)
+            self.model.setupMainItem(item)
+            cell.itemView = item
+        }
         
         return cell
     }
@@ -306,22 +104,36 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
     // Layout
     
     func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
-        let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
+        if indexPath.item == self.model.leftCount {
+            return NSSize(width: self.model.segItemWidth, height: 48)
+        } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
+            return NSSize(width: self.model.segItemWidth, height: 48)
+        }
+        
+        var idx = indexPath.item
+        if idx > (self.model.leftCount + self.model.centerCount) {
+            idx = idx - 2
+        } else if idx > self.model.leftCount {
+            idx = idx - 1
+        }
+        let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
         let item = KMToolbarItemView(itemIdentifier: itemId)
-        self._setupMainItem(item)
+        self.model.setupMainItem(item)
         return NSSize(width: item.itemWidth, height: 48)
     }
     
+    // 纵向间距
     func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
-        return 100
+        return 5
     }
     
+    // 横向间距
     func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
-        return 20
+        return 5
     }
     
     func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
-        return .init(top: 10, left: 20, bottom: 5, right: 40)
+        return .init(top: 6, left: 10, bottom: 6, right: 10)
     }
     
     

+ 62 - 7
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Controller/KMToolbarConfigViewController.xib

@@ -8,24 +8,27 @@
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="KMToolbarConfigViewController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
+                <outlet property="cancelButton" destination="Jrq-XK-HyQ" id="a5v-rh-B8T"/>
                 <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="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="1400" height="400"/>
+            <rect key="frame" x="0.0" y="0.0" width="1480" height="280"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <scrollView wantsLayer="YES" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pVa-qa-L5j">
-                    <rect key="frame" x="0.0" y="320" width="1400" height="60"/>
+                <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="1398" height="58"/>
+                        <rect key="frame" x="1" y="1" width="1478" height="58"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <collectionView id="C4M-vA-SRV">
-                                <rect key="frame" x="0.0" y="0.0" width="1398" height="158"/>
+                                <rect key="frame" x="0.0" y="0.0" width="1478" height="58"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="Ut1-FD-oCR">
                                     <size key="itemSize" width="50" height="50"/>
@@ -38,19 +41,71 @@
                         <constraint firstAttribute="height" constant="60" 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"/>
+                        <autoresizingMask key="autoresizingMask"/>
+                    </scroller>
+                    <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="vbr-Re-CHy">
+                        <rect key="frame" x="1463" y="1" width="16" height="58"/>
+                        <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"/>
+                    <clipView key="contentView" id="rRg-x2-XJs">
+                        <rect key="frame" x="1" y="1" width="1478" height="58"/>
+                        <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"/>
+                                <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
+                                <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="QkZ-GP-Y7n">
+                                    <size key="itemSize" width="50" height="50"/>
+                                </collectionViewFlowLayout>
+                                <color key="primaryBackgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
+                            </collectionView>
+                        </subviews>
+                    </clipView>
+                    <constraints>
+                        <constraint firstAttribute="height" constant="60" 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"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
-                    <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="vbr-Re-CHy">
-                        <rect key="frame" x="1383" y="1" width="16" height="58"/>
+                    <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="pNf-CQ-3JS">
+                        <rect key="frame" x="1463" y="1" width="16" height="58"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
                 </scrollView>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Jrq-XK-HyQ">
+                    <rect key="frame" x="1282" y="19" width="75" height="32"/>
+                    <buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sML-0i-cGp">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5tz-eV-Ytt">
+                    <rect key="frame" x="1372" y="19" width="75" height="32"/>
+                    <buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="9Xw-Po-Hxe">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                        <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
+                    </buttonCell>
+                </button>
             </subviews>
             <constraints>
+                <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="y3L-cT-yu5" firstAttribute="top" secondItem="pVa-qa-L5j" secondAttribute="bottom" constant="40" id="QCF-ho-vh9"/>
+                <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="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>

+ 7 - 5
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarView.swift

@@ -133,11 +133,13 @@ private let KMToolbarItemSpace = 8.0
         if self.configWindowC_ == nil {
             self.configWindowC_ = KMToolbarConfigWindowController()
         }
-        
-        var cellIdentifiers: [String] = self.delegate?.toolbarLeftDefaultItemIdentifiers?(self) ?? []
-        cellIdentifiers += (self.delegate?.toolbarDefaultItemIdentifiers?(self) ?? [])
-        cellIdentifiers += (self.delegate?.toolbarRightDefaultItemIdentifiers?(self) ?? [])
-        self.configWindowC_?.cellIdentifiers = cellIdentifiers
+        var leftCellIdentifiers = self.delegate?.toolbarLeftDefaultItemIdentifiers?(self) ?? []
+        if leftCellIdentifiers.contains(KMDocumentHomeToolbarItemIdentifier) {
+            leftCellIdentifiers.removeObject(KMDocumentHomeToolbarItemIdentifier)
+        }
+        self.configWindowC_?.leftCellIdentifiers = leftCellIdentifiers
+        self.configWindowC_?.centerCellIdentifiers = (self.delegate?.toolbarDefaultItemIdentifiers?(self) ?? [])
+        self.configWindowC_?.rightCellIdentifiers = (self.delegate?.toolbarRightDefaultItemIdentifiers?(self) ?? [])
         self.window?.beginSheet((self.configWindowC_?.window)!, completionHandler: { [weak self] resp in
             self?.configWindowC_ = nil
         })

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

@@ -8,7 +8,339 @@
 import Cocoa
 
 class KMToolbarConfigModel: NSObject {
+    var leftCellIdentifiers: [String]? {
+        didSet {
+            let ids = self.leftCellIdentifiers ?? []
+            
+            self.leftWidth = 0
+            if ids.isEmpty == false {
+                self.leftWidth += self.leftMargin + 5
+            }
+            
+            for itemId in ids {
+                let item = KMToolbarItemView(itemIdentifier: itemId)
+                self.setupMainItem(item)
+                self.leftWidth += (item.itemWidth + 5)
+            }
+        }
+    }
     
-    var cellIdentifiers: [String]?
+    var leftCount: Int {
+        get {
+            return self.leftCellIdentifiers?.count ?? 0
+        }
+    }
+    
+    var centerCellIdentifiers: [String]? {
+        didSet {
+            let ids = self.centerCellIdentifiers ?? []
+            
+            self.centerWidth = 0
+            for itemId in ids {
+                let item = KMToolbarItemView(itemIdentifier: itemId)
+                self.setupMainItem(item)
+                self.centerWidth += (item.itemWidth + 5)
+            }
+        }
+    }
+    
+    var centerCount: Int {
+        get {
+            return self.centerCellIdentifiers?.count ?? 0
+        }
+    }
+    
+    var rightCellIdentifiers: [String]? {
+        didSet {
+            let ids = self.rightCellIdentifiers ?? []
+            
+            self.rightWidth = 0
+            if ids.isEmpty == false {
+                self.rightWidth += self.rightMargin + 5
+            }
+            for itemId in ids {
+                let item = KMToolbarItemView(itemIdentifier: itemId)
+                self.setupMainItem(item)
+                self.rightWidth += (item.itemWidth + 5)
+            }
+        }
+    }
+    
+    var rightCount: Int {
+        get {
+            return self.rightCellIdentifiers?.count ?? 0
+        }
+    }
+    
+    var defaultCellIdentifiers: [String]?
+    var allowedCellIdentifiers: [String]? {
+        get {
+            let left = self.leftCellIdentifiers ?? []
+            let center = self.centerCellIdentifiers ?? []
+            let right = self.rightCellIdentifiers ?? []
+            return left + center + right
+        }
+    }
+    
+    var leftWidth: CGFloat = 0
+    var centerWidth: CGFloat = 0
+    var rightWidth: CGFloat = 0
+    
+    var leftMargin: CGFloat = 10
+    var rightMargin: CGFloat = 10
 
+    var itemH: CGFloat = 48
+    
+    var contentWidth: CGFloat {
+        get {
+            return self.leftWidth + self.centerWidth + self.rightWidth
+        }
+    }
+    
+    var windowWidth: CGFloat = 1480
+    
+    var segItemWidth: CGFloat {
+        get {
+            return (self.windowWidth - self.contentWidth) * 0.5
+        }
+    }
+}
+
+extension KMToolbarConfigModel {
+    func setupMainItem(_ item: KMToolbarItemView?) {
+        let identifier = item?.itemIdentifier
+        if identifier == KMLeftControlToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
+            item?.titleName = NSLocalizedString("Panel", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("View Settings", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMDocumentZoomToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
+            item?.titleName = NSLocalizedString("", comment: "")
+            item?.target = self
+            item?.btnTag = 1
+            item?.toolTip = NSLocalizedString("Zoom In", comment: "")
+            item?.boxImagePosition = .imageAbove
+        } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
+            item?.titleName = NSLocalizedString("", comment: "")
+            item?.target = self
+            item?.btnTag = 0
+            item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
+            item?.boxImagePosition = .imageAbove
+        } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
+            item?.titleName = NSLocalizedString("Zoom", comment: "")
+            item?.target = self
+
+            let view = KMToolbarZoomItemView(zoomView: nil)
+            item?.customizeView = view
+        } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
+            item?.titleName = NSLocalizedString("Next", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
+            item?.boxImagePosition = .imageAbove
+        } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Zoom", comment: "")
+            item?.target = self
+
+            let view = KMToolbarPreviousNextItemView()
+            item?.customizeView = view
+        } else if identifier == KMDocumentHomeToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
+            item?.titleName = NSLocalizedString("Home", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Tools", comment: "")
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
+            item?.target = self
+            item?.toolTip = String(format: "%@: %@, %@, %@, %@",  KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
+            item?.btnTag = KMToolbarViewType.Annatiton.rawValue
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMDocumentPageToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Page Edit", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
+            item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
+            item?.btnTag = KMToolbarViewType.Page.rawValue
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMDocumentConversonToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Converter", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
+            item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
+            item?.btnTag = KMToolbarViewType.Conversion.rawValue
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+
+        } 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?.promptIdentifier = identifier
+        } else if identifier == KMToolbarToolEnhancedScanIdentifier {
+            item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
+            item?.target = self
+            item?.btnTag = 0
+            item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
+            item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
+            item?.boxImagePosition = .imageLeft
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMToolbarToolOCRTextIdentifier {
+            item?.image = NSImage(named: "KMImageNameMainToolOCRText")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
+            item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
+            item?.boxImagePosition = .imageLeft
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+
+        } else if identifier == KMDocumentEditToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Edit PDF", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
+            item?.boxImagePosition = .imageAbove
+            item?.btnTag = KMToolbarViewType.editPDF.rawValue
+            item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+
+        } else if identifier == KMDocumentFormToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Forms", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
+            item?.boxImagePosition = .imageAbove
+            item?.btnTag = KMToolbarViewType.Form.rawValue
+            item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        }
+        
+        else if identifier == KMDocumentFillSginToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
+            item?.boxImagePosition = .imageAbove
+            item?.btnTag = KMToolbarViewType.FillSign.rawValue
+            item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentToolToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Editor", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
+            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?.promptIdentifier = identifier
+        } else if identifier == KMDocumentRedactToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Redact Text", comment: "")
+            item?.target = self
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
+            item?.boxImagePosition = .imageAbove
+            item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
+            item?.image = NSImage(named: "ic_function_other_AITranslation")
+            item?.titleName = "AI Translation"
+            item?.target = self
+            item?.toolTip = NSLocalizedString("AI Translation", comment: "")
+            item?.boxImagePosition = .imageOnly
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentPrintToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
+            item?.titleName = "Print"
+            item?.target = self
+            item?.toolTip = NSLocalizedString("Print", comment: "")
+            item?.boxImagePosition = .imageOnly
+        } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
+            item?.titleName = NSLocalizedString("Page Display", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("Page Display", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconAINor")
+            item?.titleName = NSLocalizedString("AI Tools", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("AI Tools", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentShareToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
+            item?.titleName = NSLocalizedString("Share", comment: "")
+            item?.target = self
+//            item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMDocumentSearchToolbarItemIdentifier {
+            item?.titleName = NSLocalizedString("Search", comment: "")
+            item?.target = self
+            let view = NSView()
+            view.frame = NSMakeRect(0, 0, 150, 40)
+            let boxView = NSView()
+            boxView.frame = NSMakeRect(0, 16, 150, 22)
+            view.addSubview(boxView)
+            let searchView = NSSearchField()
+            searchView.frame = NSMakeRect(0, 0, 150, 22)
+            searchView.placeholderString = NSLocalizedString("Search", comment: "")
+            searchView.sendsWholeSearchString = true
+            searchView.sendsSearchStringImmediately = true
+            searchView.drawsBackground = false
+//            searchView.delegate = self
+//            self.searchField = searchView
+
+//            self.refreshSearchBarMenu()
+
+            boxView.addSubview(searchView)
+            let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
+            view.addSubview(titleLabel)
+            titleLabel.frame = NSMakeRect(0, 0, 130, 14)
+            titleLabel.alignment = .center
+            titleLabel.textColor = KMAppearance.subtitleColor()
+            titleLabel.font = KMToolbarMainItemView.textFont
+
+            item?.customizeView = view
+        } else if identifier == KMRightControlToolbarItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
+            item?.titleName = NSLocalizedString("Properties", comment: "")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
+            item?.boxImagePosition = .imageAbove
+            item?.selectBackgroundType = .imageBox
+        } else if identifier == KMToolbarToolRedactItemIdentifier {
+            item?.image = NSImage(named: "KMImageNameMainToolsRedact")
+            item?.target = self
+            item?.btnTag = KMToolbarType.redact.rawValue
+            item?.toolTip = NSLocalizedString("Redact", comment: "")
+            item?.titleName = NSLocalizedString("Redact", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.promptIdentifier = identifier
+        } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
+            item?.image = NSImage(named: "DigitalSign_icon")
+            item?.target = self
+            item?.toolTip = NSLocalizedString("Digital signature ensures the authenticity and integrity of digital files. Click and drag the cursor to create a signature field on the page.", comment: "")
+            item?.titleName = NSLocalizedString("Digital Sign", comment: "")
+            item?.selectBackgroundType = .imageBox
+            item?.boxImagePosition = .imageAbove
+            item?.promptIdentifier = identifier
+        }
+    }
+    
 }

+ 22 - 7
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/Window/KMToolbarConfigWindowController.swift

@@ -12,9 +12,25 @@ class KMToolbarConfigWindowController: NSWindowController {
         KMPrint("KMToolbarConfigWindowController deinit.")
     }
     
-    var cellIdentifiers: [String]? {
+    var leftCellIdentifiers: [String]? {
         didSet {
-            self.viewC_.model.cellIdentifiers = self.cellIdentifiers
+            self.viewC_.model.leftCellIdentifiers = self.leftCellIdentifiers
+        }
+    }
+    var centerCellIdentifiers: [String]? {
+        didSet {
+            self.viewC_.model.centerCellIdentifiers = self.centerCellIdentifiers
+        }
+    }
+    var rightCellIdentifiers: [String]? {
+        didSet {
+            self.viewC_.model.rightCellIdentifiers = self.rightCellIdentifiers
+        }
+    }
+    
+    var defaultCellIdentifiers: [String]? {
+        didSet {
+            self.viewC_.model.defaultCellIdentifiers = self.defaultCellIdentifiers
         }
     }
     
@@ -29,10 +45,9 @@ class KMToolbarConfigWindowController: NSWindowController {
         
         self.window?.styleMask.insert(.fullSizeContentView)
         self.window?.contentViewController = self.viewC_
+        
+        self.viewC_.callback = { [unowned self] resp in
+            self.window?.sheetParent?.endSheet(self.window!, returnCode: resp)
+        }
     }
-    
-    override func mouseDown(with event: NSEvent) {
-        self.window?.sheetParent?.endSheet(self.window!, returnCode: .cancel)
-    }
-    
 }