Browse Source

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

tangchao 1 year ago
parent
commit
de00b03fbc

+ 54 - 135
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/Cell/KMHomeHistoryCollectionItem.swift

@@ -8,10 +8,10 @@
 import Cocoa
 
 
-typealias KMHomeHistoryCollectionItemShowPathAction = (_ view: KMHomeHistoryCollectionItem) -> Void
-typealias KMHomeHistoryCollectionItemRemovePathAction = (_ view: KMHomeHistoryCollectionItem) -> Void
-typealias KMHomeHistoryCollectionItemMouseMoveAction = (_ view: KMHomeHistoryCollectionItem, _ enter: Bool) -> Void
-typealias KMHomeHistoryCollectionItemMouseDobleClickAction = (_ view: KMHomeHistoryCollectionItem, _ url: URL) -> Void
+typealias KMHomeHistoryCollectionItemShowPathAction = (_ view: KMHomeHistoryCollectionItem, _ item: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeHistoryCollectionItemRemovePathAction = (_ view: KMHomeHistoryCollectionItem, _ item: KMHomeHistoryListViewModel) -> Void
+//typealias KMHomeHistoryCollectionItemMouseMoveAction = (_ view: KMHomeHistoryCollectionItem, _ enter: Bool) -> Void
+typealias KMHomeHistoryCollectionItemMouseDobleClickAction = (_ view: KMHomeHistoryCollectionItem, _ item: KMHomeHistoryListViewModel) -> Void
 
 class KMHomeHistoryCollectionItem: NSCollectionViewItem {
 
@@ -32,7 +32,7 @@ class KMHomeHistoryCollectionItem: NSCollectionViewItem {
     @IBOutlet weak var verticalTitleLabel: NSTextField!
     @IBOutlet weak var showImageView: NSImageView!
     
-    var url: URL? {
+    var model: KMHomeHistoryListViewModel? {
         didSet {
             self.reloadData()
         }
@@ -45,7 +45,7 @@ class KMHomeHistoryCollectionItem: NSCollectionViewItem {
 
     var showPathAction: KMHomeHistoryCollectionItemShowPathAction?
     var removeAction: KMHomeHistoryCollectionItemRemovePathAction?
-    var mouseMoveAction: KMHomeHistoryCollectionItemMouseMoveAction?
+//    var mouseMoveAction: KMHomeHistoryCollectionItemMouseMoveAction?
     var mouseDobleClickAction: KMHomeHistoryCollectionItemMouseDobleClickAction?
     
     
@@ -53,7 +53,7 @@ class KMHomeHistoryCollectionItem: NSCollectionViewItem {
         super.viewDidLoad()
         // Do view setup here.
         // 使用自动布局设置 item 宽度等于父视图的宽度
-       view.translatesAutoresizingMaskIntoConstraints = false
+//       view.translatesAutoresizingMaskIntoConstraints = false
         
         self.setup()
     }
@@ -66,6 +66,31 @@ class KMHomeHistoryCollectionItem: NSCollectionViewItem {
         self.view.wantsLayer = true;
         self.view.layer?.cornerRadius = 4.0
         
+        self.iconImageView.backgroundColor(NSColor.red)
+        
+        self.contentBox.border(NSColor.clear, 0, 8)
+        self.contentBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
+            if mouseEntered {
+                if self.showType == .horizontal {
+                    self.handleView.isHidden = false
+                    self.contentBox.fillColor = KMAppearance.Status.hovColor()
+                } else {
+                    self.showImageView.border(KMAppearance.Interactive.a0Color(), 1, 4)
+                    self.verticalTitleLabel.backgroundColor(KMAppearance.Interactive.a0Color())
+                    self.verticalTitleLabel.textColor = KMAppearance.Layout.w0Color()
+                }
+            } else {
+                if self.showType == .horizontal {
+                    self.handleView.isHidden = true
+                    self.contentBox.fillColor = NSColor.clear
+                } else {
+                    self.showImageView.border(NSColor.clear, 1, 4)
+                    self.verticalTitleLabel.backgroundColor(NSColor.clear)
+                    self.verticalTitleLabel.textColor = KMAppearance.Layout.h0Color()
+                }
+            }
+        }
+        
         showPathButton.toolTip = NSLocalizedString("Show in Finder", comment: "")
         removePathButton.toolTip = NSLocalizedString("Remove from Recents", comment: "")
         handleView.isHidden = true;
@@ -97,9 +122,16 @@ class KMHomeHistoryCollectionItem: NSCollectionViewItem {
                 removePathButton.image = NSImage(named: "KMImageNameUXIconHomeRemoveNor")
             }
         }
+        
+        //vertical
+        self.showImageView.border(NSColor.clear, 1, 4)
+        self.verticalTitleLabel.backgroundColor(NSColor.clear)
+        self.verticalTitleLabel.textColor = KMAppearance.Layout.h0Color()
     }
     
     func reloadData() {
+        self.contentBox.updateTrackingAreas()
+        
         self.updateTypeData()
         self.updateFilesData()
     }
@@ -126,123 +158,22 @@ extension KMHomeHistoryCollectionItem {
     }
     
     func updateFilesData() -> Void {
-        guard let fileUrl = url else { return }
+        guard let model = model else { return }
         
-        let attrib = try? FileManager.default.attributesOfItem(atPath: fileUrl.path) as? Dictionary<FileAttributeKey , Any>
-        if attrib != nil {
-            let dateFormatter: DateFormatter = DateFormatter.init()
-            let fileDate: Date = attrib![FileAttributeKey(rawValue: "NSFileModificationDate")] as! Date
-            var fileTime: String = ""
-            if fileDate.isToday() {
-                dateFormatter.dateFormat = "HH:mm"
-            } else if self.isDateInCurrentWeek(fileDate) {
-                dateFormatter.dateFormat = "EEE, HH:mm"
-            } else {
-                dateFormatter.dateFormat = "MMM d, yyyy"
-            }
+        horizontalTitleLabel.stringValue = model.fileName
+        verticalTitleLabel.stringValue = model.fileName
+        pathLabel.stringValue = model.showPath
             
-            let fileName = fileUrl.lastPathComponent
-//            let fileType = url.pathExtension.isEmpty ? "" : url.pathExtension
-            let fileType = ""
-            let sizeFloat: Float = attrib![FileAttributeKey(rawValue: "NSFileSize")] as? Float ?? 0.0
-            let fileSize = fileSizeString(sizeFloat).isEmpty ? "" : fileSizeString(sizeFloat)
-            let lastTime = dateFormatter.string(from: fileDate)
-            if fileDate.isToday() {
-                fileTime = String(format: "%@, %@", NSLocalizedString("Today", comment: ""), lastTime)
-            } else if isDateInCurrentWeek(fileDate) {
-                fileTime = lastTime
-            } else {
-                fileTime = lastTime
-            }
-
-            let paragraphStyle = NSMutableParagraphStyle()
-            paragraphStyle.lineSpacing = 22.0
-            horizontalTitleLabel.stringValue = fileName
-            verticalTitleLabel.stringValue = fileName
-            
-            //path
-            let array = fileUrl.path
-                .deletingLastPathComponent
-                .components(separatedBy: "/")
-            let string = NSMutableString()
+        let paragraphStyle = NSMutableParagraphStyle()
+        paragraphStyle.lineSpacing = 22.0
+        sizeLabel.attributedStringValue = NSAttributedString(string: model.fileSize, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
+        timeLabel.attributedStringValue = NSAttributedString(string: model.modificationTime, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
 
-            if array.count > 4 {
-                string.append(".../")
-                string.append(array[array.count - 3])
-                string.append("/")
-                string.append(array[array.count - 2])
-                string.append("/")
-                string.append(array[array.count - 1])
-            } else {
-                string.setString(fileUrl.path.deletingLastPathComponent)
-            }
+        
+        showImageView.image = model.iconImage
+        
+        self.view.toolTip = model.fileName
 
-            pathLabel.stringValue = string as String
-            
-    //        documentName.attributedStringValue = NSAttributedString(string: fileName, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
-//            documentType.attributedStringValue = NSAttributedString(string: fileType, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
-            sizeLabel.attributedStringValue = NSAttributedString(string: fileSize, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
-            timeLabel.attributedStringValue = NSAttributedString(string: fileTime, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
-//            mainBox.toolTip = fileName
-//            
-//            if selectUrls.contains(fileUrl) {
-//                isSelect = true
-//                mainBox.fillColor = NSColor.km_init(hex: "#CED0D4", alpha: 0.6)
-//                mainBox.borderWidth = 1.0
-//                mainBox.borderColor = NSColor.km_init(hex: "#CED0D4")
-//                mainBox.cornerRadius = 4.0
-//            } else {
-//                isSelect = false
-//                mainBox.fillColor = .clear
-//                mainBox.borderWidth = 0.0
-//                mainBox.cornerRadius = 0.0
-//            }
-//            documentName.backgroundColor = .clear
-//            documentName.textColor = NSColor.km_init(hex: "#252629")
-//            documentName.font = NSFont(name: "SFProText-Regular", size: 14)
-//            documentType.textColor = NSColor.km_init(hex: "#94989C")
-//            documentSize.textColor = NSColor.km_init(hex: "#94989C")
-//            documentName.backgroundColor = .clear
-//            lastModificationTime.textColor = NSColor.km_init(hex: "#94989C")
-//            lastModificationTime.backgroundColor = .clear
-//            moreButton.image = NSImage(named: "KMHomeMoreTools")
-            let image: NSImage = NSImage.previewForFile(path: fileUrl, ofSize: self.view.bounds.size, asIcon: true) ?? NSImage()
-            showImageView.image = image
-        }
-    }
-    
-    func fileSizeString(_ fSize: Float) -> String {
-        let fileSize = fSize / 1024
-        let size = fileSize >= 1024 ? (fileSize < 1048576 ? fileSize/1024 : fileSize/1048576.0) : fileSize
-        let unit = fileSize >= 1024 ? (fileSize < 1048576 ? "M" : "G") : "K"
-        return String(format: "%0.1f %@", size, unit)
-    }
-    
-    func isSameWeek (withDate date: Date) -> Bool {
-        let currentWeekOfYear = getWeekOfYear(date: Date.init())
-        let targetWeekOfYear = getWeekOfYear(date: date)
-        if targetWeekOfYear == currentWeekOfYear {
-            return false
-        } else {
-            return true
-        }
-    }
-    
-    func isDateInCurrentWeek(_ date: Date) -> Bool {
-        let calendar = Calendar.current
-        // 获取当前日期的星期几
-        let weekday = calendar.component(.weekday, from: Date())
-        // 获取一周的第一天(周日)的日期
-        let firstDayOfWeek = calendar.date(byAdding: .day, value: -weekday, to: Date())!
-        // 获取一周的最后一天(下周的第一天)的日期
-        let lastDayOfWeek = calendar.date(byAdding: .day, value: 7, to: firstDayOfWeek)!
-        // 判断日期是否在当前周的范围内
-        return date > firstDayOfWeek && date < lastDayOfWeek
-    }
-     
-    func getWeekOfYear(date: Date) -> Int {
-        let components = Calendar.current.dateComponents([Calendar.Component.weekOfYear], from: date)
-        return components.weekOfYear ?? 0
     }
 }
                      
@@ -250,34 +181,22 @@ extension KMHomeHistoryCollectionItem {
     @objc @IBAction func showPathButtonAction(_ sender: Any) {
         guard let callBack = showPathAction else { return }
         
-        callBack(self)
+        callBack(self, model!)
     }
     
     @objc @IBAction func removePathButtonAction(_ sender: Any) {
         guard let callBack = removeAction else { return }
         
-        callBack(self)
+        callBack(self, model!)
     }
 }
 
 extension KMHomeHistoryCollectionItem {
-    override func mouseEntered(with event: NSEvent) {
-        guard let callBack = mouseMoveAction else { return }
-        
-        callBack(self, true)
-    }
-    
-    override func mouseExited(with event: NSEvent) {
-        guard let callBack = mouseMoveAction else { return }
-        
-        callBack(self, false)
-    }
-    
     override func mouseDown(with event: NSEvent) {
         if event.clickCount == 2 {
             // 处理双击操作
             guard let callBack = mouseDobleClickAction else { return }
-            callBack(self, self.url!)
+            callBack(self, self.model!)
         } else {
             super.mouseDown(with: event)
         }

+ 29 - 27
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/Cell/KMHomeHistoryCollectionItem.xib

@@ -28,24 +28,27 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView translatesAutoresizingMaskIntoConstraints="NO" id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="618" height="88"/>
+            <rect key="frame" x="0.0" y="0.0" width="594" height="258"/>
             <subviews>
                 <box boxType="custom" borderWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="gvc-kj-Yeo" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
-                    <rect key="frame" x="16" y="16" width="586" height="56"/>
+                    <rect key="frame" x="0.0" y="0.0" width="594" height="258"/>
                     <view key="contentView" id="KgU-86-iwk">
-                        <rect key="frame" x="0.0" y="0.0" width="586" height="56"/>
+                        <rect key="frame" x="0.0" y="0.0" width="594" height="258"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     </view>
                 </box>
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="oc7-Ul-iDs">
-                    <rect key="frame" x="0.0" y="0.0" width="618" height="88"/>
+                    <rect key="frame" x="0.0" y="0.0" width="594" height="258"/>
                     <subviews>
                         <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="dbA-sb-Xfk">
-                            <rect key="frame" x="0.0" y="40" width="618" height="48"/>
+                            <rect key="frame" x="0.0" y="82" width="594" height="176"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="176" id="fUn-kK-60Z"/>
+                            </constraints>
                             <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="bdV-B5-oJm"/>
                         </imageView>
                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mZL-RM-KzQ">
-                            <rect key="frame" x="14" y="16" width="590" height="16"/>
+                            <rect key="frame" x="293" y="58" width="8" height="16"/>
                             <textFieldCell key="cell" alignment="center" id="Nso-Kd-6li">
                                 <font key="font" metaFont="system"/>
                                 <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -54,29 +57,28 @@
                         </textField>
                     </subviews>
                     <constraints>
-                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="leading" secondItem="oc7-Ul-iDs" secondAttribute="leading" constant="16" id="7fg-gh-Ipe"/>
-                        <constraint firstAttribute="trailing" secondItem="dbA-sb-Xfk" secondAttribute="trailing" id="HWM-9v-2Rd"/>
-                        <constraint firstItem="dbA-sb-Xfk" firstAttribute="top" secondItem="oc7-Ul-iDs" secondAttribute="top" id="Sv1-jj-Bfg"/>
-                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="centerX" secondItem="oc7-Ul-iDs" secondAttribute="centerX" id="U8s-bU-U33"/>
-                        <constraint firstAttribute="trailing" secondItem="mZL-RM-KzQ" secondAttribute="trailing" constant="16" id="hy9-aF-hPG"/>
-                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="top" secondItem="dbA-sb-Xfk" secondAttribute="bottom" constant="8" id="jfz-kY-uGx"/>
-                        <constraint firstAttribute="bottom" secondItem="dbA-sb-Xfk" secondAttribute="bottom" constant="40" id="lD8-TX-JUg"/>
-                        <constraint firstItem="dbA-sb-Xfk" firstAttribute="leading" secondItem="oc7-Ul-iDs" secondAttribute="leading" id="xP3-Qp-EQE"/>
+                        <constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="mZL-RM-KzQ" secondAttribute="trailing" id="7BD-64-evH"/>
+                        <constraint firstAttribute="trailing" secondItem="dbA-sb-Xfk" secondAttribute="trailing" id="80h-2r-yMV"/>
+                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="top" secondItem="dbA-sb-Xfk" secondAttribute="bottom" constant="8" id="9qi-k0-iQ9"/>
+                        <constraint firstItem="dbA-sb-Xfk" firstAttribute="top" secondItem="oc7-Ul-iDs" secondAttribute="top" id="CxI-HI-LqK"/>
+                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="centerX" secondItem="oc7-Ul-iDs" secondAttribute="centerX" id="Ex9-nS-fp9"/>
+                        <constraint firstItem="mZL-RM-KzQ" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="oc7-Ul-iDs" secondAttribute="leading" id="Xlz-5a-Mld"/>
+                        <constraint firstItem="dbA-sb-Xfk" firstAttribute="leading" secondItem="oc7-Ul-iDs" secondAttribute="leading" id="aLi-Lu-w7p"/>
                     </constraints>
                 </customView>
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="7sk-7M-lCI">
-                    <rect key="frame" x="0.0" y="0.0" width="618" height="88"/>
+                    <rect key="frame" x="0.0" y="0.0" width="594" height="258"/>
                     <subviews>
                         <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="0Mh-Sf-3a2">
-                            <rect key="frame" x="16" y="28" width="32" height="32"/>
+                            <rect key="frame" x="16" y="109" width="32" height="40"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="32" id="Hwu-re-UBO"/>
-                                <constraint firstAttribute="height" constant="32" id="Wiy-fe-sgF"/>
+                                <constraint firstAttribute="height" constant="40" id="Wiy-fe-sgF"/>
                             </constraints>
                             <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="KMImageNameUXIconPropertybarFilePdf" id="eLO-Yq-M3q"/>
                         </imageView>
                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ddV-aD-Yah">
-                            <rect key="frame" x="54" y="43" width="40" height="17"/>
+                            <rect key="frame" x="54" y="132" width="40" height="17"/>
                             <textFieldCell key="cell" lineBreakMode="truncatingMiddle" alignment="left" title="Label" id="AYN-Fy-tcy">
                                 <font key="font" metaFont="system" size="14"/>
                                 <color key="textColor" name="KMGray6Color"/>
@@ -84,7 +86,7 @@
                             </textFieldCell>
                         </textField>
                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WUP-W3-okM">
-                            <rect key="frame" x="495" y="37" width="109" height="15"/>
+                            <rect key="frame" x="471" y="122" width="109" height="15"/>
                             <textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="2020-08-01 12:39" id="PEF-8C-QEE">
                                 <font key="font" metaFont="cellTitle"/>
                                 <color key="textColor" name="KMGray5Color"/>
@@ -92,7 +94,7 @@
                             </textFieldCell>
                         </textField>
                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Der-Qi-aoW">
-                            <rect key="frame" x="93" y="28" width="35" height="15"/>
+                            <rect key="frame" x="93" y="109" width="35" height="15"/>
                             <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="2AB-HF-4Ox">
                                 <font key="font" metaFont="cellTitle"/>
                                 <color key="textColor" red="0.39607843139999999" green="0.41176470590000003" blue="0.43921568630000002" alpha="1" colorSpace="calibratedRGB"/>
@@ -100,7 +102,7 @@
                             </textFieldCell>
                         </textField>
                         <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wId-sm-qtO">
-                            <rect key="frame" x="54" y="28" width="35" height="15"/>
+                            <rect key="frame" x="54" y="109" width="35" height="15"/>
                             <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="Pbe-3u-seE">
                                 <font key="font" metaFont="cellTitle"/>
                                 <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -108,7 +110,7 @@
                             </textFieldCell>
                         </textField>
                         <customView translatesAutoresizingMaskIntoConstraints="NO" id="seD-7E-dp2">
-                            <rect key="frame" x="373" y="24" width="100" height="40"/>
+                            <rect key="frame" x="349" y="109" width="100" height="40"/>
                             <subviews>
                                 <button translatesAutoresizingMaskIntoConstraints="NO" id="HSD-uO-oml" customClass="KMButton" customModule="PDF_Master" customModuleProvider="target">
                                     <rect key="frame" x="20" y="10" width="20" height="20"/>
@@ -168,18 +170,18 @@
             <constraints>
                 <constraint firstAttribute="bottom" secondItem="7sk-7M-lCI" secondAttribute="bottom" id="1xu-Eu-Gpw"/>
                 <constraint firstItem="oc7-Ul-iDs" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="3mN-ui-HOd"/>
-                <constraint firstAttribute="trailing" secondItem="gvc-kj-Yeo" secondAttribute="trailing" constant="16" id="MQ9-mG-dvf"/>
-                <constraint firstItem="gvc-kj-Yeo" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="16" id="QNY-R7-aCn"/>
+                <constraint firstAttribute="trailing" secondItem="gvc-kj-Yeo" secondAttribute="trailing" id="MQ9-mG-dvf"/>
+                <constraint firstItem="gvc-kj-Yeo" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="QNY-R7-aCn"/>
                 <constraint firstAttribute="trailing" secondItem="oc7-Ul-iDs" secondAttribute="trailing" id="ZvQ-Yb-83f"/>
-                <constraint firstItem="gvc-kj-Yeo" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="16" id="c3K-iJ-GsK"/>
+                <constraint firstItem="gvc-kj-Yeo" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="c3K-iJ-GsK"/>
                 <constraint firstAttribute="trailing" secondItem="7sk-7M-lCI" secondAttribute="trailing" id="cqh-JA-THy"/>
                 <constraint firstItem="7sk-7M-lCI" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="e4i-JT-Slb"/>
                 <constraint firstItem="7sk-7M-lCI" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="ooa-BQ-VTr"/>
-                <constraint firstAttribute="bottom" secondItem="gvc-kj-Yeo" secondAttribute="bottom" constant="16" id="pQn-cm-GgU"/>
+                <constraint firstAttribute="bottom" secondItem="gvc-kj-Yeo" secondAttribute="bottom" id="pQn-cm-GgU"/>
                 <constraint firstAttribute="bottom" secondItem="oc7-Ul-iDs" secondAttribute="bottom" id="pjN-VI-SK1"/>
                 <constraint firstItem="oc7-Ul-iDs" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="tTF-yE-4ER"/>
             </constraints>
-            <point key="canvasLocation" x="-67" y="194"/>
+            <point key="canvasLocation" x="-526" y="331"/>
         </customView>
     </objects>
     <resources>

+ 29 - 7
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/KMHomeHistoryListView.swift

@@ -13,15 +13,25 @@ enum KMHomeHistoryListViewShowType: Int {
     case vertical //纵
 }
 
-typealias KMHomeHistoryListViewItemDidSelect = (_ view: KMHomeHistoryListView, _ url: URL) -> Void
+typealias KMHomeHistoryListViewItemDidSelect = (_ view: KMHomeHistoryListView, _ item: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeHistoryListViewItemShowPathAction = (_ view: KMHomeHistoryListView, _ item: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeHistoryListViewItemRemovePathAction = (_ view: KMHomeHistoryListView, _ item: KMHomeHistoryListViewModel) -> Void
+
 class KMHomeHistoryListView: KMBaseXibView {
     @IBOutlet weak var collectionView: NSCollectionView!
     
     var didSelect: KMHomeHistoryListViewItemDidSelect?
-    var data:[URL] = []
+    var showPathAction: KMHomeHistoryListViewItemShowPathAction?
+    var removeFileAction: KMHomeHistoryListViewItemRemovePathAction?
+    
+    var data:[KMHomeHistoryListViewModel] = []
     var showType:KMHomeHistoryListViewShowType = .horizontal {
         didSet {
             self.collectionView.reloadData()
+            //item的大小不刷新 暂时处理为刷新两次
+            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
+                self.collectionView.reloadData()
+            }
         }
     }
     
@@ -49,7 +59,7 @@ class KMHomeHistoryListView: KMBaseXibView {
         self.data.removeAll()
         for url in NSDocumentController.shared.recentDocumentURLs {
             if FileManager.default.fileExists(atPath: url.path) {
-                self.data.append(url)
+                self.data.append(KMHomeHistoryListViewModel.init(filePath: url))
             }
         }
 
@@ -97,13 +107,25 @@ extension KMHomeHistoryListView: NSCollectionViewDataSource {
         let view = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMHomeHistoryCollectionItem"), for: indexPath) as! KMHomeHistoryCollectionItem
         view.showType = self.showType
         if self.data.count > indexPath.item {
-            view.url = self.data[indexPath.item]
+            view.model = self.data[indexPath.item]
         }
     
-        view.mouseDobleClickAction = {[unowned self] view, url in
+        view.mouseDobleClickAction = {[unowned self] view, item in
             guard let callBack = didSelect else { return }
             
-            callBack(self, url)
+            callBack(self, item)
+        }
+        
+        view.showPathAction = {[unowned self] view, item in
+            guard let callBack = showPathAction else { return }
+            
+            callBack(self, item)
+        }
+        
+        view.removeAction = {[unowned self] view, item in
+            guard let callBack = removeFileAction else { return }
+            
+            callBack(self, item)
         }
         return view
     }
@@ -123,7 +145,7 @@ extension KMHomeHistoryListView: NSCollectionViewDelegateFlowLayout {
         if showType == .horizontal {
             return NSEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
         } else {
-            return NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
+            return NSEdgeInsets(top: 10, left: 0, bottom: 10, right: 10)
         }
     }
 }

+ 1 - 1
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/KMHomeHistoryListView.xib

@@ -23,7 +23,7 @@
                         <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <collectionView id="2YZ-04-yn6">
+                            <collectionView translatesAutoresizingMaskIntoConstraints="NO" id="2YZ-04-yn6">
                                 <rect key="frame" x="0.0" y="0.0" width="480" height="158"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="10" minimumLineSpacing="10" id="nLD-SM-dF9">

+ 112 - 1
PDF Office/PDF Master/Class/Home/View/HomeContentView/History/Model/KMHomeHistoryListViewModel.swift

@@ -8,5 +8,116 @@
 import Cocoa
 
 class KMHomeHistoryListViewModel: NSObject {
-
+    init(filePath: URL) {
+        super.init()
+        self.filePath = filePath
+        self.dealData(filePath: filePath)
+    }
+    
+    var filePath: URL? {
+        didSet {
+            self.dealData(filePath: filePath!)
+        }
+    }
+    
+    var showPath: String = ""
+    
+    var fileName: String = ""
+    
+    var fileSize: String = ""
+    
+    var modificationTime: String = ""
+    
+    var attributesOfItem: [FileAttributeKey : Any]?
+    
+    var iconImage: NSImage?
+    
+    
+    func dealData(filePath: URL) {
+        let attrib = try? FileManager.default.attributesOfItem(atPath: filePath.path) as? Dictionary<FileAttributeKey , Any>
+            if attrib != nil {
+                let dateFormatter: DateFormatter = DateFormatter.init()
+                let fileDate: Date = attrib![FileAttributeKey(rawValue: "NSFileModificationDate")] as! Date
+                var fileTime: String = ""
+                if fileDate.isToday() {
+                    dateFormatter.dateFormat = "HH:mm"
+                } else if self.isDateInCurrentWeek(fileDate) {
+                    dateFormatter.dateFormat = "EEE, HH:mm"
+                } else {
+                    dateFormatter.dateFormat = "MMM d, yyyy"
+                }
+    
+    //            let fileType = url.pathExtension.isEmpty ? "" : url.pathExtension
+                let fileType = ""
+                let sizeFloat: Float = attrib![FileAttributeKey(rawValue: "NSFileSize")] as? Float ?? 0.0
+                let fileSize = fileSizeString(sizeFloat).isEmpty ? "" : fileSizeString(sizeFloat)
+                let lastTime = dateFormatter.string(from: fileDate)
+                if fileDate.isToday() {
+                    fileTime = String(format: "%@, %@", NSLocalizedString("Today", comment: ""), lastTime)
+                } else if isDateInCurrentWeek(fileDate) {
+                    fileTime = lastTime
+                } else {
+                    fileTime = lastTime
+                }
+    
+                //path
+                let array = filePath.path
+                    .deletingLastPathComponent
+                    .components(separatedBy: "/")
+                let string = NSMutableString()
+    
+                if array.count > 4 {
+                    string.append(".../")
+                    string.append(array[array.count - 3])
+                    string.append("/")
+                    string.append(array[array.count - 2])
+                    string.append("/")
+                    string.append(array[array.count - 1])
+                } else {
+                    string.setString(filePath.path.deletingLastPathComponent)
+                }
+    
+                let image: NSImage = NSImage.previewForFile(path: filePath, ofSize: CGSizeMake(136, 214), asIcon: true) ?? NSImage()
+                
+                attributesOfItem = attrib
+                showPath = string.description
+                modificationTime = fileTime
+                iconImage = image
+                fileName = filePath.lastPathComponent
+            }
+        }
+            
+        func fileSizeString(_ fSize: Float) -> String {
+            let fileSize = fSize / 1024
+            let size = fileSize >= 1024 ? (fileSize < 1048576 ? fileSize/1024 : fileSize/1048576.0) : fileSize
+            let unit = fileSize >= 1024 ? (fileSize < 1048576 ? "M" : "G") : "K"
+            return String(format: "%0.1f %@", size, unit)
+        }
+        
+        func isSameWeek (withDate date: Date) -> Bool {
+            let currentWeekOfYear = getWeekOfYear(date: Date.init())
+            let targetWeekOfYear = getWeekOfYear(date: date)
+            if targetWeekOfYear == currentWeekOfYear {
+                return false
+            } else {
+                return true
+            }
+        }
+        
+        func isDateInCurrentWeek(_ date: Date) -> Bool {
+            let calendar = Calendar.current
+            // 获取当前日期的星期几
+            let weekday = calendar.component(.weekday, from: Date())
+            // 获取一周的第一天(周日)的日期
+            let firstDayOfWeek = calendar.date(byAdding: .day, value: -weekday, to: Date())!
+            // 获取一周的最后一天(下周的第一天)的日期
+            let lastDayOfWeek = calendar.date(byAdding: .day, value: 7, to: firstDayOfWeek)!
+            // 判断日期是否在当前周的范围内
+            return date > firstDayOfWeek && date < lastDayOfWeek
+        }
+         
+        func getWeekOfYear(date: Date) -> Int {
+            let components = Calendar.current.dateComponents([Calendar.Component.weekOfYear], from: date)
+            return components.weekOfYear ?? 0
+        }
 }

+ 67 - 17
PDF Office/PDF Master/Class/Home/View/HomeContentView/KMHomeContentView.swift

@@ -7,12 +7,20 @@
 
 import Cocoa
 
-typealias KMHomeContentViewHistoryDidSelect = (_ view: KMHomeContentView, _ url: URL) -> Void
+typealias KMHomeContentViewHistoryDidSelect = (_ view: KMHomeContentView, _ url: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeContentViewHistoryShowPathAction = (_ view: KMHomeContentView, _ url: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeContentViewHistoryrRemoveFileAction = (_ view: KMHomeContentView, _ url: KMHomeHistoryListViewModel) -> Void
+typealias KMHomeContentViewHistoryrRemoveAllFileAction = (_ view: KMHomeContentView) -> Void
+
+typealias KMHomeContentViewQucikToolsDidSelect = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
+typealias KMHomeContentViewQucikToolsAddAction = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
+typealias KMHomeContentViewQucikToolsRemoveAction = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
 
 class KMHomeContentView: KMBaseXibView {
     @IBOutlet weak var qucikToolsLabel: NSTextField!
     @IBOutlet weak var qucikToolsView: KMQucikToolsView!
     @IBOutlet weak var leftButton: NSButton!
+    @IBOutlet weak var pageLabel: NSTextField!
     @IBOutlet weak var rightButton: NSButton!
     @IBOutlet weak var moreButton: KMButton!
     
@@ -24,6 +32,13 @@ class KMHomeContentView: KMBaseXibView {
     @IBOutlet weak var cleanButton: KMButton!
     
     var historyDidSelect: KMHomeContentViewHistoryDidSelect?
+    var historyShowPathAction: KMHomeContentViewHistoryShowPathAction?
+    var historyRemoveFileAction: KMHomeContentViewHistoryrRemoveFileAction?
+    var historyRemoveAllFileAction: KMHomeContentViewHistoryrRemoveAllFileAction?
+    
+    var qucikToolsDidSelect: KMHomeContentViewQucikToolsDidSelect?
+    var qucikToolsAddAction: KMHomeContentViewQucikToolsAddAction?
+    var qucikToolsRemoveAction: KMHomeContentViewQucikToolsRemoveAction?
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
@@ -33,40 +48,73 @@ class KMHomeContentView: KMBaseXibView {
     }
     
     override func setup() {
-        self.historyListViewSetup()
+        self.pageLabel.textColor = KMAppearance.Layout.h0Color()
+        self.qucikToolsView.didSelect = { [unowned self] view, item in
+            guard let callBack = qucikToolsDidSelect else { return }
+            
+            callBack(self, item)
+        }
+        
+        self.qucikToolsView.pageChange = { [unowned self] view in
+            self.updatePageLabel()
+        }
+        
+        self.qucikToolsView.addAction = { [unowned self] view, item in
+            self.qucikToolsAddAction?(self, item)
+        }
+        
+        self.qucikToolsView.removeAction = { [unowned self] view, item in
+            self.qucikToolsRemoveAction?(self, item)
+        }
+        
+        self.historyListView.didSelect = { [unowned self] view, item in
+            guard let callBack = historyDidSelect else { return }
+            
+            callBack(self, item)
+        }
+        
+        self.historyListView.removeFileAction = { [unowned self] view, item in
+            guard let callBack = historyRemoveFileAction else { return }
+            
+            callBack(self, item)
+        }
+        
+        self.historyListView.showPathAction = { [unowned self] view, item in
+            guard let callBack = historyShowPathAction else { return }
+            
+            callBack(self, item)
+        }
+        
+        
+        
+        self.updatePageLabel()
     }
+    
+    func updatePageLabel() {
+        self.pageLabel.stringValue = "\(qucikToolsView.currentPage()) / \(qucikToolsView.pageCount())"
+    }
+    
 }
 
+//MARK: Action
 extension KMHomeContentView {
     @IBAction func leftButtonAction(_ sender: Any) {
-        
+        self.qucikToolsView.previousPage()
     }
     
     @IBAction func rightButtonAction(_ sender: Any) {
-        
+        self.qucikToolsView.nextPage()
     }
     
     @IBAction func moreButtonAction(_ sender: Any) {
         let homeQuickToolsWindowController: KMHomeQuickToolsWindowController = KMHomeQuickToolsWindowController.sharedHomeQuickTools
         homeQuickToolsWindowController.window?.center()
-//        homeQuickToolsWindowController.window?.orderFront(sender)
         NSWindow.currentWindow().addChildWindow(homeQuickToolsWindowController.window!, ordered: NSWindow.OrderingMode.above)
-//        NSWindow.currentWindow().beginSheet(homeQuickToolsWindowController.window!)
+
         homeQuickToolsWindowController.dataChange = { [unowned self] controller in
             self.qucikToolsView.reloadData()
         }
     }
-}
-
-extension KMHomeContentView {
-    func historyListViewSetup() {
-        self.historyListView.didSelect = { [unowned self] view, url in
-            guard let callBack = historyDidSelect else { return }
-            
-            callBack(self, url)
-        }
-        
-    }
     
     @IBAction func horizontalButtonAction(_ sender: Any) {
         self.historyListView.showType = .horizontal
@@ -77,6 +125,8 @@ extension KMHomeContentView {
     }
     
     @IBAction func cleanButtonAction(_ sender: Any) {
+        guard let callBack = historyRemoveAllFileAction else { return }
         
+        callBack(self)
     }
 }

+ 31 - 17
PDF Office/PDF Master/Class/Home/View/HomeContentView/KMHomeContentView.xib

@@ -11,12 +11,13 @@
                 <outlet property="cleanButton" destination="2pe-eQ-jim" id="NzZ-si-Lah"/>
                 <outlet property="historyListView" destination="wMw-AS-5yG" id="HHc-lb-Uau"/>
                 <outlet property="horizontalButton" destination="f8L-dW-OV5" id="2bQ-AH-t3U"/>
-                <outlet property="leftButton" destination="PwG-OP-iJ7" id="eZg-FR-Kro"/>
+                <outlet property="leftButton" destination="WXY-wn-hPk" id="hp6-fa-w4J"/>
                 <outlet property="moreButton" destination="YVh-aT-yWA" id="M54-rm-tnw"/>
+                <outlet property="pageLabel" destination="AZq-VF-EUc" id="CCP-bH-lFT"/>
                 <outlet property="qucikToolsLabel" destination="FaJ-2q-2cQ" id="q0S-ez-pED"/>
                 <outlet property="qucikToolsView" destination="ynU-RA-kWD" id="t4n-b1-mpf"/>
                 <outlet property="recentlyLabel" destination="Jq6-Hl-amd" id="cL6-5Q-9jC"/>
-                <outlet property="rightButton" destination="WPD-Y0-yC2" id="ZEL-I1-FmC"/>
+                <outlet property="rightButton" destination="34n-6o-x3z" id="qKh-a6-NQL"/>
                 <outlet property="verticalButton" destination="oce-zR-GCX" id="DXr-S4-r67"/>
             </connections>
         </customObject>
@@ -60,45 +61,58 @@
                                                             <action selector="moreButtonAction:" target="-2" id="4JY-gV-CUq"/>
                                                         </connections>
                                                     </button>
-                                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WPD-Y0-yC2">
+                                                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AZq-VF-EUc">
+                                                        <rect key="frame" x="526" y="4" width="25" height="16"/>
+                                                        <constraints>
+                                                            <constraint firstAttribute="height" constant="16" id="ysy-ux-uwA"/>
+                                                        </constraints>
+                                                        <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="1/2" id="VoQ-Tz-nCY">
+                                                            <font key="font" metaFont="cellTitle"/>
+                                                            <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.84705882349999995" colorSpace="calibratedRGB"/>
+                                                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                                        </textFieldCell>
+                                                    </textField>
+                                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="34n-6o-x3z">
                                                         <rect key="frame" x="557" y="2" width="16" height="21"/>
-                                                        <buttonCell key="cell" type="bevel" bezelStyle="rounded" image="NSTouchBarGoForwardTemplate" imagePosition="overlaps" alignment="center" imageScaling="proportionallyDown" inset="2" id="mRw-z9-Pze">
+                                                        <buttonCell key="cell" type="bevel" bezelStyle="rounded" image="NSTouchBarGoForwardTemplate" imagePosition="overlaps" alignment="center" imageScaling="proportionallyDown" inset="2" id="vf1-qw-7He">
                                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                             <font key="font" metaFont="system"/>
                                                         </buttonCell>
                                                         <constraints>
-                                                            <constraint firstAttribute="width" constant="16" id="ASJ-At-7qY"/>
-                                                            <constraint firstAttribute="height" constant="16" id="x37-9K-xk3"/>
+                                                            <constraint firstAttribute="width" constant="16" id="k4Q-hn-f2N"/>
+                                                            <constraint firstAttribute="height" constant="16" id="yiF-N3-Zwz"/>
                                                         </constraints>
                                                         <connections>
-                                                            <action selector="rightButtonAction:" target="-2" id="noR-iP-jsC"/>
+                                                            <action selector="rightButtonAction:" target="-2" id="SCM-qa-djR"/>
                                                         </connections>
                                                     </button>
-                                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PwG-OP-iJ7">
-                                                        <rect key="frame" x="509" y="2" width="16" height="21"/>
-                                                        <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="NSTouchBarGoBackTemplate" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="bil-yH-Akb">
+                                                    <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="WXY-wn-hPk">
+                                                        <rect key="frame" x="504" y="2" width="16" height="21"/>
+                                                        <buttonCell key="cell" type="square" title="Button" bezelStyle="shadowlessSquare" image="NSTouchBarGoBackTemplate" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="his-Ac-2Du">
                                                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                                             <font key="font" metaFont="system"/>
                                                         </buttonCell>
                                                         <constraints>
-                                                            <constraint firstAttribute="height" constant="16" id="Dw9-LS-jOQ"/>
-                                                            <constraint firstAttribute="width" constant="16" id="Wzf-Iv-uw7"/>
+                                                            <constraint firstAttribute="height" constant="16" id="07e-1r-Vje"/>
+                                                            <constraint firstAttribute="width" constant="16" id="CGy-dK-xkf"/>
                                                         </constraints>
                                                         <connections>
-                                                            <action selector="leftButtonAction:" target="-2" id="U2S-eX-FI8"/>
+                                                            <action selector="leftButtonAction:" target="-2" id="Ic9-Y6-q8s"/>
                                                         </connections>
                                                     </button>
                                                 </subviews>
                                                 <constraints>
-                                                    <constraint firstItem="WPD-Y0-yC2" firstAttribute="centerY" secondItem="69z-SV-dL5" secondAttribute="centerY" id="1mQ-di-yW2"/>
-                                                    <constraint firstItem="WPD-Y0-yC2" firstAttribute="leading" secondItem="PwG-OP-iJ7" secondAttribute="trailing" constant="32" id="2o2-jt-hDj"/>
+                                                    <constraint firstItem="34n-6o-x3z" firstAttribute="leading" secondItem="AZq-VF-EUc" secondAttribute="trailing" constant="8" id="5b1-3H-yqn"/>
                                                     <constraint firstAttribute="trailing" secondItem="YVh-aT-yWA" secondAttribute="trailing" id="C9W-JG-W8s"/>
+                                                    <constraint firstItem="34n-6o-x3z" firstAttribute="centerY" secondItem="WXY-wn-hPk" secondAttribute="centerY" id="HqR-w0-aOA"/>
                                                     <constraint firstItem="FaJ-2q-2cQ" firstAttribute="leading" secondItem="69z-SV-dL5" secondAttribute="leading" id="UZc-nM-Aqt"/>
                                                     <constraint firstAttribute="height" constant="24" id="VF5-NT-Dua"/>
                                                     <constraint firstItem="FaJ-2q-2cQ" firstAttribute="centerY" secondItem="69z-SV-dL5" secondAttribute="centerY" id="e4G-eL-brO"/>
-                                                    <constraint firstItem="YVh-aT-yWA" firstAttribute="leading" secondItem="WPD-Y0-yC2" secondAttribute="trailing" constant="16" id="sIP-zf-cQy"/>
+                                                    <constraint firstItem="AZq-VF-EUc" firstAttribute="leading" secondItem="WXY-wn-hPk" secondAttribute="trailing" constant="8" id="epd-Mx-BL8"/>
+                                                    <constraint firstItem="AZq-VF-EUc" firstAttribute="centerY" secondItem="69z-SV-dL5" secondAttribute="centerY" id="fCt-K0-F68"/>
+                                                    <constraint firstItem="AZq-VF-EUc" firstAttribute="centerY" secondItem="WXY-wn-hPk" secondAttribute="centerY" id="hgj-vL-sIT"/>
                                                     <constraint firstItem="YVh-aT-yWA" firstAttribute="centerY" secondItem="69z-SV-dL5" secondAttribute="centerY" id="u3H-Ys-UG6"/>
-                                                    <constraint firstItem="PwG-OP-iJ7" firstAttribute="centerY" secondItem="69z-SV-dL5" secondAttribute="centerY" id="ygX-nH-XYo"/>
+                                                    <constraint firstItem="YVh-aT-yWA" firstAttribute="leading" secondItem="34n-6o-x3z" secondAttribute="trailing" constant="16" id="wW8-yX-vAt"/>
                                                 </constraints>
                                             </customView>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="ynU-RA-kWD" customClass="KMQucikToolsView" customModule="PDF_Master" customModuleProvider="target">

+ 76 - 7
PDF Office/PDF Master/Class/Home/View/HomeContentView/QucikTools/KMQucikToolsView.swift

@@ -7,10 +7,20 @@
 
 import Cocoa
 
+typealias KMQucikToolsViewDidSelect = (_ view: KMQucikToolsView, _ item: KMQucikToolsModel) -> Void
+typealias KMQucikToolsViewPageChange = (_ view: KMQucikToolsView) -> Void
+
 class KMQucikToolsView: KMBaseXibView {
     @IBOutlet weak var collectionView: NSCollectionView!
     
+    var addAction: KMQucikToolCollectionViewItemAddAction?
+    var removeAction: KMQucikToolCollectionViewItemRemoveAction?
+    
+    var didSelect: KMQucikToolsViewDidSelect?
+    var pageChange: KMQucikToolsViewPageChange?
+    
     var data: [KMQucikToolsModel] = []
+    
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
 
@@ -33,6 +43,7 @@ class KMQucikToolsView: KMBaseXibView {
         //注册cell
         self.collectionView.register(KMQucikToolCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMQucikToolCollectionViewItem"))
         
+        NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll(notification:)), name: NSScrollView.didLiveScrollNotification, object: collectionView.enclosingScrollView)
 //        self.backgroundColor(KMAppearance.Layout.l0Color())
     }
     
@@ -46,24 +57,41 @@ class KMQucikToolsView: KMBaseXibView {
     }
 }
 
+//Notification
+extension KMQucikToolsView  {
+    @objc func scrollViewDidScroll(notification: Notification) {
+        // 处理滚动事件
+        if let scrollView = notification.object as? NSScrollView {
+            print("NSScrollView did scroll.")
+            // 获取滚动位置等信息
+            let contentOffset = scrollView.contentView.bounds.origin
+            print("Content Offset: \(contentOffset)")
+            
+        }
+        
+        guard let callBack = pageChange else { return }
+        callBack(self)
+    }
+}
+
 extension KMQucikToolsView: NSCollectionViewDelegate {
     //当item被选中
     public func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
         print("点击")
         let view = collectionView.item(at: indexPaths.first!) as! KMQucikToolCollectionViewItem
         
-//        let content = view.model
+        let content = view.model
         
-//        guard let callBack = didSelect else { return }
-//        
-//        content?.index = indexPaths.first!.item
-//        callBack(self, content!)
+        guard let callBack = didSelect else { return }
+        callBack(self, content!)
     }
     
    //当item取消选中
     public func collectionView(_ collectionView: NSCollectionView, didDeselectItemsAt indexPaths: Set<IndexPath>) {
         _ = collectionView.item(at: indexPaths.first!) as! KMQucikToolCollectionViewItem
     }
+    
+    
 }
 
 extension KMQucikToolsView: NSCollectionViewDataSource {
@@ -81,9 +109,17 @@ extension KMQucikToolsView: NSCollectionViewDataSource {
         if self.data.count > indexPath.item {
             view.model = self.data[indexPath.item]
         }
+        
+        view.addAction = { [unowned self] view, item in
+            self.addAction?(view, item)
+        }
+        
+        view.removeAction = { [unowned self] view, item in
+            self.removeAction?(view, item)
+        }
+        
         return view
     }
-    
 }
 
 extension KMQucikToolsView: NSCollectionViewDelegateFlowLayout {
@@ -93,6 +129,39 @@ extension KMQucikToolsView: NSCollectionViewDelegateFlowLayout {
     }
     
     public func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
-        return NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
+        return NSEdgeInsets(top: 10, left: 0, bottom: 10, right: 10)
+    }
+}
+
+//Collection Page
+extension KMQucikToolsView {
+    func pageCount() -> Int {
+        return Int(ceilf(Float(self.collectionView.frame.size.width / self.collectionView.visibleRect.size.width)))
+    }
+    
+    func currentPage() -> Int {
+        return Int(ceilf(Float(self.collectionView.visibleRect.origin.x / self.collectionView.visibleRect.size.width))) + 1
+    }
+    
+    func nextPage() {
+        let currentPage = self.currentPage()
+        let pageCount = self.pageCount()
+        if currentPage < pageCount {
+            self.collectionView.scroll(CGPoint(x: Int(self.collectionView.visibleRect.size.width) * currentPage, y: 0))
+            
+            guard let callBack = pageChange else { return }
+            callBack(self)
+        }
+    }
+    
+    func previousPage() {
+        let currentPage = self.currentPage()
+        let pageCount = self.pageCount()
+        if currentPage > 1 {
+            self.collectionView.scroll(CGPoint(x: Int(self.collectionView.visibleRect.size.width) * (currentPage - 2), y: 0))
+            
+            guard let callBack = pageChange else { return }
+            callBack(self)
+        }
     }
 }

+ 9 - 0
PDF Office/PDF Master/Class/Home/View/HomeContentView/QucikTools/Model/KMQucikToolsModel.swift

@@ -48,6 +48,14 @@ class KMQucikToolsModel: NSObject {
         UserDefaults.standard.synchronize()
     }
     
+    func canAdd() -> Bool {
+        let array: [DataNavigationViewButtonActionType] = [.Background, .BatesCode, .Watermark, .HeaderAndFooter, .Security]
+        return array.contains(self.type!)
+    }
+}
+
+//Data
+extension KMQucikToolsModel {
     func titleString() -> String {
         var string = ""
         
@@ -167,6 +175,7 @@ class KMQucikToolsModel: NSObject {
             
         return NSImage(named: string) ?? NSImage()
     }
+
 }
 
 

+ 27 - 7
PDF Office/PDF Master/Class/Home/View/HomeContentView/QucikTools/View/KMQucikToolCollectionViewItem.swift

@@ -7,6 +7,9 @@
 
 import Cocoa
 
+typealias KMQucikToolCollectionViewItemAddAction = (_ view: KMQucikToolCollectionViewItem, _ item: KMQucikToolsModel) -> Void
+typealias KMQucikToolCollectionViewItemRemoveAction = (_ view: KMQucikToolCollectionViewItem, _ item: KMQucikToolsModel) -> Void
+
 class KMQucikToolCollectionViewItem: NSCollectionViewItem {
     @IBOutlet weak var contentBox: KMBox!
     @IBOutlet weak var iconImageView: NSImageView!
@@ -23,6 +26,9 @@ class KMQucikToolCollectionViewItem: NSCollectionViewItem {
     @IBOutlet weak var tagLabel: NSTextField!
     
     
+    var addAction: KMQucikToolCollectionViewItemAddAction?
+    var removeAction: KMQucikToolCollectionViewItemRemoveAction?
+    
     var model: KMQucikToolsModel? {
         didSet {
             self.reloadData()
@@ -41,7 +47,9 @@ class KMQucikToolCollectionViewItem: NSCollectionViewItem {
     func setup() {
         self.tagView.isHidden = true
         
+        self.handleView.backgroundColor(KMAppearance.Interactive.a0Color())
         self.handleView.isHidden = true
+        
         self.addBox.borderColor = KMAppearance.Layout.w70Color()
         self.addBox.borderWidth = 1.0
         
@@ -78,13 +86,15 @@ class KMQucikToolCollectionViewItem: NSCollectionViewItem {
         self.contentBox.fillColor = KMAppearance.Layout.l1Color()
         self.contentBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
             if (mouseEntered) {
-//                if (blockSelf.mouseMoveCallback) {
-//                    blockSelf.mouseMoveCallback(YES);
-//                }
+                self.contentBox.fillColor = KMAppearance.Interactive.a0Color()
+                self.titleLabel.textColor = KMAppearance.Layout.w0Color()
+                self.subTitleLabel.textColor = KMAppearance.Layout.w70Color()
+                self.iconImageView.image = model?.iconImage(true)
             } else {
-//                if (blockSelf.mouseMoveCallback) {
-//                    blockSelf.mouseMoveCallback(NO);
-//                }
+                self.contentBox.fillColor = KMAppearance.Layout.l1Color()
+                self.titleLabel.textColor = KMAppearance.Layout.h0Color()
+                self.subTitleLabel.textColor = KMAppearance.Layout.h1Color()
+                self.iconImageView.image = model?.iconImage(false)
             }
         }
         
@@ -99,14 +109,18 @@ class KMQucikToolCollectionViewItem: NSCollectionViewItem {
         self.titleLabel.stringValue = model.titleString()
         self.subTitleLabel.stringValue = model.subTitleString()
         self.iconImageView.image = model.iconImage()
-        
     }
     
     @IBAction func removeButtonAction(_ sender: Any) {
+        guard let callBack = removeAction else { return }
         
+        callBack(self, model!)
     }
+    
     @IBAction func addButtonAction(_ sender: Any) {
+        guard let callBack = addAction else { return }
         
+        callBack(self, model!)
     }
     
 }
@@ -114,10 +128,16 @@ class KMQucikToolCollectionViewItem: NSCollectionViewItem {
 extension KMQucikToolCollectionViewItem {
     override func mouseEntered(with event: NSEvent) {
         self.view.backgroundColor(NSColor.green)
+        
+        
+        guard let model = self.model else { return }
+        self.handleView.isHidden = !model.canAdd()
     }
     
     override func mouseExited(with event: NSEvent) {
         self.view.backgroundColor(NSColor.red)
+        
+        self.handleView.isHidden = true
     }
     
 }

+ 7 - 3
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -326,8 +326,10 @@ extension KMHomeViewController {
                     NSDocumentController.shared.noteNewRecentDocumentURL(url)
                 }
             }
+            
+            self.homeContentView.historyListView.reloadData()
         }
-        historyFileViewController.reloadData()
+//        historyFileViewController.reloadData()
     }
     
     func openHistoryFilePath(url: URL) -> Void {
@@ -336,7 +338,8 @@ extension KMHomeViewController {
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
             alert.beginSheetModal(for: view.window!) { [unowned self] result in
-                self.historyFileViewController.reloadData()
+                self.homeContentView.historyListView.reloadData()
+//                self.historyFileViewController.reloadData()
             }
             return
         }
@@ -396,7 +399,8 @@ extension KMHomeViewController {
                 alert.alertStyle = .critical
                 alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
                 alert.beginSheetModal(for: view.window!) { [unowned self] result in
-                    self.historyFileViewController.reloadData()
+                    self.homeContentView.historyListView.reloadData()
+//                    self.historyFileViewController.reloadData()
                 }
             }
         } else {

+ 30 - 2
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController.swift

@@ -184,6 +184,7 @@ import Cocoa
     }
     
     func setup() {
+        //creatPDF
         self.creatPDFView.openPDFAction = { [unowned self] view, sender in
             self.openPDFAction(sender)
         }
@@ -192,8 +193,35 @@ import Cocoa
             self.creatPDFAction(sender)
         }
         
-        self.homeContentView.historyDidSelect = { [unowned self] view, url in
-            self.openFile(withFilePath: url)
+        //history
+        self.homeContentView.historyDidSelect = { [unowned self] view, item in
+            self.openHistoryFilePath(url: item.filePath!)
+        }
+        
+        self.homeContentView.historyRemoveFileAction = { [unowned self] view, item in
+            self.historyFile(deleteDocuments: [item.filePath!])
+        }
+        
+        self.homeContentView.historyShowPathAction = { [unowned self] view, item in
+            NSWorkspace.shared.open(item.filePath!.deletingLastPathComponent())
+        }
+        
+        self.homeContentView.historyRemoveAllFileAction = { [unowned self] view in
+            let urls: Array<URL> = NSDocumentController.shared.recentDocumentURLs
+            self.historyFileDeleteAction(urls)
+        }
+        
+        //quciktools
+        self.homeContentView.qucikToolsDidSelect = { [unowned self] view, item in
+            self.fastToolItemAction(item.type!)
+        }
+        
+        self.homeContentView.qucikToolsAddAction = { [unowned self] view, item in
+            self.fastToolItemAction(item.type!)
+        }
+        
+        self.homeContentView.qucikToolsRemoveAction = { [unowned self] view, item in
+            self.fastToolItemAction(item.type!)
         }
     }