Browse Source

【2025】【Edit】页眉页脚列表右键操作完善

niehaoyu 4 weeks ago
parent
commit
b2499e3fb1

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/Redact/Window/KMRedactPropertiesWindowController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="23504" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="23504"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -39,7 +39,7 @@
             <windowStyleMask key="styleMask" titled="YES" fullSizeContentView="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="1164" y="250" width="554" height="862"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
             <value key="minSize" type="size" width="360" height="406"/>
             <view key="contentView" id="se5-gp-TjO">
                 <rect key="frame" x="0.0" y="0.0" width="356" height="470"/>

+ 21 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/HeaderFooter/KMHeaderFooterManager.swift

@@ -110,6 +110,27 @@ class KMHeaderFooterManager: NSObject {
         return result
     }
     
+    func removeAllHeaderFooters() -> Bool {
+        if (!FileManager.default.fileExists(atPath: kHeaderFooterPlistPath!)) {
+            return false
+        }
+         
+        let dictionary = NSDictionary(contentsOfFile: kHeaderFooterPlistPath!)
+        var newDictionary: NSMutableDictionary!
+        if (dictionary != nil) {
+            newDictionary = NSMutableDictionary(dictionary: dictionary!)
+        } else {
+            newDictionary = NSMutableDictionary()
+        }
+        newDictionary.removeAllObjects()
+        
+        let result = newDictionary.write(toFile: kHeaderFooterPlistPath!, atomically: true)
+        if (result) {
+            self.headFooterObjects.removeAll()
+        }
+        return result
+    }
+    
     func updateHeaderFooter(theModel: KMHeaderFooterModel) -> Bool {
         var flagModel: KMHeaderFooterModel!
         for model in self.headFooterObjects {

+ 117 - 1
PDF Office/PDF Master/KMClass/KMPDFViewController/HeaderFooter/Views/KMHFTemplateController.swift

@@ -31,6 +31,9 @@ class KMHFTemplateController: NSViewController {
     
     weak open var delegate: KMHFTemplateControllerDelegate?
     
+    var groupView: ComponentGroup?
+    var editCell: KMHeaderTemplateItem?
+    
     var selectedModel: KMHeaderFooterModel?
     
     override func viewDidLoad() {
@@ -125,6 +128,78 @@ class KMHFTemplateController: NSViewController {
             delegate?.templateControllerDidAddData?(self)
         }
     }
+    
+    override func rightMouseUp(with event: NSEvent) {
+        super.rightMouseUp(with: event)
+        
+        var items: [String] = []
+        var point = self.view.convert(event.locationInWindow, from: nil)
+        let collectionPoint = self.view.convert(point, to: collectionView)
+        
+        self.editCell = nil
+        
+        if let indexPath = self.collectionView.indexPathForItem(at: collectionPoint) {
+            let cellView = collectionView.item(at: indexPath) as? KMHeaderTemplateItem
+            self.editCell = cellView
+            items.append(KMLocalizedString("Rename"))
+            items.append(KMLocalizedString("Edit"))
+            items.append(KMLocalizedString("Delete"))
+            items.append(KMLocalizedString("Remove All"))
+            
+            self.showGroupView(items, event.locationInWindow)
+        }
+    }
+    
+    func showRenameWindow() {
+        let saveWindow: KMWatermarkSaveWindow = KMWatermarkSaveWindow(windowNibName: "KMWatermarkSaveWindow")
+        if let item = self.editCell, let name = item.dataModel?.name {
+            saveWindow.nameValue = name
+        } else {
+            saveWindow.nameValue = ""
+        }
+        saveWindow.saveHandler = {[weak self] string in
+            guard let weakSelf = self else { return }
+            DispatchQueue.main.async {
+                weakSelf.editCell?.dataModel?.name = string ?? ""
+                if let model = weakSelf.editCell?.dataModel, KMHeaderFooterManager.defaultManager.updateHeaderFooter(theModel: model) {
+                    weakSelf.reloadData()
+                }
+            }
+        }
+        saveWindow.own_beginSheetModal(for: view.window) { string in
+            
+        }
+        saveWindow.titleLabel.stringValue = KMLocalizedString("Rename")
+    }
+    
+    func showGroupView(_ items: [String], _ point: CGPoint) {
+        var viewHeight: CGFloat = 8
+        var menuItemArr: [ComponentMenuitemProperty] = []
+        for i in items {
+            let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
+                                                                                           itemSelected: false,
+                                                                                           isDisabled: false,
+                                                                                           keyEquivalent: nil,
+                                                                                           text: KMLocalizedString(i),
+                                                                                           identifier: i)
+            menuItemArr.append(properties_Menuitem)
+            viewHeight += 36
+        }
+        
+        if groupView == nil {
+            groupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
+        }
+        groupView?.groupDelegate = self
+        var viewPoint = point
+        viewPoint.y -= viewHeight
+
+        groupView?.frame = CGRectMake(310, 0, 200, viewHeight)
+        groupView?.updateGroupInfo(menuItemArr)
+        groupView?.showWithPoint(viewPoint, relativeTo: nil)
+         
+    }
+    
+    
 }
 
 //MARK: - NSCollectionViewDelegate, NSCollectionViewDataSource
@@ -214,7 +289,7 @@ extension KMHFTemplateController: KMHeaderTemplateItemDelegate {
         if let data = view.dataModel {
             let alert = NSAlert()
             alert.alertStyle = .critical
-            alert.messageText = String(format: KMLocalizedString("Are you sure you want to remove the background?"))
+            alert.messageText = String(format: KMLocalizedString("Are you sure you want to remove the Header&Footer?"))
             alert.addButton(withTitle: KMLocalizedString("Delete"))
             alert.addButton(withTitle: KMLocalizedString("Cancel"))
             
@@ -231,4 +306,45 @@ extension KMHFTemplateController: KMHeaderTemplateItemDelegate {
             }
         }
     }
+    
+    func kmHeaderTemplateItemDidDeleteAll() {
+        let alert = NSAlert()
+        alert.alertStyle = .critical
+        alert.messageText = String(format: KMLocalizedString("Are you sure you want to remove all the Header&Footer?"))
+        alert.addButton(withTitle: KMLocalizedString("Delete"))
+        alert.addButton(withTitle: KMLocalizedString("Cancel"))
+        
+        alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
+            if response == .alertFirstButtonReturn {
+                let _ = KMHeaderFooterManager.defaultManager.removeAllHeaderFooters()
+                if let _ = self.selectedModel {
+                    self.selectedModel = nil
+                    
+                    self.delegate?.templateControllerDidSelectedChanged?(self)
+                }
+                self.reloadData()
+            }
+        }
+    }
+}
+
+//MARK: - ComponentGroupDelegate
+extension KMHFTemplateController: ComponentGroupDelegate {
+    func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
+        if menuItemProperty?.identifier == KMLocalizedString("Rename") {
+            self.showRenameWindow()
+        } else if menuItemProperty?.identifier == KMLocalizedString("Edit") {
+            if let cell = self.editCell {
+                self.kmHeaderTemplateItemDidEdit(cell)
+            }
+        } else if menuItemProperty?.identifier == KMLocalizedString("Delete") {
+            if let cell = self.editCell {
+                self.kmHeaderTemplateItemDidDelete(cell)
+            }
+        } else if menuItemProperty?.identifier == KMLocalizedString("Remove All") {
+            self.kmHeaderTemplateItemDidDeleteAll()
+            
+        }
+    }
+    
 }