Browse Source

【注释回复】UI补充

tangchao 5 months ago
parent
commit
078a77dd3b

+ 74 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteFooterCellView.swift

@@ -9,7 +9,8 @@ import Cocoa
 
 class KMNoteFooterCellView: NSTableCellView, NibLoadable {
     @IBOutlet weak var replyBox: NSBox!
-    @IBOutlet weak var inputBox: NSBox!
+    @IBOutlet weak var inputBox: KMBox!
+    @IBOutlet weak var inputTextF: KMTextField!
     @IBOutlet weak var replyButton: NSButton!
     @IBOutlet weak var cancelButton: NSButton!
     
@@ -23,8 +24,13 @@ class KMNoteFooterCellView: NSTableCellView, NibLoadable {
     @IBOutlet weak var operationIv2: NSImageView!
     @IBOutlet weak var operationButton: NSButton!
     
+    @IBOutlet weak var inputBoxHeightConst: NSLayoutConstraint!
+    @IBOutlet weak var replyButtonTopConst: NSLayoutConstraint!
+    
     var itemClick: KMCommonClickBlock?
     
+    private var flag_ = false
+    
     override func draw(_ dirtyRect: NSRect) {
         
         super.draw(dirtyRect)
@@ -35,6 +41,37 @@ class KMNoteFooterCellView: NSTableCellView, NibLoadable {
     override func awakeFromNib() {
         super.awakeFromNib()
         
+        self.flag_ = false
+        
+        self.inputBox.borderColor = NSColor(white: 0, alpha: 0.2)
+        self.inputBox.fillColor = .white
+        self.inputBox.moveCallback = { [weak self] enter, theBox in
+            if enter {
+                theBox.borderColor = NSColor.km_init(hex: "#1770F4")
+            } else {
+//                let focus = theBox.window?.firstResponder == self?.inputTextF
+                let focus = self?.flag_ ?? false
+                if focus == false {
+                    theBox.borderColor = NSColor(white: 0, alpha: 0.2)
+                }
+            }
+        }
+        self.inputTextF.drawsBackground = false
+        self.inputTextF.isBordered = false
+        self.inputTextF.isBezeled = false
+        self.inputTextF.focusRingType = .none
+        self.inputTextF.backgroundColor = .clear
+        self.inputTextF.wantsLayer = true
+        self.inputTextF.layer?.backgroundColor = .clear
+        self.inputTextF.delegate = self
+        self.inputTextF.firstResponderHandler = { [weak self] result in
+            self?.flag_ = result
+            if result {
+                self?.inputBox.borderColor = NSColor.km_init(hex: "#1770F4")
+            } else {
+                self?.inputBox.borderColor = NSColor(white: 0, alpha: 0.2)
+            }
+        }
         self.replyButton.title = NSLocalizedString("Reply", comment: "")
         self.replyButton.wantsLayer = true
         self.replyButton.setTitleColor(color: .white, font: .SFProTextRegularFont(14))
@@ -58,10 +95,36 @@ class KMNoteFooterCellView: NSTableCellView, NibLoadable {
         self.operationButton.title = ""
         self.operationButton.target = self
         self.operationButton.action = #selector(operationAction)
+        
+        self.updateUI(expand: false, animated: false)
+    }
+    
+    func updateUI(expand: Bool, animated: Bool) {
+        if expand {
+            // 64
+            if animated {
+                self.inputBoxHeightConst.animator().constant = 64
+            } else {
+                self.inputBoxHeightConst.constant = 64
+            }
+            // 12
+            self.replyButtonTopConst.constant = 8
+            self.replyBox.isHidden = false
+        } else {
+            // 64
+            if animated {
+                self.inputBoxHeightConst.animator().constant = 0
+            } else {
+                self.inputBoxHeightConst.constant = 0
+            }
+            // 12
+            self.replyButtonTopConst.constant = 0
+            self.replyBox.isHidden = true
+        }
     }
     
     @objc func replyAction(_ sender: NSButton) {
-        self.itemClick?(3)
+        self.itemClick?(3, self.inputTextF.stringValue)
     }
     
     @objc func cancelAction(_ sender: NSButton) {
@@ -76,3 +139,12 @@ class KMNoteFooterCellView: NSTableCellView, NibLoadable {
         self.itemClick?(2, sender)
     }
 }
+
+extension KMNoteFooterCellView: NSTextFieldDelegate {
+    func controlTextDidEndEditing(_ obj: Notification) {
+        if self.inputTextF.isEqual(to: obj.object) {
+            self.inputBox.borderColor = NSColor(white: 0, alpha: 0.2)
+            self.flag_ = false
+        }
+    }
+}

+ 25 - 4
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteFooterCellView.xib

@@ -14,31 +14,49 @@
                 <outlet property="commentIv" destination="M9A-Ef-540" id="wQx-Fk-oUm"/>
                 <outlet property="commentNumberLabel" destination="qTH-Ub-ikb" id="Gcb-LO-BTR"/>
                 <outlet property="inputBox" destination="nRc-Dh-PEL" id="Opi-DP-7vf"/>
+                <outlet property="inputBoxHeightConst" destination="Mlc-8C-aLh" id="tJ4-lF-HtB"/>
+                <outlet property="inputTextF" destination="HuQ-4F-E6t" id="Zih-DQ-Hma"/>
                 <outlet property="operationBox" destination="D8j-Z1-l9J" id="70j-Kc-RgO"/>
                 <outlet property="operationButton" destination="7m2-cH-Gl5" id="KLF-9o-FZU"/>
                 <outlet property="operationIv" destination="nhM-fn-Lml" id="0XX-Wz-2NY"/>
                 <outlet property="operationIv2" destination="33u-Me-AUW" id="xAb-2S-GWS"/>
                 <outlet property="replyBox" destination="Zps-kZ-RvQ" id="sqd-Ip-mVO"/>
                 <outlet property="replyButton" destination="d2W-fA-bBI" id="tcc-kg-HEU"/>
+                <outlet property="replyButtonTopConst" destination="fbR-we-VWb" id="uOo-fO-yWA"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="c22-O7-iKe" customClass="KMNoteFooterCellView" customModule="PDF_Reader_Pro" customModuleProvider="target">
-            <rect key="frame" x="0.0" y="0.0" width="453" height="112"/>
+            <rect key="frame" x="0.0" y="0.0" width="453" height="108"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <box borderType="line" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="Zps-kZ-RvQ">
-                    <rect key="frame" x="-3" y="44" width="459" height="70"/>
+                    <rect key="frame" x="-3" y="40" width="459" height="70"/>
                     <view key="contentView" id="fr9-7p-tnW">
                         <rect key="frame" x="3" y="3" width="453" height="64"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="nRc-Dh-PEL">
+                            <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="nRc-Dh-PEL" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                 <rect key="frame" x="32" y="32" width="409" height="32"/>
                                 <view key="contentView" id="fIS-wd-lpj">
                                     <rect key="frame" x="1" y="1" width="407" height="30"/>
                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                                    <subviews>
+                                        <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HuQ-4F-E6t" customClass="KMTextField" customModule="PDF_Reader_Pro" customModuleProvider="target">
+                                            <rect key="frame" x="4" y="7" width="399" height="16"/>
+                                            <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="6De-hm-do0">
+                                                <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 firstItem="HuQ-4F-E6t" firstAttribute="leading" secondItem="fIS-wd-lpj" secondAttribute="leading" constant="6" id="YVY-9j-nCm"/>
+                                        <constraint firstAttribute="trailing" secondItem="HuQ-4F-E6t" secondAttribute="trailing" constant="6" id="gLj-B4-sPn"/>
+                                        <constraint firstItem="HuQ-4F-E6t" firstAttribute="centerY" secondItem="fIS-wd-lpj" secondAttribute="centerY" id="vMs-zf-pbd"/>
+                                    </constraints>
                                 </view>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="32" id="SYy-3T-Ng5"/>
@@ -171,7 +189,7 @@
                 <constraint firstAttribute="bottom" secondItem="AKC-lX-l6Q" secondAttribute="bottom" constant="12" id="Nol-iE-7UE"/>
                 <constraint firstAttribute="trailing" secondItem="Zps-kZ-RvQ" secondAttribute="trailing" id="RVa-g5-2Gl"/>
                 <constraint firstItem="Zps-kZ-RvQ" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="UP8-yd-0EJ"/>
-                <constraint firstItem="AKC-lX-l6Q" firstAttribute="top" secondItem="Zps-kZ-RvQ" secondAttribute="bottom" constant="16" id="fbR-we-VWb"/>
+                <constraint firstItem="AKC-lX-l6Q" firstAttribute="top" secondItem="Zps-kZ-RvQ" secondAttribute="bottom" constant="12" id="fbR-we-VWb"/>
                 <constraint firstAttribute="trailing" secondItem="AKC-lX-l6Q" secondAttribute="trailing" constant="12" id="gFB-6P-VV3"/>
                 <constraint firstItem="AKC-lX-l6Q" firstAttribute="leading" secondItem="D8j-Z1-l9J" secondAttribute="trailing" constant="16" id="gdQ-4H-R9l"/>
                 <constraint firstItem="Zps-kZ-RvQ" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="klZ-3P-NUk"/>
@@ -183,12 +201,15 @@
                 <outlet property="commentIv" destination="M9A-Ef-540" id="EVD-Dc-BoI"/>
                 <outlet property="commentNumberLabel" destination="qTH-Ub-ikb" id="Jig-To-gZK"/>
                 <outlet property="inputBox" destination="nRc-Dh-PEL" id="2fg-aA-Cce"/>
+                <outlet property="inputBoxHeightConst" destination="Mlc-8C-aLh" id="WTX-ef-oKU"/>
+                <outlet property="inputTextF" destination="HuQ-4F-E6t" id="Joi-Nr-pTm"/>
                 <outlet property="operationBox" destination="D8j-Z1-l9J" id="O4w-ur-fTG"/>
                 <outlet property="operationButton" destination="7m2-cH-Gl5" id="tTi-vO-4R6"/>
                 <outlet property="operationIv" destination="nhM-fn-Lml" id="4eY-xa-myG"/>
                 <outlet property="operationIv2" destination="33u-Me-AUW" id="JAg-dD-R7S"/>
                 <outlet property="replyBox" destination="Zps-kZ-RvQ" id="IzR-7Q-Nck"/>
                 <outlet property="replyButton" destination="d2W-fA-bBI" id="MNi-3b-r36"/>
+                <outlet property="replyButtonTopConst" destination="fbR-we-VWb" id="BOc-wA-UTX"/>
             </connections>
             <point key="canvasLocation" x="-42.5" y="59.5"/>
         </customView>

+ 3 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -1000,12 +1000,15 @@ extension KMLeftSideViewController {
                     replyM.anno = anno
                     replyM.replyAnno = replyAnno
 //                    secM?.items.append(replyM)
+                    replyM.annoModel = item
                     item.replyAnnos.append(replyM)
                 }
                 
                 let footerI = KMBotaAnnotationFooterModel()
                 footerI.anno = anno
                 secM?.items.append(footerI)
+                item.footerModel = footerI
+                footerI.annoModel = item
 //                }
                 
 //                let item = KMBotaAnnotationModel()

+ 26 - 4
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -2096,14 +2096,32 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     cell?.operationIv.image = NSImage(named: "KMImageNameBotaNoteStateRejected")
                 }
                 
+                cell?.updateUI(expand: data.isExpand, animated: data.animated)
+                data.animated = false
+                
                 cell?.itemClick = { [weak self] idx, param in
                     if idx == 1 { // comment
-                        KMPrint("comment")
+                        data.isExpand = !data.isExpand
+                        data.animated = true
+                        self?.noteOutlineView.reloadItem(data)
                     } else if idx == 2 { //
                         self?.noteReplyHanddler.showStatePopView(sender: param.first as! NSView, anno: data.anno)
                     } else if idx == 3 { // reply
-                        if let _ = self?.noteReplyHanddler.createReplyAnnotation(data.anno, content: "Here is the focus of the work Here is the focus of the work Here is the focus of the work", userName: KMPreference.shared.author) {
-                            self?.reloadAnnotation()
+                        let content = param.first as? String ?? ""
+                        if content.isEmpty {
+                            Task {
+                                _ = await KMAlertTool.runModel(message: NSLocalizedString("Error", comment: ""))
+                            }
+                            return
+                        }
+                        if let replyAnno = self?.noteReplyHanddler.createReplyAnnotation(data.anno, content: content, userName: KMPreference.shared.author) {
+//                            self?.reloadAnnotation()
+                            let model = KMBotaAnnotationReplyModel()
+                            model.anno = data.anno
+                            model.replyAnno = replyAnno
+                            model.annoModel = data.annoModel
+                            data.annoModel?.replyAnnos.append(model)
+                            self?.noteOutlineView.reloadData()
                         }
                     } else if idx == 4 { // cancel
                         
@@ -2171,9 +2189,13 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     }
                 }
             }
-            cell.isUnFoldNote = { cellNote, isUnfold in
+            cell.isUnFoldNote = { [weak self] cellNote, isUnfold in
                 // 将折叠状态记录到模型
                 model?.foldType = isUnfold  ? .unfold : .fold
+                
+//                self?.note_reloadDataForAnnoIfNeed(anno: <#T##CPDFAnnotation#>)
+                model?.footerModel?.isExpand = isUnfold
+                self?.noteOutlineView.reloadItem(model?.footerModel)
             }
             return cell
         }

+ 5 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Model/KMAnnotationModel.swift

@@ -13,6 +13,7 @@ class KMAnnotationModel: NSObject {
 
 class KMBotaAnnotationBaseModel: KMAnnotationModel {
     var isExpand = false
+    var animated = false
 }
 
 class KMBotaAnnotationModel: KMBotaAnnotationBaseModel {
@@ -23,6 +24,7 @@ class KMBotaAnnotationModel: KMBotaAnnotationBaseModel {
     var foldType: KMFoldType    = .none
     var foldH: CGFloat = 30
     
+    weak var footerModel: KMBotaAnnotationFooterModel?
     var replyAnnos: [KMBotaAnnotationReplyModel] = []
     
     func isFold() -> Bool {
@@ -47,12 +49,14 @@ class KMBotaAnnotationModel: KMBotaAnnotationBaseModel {
 }
 
 class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel {
-    
+    weak var annoModel: KMBotaAnnotationModel?
 }
 
 class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel {
     // weak
     var replyAnno: CPDFAnnotation?
+    
+    weak var annoModel: KMBotaAnnotationModel?
 }
 
 class KMBotaAnnotationSectionModel: NSObject {