Ver código fonte

标记密文-新增页面标记密文窗口和其功能实现

tangchao 2 anos atrás
pai
commit
6b2a456e89

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

@@ -1558,6 +1558,12 @@
 		BBB14A5B2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5A2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift */; };
 		BBB14A5C2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5A2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift */; };
 		BBB14A5D2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5A2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift */; };
+		BBB14A5F297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5E297929BD00936EDB /* KMRedactPageRangeWindowController.swift */; };
+		BBB14A60297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5E297929BD00936EDB /* KMRedactPageRangeWindowController.swift */; };
+		BBB14A61297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A5E297929BD00936EDB /* KMRedactPageRangeWindowController.swift */; };
+		BBB14A6329792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A6229792D6900936EDB /* KMRedactPageRangeContentView.swift */; };
+		BBB14A6429792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A6229792D6900936EDB /* KMRedactPageRangeContentView.swift */; };
+		BBB14A6529792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBB14A6229792D6900936EDB /* KMRedactPageRangeContentView.swift */; };
 		BBC2BCC6295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
 		BBC2BCC7295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
 		BBC2BCC8295DA8F30036B983 /* KMCropPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */; };
@@ -2646,6 +2652,8 @@
 		BBB14A522978DD5400936EDB /* KMRedactTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactTools.swift; sourceTree = "<group>"; };
 		BBB14A562978E75D00936EDB /* KMRedactMutilPageFlagWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactMutilPageFlagWindowController.swift; sourceTree = "<group>"; };
 		BBB14A5A2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactMutilPageFlagContentView.swift; sourceTree = "<group>"; };
+		BBB14A5E297929BD00936EDB /* KMRedactPageRangeWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactPageRangeWindowController.swift; sourceTree = "<group>"; };
+		BBB14A6229792D6900936EDB /* KMRedactPageRangeContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactPageRangeContentView.swift; sourceTree = "<group>"; };
 		BBC2BCC4295DA8F30036B983 /* KMCropPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCropPreviewController.swift; sourceTree = "<group>"; };
 		BBC2BCC5295DA8F30036B983 /* KMCropPreviewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCropPreviewController.xib; sourceTree = "<group>"; };
 		BBC347FC295448DE008D2CD1 /* KMWatermarkTemplateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMWatermarkTemplateModel.swift; sourceTree = "<group>"; };
@@ -4412,6 +4420,7 @@
 				BB4EEF472976504C003A3537 /* KMRedactColorView.swift */,
 				BB4EEF4B2976544F003A3537 /* KMRedactAligementView.swift */,
 				BBB14A5A2978EBBE00936EDB /* KMRedactMutilPageFlagContentView.swift */,
+				BBB14A6229792D6900936EDB /* KMRedactPageRangeContentView.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -4469,6 +4478,7 @@
 				BB24D4A52977BE6700041659 /* KMRedactConfirmWindowController.swift */,
 				BB24D4A62977BE6700041659 /* KMRedactConfirmWindowController.xib */,
 				BBB14A562978E75D00936EDB /* KMRedactMutilPageFlagWindowController.swift */,
+				BBB14A5E297929BD00936EDB /* KMRedactPageRangeWindowController.swift */,
 			);
 			path = Window;
 			sourceTree = "<group>";
@@ -6479,6 +6489,7 @@
 				BBF38A62294F53FD0086D025 /* KMWatermarkFileView.swift in Sources */,
 				BBC3482E29559E12008D2CD1 /* KMBackgroundModel.swift in Sources */,
 				9F1F82C3292F113A0092C4B4 /* KMHomeDragView.swift in Sources */,
+				BBB14A5F297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */,
 				89E4E7822967BF5A002DBA6F /* KMCustomizeStampViewController.m in Sources */,
 				89E4E7052963D588002DBA6F /* KMBox.m in Sources */,
 				9F8DDF2D2924B855006CDC73 /* KMPDFToolsViewController.swift in Sources */,
@@ -6509,6 +6520,7 @@
 				89D2D2C129495D2100BFF5FE /* KMFormModel.swift in Sources */,
 				89316822296D73CC0073EA59 /* KMSignatureAnnotationViewController.m in Sources */,
 				BB89723A294B3C840045787C /* KMWatermarkPropertyController.swift in Sources */,
+				BBB14A6329792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */,
 				ADCB98F629274B6B00B51A03 /* KMBatchProcessingTableView.swift in Sources */,
 				BB88E43B294023CB002B3655 /* KMDocumentModel.swift in Sources */,
 				BBC3482929559B22008D2CD1 /* KMBackgroundListCell.swift in Sources */,
@@ -6963,6 +6975,7 @@
 				9F705F77291A3A84005199AD /* KMHistoryFileDeleteWindowController.swift in Sources */,
 				BBC3482F29559E12008D2CD1 /* KMBackgroundModel.swift in Sources */,
 				BB88E45929404752002B3655 /* KMPDFConvert.swift in Sources */,
+				BBB14A60297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */,
 				89E4E7832967BF5A002DBA6F /* KMCustomizeStampViewController.m in Sources */,
 				89E4E7062963D588002DBA6F /* KMBox.m in Sources */,
 				BB897252294C3F660045787C /* KMMenuTableView.swift in Sources */,
@@ -6993,6 +7006,7 @@
 				BB6DD815293486FA001F0544 /* KMSecureEncryptPasswordCellView.swift in Sources */,
 				89316823296D73CC0073EA59 /* KMSignatureAnnotationViewController.m in Sources */,
 				BB88E43C294023CB002B3655 /* KMDocumentModel.swift in Sources */,
+				BBB14A6429792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */,
 				BBC347FE295448DE008D2CD1 /* KMWatermarkTemplateModel.swift in Sources */,
 				BB6DD81D29348F31001F0544 /* KMSecureTextFiled.swift in Sources */,
 				BBC3482A29559B22008D2CD1 /* KMBackgroundListCell.swift in Sources */,
@@ -7251,6 +7265,7 @@
 				BBFE6E772930E53000142C01 /* KMMergePopoverViewController.swift in Sources */,
 				89E4E7102963D62C002DBA6F /* KMAnnotationFontWindowController.m in Sources */,
 				AD9527C0295294E20039D2BC /* KMPrintPageModel.swift in Sources */,
+				BBB14A6529792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */,
 				9FDD0F8A2952FCC6000C4DAD /* KMCompLightParser.swift in Sources */,
 				9FA607DB28F8227500B46586 /* KMBox.swift in Sources */,
 				89D2D2E4294C452B00BFF5FE /* KMPDFThumbnailView.swift in Sources */,
@@ -7565,6 +7580,7 @@
 				BB4EEF4229764FCC003A3537 /* KMWatermarkColorView.swift in Sources */,
 				BB24D4A92977BE6700041659 /* KMRedactConfirmWindowController.swift in Sources */,
 				AD4B455829408CB00076FA14 /* KMOCRChooseView.swift in Sources */,
+				BBB14A61297929BD00936EDB /* KMRedactPageRangeWindowController.swift in Sources */,
 				BB5DF1F32959C9F00025CDA1 /* KMHeaderFooterController.swift in Sources */,
 				9F8DDF2829237910006CDC73 /* Array+KMExtensions.swift in Sources */,
 				89E4E6FD2963D341002DBA6F /* KMPopUpButton.m in Sources */,

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 96 - 0
PDF Office/PDF Office/Class/PDFTools/Redact/Base/KMRedactBaseWindowController.xib

@@ -457,5 +457,101 @@
             </connections>
             <point key="canvasLocation" x="109" y="959"/>
         </customView>
+        <customView id="vvO-Qt-9B1" customClass="KMRedactPageRangeContentView" customModule="PDF_Office" customModuleProvider="target">
+            <rect key="frame" x="0.0" y="0.0" width="404" height="256"/>
+            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+            <subviews>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iCx-p6-gVj">
+                    <rect key="frame" x="14" y="209" width="61" height="18"/>
+                    <buttonCell key="cell" type="radio" title="Radio" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="N4i-F4-KV1">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9IH-86-i8h">
+                    <rect key="frame" x="14" y="180" width="61" height="18"/>
+                    <buttonCell key="cell" type="radio" title="Radio" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="nlV-IZ-ffD">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="auy-dS-iyc">
+                    <rect key="frame" x="14" y="151" width="61" height="18"/>
+                    <buttonCell key="cell" type="radio" title="Radio" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="RS5-3K-2gs">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hBi-lG-cRT">
+                    <rect key="frame" x="14" y="122" width="61" height="18"/>
+                    <buttonCell key="cell" type="radio" title="Radio" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="ppl-Dp-0vf">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="vmQ-4M-Q5n">
+                    <rect key="frame" x="14" y="93" width="61" height="18"/>
+                    <buttonCell key="cell" type="radio" title="Radio" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="uuQ-l6-E61">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                </button>
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="l6f-8u-7L2">
+                    <rect key="frame" x="87" y="86" width="140" height="32"/>
+                    <subviews>
+                        <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Kxc-cY-iKV">
+                            <rect key="frame" x="16" y="8" width="108" height="16"/>
+                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="YVu-Fw-ols">
+                                <font key="font" usesAppearanceFont="YES"/>
+                                <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                            </textFieldCell>
+                        </textField>
+                    </subviews>
+                    <constraints>
+                        <constraint firstAttribute="width" constant="140" id="2us-6c-7tE"/>
+                        <constraint firstAttribute="trailing" secondItem="Kxc-cY-iKV" secondAttribute="trailing" constant="18" id="Bja-FX-pLH"/>
+                        <constraint firstAttribute="height" constant="32" id="O4u-CU-7eF"/>
+                        <constraint firstItem="Kxc-cY-iKV" firstAttribute="leading" secondItem="l6f-8u-7L2" secondAttribute="leading" constant="18" id="gK5-Jc-fun"/>
+                        <constraint firstItem="Kxc-cY-iKV" firstAttribute="centerY" secondItem="l6f-8u-7L2" secondAttribute="centerY" id="hUt-1S-SOL"/>
+                    </constraints>
+                </customView>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="iBI-kt-5Zo">
+                    <rect key="frame" x="237" y="94" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="gCa-pa-cNO">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+            </subviews>
+            <constraints>
+                <constraint firstItem="vmQ-4M-Q5n" firstAttribute="top" secondItem="hBi-lG-cRT" secondAttribute="bottom" constant="13" id="6De-gm-TIe"/>
+                <constraint firstItem="iCx-p6-gVj" firstAttribute="leading" secondItem="vvO-Qt-9B1" secondAttribute="leading" constant="16" id="6lu-iW-ggB"/>
+                <constraint firstItem="hBi-lG-cRT" firstAttribute="leading" secondItem="vvO-Qt-9B1" secondAttribute="leading" constant="16" id="Dad-2a-LoG"/>
+                <constraint firstItem="iCx-p6-gVj" firstAttribute="top" secondItem="vvO-Qt-9B1" secondAttribute="top" constant="30" id="F8v-Sm-yA6"/>
+                <constraint firstItem="iBI-kt-5Zo" firstAttribute="leading" secondItem="l6f-8u-7L2" secondAttribute="trailing" constant="12" id="TbS-3W-qgq"/>
+                <constraint firstItem="vmQ-4M-Q5n" firstAttribute="leading" secondItem="vvO-Qt-9B1" secondAttribute="leading" constant="16" id="YOK-DH-6i6"/>
+                <constraint firstItem="iBI-kt-5Zo" firstAttribute="centerY" secondItem="l6f-8u-7L2" secondAttribute="centerY" id="bpY-ov-laU"/>
+                <constraint firstItem="auy-dS-iyc" firstAttribute="leading" secondItem="vvO-Qt-9B1" secondAttribute="leading" constant="16" id="c0j-M1-nA6"/>
+                <constraint firstItem="hBi-lG-cRT" firstAttribute="top" secondItem="auy-dS-iyc" secondAttribute="bottom" constant="13" id="dZG-hO-MX8"/>
+                <constraint firstItem="9IH-86-i8h" firstAttribute="top" secondItem="iCx-p6-gVj" secondAttribute="bottom" constant="13" id="hdK-nG-wYZ"/>
+                <constraint firstItem="auy-dS-iyc" firstAttribute="top" secondItem="9IH-86-i8h" secondAttribute="bottom" constant="13" id="lfl-iC-lf2"/>
+                <constraint firstItem="9IH-86-i8h" firstAttribute="leading" secondItem="vvO-Qt-9B1" secondAttribute="leading" constant="16" id="pfB-tW-fim"/>
+                <constraint firstItem="l6f-8u-7L2" firstAttribute="centerY" secondItem="vmQ-4M-Q5n" secondAttribute="centerY" id="qwc-fP-hjt"/>
+                <constraint firstItem="l6f-8u-7L2" firstAttribute="leading" secondItem="vmQ-4M-Q5n" secondAttribute="trailing" constant="12" id="xhi-0k-yCW"/>
+            </constraints>
+            <connections>
+                <outlet property="allPageRadio" destination="9IH-86-i8h" id="MZU-sy-mIn"/>
+                <outlet property="currentPageRadio" destination="iCx-p6-gVj" id="lLW-Vg-Dsk"/>
+                <outlet property="customPageRadio" destination="vmQ-4M-Q5n" id="LOm-cI-8eL"/>
+                <outlet property="evenPageRadio" destination="hBi-lG-cRT" id="dpb-Du-sb8"/>
+                <outlet property="inputTextField" destination="Kxc-cY-iKV" id="uYV-0h-90K"/>
+                <outlet property="inputView" destination="l6f-8u-7L2" id="vRW-l9-pPW"/>
+                <outlet property="oddPageRadio" destination="auy-dS-iyc" id="bNm-xB-xcT"/>
+                <outlet property="totalNumberLabel" destination="iBI-kt-5Zo" id="yAy-zu-LHx"/>
+            </connections>
+            <point key="canvasLocation" x="109" y="1255"/>
+        </customView>
     </objects>
 </document>

+ 1 - 1
PDF Office/PDF Office/Class/PDFTools/Redact/Tools/KMRedactTools.swift

@@ -50,7 +50,7 @@ class KMRedactTools: NSObject {
         } else if (type == 4) {
             let array = KMPageRangeTools.findSelectPage(pageRangeString: string, pageCount: pageCount)
             for i in array {
-                indexs.insert(i)
+                indexs.insert(i-1)
             }
         }
         return indexs

+ 3 - 3
PDF Office/PDF Office/Class/PDFTools/Redact/View/KMRedactMutilPageFlagContentView.swift

@@ -26,9 +26,9 @@ class KMRedactMutilPageFlagContentView: KMRedactContentBaseView {
         }
     }
     
-    override func draw(_ dirtyRect: NSRect) {
-        super.draw(dirtyRect)
-
+    override func awakeFromNib() {
+        super.awakeFromNib()
+        
         self.allPageRadio.title = "所有页面"
         self.oddPageRadio.title = "奇数页"
         self.evenPageRadio.title = "偶数页"

+ 99 - 0
PDF Office/PDF Office/Class/PDFTools/Redact/View/KMRedactPageRangeContentView.swift

@@ -0,0 +1,99 @@
+//
+//  KMRedactPageRangeContentView.swift
+//  PDF Office
+//
+//  Created by tangchao on 2023/1/19.
+//
+
+import Cocoa
+
+class KMRedactPageRangeContentView: KMRedactContentBaseView {
+
+    @IBOutlet weak var currentPageRadio: NSButton!
+    @IBOutlet weak var allPageRadio: NSButton!
+    @IBOutlet weak var oddPageRadio: NSButton!
+    @IBOutlet weak var evenPageRadio: NSButton!
+    @IBOutlet weak var customPageRadio: NSButton!
+    @IBOutlet weak var inputView: NSView!
+    @IBOutlet weak var inputTextField: NSTextField!
+    @IBOutlet weak var totalNumberLabel: NSTextField!
+    
+    var pageCount: Int {
+        get {
+            -1
+        }
+        set {
+            self.totalNumberLabel.stringValue = "/\(newValue)"
+        }
+    }
+    
+    override func awakeFromNib() {
+        super.awakeFromNib()
+        
+        self.currentPageRadio.title = "当前页面"
+        self.allPageRadio.title = "全部页面"
+        self.oddPageRadio.title = "奇数页面"
+        self.evenPageRadio.title = "偶数页面"
+        self.customPageRadio.title = "指定页面范围"
+        
+        for radio in [self.currentPageRadio, self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] {
+            radio?.target = self
+            radio?.action = #selector(radioAction)
+        }
+        
+        selectRadio(self.currentPageRadio)
+        
+        self.inputView.wantsLayer = true
+        self.inputView.layer?.backgroundColor = NSColor(white: 238.0/255.0, alpha: 1.0).cgColor
+        self.inputTextField.placeholderString = "eg. 1,3-5,10"
+        self.inputTextField.focusRingType = .none
+        self.inputTextField.delegate = self
+    }
+    
+    @objc private func radioAction(sender: NSButton) {
+        selectRadio(sender)
+        
+        guard let callback = self.itemClick else {
+            return
+        }
+        
+        var index: Int = 1
+        for radio in [self.currentPageRadio, self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] {
+            if ((radio?.isEqual(to: sender))!) {
+                break
+            }
+            index += 1
+        }
+        
+        callback(index, nil)
+    }
+    
+    private func selectRadio(_ selectedRadio: NSButton) {
+        for radio in [self.currentPageRadio, self.allPageRadio, self.oddPageRadio, self.evenPageRadio, self.customPageRadio] {
+            if ((radio?.isEqual(to: selectedRadio))!) {
+                radio?.state = .on
+            } else {
+                radio?.state = .off
+            }
+        }
+        
+        if (customPageRadio.state == .on) {
+            self.inputTextField.isEditable = true
+        } else {
+            self.inputTextField.isEditable = false
+        }
+    }
+}
+
+extension KMRedactPageRangeContentView: NSTextFieldDelegate {
+    func controlTextDidChange(_ obj: Notification) {
+        if ((self.inputTextField.isEqual(to: obj.object)) == false) {
+            return
+        }
+        
+        guard let callback = self.itemClick else {
+            return
+        }
+        callback(6, self.inputTextField.stringValue)
+    }
+}

+ 49 - 0
PDF Office/PDF Office/Class/PDFTools/Redact/Window/KMRedactPageRangeWindowController.swift

@@ -0,0 +1,49 @@
+//
+//  KMRedactPageRangeWindowController.swift
+//  PDF Office
+//
+//  Created by tangchao on 2023/1/19.
+//
+
+import Cocoa
+
+class KMRedactPageRangeWindowController: KMRedactBaseWindowController {
+
+    var pageType: Int = 1
+    var pageString: String = ""
+    
+    override func windowDidLoad() {
+        super.windowDidLoad()
+    
+        self.setContentSize(NSSize(width: 404, height: 336))
+        
+        self.titleLabel.stringValue = "标记密文页面范围"
+        self.funcButton.title = NSLocalizedString("确认", comment: "")
+        self.funcButton.layer?.backgroundColor = NSColor.black.cgColor
+        self.funcButton.attributedTitle = NSMutableAttributedString(string: self.funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
+        
+        let contentView = KMRedactPageRangeContentView.createFromNib()
+        contentView?.frame = self.contentBox.contentView!.bounds
+        contentView?.autoresizingMask = [.width,.height]
+        self.contentBox.contentView?.addSubview(contentView!)
+        self.contentView = contentView
+        contentView?.pageCount = self.pageCount
+        
+        contentView?.itemClick = {[weak self] index, value in
+            if (index == 1) { /// 当前页面
+                self!.pageType = 1
+            } else if (index == 2) { /// 全部页面
+                self!.pageType = 2
+            } else if (index == 3) { /// 奇数页面
+                self!.pageType = 3
+            } else if (index == 4) { /// 偶数页面
+                self!.pageType = 4
+            } else if (index == 5) { /// 自定义页面
+                self!.pageType = 5
+            } else if (index == 6) {
+                self?.pageString = value as! String
+            }
+        }
+    }
+
+}

+ 9 - 2
PDF Office/PDF Office/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -175,11 +175,18 @@ class KMToolbarController: NSViewController {
     
     func fetchTopBarView() -> NSView? {
         let topBarView = self.mainToolBarView?.toolbar.subviews.last
-        if (topBarView == nil || topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self) == false) {
+        if (topBarView == nil) {
             return nil
         }
+        if (topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self) == true) {
+            return topBarView
+        }
+        
+        if (topBarView?.isKind(of: KMRedactTopToolBar.self) == true) {
+            return topBarView
+        }
         
-        return topBarView
+        return nil
     }
     
     func enterRedact() {

+ 50 - 0
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1088,6 +1088,56 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 return
             }
             if (index == 5) { /// 页面
+                let windowController = KMRedactPageRangeWindowController(windowNibName: "KMRedactBaseWindowController")
+                self.view.window?.beginSheet(windowController.window!)
+                self.currentWindowController = windowController
+                
+                windowController.itemClick = { [weak self] index, value in
+                    if (index == 1) {
+                        let topBarView = self?.toolbarController.fetchTopBarView()
+                        if (topBarView == nil || topBarView?.isKind(of: KMRedactTopToolBar.self) == false) {
+                            return
+                        }
+                        (topBarView as! KMRedactTopToolBar).selectItem(0)
+                        self?.view.window?.endSheet((self?.currentWindowController.window)!)
+                        self?.currentWindowController = nil
+                        return
+                    }
+                    
+                    let windowController_pageRange = self?.currentWindowController as! KMRedactPageRangeWindowController
+                    let pageType = windowController_pageRange.pageType
+                    let pageString = windowController_pageRange.pageString
+                    if (pageType == 5) { /// 自定义页面
+                        let array = KMPageRangeTools.findSelectPage(pageRangeString: pageString, pageCount: Int((self?.listView.document.pageCount)!))
+                        if (array.count == 0) {
+                            let alert = NSAlert()
+                            alert.messageText = "页面范围有误"
+                            alert.runModal()
+                            return
+                        }
+                    }
+                    
+                    self!.view.window?.endSheet(self!.currentWindowController.window!)
+                    self!.currentWindowController = nil
+                    var indexs: IndexSet = []
+                    if (pageType == 1) { /// 当前页面
+                        indexs.insert((self?.listView.currentPageIndex)!)
+                    } else {
+                        indexs = KMRedactTools.getPageIndexs(pageType-1, string: pageString, Int((self?.listView.document.pageCount)!))
+                    }
+                    
+                    if (indexs.count == 0) {
+                        return
+                    }
+                    
+                    for i in indexs {
+                        let page: CPDFPage = (self?.listView.document.page(at: UInt(i)))!
+                        let redactAnno = CPDFRedactAnnotation(pdfListViewNoteWith: self?.listView.document)
+                        redactAnno?.bounds = page.bounds
+                        self?.listView.add(redactAnno, to: page)
+                    }
+                }
+                
                 return
             }
         }

+ 1 - 1
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -87,7 +87,7 @@ import Cocoa
         self.rightSideViewController.propertyDidChange = {
             [weak self] (model: AnyObject?) in
             let topBarView = self?.toolbarController.fetchTopBarView()
-            if (topBarView == nil) {
+            if (topBarView == nil || ((topBarView?.isKind(of: KMWatermarkAdjectiveTopBarView.self)) == false)) {
                 return
             }