瀏覽代碼

【工具】查找UI实现

lizhe 1 年之前
父節點
當前提交
ca3b666ba2

+ 5 - 0
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -789,6 +789,11 @@ extension KMBrowserWindowController {
     }
     @IBAction func performFindPanelAction(_ sender: Any?) {
         KMPrint("performFindPanelAction ...")
+        if let document = self.browser.activeTabContents() as? KMMainDocument {
+            if document.isHome == false {
+                document.mainViewController?.toolbarController.showFindBar()
+            }
+        }
     }
     @IBAction func scrollUp(_ sender: Any?) {
         KMPrint("scrollUp ...")

+ 1 - 0
PDF Office/PDF Master/Class/Document/KMMainDocument.swift

@@ -573,6 +573,7 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
     }
     @IBAction func performFindPanelAction(_ sender: Any?) {
         KMPrint("performFindPanelAction")
+        self.mainViewController?.toolbarController.showFindBar()
     }
     
     @IBAction func addBookmark(_ sender: Any?) {

+ 15 - 94
PDF Office/PDF Master/Class/PDFTools/FindSearch/KMSearchFindView.swift

@@ -7,18 +7,15 @@
 
 import Cocoa
 
-protocol SKFindControllerDelegate: AnyObject {
-    func findString(_ searchString: String, forward: Bool) -> Bool
-    func showFindView(_ sender: AnyObject)
-}
+typealias KMSearchFindViewDoneAction = (_ view: KMSearchFindView) -> Void
+typealias KMSearchFindViewSearchAction = (_ view: KMSearchFindView, _ searchString: String, _ forward: Bool) -> Bool
+typealias KMSearchFindViewShowAllAction = (_ view: KMSearchFindView) -> Void
 
 class KMSearchFindView: KMBaseXibView {
-
-    weak var delegate: SKFindControllerDelegate?
-    @IBOutlet var findField: NSTextField!
+    @IBOutlet var findField: NSSearchField!
     @IBOutlet var messageField: NSTextField!
     @IBOutlet var doneButton: NSButton!
-    @IBOutlet var navigationButton: NSButton!
+    @IBOutlet var navigationButton: NSSegmentedControl!
     @IBOutlet var showAllButton: NSButton!
     
     var ownerController: AnyObject?
@@ -27,6 +24,10 @@ class KMSearchFindView: KMBaseXibView {
     private var lastChangeCount: Int = 0
     private var didChange: Bool = false
     private var animating: Bool = false
+    
+    var showAllAction: KMSearchFindViewShowAllAction?
+    var doneAction: KMSearchFindViewDoneAction?
+    var searchAction: KMSearchFindViewSearchAction?
 
     override func setup() {
         refreshSearchBarMenu()
@@ -100,87 +101,6 @@ class KMSearchFindView: KMBaseXibView {
         }
     }
 
-    func toggleAboveView(_ view: NSView?, animate: Bool) {
-        if animating {
-            return
-        }
-
-        if UserDefaults.standard.bool(forKey: SKDisableAnimationsKey) {
-            animating = false
-        }
-
-        let findBar = self
-
-        var viewToAttachTo: NSView?
-        if view == nil {
-            let subviews = findBar.superview?.subviews ?? []
-            for v in subviews {
-                if v != findBar && (fabs(NSMinY(v.frame) - NSMaxY(findBar.frame)) <= 0.0 ||
-                    fabs(NSMaxY(v.frame) - NSMinY(findBar.frame)) <= 0.0) {
-                    viewToAttachTo = v
-                    break
-                }
-            }
-        } else {
-            viewToAttachTo = view
-        }
-
-        guard let attachView = viewToAttachTo else { return }
-
-        let viewFrame = attachView.frame
-        guard let contentView = attachView.superview else { return }
-        var barRect = attachView.frame
-        var barHeight = NSHeight(findBar.frame)
-        var visible = findBar.superview != nil
-
-        barRect.size.height = barHeight
-
-        if visible {
-            if contentView.isFlipped {
-                barRect.origin.y -= barHeight
-            } else {
-                barRect.origin.y = NSMaxY(contentView.bounds)
-            }
-
-            findBar.frame = barRect
-            contentView.addSubview(findBar, positioned: .below, relativeTo: nil)
-            barHeight = -barHeight
-        } else {
-            if contentView.isFlipped {
-                barRect.origin.y -= barHeight
-            } else {
-                barRect.origin.y = NSMaxY(contentView.bounds) - barHeight
-            }
-            contentView.addSubview(findBar, positioned: .below, relativeTo: nil)
-        }
-
-        if animate {
-            animating = true
-            NSAnimationContext.runAnimationGroup({ context in
-                context.duration = 0.5 * context.duration
-                view?.animator().frame = viewFrame
-                findBar.animator().frame = barRect
-            }, completionHandler: {
-                [weak self] in
-                guard let self = self else { return }
-                let window = self.window
-                if !visible {
-                    self.removeFromSuperview()
-                }
-                window?.recalculateKeyViewLoop()
-                self.animating = false
-            })
-        } else {
-            view?.frame = viewFrame
-            findBar.frame = barRect
-            let window = contentView.window
-            if !visible {
-                findBar.removeFromSuperview()
-            }
-            window?.recalculateKeyViewLoop()
-        }
-    }
-
     func setFindString(_ newFindString: String?) {
         if findString != newFindString {
             findString = newFindString
@@ -191,7 +111,8 @@ class KMSearchFindView: KMBaseXibView {
     func findForward(_ forward: Bool) {
         var found = true
         if let findStringLength = findString?.count, findStringLength > 0 {
-            found = delegate?.findString(findString!, forward: forward) ?? false
+            guard let searchAction = searchAction else { return }
+            found = searchAction(self,findString!,forward)
             updateFindPboard()
 
             if var words = UserDefaults.standard.object(forKey: "kmDocumentSearchWordArrays") as? [String] {
@@ -212,16 +133,16 @@ class KMSearchFindView: KMBaseXibView {
         messageField.isHidden = found
     }
 
-    @IBAction func find(_ sender: NSButton) {
-        findForward(sender.tag == 1)
+    @IBAction func find(_ sender: Any) {
+        findForward((sender as AnyObject).selectedTag() == 1)
     }
 
     @IBAction func buttonItemClick_ShowAll(_ sender: NSButton) {
-        delegate?.showFindView(self)
+        showAllAction?(self)
     }
 
     @IBAction func remove(_ sender: Any) {
-        toggleAboveView(nil, animate: true)
+        doneAction?(self)
     }
 
     @IBAction func toggleCaseInsensitiveFind(_ sender: Any) {

+ 21 - 1
PDF Office/PDF Master/Class/PDFTools/FindSearch/KMSearchFindView.xib

@@ -6,7 +6,15 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMSearchFindView" customModule="PDF_Reader_Pro" customModuleProvider="target"/>
+        <customObject id="-2" userLabel="File's Owner" customClass="KMSearchFindView" customModule="PDF_Reader_Pro" customModuleProvider="target">
+            <connections>
+                <outlet property="doneButton" destination="ZGn-Xg-mLb" id="9Ib-aL-JXX"/>
+                <outlet property="findField" destination="uqd-u5-RCM" id="05y-bI-zcX"/>
+                <outlet property="messageField" destination="Jox-sd-bZ1" id="OYp-cH-Qfs"/>
+                <outlet property="navigationButton" destination="Kpw-uz-fLM" id="tMR-3o-bxS"/>
+                <outlet property="showAllButton" destination="nvA-dy-fag" id="fAf-hs-eUR"/>
+            </connections>
+        </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="c22-O7-iKe">
@@ -24,6 +32,9 @@
                                 <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                 <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                             </searchFieldCell>
+                            <connections>
+                                <action selector="find:" target="-2" id="7mk-EG-drS"/>
+                            </connections>
                         </searchField>
                         <segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Kpw-uz-fLM">
                             <rect key="frame" x="149" y="3" width="43" height="20"/>
@@ -35,6 +46,9 @@
                                     <segment image="NSGoRightTemplate" width="18" tag="1"/>
                                 </segments>
                             </segmentedCell>
+                            <connections>
+                                <action selector="find:" target="-2" id="bzA-ov-IEz"/>
+                            </connections>
                         </segmentedControl>
                         <button imageHugsTitle="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZGn-Xg-mLb">
                             <rect key="frame" x="372" y="3" width="42" height="19"/>
@@ -46,6 +60,9 @@
 Gw
 </string>
                             </buttonCell>
+                            <connections>
+                                <action selector="remove:" target="-2" id="EjK-fP-DSG"/>
+                            </connections>
                         </button>
                         <button imageHugsTitle="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nvA-dy-fag">
                             <rect key="frame" x="75" y="3" width="59" height="19"/>
@@ -57,6 +74,9 @@ Gw
 Gw
 </string>
                             </buttonCell>
+                            <connections>
+                                <action selector="buttonItemClick_ShowAll:" target="-2" id="Phn-iN-YPG"/>
+                            </connections>
                         </button>
                         <textField hidden="YES" focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jox-sd-bZ1">
                             <rect key="frame" x="7" y="6" width="58" height="14"/>

+ 54 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -70,6 +70,9 @@ class KMToolbarController: NSViewController {
     
     var popover: NSPopover?
     
+    //find seaarch
+    @IBOutlet weak var findSearchView: KMSearchFindView!
+    
     // 是否显示所有注释
     private var _isShowAllAnnotations = true
     // 是否显示所有注释
@@ -505,6 +508,57 @@ class KMToolbarController: NSViewController {
     }
 }
 
+//MARK: Find Search
+extension KMToolbarController {
+    func showFindBar() {
+        print("showFindBar")
+        var height: Float = 0.0
+        if _toolbarType == .None {
+            bottomOffset.constant = 0 + 25
+            height = 40 + 8
+        } else if _toolbarType == .Page || _toolbarType == .LeftPanel || _toolbarType == .redact {
+            bottomOffset.constant = 0 + 25
+            height = 40 + 8
+        } else {
+            bottomOffset.constant = 41 + 25
+            height = 81 + 8
+        }
+        height = height + 25
+        self.delegate?.toolbarController?(self, heightOffsetChange: height)
+        
+        
+        self.findSearchView.doneAction = { [unowned self] view in
+            self.exitFindBar()
+        }
+        
+        self.findSearchView.searchAction = { view, searchString, forward in
+            
+            return true
+        }
+        
+        self.findSearchView.showAllAction = { view in
+            
+        }
+    }
+    
+    func exitFindBar() {
+        var height: Float = 0.0
+        if _toolbarType == .None {
+            bottomOffset.constant = 0
+            height = 40 + 8
+        } else if _toolbarType == .Page || _toolbarType == .LeftPanel || _toolbarType == .redact {
+            bottomOffset.constant = 0
+            height = 40 + 8
+        } else {
+            bottomOffset.constant = 41
+            height = 81 + 8
+        }
+        self.delegate?.toolbarController?(self, heightOffsetChange: height)
+        
+        print("exitFindBar")
+    }
+}
+
 extension KMToolbarController: KMToolbarViewControllerDelegate {
     func changeAnnotationModeAction(item: KMToolbarClickButton) {
         let type = CAnnotationType(rawValue: item.tag) ?? CAnnotationType.unkown

+ 21 - 11
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.xib

@@ -6,11 +6,12 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMToolbarController" customModule="PDF_Master" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMToolbarController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="bottomOffset" destination="13q-tk-M06" id="wDV-8G-vPv"/>
                 <outlet property="childToolBarBox" destination="aNc-zO-23T" id="f2v-x5-6Se"/>
                 <outlet property="childToolBarHeight" destination="TS3-rt-q1o" id="pRJ-KU-WHX"/>
+                <outlet property="findSearchView" destination="tGD-NS-sob" id="fbh-Hj-RAf"/>
                 <outlet property="mainToolBarBox" destination="b8z-Di-m1z" id="ran-wB-8oy"/>
                 <outlet property="mainToolBarHeight" destination="i7L-pj-kvo" id="abG-kF-buD"/>
                 <outlet property="secondaryToolBarBox" destination="Mqb-Vg-uBB" id="emt-w0-x3t"/>
@@ -21,13 +22,20 @@
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="127"/>
+            <rect key="frame" x="0.0" y="0.0" width="652" height="127"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="tGD-NS-sob" customClass="KMSearchFindView" customModule="PDF_Reader_Pro" customModuleProvider="target">
+                    <rect key="frame" x="152" y="0.0" width="500" height="25"/>
+                    <constraints>
+                        <constraint firstAttribute="height" constant="25" id="4Rt-cP-Bov"/>
+                        <constraint firstAttribute="width" constant="500" id="dWa-gK-AJ7"/>
+                    </constraints>
+                </customView>
                 <box boxType="custom" borderType="none" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="b8z-Di-m1z">
-                    <rect key="frame" x="0.0" y="86" width="480" height="41"/>
+                    <rect key="frame" x="0.0" y="86" width="652" height="41"/>
                     <view key="contentView" id="9dq-dZ-TkR">
-                        <rect key="frame" x="0.0" y="0.0" width="480" height="41"/>
+                        <rect key="frame" x="0.0" y="0.0" width="652" height="41"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     </view>
                     <constraints>
@@ -35,9 +43,9 @@
                     </constraints>
                 </box>
                 <box boxType="custom" borderType="none" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="aNc-zO-23T">
-                    <rect key="frame" x="0.0" y="45" width="480" height="41"/>
+                    <rect key="frame" x="0.0" y="45" width="652" height="41"/>
                     <view key="contentView" id="4e8-ss-OHq">
-                        <rect key="frame" x="0.0" y="0.0" width="480" height="41"/>
+                        <rect key="frame" x="0.0" y="0.0" width="652" height="41"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     </view>
                     <constraints>
@@ -45,9 +53,9 @@
                     </constraints>
                 </box>
                 <box boxType="custom" borderType="none" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Mqb-Vg-uBB">
-                    <rect key="frame" x="0.0" y="0.0" width="480" height="50"/>
+                    <rect key="frame" x="0.0" y="25" width="652" height="50"/>
                     <view key="contentView" id="bQJ-7e-vje">
-                        <rect key="frame" x="0.0" y="0.0" width="480" height="50"/>
+                        <rect key="frame" x="0.0" y="0.0" width="652" height="50"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     </view>
                     <constraints>
@@ -55,7 +63,7 @@
                     </constraints>
                 </box>
                 <box hidden="YES" verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="6Gq-nS-ePL">
-                    <rect key="frame" x="0.0" y="83" width="480" height="5"/>
+                    <rect key="frame" x="0.0" y="83" width="652" height="5"/>
                 </box>
             </subviews>
             <constraints>
@@ -65,15 +73,17 @@
                 <constraint firstItem="aNc-zO-23T" firstAttribute="top" secondItem="b8z-Di-m1z" secondAttribute="bottom" id="7cT-BK-jfd"/>
                 <constraint firstItem="6Gq-nS-ePL" firstAttribute="top" secondItem="b8z-Di-m1z" secondAttribute="bottom" id="84r-zI-3xp"/>
                 <constraint firstItem="Mqb-Vg-uBB" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="ALz-dn-I4s"/>
+                <constraint firstAttribute="trailing" secondItem="tGD-NS-sob" secondAttribute="trailing" id="CK2-Pi-kaH"/>
                 <constraint firstItem="b8z-Di-m1z" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="DG7-MZ-ez8"/>
+                <constraint firstAttribute="bottom" secondItem="tGD-NS-sob" secondAttribute="bottom" id="b1n-qv-gh9"/>
                 <constraint firstItem="aNc-zO-23T" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="ek5-er-ZkU"/>
-                <constraint firstAttribute="bottom" secondItem="Mqb-Vg-uBB" secondAttribute="bottom" id="j17-ns-JOp"/>
                 <constraint firstItem="b8z-Di-m1z" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="qTB-C9-Nww"/>
                 <constraint firstAttribute="trailing" secondItem="b8z-Di-m1z" secondAttribute="trailing" id="xHV-p9-ygz"/>
                 <constraint firstAttribute="trailing" secondItem="Mqb-Vg-uBB" secondAttribute="trailing" id="z4V-jY-edh"/>
                 <constraint firstAttribute="trailing" secondItem="aNc-zO-23T" secondAttribute="trailing" id="zmB-rc-hCx"/>
+                <constraint firstItem="tGD-NS-sob" firstAttribute="top" secondItem="Mqb-Vg-uBB" secondAttribute="bottom" id="zrp-Bb-3LH"/>
             </constraints>
-            <point key="canvasLocation" x="-7" y="152.5"/>
+            <point key="canvasLocation" x="-93" y="180.5"/>
         </customView>
     </objects>
 </document>