Browse Source

【书签】数据加载

lizhe 1 year ago
parent
commit
80b172c8d3

+ 2 - 2
PDF Office/PDF Master/Class/DigtalSignature/ViewControllers/Views/DSignatureFileListCellView.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" 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="22154"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>

+ 3 - 0
PDF Office/PDF Master/Class/PDFTools/KMBookmark/Controller/KMBookmarkController.swift

@@ -54,6 +54,9 @@ class KMBookmarkController: NSWindowController {
         outlineView.dataSource = self
         outlineView.registerForDraggedTypes([kPasteboardTypeBookmarkRows, .fileURL, .string])
         outlineView.doubleAction = #selector(doubleClickBookmark(_:))
+        
+        
+        bookmarkOutlineView.data = self.bookmarkRoot
     }
 
     func updateStatus() {

+ 48 - 30
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/KMBookmarkOutlineView.swift

@@ -7,12 +7,14 @@
 
 import Cocoa
 
+private let kLabelIdentifier = NSUserInterfaceItemIdentifier("Label")
+private let kFileIdentifier  = NSUserInterfaceItemIdentifier("File")
+private let kPageIdentifier  = NSUserInterfaceItemIdentifier("Page")
+
 class KMBookmarkOutlineView: KMBaseXibView {
     @IBOutlet weak var outlineView: NSOutlineView!
     
-    
-    
-    var data: [[String: Any]] = [] {
+    var data: KMRootBookmark? {
         didSet {
             self.reloadData()
         }
@@ -24,39 +26,44 @@ class KMBookmarkOutlineView: KMBaseXibView {
         // Drawing code here.
     }
     
+    override func setup() {
+        outlineView.delegate = self
+        outlineView.dataSource = self
+        outlineView.registerForDraggedTypes([kPasteboardTypeBookmarkRows, .fileURL, .string])
+        outlineView.doubleAction = #selector(doubleClickBookmark)
+    }
+    
     override func reloadData() {
+        guard let data = data else { return }
         
+        self.outlineView.reloadData()
     }
     
 }
 
+//MARK: Action
+extension KMBookmarkOutlineView {
+    @objc func doubleClickBookmark() {
+        
+    }
+}
+
 // MARK: - NSOutlineViewDataSource
 extension KMBookmarkOutlineView: NSOutlineViewDataSource {
     func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
-        if item == nil {
-            return data.count
-        }
-//        if let key = item as? String, let children = data[key] {
-//            return children.count
-//        }
-        return 0
+        let bookmark = item as? KMBookmark ?? data
+        guard let bookmark = bookmark else { return 0}
+        return bookmark.bookmarkType == .folder ? bookmark.children.count : 0
     }
     
     func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
-//        if let key = item as? String {
-//            return data[key] != nil
-//        }
-        return false
+        let bookmark = item as! KMBookmark
+        return bookmark.bookmarkType == .folder
     }
     
     func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
-//        if item == nil {
-//            return Array(data.keys)[index]
-//        }
-//        if let key = item as? String, let children = data[key] {
-//            return children[index]
-//        }
-        return ""
+        let bookmark = (item as? KMBookmark) ?? data
+        return bookmark?.objectOfChidren(index: index) as Any
     }
 }
 
@@ -64,15 +71,26 @@ extension KMBookmarkOutlineView: NSOutlineViewDelegate {
     // MARK: - NSOutlineViewDelegate
     
     func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
-        if let key = item as? String {
-            let view = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "HeaderCell"), owner: self) as? NSTableCellView
-            view?.textField?.stringValue = key
-            return view
-        } else if let value = item as? String {
-            let view = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DataCell"), owner: self) as? NSTableCellView
-            view?.textField?.stringValue = value
-            return view
+        guard let column = tableColumn else { return nil }
+        guard let item = item as? KMBookmark else { return nil }
+        let identifier = column.identifier
+        
+        var cell: NSTableCellView = NSTableCellView()
+        switch identifier {
+        case kLabelIdentifier: do {
+            cell = KMBookmarkOutlineTitleCellView()
+        }
+        case kPageIdentifier: do {
+            cell = KMBookmarkOutlinePageCellView()
         }
-        return nil
+        case kFileIdentifier: do {
+            cell = KMBookmarkOutlineFileCellView()
+        }
+            
+        default:
+            break
+        }
+        
+        return cell
     }
 }

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/KMBookmarkOutlineView.xib

@@ -30,7 +30,7 @@
                                 <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                                 <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
                                 <tableColumns>
-                                    <tableColumn identifier="AutomaticTableColumnIdentifier.0" width="116" minWidth="40" maxWidth="1000" id="sMA-Yh-GT9">
+                                    <tableColumn identifier="Label" width="116" minWidth="40" maxWidth="1000" id="sMA-Yh-GT9">
                                         <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Label">
                                             <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
@@ -62,7 +62,7 @@
                                             </tableCellView>
                                         </prototypeCellViews>
                                     </tableColumn>
-                                    <tableColumn identifier="AutomaticTableColumnIdentifier.1" width="182" minWidth="40" maxWidth="1000" id="GPb-Sb-7Xi">
+                                    <tableColumn identifier="File" width="182" minWidth="40" maxWidth="1000" id="GPb-Sb-7Xi">
                                         <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="File">
                                             <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
@@ -94,7 +94,7 @@
                                             </tableCellView>
                                         </prototypeCellViews>
                                     </tableColumn>
-                                    <tableColumn width="302" minWidth="10" maxWidth="3.4028234663852886e+38" id="Kie-Fu-Yhs">
+                                    <tableColumn identifier="Page" width="302" minWidth="10" maxWidth="3.4028234663852886e+38" id="Kie-Fu-Yhs">
                                         <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Page">
                                             <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
                                             <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

+ 2 - 1
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlineFileCellView.swift

@@ -9,6 +9,7 @@ import Cocoa
 
 class KMBookmarkOutlineFileCellView: NSTableCellView {
     @IBOutlet var contentView: NSView!
+    @IBOutlet weak var titleLabel: NSTextField!
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
@@ -46,7 +47,7 @@ class KMBookmarkOutlineFileCellView: NSTableCellView {
     }
     
     func setup() {
-        
+        self.titleLabel.textColor = KMAppearance.Layout.w0Color()
     }
     
     func reloadData() {

+ 17 - 2
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlineFileCellView.xib

@@ -9,14 +9,29 @@
         <customObject id="-2" userLabel="File's Owner" customClass="KMBookmarkOutlineFileCellView" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="contentView" destination="c22-O7-iKe" id="ZWl-7Y-Rof"/>
+                <outlet property="titleLabel" destination="Ymy-gW-lXL" id="yKY-Q1-GEm"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="c22-O7-iKe">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
+            <rect key="frame" x="0.0" y="0.0" width="100" height="39"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-            <point key="canvasLocation" x="98" y="133"/>
+            <subviews>
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ymy-gW-lXL">
+                    <rect key="frame" x="6" y="12" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="zyJ-bQ-Ieg">
+                        <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="Ymy-gW-lXL" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="90a-HL-C3i"/>
+                <constraint firstItem="Ymy-gW-lXL" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="8" id="X1J-Ns-qZv"/>
+            </constraints>
+            <point key="canvasLocation" x="95" y="147.5"/>
         </customView>
     </objects>
 </document>

+ 2 - 1
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlinePageCellView.swift

@@ -10,6 +10,7 @@ import Cocoa
 class KMBookmarkOutlinePageCellView: NSTableCellView {
 
     @IBOutlet var contentView: NSView!
+    @IBOutlet weak var titleLabel: NSTextField!
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
 
@@ -46,7 +47,7 @@ class KMBookmarkOutlinePageCellView: NSTableCellView {
     }
     
     func setup() {
-        
+        self.titleLabel.textColor = KMAppearance.Layout.w0Color()
     }
     
     func reloadData() {

+ 17 - 2
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlinePageCellView.xib

@@ -9,14 +9,29 @@
         <customObject id="-2" userLabel="File's Owner" customClass="KMBookmarkOutlinePageCellView" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="contentView" destination="c22-O7-iKe" id="CDE-qQ-uz0"/>
+                <outlet property="titleLabel" destination="6rd-c6-xiO" id="lD4-8c-FAh"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="c22-O7-iKe">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
+            <rect key="frame" x="0.0" y="0.0" width="232" height="49"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-            <point key="canvasLocation" x="34" y="-72"/>
+            <subviews>
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6rd-c6-xiO">
+                    <rect key="frame" x="6" y="17" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="y9R-V3-HMJ">
+                        <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="6rd-c6-xiO" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="aiv-2l-ujJ"/>
+                <constraint firstItem="6rd-c6-xiO" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="8" id="pZe-W9-osc"/>
+            </constraints>
+            <point key="canvasLocation" x="38" y="-25.5"/>
         </customView>
     </objects>
 </document>

+ 6 - 2
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlineTitleCellView.swift

@@ -9,7 +9,11 @@ import Cocoa
 
 class KMBookmarkOutlineTitleCellView: NSTableCellView {
 
-    @IBOutlet var contentView: KMBookmarkOutlineTitleCellView!
+    @IBOutlet weak var iconImageView: NSImageView!
+    @IBOutlet weak var titleLabel: NSTextField!
+    
+    
+    @IBOutlet var contentView: NSView!
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
 
@@ -46,7 +50,7 @@ class KMBookmarkOutlineTitleCellView: NSTableCellView {
     }
     
     func setup() {
-        
+        self.titleLabel.textColor = KMAppearance.Layout.w0Color()
     }
     
     func reloadData() {

+ 30 - 4
PDF Office/PDF Master/Class/PDFTools/KMBookmark/View/OutlineView/View/KMBookmarkOutlineTitleCellView.xib

@@ -8,15 +8,41 @@
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="KMBookmarkOutlineTitleCellView" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
-                <outlet property="contentView" destination="c22-O7-iKe" id="kgI-sL-XI6"/>
+                <outlet property="contentView" destination="c22-O7-iKe" id="D3l-Ey-JD2"/>
+                <outlet property="iconImageView" destination="QOJ-Np-rGX" id="K5a-4H-fjb"/>
+                <outlet property="titleLabel" destination="O2g-MZ-HgZ" id="LiC-Y5-1B3"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
-        <customView id="c22-O7-iKe" customClass="KMBookmarkOutlineTitleCellView" customModule="PDF_Reader_Pro" customModuleProvider="target">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
+        <customView id="c22-O7-iKe">
+            <rect key="frame" x="0.0" y="0.0" width="169" height="44"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-            <point key="canvasLocation" x="34" y="-72"/>
+            <subviews>
+                <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="QOJ-Np-rGX">
+                    <rect key="frame" x="8" y="12" width="20" height="20"/>
+                    <constraints>
+                        <constraint firstAttribute="width" constant="20" id="EcX-nM-Kiw"/>
+                        <constraint firstAttribute="height" constant="20" id="wjS-vc-3rG"/>
+                    </constraints>
+                    <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="k8e-0B-Ovx"/>
+                </imageView>
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="O2g-MZ-HgZ">
+                    <rect key="frame" x="34" y="14" width="37" height="16"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="dZr-Df-1xG">
+                        <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="O2g-MZ-HgZ" firstAttribute="leading" secondItem="QOJ-Np-rGX" secondAttribute="trailing" constant="8" id="7im-Gb-1ak"/>
+                <constraint firstItem="QOJ-Np-rGX" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="SIX-gb-TeH"/>
+                <constraint firstItem="O2g-MZ-HgZ" firstAttribute="centerY" secondItem="c22-O7-iKe" secondAttribute="centerY" id="Ycj-22-abn"/>
+                <constraint firstItem="QOJ-Np-rGX" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="8" id="fB6-QE-pjp"/>
+            </constraints>
+            <point key="canvasLocation" x="-117.5" y="91"/>
         </customView>
     </objects>
 </document>