Selaa lähdekoodia

Merge branch 'develop_2025' of git.kdan.cc:Mac_PDF/PDF_Office into develop_2025

niehaoyu 4 kuukautta sitten
vanhempi
commit
6ab194a6d5

+ 196 - 22
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNPDFInsert/KMNPDFInsertBlankWindowController.swift

@@ -44,12 +44,15 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
     @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
     
     private var orgDocument:CPDFDocument?
-    private var orgPageIndex:Int = 0
-        
-    convenience init(_ document: CPDFDocument?, currentPageIndex: Int) {
+    private var selectionIndexPaths:Set<IndexPath>?
+    private var lastUnitString: String = "mm"
+
+    var callback: ((CGSize, Int) -> Void)?
+
+    convenience init(_ document: CPDFDocument?, selectionIndexPaths: Set<IndexPath>?) {
         self.init(windowNibName: "KMNPDFInsertBlankWindowController")
         orgDocument = document
-        orgPageIndex = currentPageIndex
+        self.selectionIndexPaths = selectionIndexPaths
     }
 
     convenience init(_ filePath: String,password:String?) {
@@ -78,7 +81,7 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
     
     private func setUpUnitSelctProperty() {
         var menuItemArr: [ComponentMenuitemProperty] = []
-        for language in [KMLocalizedString("mm"),KMLocalizedString("cn"),KMLocalizedString("in")] {
+        for language in ["mm","cm","in"] {
             let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
                                                                                     itemSelected: false,
                                                                                     isDisabled: false,
@@ -126,11 +129,23 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
         positionLabel.stringValue = KMLocalizedString("Where to insert?")
         positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
         positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
+        var currentPageDex = 0
         
-        let page = self.orgDocument?.page(at: UInt(orgPageIndex)) as? CPDFPage
+        if(selectionIndexPaths?.count ?? 0 > 0) {
+            pageRadioButton.properties.checkboxType = .selected
+            
+            let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
+            currentPageDex = maxmumIndexPath?.item ?? 0
+        }
+        let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
         let rect = page?.bounds ?? CGRectZero
-        let width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
-        let height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
+        var width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
+        var height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
+
+        if((page?.rotation ?? 0) % 180 != 0) {
+            width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/595 * 210))
+            height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/842 * 297))
+        }
 
         currentRadioButton.properties = ComponentCheckBoxProperty(size: .s,
                                                                 state: .normal,
@@ -177,17 +192,17 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
                                                                 isDisabled: false,
                                                                 showhelp: false,
                                                                 text: KMLocalizedString("Landscape pages"),
-                                                                checkboxType: .selected)
+                                                                checkboxType: .normal)
         horizontalRadioButton.properties = ComponentCheckBoxProperty(size: .s,
                                                                 state: .normal,
                                                                 isDisabled: false,
                                                                 showhelp: false,
                                                                 text: KMLocalizedString("Portrait pages"),
-                                                                checkboxType: .normal)
+                                                                checkboxType: .selected)
         
         unitSelect.properties = ComponentSelectProperties(size: .s,
                                                                 state: .normal,
-                                                                isDisabled: false,
+                                                                isDisabled: true,
                                                                 isError: false,
                                                                 leftIcon: false,
                                                                 placeholder: nil,
@@ -198,7 +213,7 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
         
         standardSelect.properties = ComponentSelectProperties(size: .s,
                                                                 state: .normal,
-                                                                isDisabled: false,
+                                                                isDisabled: true,
                                                                 isError: false,
                                                                 leftIcon: false,
                                                                 placeholder: nil,
@@ -263,10 +278,11 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
                                                                            showPrefix: false,
                                                                            showSuffix: false,
                                                                            showClear: false,
-                                                                           isDisabled: false,
+                                                                           isDisabled: true,
                                                                            placeholder: "210",
                                                                            text: "210")
         widthInput.properties = inputWidthProperty
+        widthInput.delegate = self
         
         let inputHeightProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
                                                                            state:.pressed ,
@@ -274,11 +290,12 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
                                                                            showPrefix: false,
                                                                            showSuffix: false,
                                                                            showClear: false,
-                                                                           isDisabled: false,
+                                                                           isDisabled: true,
                                                                            placeholder: "297",
                                                                            text: "297")
         heightInput.properties = inputHeightProperty
-                
+        heightInput.delegate = self
+        
         pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
         
         setUpPositionSelctProperty()
@@ -301,14 +318,30 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
         positionSelect.selectItemAtIndex(0)
         unitSelect.selectItemAtIndex(0)
         standardSelect.selectItemAtIndex(1)
-
-        pageRadioButton.properties.checkboxType = .selected
-        pageRadioButton.reloadData()
-        
-        pageNumInput.properties.text = String((orgPageIndex+1))
-        pageNumInput.reloadData()
+                
+        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
         
-        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)        
+        if(selectionIndexPaths?.count ?? 0 > 0) {
+            pageRadioButton.properties.checkboxType = .selected
+
+            let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
+            pageNumInput.properties.text = String((maxmumIndexPath?.item ?? 0)+1)
+            
+            pageRadioButton.reloadData()
+            pageNumInput.reloadData()
+        } else {
+            firstRadioButton.properties.checkboxType = .selected
+            pageRadioButton.properties.checkboxType = .normal
+            
+            positionSelect.properties.isDisabled = true
+            pageNumInput.properties.isDisabled = true
+            
+            firstRadioButton.reloadData()
+            pageRadioButton.reloadData()
+            pageNumInput.reloadData()
+            positionSelect.reloadData()
+        }
+
     }
     
     //MARK: - Action
@@ -317,6 +350,85 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
     }
     
     @objc func insertButtonClicked(_ sender: NSView) {
+        self.window?.makeFirstResponder(nil)
+        var currentPageDex = 0
+        if(selectionIndexPaths?.count ?? 0 > 0) {
+            pageRadioButton.properties.checkboxType = .selected
+            
+            let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
+            currentPageDex = maxmumIndexPath?.item ?? 0
+        }
+        
+        var height: CGFloat = 0
+        var width: CGFloat = 0
+        if currentRadioButton.properties.checkboxType == .selected {
+            let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
+            let rect = page?.bounds ?? .zero
+            width = rect.size.width
+            height = rect.size.height
+            
+            let w = KMPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
+            let h = KMPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
+
+            width = w.stringToCGFloat()
+            height = h.stringToCGFloat()
+
+            if((page?.rotation ?? 0) % 180 != 0) {
+                width = h.stringToCGFloat()
+                height = w.stringToCGFloat()
+            }
+        } else if standardRadioButton.properties.checkboxType == .selected {
+            let sizeString = standardSelect.properties.text ?? KMNPaperSizeNameA4
+            let tSize = KMPageSizeTool.getPaperSize(paperName: sizeString)
+            width = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.width).stringToCGFloat()
+            height = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.height).stringToCGFloat()
+
+        } else if customizationRadioButton.properties.checkboxType == .selected {
+            let unitString = unitSelect.properties.text ?? "mm"
+            height = widthInput.properties.text.stringToCGFloat()
+            width = heightInput.properties.text.stringToCGFloat()
+            
+            width = KMPageSizeTool.conversion(with: "mm", from: unitString, value: width).stringToCGFloat()
+            height = KMPageSizeTool.conversion(with: "mm", from: unitString, value: height).stringToCGFloat()
+
+            if(!(width > 0 && height > 0)) {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = KMLocalizedString("Please enter the correct size.")
+                alert.runModal()
+                return
+            }
+        }
+        
+        width *= 595 / 210
+        height *= 842 / 297
+
+        var insertSize = CGSize(width: width, height: height)
+        if(verticalRadioButton.properties.checkboxType == .selected) {
+            if(width < height) {
+                insertSize = CGSize(width: height, height: width)
+            }
+        } else if(horizontalRadioButton.properties.checkboxType == .selected){
+            if(width > height) {
+                insertSize = CGSize(width: height, height: width)
+            }
+        }
+        
+        var insetPageDex:Int = 0
+        if firstRadioButton.properties.checkboxType == .selected {
+            insetPageDex = 0
+        } else if lastRadioButton.properties.checkboxType == .selected {
+            insetPageDex = Int(orgDocument?.pageCount ?? 0)
+        } else if pageRadioButton.properties.checkboxType == .selected {
+            insetPageDex = Int(pageNumInput.properties.text ?? "0") ?? 0
+            let positionSelectIndex = positionSelect.indexOfSelect()
+            if (1 == positionSelectIndex) {
+                insetPageDex -= 1
+            }
+        }
+        
+        callback?(insertSize, insetPageDex)
+        
         own_closeEndSheet()
     }
     
@@ -379,6 +491,29 @@ class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
             oldSelectRadioBtn?.properties.checkboxType = .normal
             oldSelectRadioBtn?.reloadData()
         }
+        
+        let widthString = widthInput.properties.text
+        let heightString = heightInput.properties.text
+
+        var width = widthString.stringToCGFloat()
+        var height = heightString.stringToCGFloat()
+       
+        if(verticalRadioButton.properties.checkboxType == .selected) {
+            if(width < height) {
+                widthInput.properties.text = heightString
+                heightInput.properties.text = widthString
+                widthInput.reloadData()
+                heightInput.reloadData()
+            }
+        } else if(horizontalRadioButton.properties.checkboxType == .selected){
+            if(width > height) {
+                widthInput.properties.text = heightString
+                heightInput.properties.text = widthString
+                widthInput.reloadData()
+                heightInput.reloadData()
+            }
+            
+        }
     }
 
     @objc func insertPageSizeAction(_ sender: NSView) {
@@ -450,7 +585,14 @@ extension KMNPDFInsertBlankWindowController: ComponentInputNumberDelegate {
 extension KMNPDFInsertBlankWindowController: ComponentSelectDelegate {
     func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
         if(view == unitSelect) {
+            let width = widthInput.properties.text.stringToCGFloat()
+            let height = heightInput.properties.text.stringToCGFloat()
+            widthInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: width)
+            heightInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: height)
             
+            lastUnitString = unitSelect.properties.text ?? "mm"
+            widthInput.reloadData()
+            heightInput.reloadData()
         } else if (view == standardSelect) {
             
         } else if (view == positionSelect) {
@@ -458,4 +600,36 @@ extension KMNPDFInsertBlankWindowController: ComponentSelectDelegate {
         }
 
     }
+    
+}
+
+extension KMNPDFInsertBlankWindowController: ComponentInputDelegate {
+   
+    //文字变化
+    func componentInputDidChanged(inputView: ComponentInput) {
+         if (inputView == widthInput) {
+             let fValue = widthInput.properties.text.stringToCGFloat()
+             if fValue > heightInput.properties.text.stringToCGFloat() {
+                 verticalRadioButton.properties.checkboxType = .selected
+                 horizontalRadioButton.properties.checkboxType = .normal
+            } else {
+                verticalRadioButton.properties.checkboxType = .normal
+                horizontalRadioButton.properties.checkboxType = .selected
+            }
+             verticalRadioButton.reloadData()
+             horizontalRadioButton.reloadData()
+        } else if (inputView == heightInput) {
+            let fValue = heightInput.properties.text.stringToCGFloat()
+            if fValue > widthInput.properties.text.stringToCGFloat() {
+                verticalRadioButton.properties.checkboxType = .normal
+                horizontalRadioButton.properties.checkboxType = .selected
+            } else {
+                verticalRadioButton.properties.checkboxType = .selected
+                horizontalRadioButton.properties.checkboxType = .normal
+            }
+            verticalRadioButton.reloadData()
+            horizontalRadioButton.reloadData()
+
+        }
+    }
 }

+ 0 - 195
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNPDFInsert/KMNPDFInsertClipboardWindowController.swift

@@ -1,195 +0,0 @@
-//
-//  KMNPDFInsertClipboardWindowController.swift
-//  PDF Reader Pro
-//
-//  Created by 丁林圭 on 2024/10/23.
-//
-
-import Cocoa
-
-import KMComponentLibrary
-
-class KMNPDFInsertClipboardWindowController: KMNBaseWindowController {
-    private var orgDocument:CPDFDocument?
-    private var orgPageIndex:Int = 0
-    
-    @IBOutlet var titleLabel: NSTextField!
-
-    @IBOutlet var positionLabel: NSTextField!
-    @IBOutlet var firstRadioButton: ComponentRadio!
-    @IBOutlet var lastRadioButton: ComponentRadio!
-    @IBOutlet var pageRadioButton: ComponentRadio!
-    @IBOutlet var pageNumInput: ComponentInputNumber!
-    @IBOutlet var pageCountLabel: NSTextField!
-    @IBOutlet var positionSelect: ComponentSelect!
-
-    @IBOutlet var cancelButton: ComponentButton!
-    @IBOutlet var insertButton: ComponentButton!
-
-    @IBOutlet var cancelWidthButton:NSLayoutConstraint!
-    @IBOutlet var insertWidthButton:NSLayoutConstraint!
-    @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
-
-    convenience init(_ document: CPDFDocument?, currentPageIndex: Int) {
-        self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
-        orgDocument = document
-        orgPageIndex = currentPageIndex
-    }
-
-    convenience init(_ filePath: String,password:String?) {
-        self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
-        let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
-        if password != nil {
-            document?.unlock(withPassword: password as String?)
-        }
-
-        orgDocument = document
-    }
-
-    override func windowDidLoad() {
-        super.windowDidLoad()
-
-        setUpProperty()
-        positionSelect.selectItemAtIndex(0)
-        
-        pageRadioButton.properties.checkboxType = .selected
-        pageRadioButton.reloadData()
-        
-        pageNumInput.properties.text = String((orgPageIndex+1))
-        pageNumInput.reloadData()
-        
-        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
-    }
-    
-    private func setUpPositionSelctProperty() {
-        positionSelect.properties = ComponentSelectProperties(size: .s,
-                                                                state: .normal,
-                                                                isDisabled: false,
-                                                                isError: false,
-                                                                leftIcon: false,
-                                                                placeholder: nil,
-                                                                errorText: nil,
-                                                                creatable: false,
-                                                                text: KMLocalizedString("After", comment: ""))
-        
-        var menuItemArr: [ComponentMenuitemProperty] = []
-        for language in [KMLocalizedString("After"),KMLocalizedString("Before")] {
-            let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
-                                                                                    itemSelected: false,
-                                                                                    isDisabled: false,
-                                                                                    keyEquivalent: nil,
-                                                                                    text: language)
-            menuItemArr.append(itemProperty)
-        }
-        
-        positionSelect.updateMenuItemsArr(menuItemArr)
-        positionSelect.delegate = self
-    }
-    
-    private func setUpProperty() {
-        titleLabel.stringValue = KMLocalizedString("From Clipboard")
-        titleLabel.font =  ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
-        titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
-        
-        positionLabel.stringValue = KMLocalizedString("Where to insert?")
-        positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
-        positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
-        
-        insertButton.properties = ComponentButtonProperty(type: .primary,
-                                                          size: .s,
-                                                          state: .normal,
-                                                          buttonText: KMLocalizedString("Insert"))
-        insertButton.setTarget(self, action: #selector(insertButtonClicked(_ :)))
-        insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
-        
-        cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
-                                                          size: .s,
-                                                          state: .normal,
-                                                          buttonText: KMLocalizedString("Cancel"))
-        cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
-        cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
-        
-        firstRadioButton.properties = ComponentCheckBoxProperty(size: .s,
-                                                                state: .normal,
-                                                                isDisabled: false,
-                                                                showhelp: false,
-                                                                text: KMLocalizedString("First"),
-                                                                checkboxType: .normal)
-        lastRadioButton.properties = ComponentCheckBoxProperty(size: .s,
-                                                                state: .normal,
-                                                                isDisabled: false,
-                                                                showhelp: false,
-                                                                text: KMLocalizedString("Last"),
-                                                                checkboxType: .normal)
-        
-        pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
-                                                                state: .normal,
-                                                                isDisabled: false,
-                                                                showhelp: false,
-                                                                text: KMLocalizedString("Page"),
-                                                                checkboxType: .normal)
-
-        
-        firstRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
-        lastRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
-        pageRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
-
-        pageNumInput.properties = ComponentInputNumberProperty(alignment: .left,
-                                                                          size: .s,
-                                                                          state: .normal,
-                                                                          isError: false,
-                                                                          showErrorInfo: false,
-                                                                          isDisabled: true,
-                                                                          showPrefix: false,
-                                                                          showSuffix: false,
-                                                                          minSize: 1,
-                                                                          maxSize: Int(orgDocument?.pageCount ?? 1),
-                                                                          text: SettingsManager.sharedInstance.autoSaveMinutes)
-        pageNumInput.inputNumberDelegate = self
-                
-        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
-        
-        setUpPositionSelctProperty()
-        
-        pageRadioWidthButton.constant = pageRadioButton.properties.propertyInfo.viewWidth
-        cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
-        insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
-  }
-    
-    //MARK: - Action
-    @objc func cancelButtonClicked(_ sender: NSView) {
-        own_closeEndSheet()
-    }
-    
-    @objc func insertButtonClicked(_ sender: NSView) {
-        own_closeEndSheet()
-    }
-    
-    @objc func insertPositionAction(_ sender: NSView) {
-        if sender == lastRadioButton {
-            
-        } else if sender == firstRadioButton {
-            
-        } else if sender == pageRadioButton {
-            
-        }
-    }
-
-}
-
-extension KMNPDFInsertClipboardWindowController: ComponentInputNumberDelegate {
-    func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
-        if(inputNumber == pageNumInput) {
-            
-        }
-    }
-}
-
-extension KMNPDFInsertClipboardWindowController: ComponentSelectDelegate {
-    func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
-        if(view == positionSelect) {
-            
-        }
-
-    }
-}

+ 0 - 192
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNPDFInsert/KMNPDFInsertClipboardWindowController.xib

@@ -1,192 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
-    <dependencies>
-        <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
-        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
-    </dependencies>
-    <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMNPDFInsertClipboardWindowController" customModule="PDF_Reader_Pro" customModuleProvider="target">
-            <connections>
-                <outlet property="cancelButton" destination="kbx-r8-FfZ" id="Lzz-Ot-edh"/>
-                <outlet property="cancelWidthButton" destination="eaf-lr-qUJ" id="jJy-G2-ohK"/>
-                <outlet property="firstRadioButton" destination="Jpf-4m-uhA" id="C9Q-fB-e3U"/>
-                <outlet property="insertButton" destination="jUu-dJ-JTK" id="vZs-SZ-1bb"/>
-                <outlet property="insertWidthButton" destination="XWY-SY-DFJ" id="2b7-NS-UcI"/>
-                <outlet property="lastRadioButton" destination="5GE-Zd-UxG" id="DUI-xT-8F8"/>
-                <outlet property="pageCountLabel" destination="0y2-gu-PB5" id="ceY-MI-1Bh"/>
-                <outlet property="pageNumInput" destination="bXL-VD-0g6" id="MLw-wS-kgk"/>
-                <outlet property="pageRadioButton" destination="WI9-2y-RIs" id="Kmp-Ek-ew7"/>
-                <outlet property="pageRadioWidthButton" destination="pmZ-Lm-erY" id="E7q-CM-Vec"/>
-                <outlet property="positionLabel" destination="vvh-mZ-hZZ" id="k7b-J9-M23"/>
-                <outlet property="positionSelect" destination="Fr6-uf-h6g" id="Dc3-t4-yT3"/>
-                <outlet property="titleLabel" destination="AiR-qt-ZiL" id="M9B-wM-5Jq"/>
-                <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
-            </connections>
-        </customObject>
-        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
-        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
-        <window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="F0z-JX-Cv5">
-            <windowStyleMask key="styleMask" titled="YES" fullSizeContentView="YES"/>
-            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
-            <rect key="contentRect" x="196" y="240" width="480" height="270"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="1512" height="944"/>
-            <view key="contentView" id="se5-gp-TjO">
-                <rect key="frame" x="0.0" y="0.0" width="480" height="248"/>
-                <autoresizingMask key="autoresizingMask"/>
-                <subviews>
-                    <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="o8W-OS-QlF">
-                        <rect key="frame" x="24" y="16" width="432" height="216"/>
-                        <view key="contentView" id="VBw-Jy-eh0">
-                            <rect key="frame" x="0.0" y="0.0" width="432" height="216"/>
-                            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                            <subviews>
-                                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AiR-qt-ZiL">
-                                    <rect key="frame" x="-2" y="200" width="436" height="16"/>
-                                    <textFieldCell key="cell" lineBreakMode="clipping" title="Insert from Clipboard" id="XkL-Nc-SHI">
-                                        <font key="font" usesAppearanceFont="YES"/>
-                                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                    </textFieldCell>
-                                </textField>
-                                <box boxType="custom" borderWidth="0.0" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="CRF-nS-iRX">
-                                    <rect key="frame" x="0.0" y="0.0" width="432" height="32"/>
-                                    <view key="contentView" id="VsO-t6-lE6">
-                                        <rect key="frame" x="0.0" y="0.0" width="432" height="32"/>
-                                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                        <subviews>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="jUu-dJ-JTK" customClass="ComponentButton" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="370" y="0.0" width="62" height="32"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="32" id="3Bk-48-wJh"/>
-                                                    <constraint firstAttribute="width" constant="62" id="XWY-SY-DFJ"/>
-                                                </constraints>
-                                            </customView>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="kbx-r8-FfZ" customClass="ComponentButton" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="300" y="0.0" width="62" height="32"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="32" id="Wjn-ma-mqm"/>
-                                                    <constraint firstAttribute="width" constant="62" id="eaf-lr-qUJ"/>
-                                                </constraints>
-                                            </customView>
-                                        </subviews>
-                                        <constraints>
-                                            <constraint firstItem="jUu-dJ-JTK" firstAttribute="leading" secondItem="kbx-r8-FfZ" secondAttribute="trailing" constant="8" id="UVS-Fc-TYh"/>
-                                            <constraint firstAttribute="trailing" secondItem="jUu-dJ-JTK" secondAttribute="trailing" id="bXB-5k-bhX"/>
-                                            <constraint firstAttribute="bottom" secondItem="kbx-r8-FfZ" secondAttribute="bottom" id="kbY-m6-lhz"/>
-                                            <constraint firstItem="kbx-r8-FfZ" firstAttribute="top" secondItem="VsO-t6-lE6" secondAttribute="top" id="mAH-Dm-gKC"/>
-                                            <constraint firstItem="jUu-dJ-JTK" firstAttribute="centerY" secondItem="kbx-r8-FfZ" secondAttribute="centerY" id="tH0-Dp-gJh"/>
-                                        </constraints>
-                                    </view>
-                                </box>
-                                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="cbF-CW-LAo">
-                                    <rect key="frame" x="0.0" y="48" width="432" height="136"/>
-                                    <view key="contentView" id="yMB-lF-kmQ">
-                                        <rect key="frame" x="0.0" y="0.0" width="432" height="136"/>
-                                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                                        <subviews>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="Jpf-4m-uhA" customClass="ComponentRadio" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="0.0" y="76" width="432" height="20"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="20" id="LZN-tC-bMG"/>
-                                                </constraints>
-                                            </customView>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="5GE-Zd-UxG" customClass="ComponentRadio" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="0.0" y="48" width="432" height="20"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="20" id="jxD-uV-Tlb"/>
-                                                </constraints>
-                                            </customView>
-                                            <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vvh-mZ-hZZ">
-                                                <rect key="frame" x="-2" y="108" width="436" height="16"/>
-                                                <textFieldCell key="cell" lineBreakMode="clipping" title="Insertion Position" id="Pzv-T6-WIY">
-                                                    <font key="font" usesAppearanceFont="YES"/>
-                                                    <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                                    <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                                </textFieldCell>
-                                            </textField>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="WI9-2y-RIs" customClass="ComponentRadio" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="0.0" y="14" width="90" height="20"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="20" id="ma1-gQ-G5B"/>
-                                                    <constraint firstAttribute="width" constant="90" id="pmZ-Lm-erY"/>
-                                                </constraints>
-                                            </customView>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="bXL-VD-0g6" customClass="ComponentInputNumber" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="98" y="8" width="96" height="32"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="width" constant="96" id="YCl-br-gKF"/>
-                                                    <constraint firstAttribute="height" constant="32" id="n3H-6d-HZ2"/>
-                                                </constraints>
-                                            </customView>
-                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="Fr6-uf-h6g" customClass="ComponentSelect" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="232" y="8" width="200" height="32"/>
-                                                <constraints>
-                                                    <constraint firstAttribute="height" constant="32" id="TF4-EP-Uk3"/>
-                                                </constraints>
-                                            </customView>
-                                            <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0y2-gu-PB5">
-                                                <rect key="frame" x="194" y="16" width="32" height="16"/>
-                                                <textFieldCell key="cell" lineBreakMode="clipping" title="/200" id="MwL-z3-jqh">
-                                                    <font key="font" usesAppearanceFont="YES"/>
-                                                    <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                                    <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                                </textFieldCell>
-                                            </textField>
-                                        </subviews>
-                                        <constraints>
-                                            <constraint firstItem="bXL-VD-0g6" firstAttribute="leading" secondItem="WI9-2y-RIs" secondAttribute="trailing" constant="8" id="0S4-My-lAt"/>
-                                            <constraint firstAttribute="trailing" secondItem="5GE-Zd-UxG" secondAttribute="trailing" id="A6p-ot-bSm"/>
-                                            <constraint firstAttribute="bottom" secondItem="WI9-2y-RIs" secondAttribute="bottom" constant="14" id="EdK-3j-YSm"/>
-                                            <constraint firstAttribute="trailing" secondItem="vvh-mZ-hZZ" secondAttribute="trailing" id="Fy8-EA-AYd"/>
-                                            <constraint firstAttribute="trailing" secondItem="Jpf-4m-uhA" secondAttribute="trailing" id="JdV-jv-d19"/>
-                                            <constraint firstItem="WI9-2y-RIs" firstAttribute="top" secondItem="5GE-Zd-UxG" secondAttribute="bottom" constant="14" id="LKx-V2-fcE"/>
-                                            <constraint firstAttribute="trailing" secondItem="Fr6-uf-h6g" secondAttribute="trailing" id="PLt-fG-jvc"/>
-                                            <constraint firstItem="Jpf-4m-uhA" firstAttribute="leading" secondItem="yMB-lF-kmQ" secondAttribute="leading" id="QUg-0D-hXX"/>
-                                            <constraint firstItem="5GE-Zd-UxG" firstAttribute="top" secondItem="Jpf-4m-uhA" secondAttribute="bottom" constant="8" id="dXh-OE-RBd"/>
-                                            <constraint firstItem="bXL-VD-0g6" firstAttribute="centerY" secondItem="WI9-2y-RIs" secondAttribute="centerY" id="fF2-R9-IZd"/>
-                                            <constraint firstItem="0y2-gu-PB5" firstAttribute="centerY" secondItem="bXL-VD-0g6" secondAttribute="centerY" id="kKo-eW-f3E"/>
-                                            <constraint firstItem="WI9-2y-RIs" firstAttribute="leading" secondItem="yMB-lF-kmQ" secondAttribute="leading" id="pF4-qM-kZo"/>
-                                            <constraint firstItem="5GE-Zd-UxG" firstAttribute="leading" secondItem="yMB-lF-kmQ" secondAttribute="leading" id="pMs-rK-Dpz"/>
-                                            <constraint firstItem="Fr6-uf-h6g" firstAttribute="centerY" secondItem="WI9-2y-RIs" secondAttribute="centerY" id="r2i-nY-6Cg"/>
-                                            <constraint firstItem="vvh-mZ-hZZ" firstAttribute="top" secondItem="yMB-lF-kmQ" secondAttribute="top" constant="12" id="t3d-8R-Juw"/>
-                                            <constraint firstItem="Jpf-4m-uhA" firstAttribute="top" secondItem="vvh-mZ-hZZ" secondAttribute="bottom" constant="12" id="uXO-6j-uvQ"/>
-                                            <constraint firstItem="Fr6-uf-h6g" firstAttribute="leading" secondItem="0y2-gu-PB5" secondAttribute="trailing" constant="8" id="xV6-Gb-E1O"/>
-                                            <constraint firstItem="vvh-mZ-hZZ" firstAttribute="leading" secondItem="yMB-lF-kmQ" secondAttribute="leading" id="z3O-nB-Rux"/>
-                                            <constraint firstItem="0y2-gu-PB5" firstAttribute="leading" secondItem="bXL-VD-0g6" secondAttribute="trailing" constant="2" id="zyn-Rf-W5k"/>
-                                        </constraints>
-                                    </view>
-                                </box>
-                            </subviews>
-                            <constraints>
-                                <constraint firstItem="CRF-nS-iRX" firstAttribute="top" secondItem="cbF-CW-LAo" secondAttribute="bottom" constant="16" id="GQY-7C-kp9"/>
-                                <constraint firstItem="CRF-nS-iRX" firstAttribute="leading" secondItem="VBw-Jy-eh0" secondAttribute="leading" id="L6t-UR-8Lv"/>
-                                <constraint firstAttribute="trailing" secondItem="AiR-qt-ZiL" secondAttribute="trailing" id="M0c-iw-hoP"/>
-                                <constraint firstAttribute="bottom" secondItem="CRF-nS-iRX" secondAttribute="bottom" id="SPw-gH-4Bl"/>
-                                <constraint firstItem="cbF-CW-LAo" firstAttribute="top" secondItem="AiR-qt-ZiL" secondAttribute="bottom" constant="16" id="VRy-8T-Rp8"/>
-                                <constraint firstItem="AiR-qt-ZiL" firstAttribute="top" secondItem="VBw-Jy-eh0" secondAttribute="top" id="eIz-c6-P1w"/>
-                                <constraint firstItem="cbF-CW-LAo" firstAttribute="leading" secondItem="VBw-Jy-eh0" secondAttribute="leading" id="fTo-W5-a0I"/>
-                                <constraint firstAttribute="trailing" secondItem="CRF-nS-iRX" secondAttribute="trailing" id="gRG-pd-I8T"/>
-                                <constraint firstItem="AiR-qt-ZiL" firstAttribute="leading" secondItem="VBw-Jy-eh0" secondAttribute="leading" id="gco-I3-0tj"/>
-                                <constraint firstAttribute="trailing" secondItem="cbF-CW-LAo" secondAttribute="trailing" id="l80-5z-asR"/>
-                            </constraints>
-                        </view>
-                        <constraints>
-                            <constraint firstAttribute="width" constant="432" id="D0K-WH-fTy"/>
-                        </constraints>
-                    </box>
-                </subviews>
-                <constraints>
-                    <constraint firstItem="o8W-OS-QlF" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="16" id="CsC-6n-zAa"/>
-                    <constraint firstAttribute="trailing" secondItem="o8W-OS-QlF" secondAttribute="trailing" constant="24" id="J1L-pA-53g"/>
-                    <constraint firstAttribute="bottom" secondItem="o8W-OS-QlF" secondAttribute="bottom" constant="16" id="hZH-rT-7dz"/>
-                    <constraint firstItem="o8W-OS-QlF" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="24" id="ixD-rP-EH1"/>
-                </constraints>
-            </view>
-            <connections>
-                <outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
-            </connections>
-            <point key="canvasLocation" x="-11" y="112"/>
-        </window>
-    </objects>
-</document>

+ 122 - 75
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNPDFInsert/KMNPDFInsertPDFWindowController.swift

@@ -34,51 +34,72 @@ class KMNPDFInsertPDFWindowController: KMNBaseWindowController {
     @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
     
     private var orgDocument:CPDFDocument?
+    private var insertFilePath:String?
+    private var insertPDFPassword:String?
     private var insertDocument:CPDFDocument?
-    private var orgPageIndex:Int = 0
+    private var selectionIndexPaths:Set<IndexPath>?
     
-    var callback: ((KMNFileAttribute, Int) -> Void)?
+    var pdfCallback: ((KMNFileAttribute, Int) -> Void)?
     
-    convenience init(_ document: CPDFDocument?, currentPageIndex: Int) {
+    var fileCallback: ((String, Int) -> Void)?
+    
+    convenience init(_ document: CPDFDocument?, selectionIndexPaths: Set<IndexPath>?) {
         self.init(windowNibName: "KMNPDFInsertPDFWindowController")
         orgDocument = document
-        orgPageIndex = currentPageIndex  // 修正此行
-    }
+        self.selectionIndexPaths = selectionIndexPaths
 
-    convenience init(_ filePath: String,password:String?) {
+    }
+    convenience init(_ document: CPDFDocument?,filePath: String,password:String?,selectionIndexPaths: Set<IndexPath>?) {
         self.init(windowNibName: "KMNPDFInsertPDFWindowController")
-        let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
-        if password != nil {
-            document?.unlock(withPassword: password as String?)
-        }
-
         orgDocument = document
+        insertPDFPassword = password
+        insertFilePath = filePath
+        self.selectionIndexPaths = selectionIndexPaths
     }
     
     override func windowDidLoad() {
         super.windowDidLoad()
-
+        
+        if insertFilePath?.isEmpty == false && insertFilePath?.pathExtension == "pdf" {
+            insertDocument = CPDFDocument(url: NSURL.fileURL(withPath: insertFilePath ?? ""))
+            if let data = insertDocument?.isLocked, data {
+               insertDocument?.unlock(withPassword: insertPDFPassword)
+            }
+        }
              
+        setUpProperty()
     }
     
-    
-    
     override func beginSheetFinish() {
         super.beginSheetFinish()
         
-        setUpProperty()
+        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
         
         pageRangeSelect.selectItemAtIndex(0)
         positionSelect.selectItemAtIndex(0)
         
-        pageRadioButton.properties.checkboxType = .selected
-        pageRadioButton.reloadData()
-        
-        pageNumInput.properties.text = String((orgPageIndex+1))
-        pageNumInput.reloadData()
+        if(selectionIndexPaths?.count ?? 0 > 0) {
+            pageRadioButton.properties.checkboxType = .selected
+
+            let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
+            pageNumInput.properties.text = String((maxmumIndexPath?.item ?? 0)+1)
+            
+            pageRadioButton.reloadData()
+            pageNumInput.reloadData()
+        } else {
+            firstRadioButton.properties.checkboxType = .selected
+            pageRadioButton.properties.checkboxType = .normal
+            
+            positionSelect.properties.isDisabled = true
+            pageNumInput.properties.isDisabled = true
+            
+            firstRadioButton.reloadData()
+            pageRadioButton.reloadData()
+            pageNumInput.reloadData()
+            positionSelect.reloadData()
+        }
         
-        pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
-         
+        self.updateInsertPDF()
     }
     
     private func setUpPageSelctProperty() {
@@ -242,14 +263,24 @@ class KMNPDFInsertPDFWindowController: KMNBaseWindowController {
     }
     
     private func updateInsertPDF() {
-        fileNameInput.properties.text = insertDocument?.documentURL.path ?? ""
+        fileNameInput.properties.text = insertFilePath ?? ""
         fileNameInput.reloadData()
         window?.makeFirstResponder(self)
-        pageRangeSelect.properties.isDisabled = false
-        setUpPageSelctProperty()
-        pageRangeSelect.selectItemAtIndex(0)
         
         if(insertDocument != nil) {
+            pageRangeSelect.properties.isDisabled = false
+            pageRangeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
+            setUpPageSelctProperty()
+            pageRangeSelect.selectItemAtIndex(0)
+            pageRangeSelect.reloadData()
+        } else {
+            pageRangeSelect.properties.isDisabled = true
+            pageRangeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-dis")
+            pageRangeSelect.selectItemAtIndex(0)
+            pageRangeSelect.reloadData()
+        }
+        
+        if(insertFilePath?.isEmpty == false) {
             if insertButton.properties.isDisabled == true {
                 insertButton.properties.isDisabled = false
                 insertButton.reloadData()
@@ -263,43 +294,6 @@ class KMNPDFInsertPDFWindowController: KMNBaseWindowController {
     }
     
     @objc func insertButtonClicked(_ sender: NSView) {
-        let pageRangeSelectIndex = pageRangeSelect.indexOfSelect()
-
-        let fileAttribute = KMNFileAttribute()
-        fileAttribute.password = insertDocument?.password ?? ""
-        fileAttribute.filePath =  insertDocument?.documentURL.path ?? ""
-
-        if pageRangeSelectIndex == 0  {
-            fileAttribute.bAllPage = true
-            fileAttribute.pagesType = .AllPages
-        } else if pageRangeSelectIndex == 1 {
-            fileAttribute.bAllPage = false
-            fileAttribute.pagesType = .OnlyOdd
-        } else {
-            if(insertDocument?.pageCount ?? 0 <= 1) {
-                fileAttribute.bAllPage = false
-                fileAttribute.pagesType = .PagesString
-                fileAttribute.pagesString = pageRangeSelect.properties.text ?? ""
-            } else {
-                fileAttribute.bAllPage = false
-                if(pageRangeSelectIndex == 2) {
-                    fileAttribute.pagesType = .OnlyEven
-                } else {
-                    fileAttribute.bAllPage = false
-                    fileAttribute.pagesType = .PagesString
-                    fileAttribute.pagesString = pageRangeSelect.properties.text ?? ""
-                }
-            }
-        }
-        
-        if (fileAttribute.fetchSelectPages().isEmpty) {
-            let alert = NSAlert()
-            alert.alertStyle = .critical
-            alert.messageText = String(format: "%@ %@", fileAttribute.filePath.lastPathComponent, KMLocalizedString("Invalid page range or the page number is out of range. Please try again."))
-            alert.runModal()
-            return
-        }
-        
         var insetPageDex:Int = 0
         if firstRadioButton.properties.checkboxType == .selected {
             insetPageDex = 0
@@ -312,7 +306,50 @@ class KMNPDFInsertPDFWindowController: KMNBaseWindowController {
                 insetPageDex -= 1
             }
         }
-        callback?(fileAttribute,insetPageDex)
+
+        if(insertDocument != nil) {
+            let pageRangeSelectIndex = pageRangeSelect.indexOfSelect()
+            
+            let fileAttribute = KMNFileAttribute()
+            fileAttribute.pdfDocument = insertDocument
+            fileAttribute.password = insertDocument?.password ?? ""
+            fileAttribute.filePath =  insertDocument?.documentURL.path ?? ""
+            
+            if pageRangeSelectIndex == 0  {
+                fileAttribute.bAllPage = true
+                fileAttribute.pagesType = .AllPages
+            } else if pageRangeSelectIndex == 1 {
+                fileAttribute.bAllPage = false
+                fileAttribute.pagesType = .OnlyOdd
+            } else {
+                if(insertDocument?.pageCount ?? 0 <= 1) {
+                    fileAttribute.bAllPage = false
+                    fileAttribute.pagesType = .PagesString
+                    fileAttribute.pagesString = pageRangeSelect.properties.text ?? ""
+                } else {
+                    fileAttribute.bAllPage = false
+                    if(pageRangeSelectIndex == 2) {
+                        fileAttribute.pagesType = .OnlyEven
+                    } else {
+                        fileAttribute.bAllPage = false
+                        fileAttribute.pagesType = .PagesString
+                        fileAttribute.pagesString = pageRangeSelect.properties.text ?? ""
+                    }
+                }
+            }
+            
+            if (fileAttribute.fetchSelectPages().isEmpty) {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = String(format: "%@ %@", fileAttribute.filePath.lastPathComponent, KMLocalizedString("Invalid page range or the page number is out of range. Please try again."))
+                alert.runModal()
+                return
+            }
+            
+            pdfCallback?(fileAttribute,insetPageDex)
+        } else {
+            fileCallback?(insertFilePath ?? "",insetPageDex)
+        }
                 
         own_closeEndSheet()
     }
@@ -362,26 +399,36 @@ class KMNPDFInsertPDFWindowController: KMNBaseWindowController {
     
     @objc func chooseURLAction(_ sender: NSView) {
         let openPanel = NSOpenPanel()
-        openPanel.allowedFileTypes = ["pdf","PDF"]
+        let supportFiles = KMNConvertTool.pdfExtensions + KMConvertPDFManager.supportFileType()
+
+        openPanel.allowedFileTypes = supportFiles
         openPanel.allowsMultipleSelection = false
         openPanel.beginSheetModal(for: self.window!) { [self] result in
             if (result == .OK) {
                 let fileURL = openPanel.url
-                let pdfDoc = CPDFDocument(url: fileURL)
-                if let data = pdfDoc?.isLocked, data {
-                    DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
-                        KMNBaseWindowController.checkPassword(url: fileURL ?? NSURL.fileURL(withPath: ""), type: .owner) { result, pwd in
-                            if (pwd.isEmpty == false) {
-                                self.insertDocument = CPDFDocument(url: fileURL)
-                                if let data = self.insertDocument?.isLocked, data {
-                                    self.insertDocument?.unlock(withPassword: pwd)
+                if(fileURL?.pathExtension == "pdf") {
+                    let pdfDoc = CPDFDocument(url: fileURL)
+                    if let data = pdfDoc?.isLocked, data {
+                        DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
+                            KMNBaseWindowController.checkPassword(url: fileURL ?? NSURL.fileURL(withPath: ""), type: .owner) { result, pwd in
+                                if (pwd.isEmpty == false) {
+                                    self.insertDocument = CPDFDocument(url: fileURL)
+                                    if let data = self.insertDocument?.isLocked, data {
+                                        self.insertDocument?.unlock(withPassword: pwd)
+                                    }
+                                    self.insertFilePath = fileURL?.path
+                                    self.updateInsertPDF()
                                 }
-                                self.updateInsertPDF()
                             }
                         }
+                    } else {
+                        self.insertDocument = CPDFDocument(url: fileURL)
+                        self.insertFilePath = fileURL?.path
+                        self.updateInsertPDF()
                     }
                 } else {
-                    self.insertDocument = CPDFDocument(url: fileURL)
+                    self.insertDocument = nil
+                    self.insertFilePath = fileURL?.path
                     self.updateInsertPDF()
                 }
             }

+ 2 - 1
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNPDFSplit/KMNSplitPDFWindowController.swift

@@ -75,7 +75,7 @@ class KMNSplitPDFWindowController: KMNBaseWindowController {
                                                                checkboxType: .normal)
         averagePernLabel.stringValue = KMLocalizedString("page(s)")
         averagePernLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-dis")
-        averagePernLabel.font =  ComponentLibrary.shared.getFontFromKey("comp-field/colorText-filled-dis")
+        averagePernLabel.font =  ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
 
         averageSplitRadio.properties = ComponentCheckBoxProperty(size: .s,
                                                                  state: .normal,
@@ -332,6 +332,7 @@ class KMNSplitPDFWindowController: KMNBaseWindowController {
         let fileAttribute = KMNFileAttribute()
         if(splitRangeRadio.properties.checkboxType == .selected) {
             fileAttribute.password = orgDocument?.password ?? ""
+            fileAttribute.pdfDocument = orgDocument
             fileAttribute.filePath =  orgDocument?.documentURL.path ?? ""
             if(pageRangeSelectIndex == 0) {
                 fileAttribute.bAllPage = false

+ 72 - 20
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNThumbnailView/KMNPageEditViewController.swift

@@ -110,30 +110,60 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
             KMPurchaseCompareWindowController.sharedInstance()?.showWindow(nil)
             return
         }
+        
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = supportDragFileTypes()
+        openPanel.allowsMultipleSelection = false
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) {[weak self] result in
+            if result == NSApplication.ModalResponse.OK {
+                guard let weakSelf = self else { return }
+                let fileURL = openPanel.url
+                if(fileURL?.pathExtension == "pdf") {
+                    let pdfDoc = CPDFDocument(url: fileURL)
+                    if let data = pdfDoc?.isLocked, data {
+                        DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
+                            KMNBaseWindowController.checkPassword(url: fileURL ?? NSURL.fileURL(withPath: ""), type: .owner) { result, pwd in
+                                if (pwd.isEmpty == false) {
+                                    self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: pwd)
+                                }
+                            }
+                        }
+                    } else {
+                        self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: nil)
+                    }
+                } else {
+                    self?.insertFilePath(filePath: fileURL?.path ?? "", pdfPassword: nil)
+                }
 
+            }
+        }
+    }
+    
+    private func insertFilePath(filePath:String,pdfPassword:String?) {
         let selectedIndexPaths = collectionView.selectionIndexPaths
-        let minimumIndexPath = selectedIndexPaths.min(by: { $0 < $1 })
-        let open = NSOpenPanel()
-
-        let insertPDF = KMNPDFInsertPDFWindowController(self.showDocument, currentPageIndex: minimumIndexPath?.item ?? 0)
-        insertPDF.callback = { [weak self] fileAttribute, insertIdx in
+        
+        let insertPDF = KMNPDFInsertPDFWindowController(showDocument, filePath: filePath, password: pdfPassword, selectionIndexPaths: selectedIndexPaths)
+        insertPDF.pdfCallback = { [weak self] fileAttribute, insertIdx in
             let doc = fileAttribute.pdfDocument
-            self?.thumbnailBaseViewDelegate?.insertPDFThumbnailViewControlle?(pageEditVC: self, pdfDocment: doc)
-            var insertIndex = insertIdx
             
             var insertPages: [CPDFPage] = []
-            var indexpaths = Set<IndexPath>()
-
+            
             for number in fileAttribute.fetchSelectPages() {
                 if let page = doc?.page(at: UInt(number-1)) {
                     insertPages.append(page)
-                    indexpaths.insert(IndexPath(item: insertIndex, section: 0))
-                    insertIndex += 1
                 }
             }
+            self?.thumbnailBaseViewDelegate?.insertPDFThumbnailViewControlle?(pageEditVC: self, pdfDocment: doc)
             
             self?.insertFormPDF(insertPages: insertPages, pageDex: insertIdx)
         }
+        insertPDF.fileCallback = { [weak self] filePath, insertIdx in
+            self?.insertFromFilePath(fileNames: [filePath], formDex: 0, indexDex: UInt(insertIdx), selectIndexs: []) { newSelectIndexs in
+                self?.refreshDatas()
+                self?.selectPages(with: newSelectIndexs)
+            }
+        }
+        
         insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
     }
     
@@ -144,9 +174,11 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
         }
         
         let selectedIndexPaths = collectionView.selectionIndexPaths
-        let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
 
-        let insertPDF = KMNPDFInsertBlankWindowController(self.showDocument, currentPageIndex: maxmumIndexPath?.item ?? 0)
+        let insertPDF = KMNPDFInsertBlankWindowController(self.showDocument, selectionIndexPaths: selectedIndexPaths)
+        insertPDF.callback = { [weak self] pageSize, insertIdx in
+            self?.insertBlankPage(pageSize: pageSize, pageDex: insertIdx)
+        }
         insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
     }
     
@@ -156,10 +188,26 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
             return
         }
         let selectedIndexPaths = collectionView.selectionIndexPaths
-        let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
-
-        let insertPDF = KMNPDFInsertClipboardWindowController(self.showDocument, currentPageIndex: maxmumIndexPath?.item ?? 0)
-        insertPDF.own_beginSheetModal(for: self.view.window, completionHandler: nil)
+        var maxmumIndex = 1
+        if(selectedIndexPaths.count > 0) {
+            let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
+            maxmumIndex = (maxmumIndexPath?.item ?? 0) + 1
+        }
+        
+        var error: NSError?
+        guard let document: CPDFDocument = self.openDocumentWithImageFromPasteboard(NSPasteboard.general, error: &error) else {
+            return
+        }
+        if let page: CPDFPage = (document.page(at: 0)) {
+            insertFormPDF(insertPages: [page], pageDex: maxmumIndex)
+        }
+        
+        self.thumbnailBaseViewDelegate?.insertPDFThumbnailViewControlle?(pageEditVC: self, pdfDocment: document)
+        let ips: Set<IndexPath> = [IndexPath(item: maxmumIndex, section: 0)]
+        
+        refreshDatas()
+        collectionView.selectionIndexPaths = ips
+        collectionView.scrollToItems(at: ips, scrollPosition: .centeredVertically)
     }
     
     public func insertFromScannerAction() {
@@ -176,10 +224,14 @@ class KMNPageEditViewController: KMNThumbnailBaseViewController {
         vc.importScannerFileCallback = { [weak self] (url: NSURL) -> Void in
             if let imag = NSImage(contentsOfFile: url.path! ) {
                 let index = (maxmumIndexPath?.item ?? 0) + 1
-                let document = CPDFDocument()
-                _ = document?.km_insertPage(imag.size, withImage: url.path! , at:UInt(index))
+                _ = self?.showDocument?.km_insertPage(imag.size, withImage: url.path! , at:UInt(index))
+                
                 self?.refreshDatas()
-               
+                
+                let ips: Set<IndexPath> = [IndexPath(item: index, section: 0)]
+
+                self?.collectionView.selectionIndexPaths = ips
+                self?.collectionView.scrollToItems(at: ips, scrollPosition: .centeredVertically)
             }
         }
         vc.showWindow(nil)

+ 76 - 12
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNThumbnailView/KMNThumbnailBaseViewController+Action.swift

@@ -8,7 +8,7 @@
 import Foundation
 
 extension KMNThumbnailBaseViewController {
-    private func fileNameWithSelectedPages(_ itemIndexes: IndexSet) -> String {
+    public func fileNameWithSelectedPages(_ itemIndexes: IndexSet) -> String {
         var pagesName = ""
         if (itemIndexes.count > 1) {
             pagesName.append(" pages")
@@ -21,6 +21,21 @@ extension KMNThumbnailBaseViewController {
         return String(format: "%@%@", docmentName,tFileName)
     }
     
+    private func convertTIFFDataToPDF(_ tiffData: Data) -> Data? {
+        guard let imsrc = CGImageSourceCreateWithData(tiffData as CFData, [kCGImageSourceTypeIdentifierHint: kUTTypeTIFF] as CFDictionary), CGImageSourceGetCount(imsrc) > 0, let cgImage = CGImageSourceCreateImageAtIndex(imsrc, 0, nil) else { return nil }
+        let pdfData = NSMutableData(capacity: tiffData.count)
+        let consumer = CGDataConsumer(data: pdfData! as CFMutableData)!
+        
+        var rect = CGRect(x: 0, y: 0, width: CGFloat(cgImage.width), height: CGFloat(cgImage.height))
+        let ctxt = CGContext(consumer: consumer, mediaBox: &rect, nil)
+        ctxt!.beginPDFPage(nil)
+        ctxt!.draw(cgImage, in: rect)
+        ctxt!.endPDFPage()
+        ctxt!.closePDF()
+        
+        return pdfData as? Data
+    }
+    
     public func selectPages(with array: [Int]) {
         var selectIndexPaths: Set<IndexPath> = []
 
@@ -58,21 +73,69 @@ extension KMNThumbnailBaseViewController {
         var pageIndexDex: Int = pageDex
         var indexpaths = Set<IndexPath>()
         for page in insertPages {
-            showDocument?.insertPageObject(page, at: UInt(pageIndexDex))
-            indexpaths.insert(IndexPath(item: pageIndexDex, section: 0))
-            pageIndexDex += 1
+           let isSuccessFul = showDocument?.insertPageObject(page, at: UInt(pageIndexDex))
+            if(isSuccessFul == true) {
+                indexpaths.insert(IndexPath(item: pageIndexDex, section: 0))
+                pageIndexDex += 1
+            }
         }
-        
+        refreshDatas()
+        collectionView.reloadData()
         collectionView.scrollToItems(at: indexpaths, scrollPosition: .centeredVertically)
-        
-        //        (currentUndoManager?.prepare(withInvocationTarget: self) as KMNThumbnailBaseViewController).deletePDFPages(indexpaths: indexpaths, scroIndex: pageDex)
-        
+        collectionView.selectionIndexPaths = indexpaths
     }
     
-    public func deletePDFPages(indexpaths:Set<IndexPath>,scroIndex:Int) {
+    public func insertBlankPage(pageSize: CGSize,pageDex:Int) {
+        var indexpaths = Set<IndexPath>()
+        let isSuccessFul = showDocument?.insertBlankPage(pageSize: pageSize, at: pageDex)
+         if(isSuccessFul == true) {
+             indexpaths.insert(IndexPath(item: pageDex, section: 0))
+         }
+
+        refreshDatas()
         collectionView.reloadData()
-        collectionView.scrollToItems(at: [IndexPath(item: scroIndex, section: 0)], scrollPosition: .centeredVertically)
+        collectionView.scrollToItems(at: indexpaths, scrollPosition: .centeredVertically)
+        collectionView.selectionIndexPaths = indexpaths
+    }
+    
+    public func openDocumentWithImageFromPasteboard(_ pboard: NSPasteboard, error outError: AutoreleasingUnsafeMutablePointer<NSError?>?) -> CPDFDocument? {
+        var document: CPDFDocument? = nil
+        var data: Data? = nil
+        
+        if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.pdf.rawValue]) {
+            data = pboard.data(forType: NSPasteboard.PasteboardType.pdf)
+        } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.postScript.rawValue]) {
+            data = pboard.data(forType: NSPasteboard.PasteboardType.postScript)
+        } else if pboard.canReadItem(withDataConformingToTypes: [NSPasteboard.PasteboardType.tiff.rawValue]) {
+            data = convertTIFFDataToPDF(pboard.data(forType: NSPasteboard.PasteboardType.tiff) ?? Data())
+        } else {
+            let images = pboard.readObjects(forClasses: [NSImage.self], options: [:])
+            let strings = pboard.readObjects(forClasses: [NSAttributedString.self], options: [:])
+            if images?.count ?? 0 > 0 {
+                data = convertTIFFDataToPDF((images![0] as AnyObject).tiffRepresentation!)
+            } else if strings?.count ?? 0 > 0 {
+                data = KMOCTool.convertStringsToPDF(withString: strings ?? [""]) // convertStringsToPDF(strings!)
+            }
+        }
+        
+        if let data = data {
+            document = CPDFDocument(data: data)
+            
+        } else if let outError = outError {
+            outError.pointee = NSError(domain: "SKDocumentErrorDomain", code: 3, userInfo: [NSLocalizedDescriptionKey: NSLocalizedString("Unable to load data from clipboard", comment: "Error description")])
+        }
         
+        return document
+    }
+    
+    public func insertImageFilePath(imagePath:String,pageDex:Int)->Bool{
+        var isSuccessFul:Bool = false
+        if (FileManager.default.fileExists(atPath: imagePath)) {
+            if let image = NSImage(contentsOfFile: imagePath) {
+                isSuccessFul = showDocument?.km_insertPage(image.size, withImage: imagePath, at: UInt(pageDex)) == true
+            }
+        }
+        return isSuccessFul
     }
     
     public func rotatePages(indexPaths: Set<IndexPath>, rotateAngle: Int) {
@@ -256,8 +319,9 @@ extension KMNThumbnailBaseViewController {
             }
         } else if supportDragFileTypes().contains(pathExtension) {
             if KMConvertPDFManager.supportImages().contains(pathExtension) {
-                if let image = NSImage(contentsOfFile: path) {
-                     _ = showDocument?.km_insertPage(image.size, withImage: path, at: indexDex)
+
+              let isSueccessFul = insertImageFilePath(imagePath: path, pageDex: Int(indexDex))
+                if(isSueccessFul) {
                     tSelectIndex.append(Int(insertDex))
                     insertDex += 1
                 }

+ 82 - 0
PDF Office/PDF Master/KMClass/KMNPDFPageEdit/KMNThumbnailView/KMNThumbnailBaseViewController.swift

@@ -11,6 +11,17 @@ import Cocoa
     @objc optional func clickThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,currentIndex:Int)
     
     @objc optional func insertPDFThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,pdfDocment:CPDFDocument?)
+    
+    @objc optional func changeIndexPathsThumbnailViewControlle(pageEditVC:KMNThumbnailBaseViewController?,selectionIndexPaths: Set<IndexPath>,selectionStrings:String )
+}
+
+enum KMNThumbnailChoosePageStyle: Int {
+    case odd
+    case even
+    case horizontal
+    case vertical
+    case allPage
+    case custom
 }
 
 internal let kmnThumLocalForDraggedTypes = NSPasteboard.PasteboardType(rawValue: "kmnThumLocalForDraggedTypes")
@@ -35,6 +46,58 @@ class KMNThumbnailBaseViewController: KMNBaseViewController,NSCollectionViewDele
     }
     private var thumbnails:[KMNThumbnail] = []
     
+    private var isChangeIndexPaths = false
+    
+    public var thumbnailChoosePageStyle:KMNThumbnailChoosePageStyle = .custom {
+        didSet {
+            var tSelectionIndexPaths: Set<IndexPath> = []
+            let pageCount = currentDocument?.pageCount ?? 0
+            switch thumbnailChoosePageStyle {
+            case .even:
+                for i in 0 ..< pageCount {
+                    if(i % 2 == 0) {
+                        tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
+                    }
+                }
+                
+            case .odd:
+                for i in 0 ..< pageCount {
+                    if(i % 2 != 0) {
+                        tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
+                    }
+                }
+            case .allPage:
+                for i in 0 ..< pageCount {
+                    tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
+                    
+                }
+            case .vertical:
+                for i in 0 ..< pageCount {
+                    let page = showDocument?.page(at: i)
+                    if(page != nil) {
+                        if(page!.rotation % 180 != 0) {
+                            tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
+                        }
+                    }
+                }
+            case .horizontal:
+                for i in 0 ..< pageCount {
+                    let page = showDocument?.page(at: i)
+                    if(page != nil) {
+                        if(page!.rotation % 180 == 0) {
+                            tSelectionIndexPaths.insert(IndexPath(item: Int(i), section: 0))
+                        }
+                    }
+                }
+            default: break
+            }
+            
+            isChangeIndexPaths = true
+            collectionView.selectionIndexPaths = tSelectionIndexPaths
+            isChangeIndexPaths = false
+        }
+    }
+    
     var selectionIndexPaths: Set<IndexPath> = [] {
         didSet {
             var indexpaths: Set<IndexPath> = []
@@ -173,6 +236,25 @@ class KMNThumbnailBaseViewController: KMNBaseViewController,NSCollectionViewDele
         return item
     }
     
+    func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
+        if isChangeIndexPaths == false {
+            let indexpathsz = self.collectionView.selectionIndexPaths
+            let dex:IndexSet = indexpathsToIndexs(indexpaths: indexpathsz)
+            let selectedIndexPathsString = KMNTools.parseIndexSet(indexSet: dex)
+            
+            thumbnailBaseViewDelegate?.changeIndexPathsThumbnailViewControlle?(pageEditVC: self, selectionIndexPaths: indexpathsz, selectionStrings: selectedIndexPathsString)
+        }
+    }
+    
+    func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
+        if isChangeIndexPaths == false {
+            let indexpathsz = self.collectionView.selectionIndexPaths
+            let dex:IndexSet = indexpathsToIndexs(indexpaths: indexpathsz)
+            let selectedIndexPathsString = KMNTools.parseIndexSet(indexSet: dex)
+            
+            thumbnailBaseViewDelegate?.changeIndexPathsThumbnailViewControlle?(pageEditVC: self, selectionIndexPaths: indexpathsz, selectionStrings: selectedIndexPathsString)
+        }
+    }
     
     // MARK: - NSCollectionViewDelegateFlowLayout
     

+ 57 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/KMPDFViewController.swift

@@ -450,6 +450,11 @@ extension KMPDFViewController: KMPDFToolbarControllerDelegate {
             pageEditViewController?.deletePageAction()
         } else if itemIdentifier == KMPDFToolbar_PageEdit_Reduce_Identifier {
             pageEditViewController?.zoomOutPageAction()
+            if(pageEditViewController?.canZoomInPageSize() == false) {
+                toolbarManager.page_Increase_Property.isDisabled = true
+            } else {
+                toolbarManager.page_Increase_Property.isDisabled = false
+            }
             if(pageEditViewController?.canZoomOutPageSize() == false) {
                 toolbarManager.page_Reduce_Property.isDisabled = true
             } else {
@@ -464,6 +469,48 @@ extension KMPDFViewController: KMPDFToolbarControllerDelegate {
             } else {
                 toolbarManager.page_Increase_Property.isDisabled = false
             }
+            if(pageEditViewController?.canZoomOutPageSize() == false) {
+                toolbarManager.page_Reduce_Property.isDisabled = true
+            } else {
+                toolbarManager.page_Reduce_Property.isDisabled = false
+            }
+            controller.refreshSecondToolbarItemsState()
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_oddPage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .odd
+            if(toolbarManager.page_pageInfo_Property.creatable == true) {
+                toolbarManager.page_pageInfo_Property.creatable = false
+                controller.refreshSecondToolbarItemsState()
+            }
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_EvenPage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .even
+            if(toolbarManager.page_pageInfo_Property.creatable == true) {
+                toolbarManager.page_pageInfo_Property.creatable = false
+                controller.refreshSecondToolbarItemsState()
+            }
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_PortraitPage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .horizontal
+            if(toolbarManager.page_pageInfo_Property.creatable == true) {
+                toolbarManager.page_pageInfo_Property.creatable = false
+                controller.refreshSecondToolbarItemsState()
+            }
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_LandscapePage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .vertical
+            if(toolbarManager.page_pageInfo_Property.creatable == true) {
+                toolbarManager.page_pageInfo_Property.creatable = false
+                controller.refreshSecondToolbarItemsState()
+            }
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_AllPage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .allPage
+            if(toolbarManager.page_pageInfo_Property.creatable == true) {
+                toolbarManager.page_pageInfo_Property.creatable = false
+                controller.refreshSecondToolbarItemsState()
+            }
+        } else if itemIdentifier == KMPDFToolbar_PageEdit_page_CustomPage_Identifier {
+            pageEditViewController?.thumbnailChoosePageStyle = .custom
+            toolbarManager.page_pageInfo_Property.text = nil
+            if(toolbarManager.page_pageInfo_Property.creatable == false) {
+                toolbarManager.page_pageInfo_Property.creatable = true
+            }
             controller.refreshSecondToolbarItemsState()
         }
         
@@ -702,6 +749,16 @@ extension KMPDFViewController: KMNThumbnailBaseViewDelegate {
             insertDocuments.insert(pdfDocment!)
         }
     }
+    
+    func changeIndexPathsThumbnailViewControlle(pageEditVC: KMNThumbnailBaseViewController?, selectionIndexPaths: Set<IndexPath>, selectionStrings: String) {
+        toolbarManager.page_pageInfo_Property.text = selectionStrings
+        
+        if(toolbarManager.page_pageInfo_Property.creatable == false) {
+            toolbarManager.page_pageInfo_Property.creatable = true
+        }
+        pdfToolbarController?.refreshSecondToolbarItemsState()
+    }
+
 }
     
 

+ 2 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/KMPDFViewController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>

+ 2 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/Toolbar/KMPDFSecToolbarController.swift

@@ -248,6 +248,8 @@ class KMPDFSecToolbarController: NSViewController {
                 (view as! ComponentButton).reloadData()
             } else if view is ComponentDropdownTool {
                 (view as! ComponentDropdownTool).reloadData()
+            } else if view is ComponentSelect {
+                (view as! ComponentSelect).reloadData()
             }
         }
     }

+ 1 - 1
PDF Office/PDF Master/KMClass/Tools/Tool/KMNPageSizeTool.swift

@@ -114,7 +114,7 @@ let KMNPaperSizeNameUSLetter: String = KMLocalizedString("US Letter")
                 f = value/25.4
             } else if(funit == "mm") {
                 f = value/10.0
-                f = value/25.4
+                f = f/25.4
             }
         }
         if (fmod(f, 1) == 0) { //如果有一位小数点

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

@@ -5721,12 +5721,6 @@
 		F3A0F85C2CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8582CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib */; };
 		F3A0F85D2CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8582CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib */; };
 		F3A0F85E2CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8582CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib */; };
-		F3A0F8612CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F85F2CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift */; };
-		F3A0F8622CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F85F2CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift */; };
-		F3A0F8632CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F85F2CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift */; };
-		F3A0F8642CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8602CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib */; };
-		F3A0F8652CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8602CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib */; };
-		F3A0F8662CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3A0F8602CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib */; };
 		F3A0F86D2CCA118D00E7373F /* KMNTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F86C2CCA118D00E7373F /* KMNTools.swift */; };
 		F3A0F86E2CCA118D00E7373F /* KMNTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F86C2CCA118D00E7373F /* KMNTools.swift */; };
 		F3A0F86F2CCA118D00E7373F /* KMNTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3A0F86C2CCA118D00E7373F /* KMNTools.swift */; };
@@ -8210,8 +8204,6 @@
 		F3A0F8532CC8F59400E7373F /* KMNConvertTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMNConvertTool.swift; sourceTree = "<group>"; };
 		F3A0F8572CC940DD00E7373F /* KMNPDFInsertBlankWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMNPDFInsertBlankWindowController.swift; sourceTree = "<group>"; };
 		F3A0F8582CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMNPDFInsertBlankWindowController.xib; sourceTree = "<group>"; };
-		F3A0F85F2CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMNPDFInsertClipboardWindowController.swift; sourceTree = "<group>"; };
-		F3A0F8602CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMNPDFInsertClipboardWindowController.xib; sourceTree = "<group>"; };
 		F3A0F86C2CCA118D00E7373F /* KMNTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMNTools.swift; sourceTree = "<group>"; };
 		F3A9DC7D294309D80074E5D2 /* CPDFListEditAnnotationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CPDFListEditAnnotationViewController.xib; sourceTree = "<group>"; };
 		F3B7DF992948565000333201 /* CPDFListHoverAnnotationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CPDFListHoverAnnotationViewController.xib; sourceTree = "<group>"; };
@@ -15163,8 +15155,6 @@
 				F337CC442CC7EEE100D46AF4 /* KMNPDFInsertPDFWindowController.xib */,
 				F3A0F8572CC940DD00E7373F /* KMNPDFInsertBlankWindowController.swift */,
 				F3A0F8582CC940DD00E7373F /* KMNPDFInsertBlankWindowController.xib */,
-				F3A0F85F2CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift */,
-				F3A0F8602CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib */,
 			);
 			path = KMNPDFInsert;
 			sourceTree = "<group>";
@@ -16073,7 +16063,6 @@
 				BBFD2B162AEFAC9C0016C456 /* KMBatchOperateBaseViewController.xib in Resources */,
 				F30B22882CB8D9630041002E /* KMNQuickToolCollectionViewItem.xib in Resources */,
 				AD867FAA29DFB78200F00440 /* KMAnnotationOutlineView.xib in Resources */,
-				F3A0F8642CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */,
 				BBC821E32B0D9F72004B7E8E /* KMStampCreaterWindowController.xib in Resources */,
 				BB03D6A02B024AC8008C9976 /* KMPDFEditInsertPageWindow.xib in Resources */,
 				AD1D48252AFB6BCB007AC1F0 /* KMMergeView.xib in Resources */,
@@ -16683,7 +16672,6 @@
 				ADE8BC2B29F7CDB000570F89 /* KMPageNumberDisplayView.xib in Resources */,
 				BB65A05E2AF8BF2A003A27A0 /* NotesPreferences.xib in Resources */,
 				BB1B0AEA2B4FC6E900889528 /* KMFunctionGuideMultiController.xib in Resources */,
-				F3A0F8652CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */,
 				ADBC374D29CAD65D00D93208 /* KMComparativeOutlineCell.xib in Resources */,
 				BBB789C12BE8BF2400F7E09C /* AIChatView.xib in Resources */,
 				9FF371F52C69E1B2005F9CC5 /* Localizable.strings in Resources */,
@@ -17262,7 +17250,6 @@
 				BB1E7F2E2B4FE2C6002D9785 /* GuideInfoImages.xcassets in Resources */,
 				BBC745EF295F067B0072C2ED /* KMCropSettingWindowController.xib in Resources */,
 				BBAFC84F298519F700D0648E /* KMSavePanelAccessoryController.xib in Resources */,
-				F3A0F8662CC9459400E7373F /* KMNPDFInsertClipboardWindowController.xib in Resources */,
 				BBEC00C4295C306400A26C98 /* KMBatesPropertyController.xib in Resources */,
 				ADDF83A62B391A5D00A81A4E /* DSignatureConfigWindowController.xib in Resources */,
 				BB19A76D2CB7D107008204DC /* KMHomeFilesEmptyHeaderView.xib in Resources */,
@@ -18714,7 +18701,6 @@
 				BB74DA772AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */,
 				BB6B43662A04919200E02B54 /* KMBaseViewController.swift in Sources */,
 				AD3AAD412B0B7B6C00DE5FE7 /* KMCompareManager.swift in Sources */,
-				F3A0F8612CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */,
 				AD055EB92B8843FD0035F824 /* SKToolbarItem.m in Sources */,
 				651A59832C8EA210005A35FB /* KMPurchaseEmbeddedWindowController.swift in Sources */,
 				AD055E812B88294F0035F824 /* SKBookmarkController.m in Sources */,
@@ -19077,7 +19063,6 @@
 				BB6BA4C52B0B4A0F00462CAE /* KMLeftSideEmptyFileViewController.swift in Sources */,
 				9FDD0FB329534FEA000C4DAD /* KMGlobal.swift in Sources */,
 				ADF6B87F2A485A8F0090CB78 /* KMComparativeViewCollectionItemItem.swift in Sources */,
-				F3A0F8622CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */,
 				AD3AAD892B10349600DE5FE7 /* KMHeaderFooterWindowController.swift in Sources */,
 				BBB7B4922A03AD2A00B58A5A /* KMPDFEditToolbar.swift in Sources */,
 				ADDEEA8F2AD78E4400EF675D /* KMSelfSignAnnotation.swift in Sources */,
@@ -20402,7 +20387,6 @@
 				AD7D5CD52B957442006562CD /* KMBookmarkOutlineFileCellView.swift in Sources */,
 				AD0257412A8601CD00EAD5D5 /* KMAppleLoginManager.swift in Sources */,
 				BB003037298D356E002DD1A0 /* KMPreferenceMarkupColorView.swift in Sources */,
-				F3A0F8632CC9459400E7373F /* KMNPDFInsertClipboardWindowController.swift in Sources */,
 				BB1969CF2B2833DA00922736 /* KMProgressWindowController.swift in Sources */,
 				AD7D5C942B8F20FE006562CD /* synctex_parser_utils.m in Sources */,
 				BBD7FE062A1323F000F96075 /* KMCustomTableRowView.swift in Sources */,