Skip to content

Commit 2e85dc3

Browse files
committed
Can activate find
1 parent 792401b commit 2e85dc3

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

devdocs-macos/AppDelegate.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2323
@IBAction func showAppPreferences(sender: Any) {
2424
PreferencesWindowController.shared.showWindow(self)
2525
}
26+
27+
@IBAction func performFindAction(_ sender: Any) {
28+
guard let window = NSApp.mainWindow else { return }
29+
let dwc = window.windowController.map { wc in
30+
wc as! DocumentationWindowController
31+
}
32+
dwc?.activateFind()
33+
}
2634
}

devdocs-macos/Base.lproj/MainMenu.xib

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
55
</dependencies>
66
<objects>
77
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -148,7 +148,7 @@
148148
<items>
149149
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
150150
<connections>
151-
<action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
151+
<action selector="performFindAction:" target="Voe-Tx-rLC" id="vhB-Hv-WQM"/>
152152
</connections>
153153
</menuItem>
154154
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
@@ -595,7 +595,7 @@
595595
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
596596
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
597597
<connections>
598-
<action selector="toggleSourceList:" target="-1" id="iwa-gc-5KM"/>
598+
<action selector="toggleSidebar:" target="-1" id="iwa-gc-5KM"/>
599599
</connections>
600600
</menuItem>
601601
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
@@ -645,6 +645,7 @@
645645
</menu>
646646
</menuItem>
647647
</items>
648+
<point key="canvasLocation" x="10" y="39"/>
648649
</menu>
649650
</objects>
650651
</document>

devdocs-macos/DocumentationViewController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DocumentationViewController:
100100
return
101101
}
102102
guard let vc = searchCVC else { return }
103-
vc.view.isHidden = false
103+
vc.activate()
104104
}
105105

106106
// MARK:- WKUIDelegate
@@ -220,7 +220,5 @@ extension DocumentationViewController: SearchControlDelegate {
220220

221221
func dismiss() {
222222
webView.evaluateJavaScript("resetSearch();")
223-
guard let vc = searchCVC else { return }
224-
vc.view.isHidden = true
225223
}
226224
}

devdocs-macos/DocumentationWindowController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class DocumentationWindowController: NSWindowController {
2828
observeEffectiveAppearance()
2929
}
3030

31+
func activateFind() {
32+
guard let dvc = documentationViewController else { return }
33+
dvc.showSearchControl()
34+
}
35+
3136
private func observeViewerState() {
3237
guard let dvc = documentationViewController else { return }
3338
observations.insert(

devdocs-macos/SearchControlView.xib

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
<objects>
88
<customObject id="-2" userLabel="File's Owner" customClass="SearchControlViewController" customModule="DevDocs" customModuleProvider="target">
99
<connections>
10+
<outlet property="searchField" destination="Sob-7j-rmS" id="N7c-vj-yOn"/>
1011
<outlet property="view" destination="c22-O7-iKe" id="8CF-Bz-17c"/>
1112
</connections>
1213
</customObject>
1314
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1415
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
1516
<customView id="c22-O7-iKe">
16-
<rect key="frame" x="0.0" y="0.0" width="269" height="35"/>
17+
<rect key="frame" x="0.0" y="0.0" width="269" height="36"/>
1718
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
1819
<subviews>
1920
<stackView distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j60-Tm-mzj">
20-
<rect key="frame" x="8" y="8" width="253" height="19"/>
21+
<rect key="frame" x="8" y="8" width="253" height="20"/>
2122
<subviews>
2223
<searchField wantsLayer="YES" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sob-7j-rmS">
2324
<rect key="frame" x="0.0" y="0.0" width="200" height="19"/>
@@ -27,17 +28,18 @@
2728
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
2829
</searchFieldCell>
2930
<connections>
30-
<action selector="performSearch:" target="-2" id="i8X-0A-USs"/>
31+
<action selector="performSearch:" target="-2" id="exz-1K-crg"/>
32+
<outlet property="delegate" destination="-2" id="uOj-0Y-Jyb"/>
3133
</connections>
3234
</searchField>
3335
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NIJ-J2-h3b">
34-
<rect key="frame" x="208" y="1" width="45" height="17"/>
36+
<rect key="frame" x="208" y="1" width="45" height="19"/>
3537
<constraints>
3638
<constraint firstAttribute="width" constant="45" id="7hz-st-MQx"/>
3739
</constraints>
38-
<buttonCell key="cell" type="roundRect" title="Done" bezelStyle="roundedRect" alignment="center" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="HKN-5M-iIK">
40+
<buttonCell key="cell" type="roundRect" title="Done" bezelStyle="roundedRect" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="HKN-5M-iIK">
3941
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
40-
<font key="font" metaFont="smallSystem"/>
42+
<font key="font" metaFont="cellTitle"/>
4143
</buttonCell>
4244
<connections>
4345
<action selector="dismissSearch:" target="-2" id="qfV-XO-2d2"/>

devdocs-macos/SearchControlViewController.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Cocoa
22

33
class SearchControlViewController: NSViewController {
44
weak var delegate: SearchControlDelegate?
5+
@IBOutlet weak var searchField: NSSearchField!
56

67
init() {
78
super.init(nibName: NSNib.Name("SearchControlView"), bundle: nil)
@@ -18,7 +19,32 @@ class SearchControlViewController: NSViewController {
1819
view.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
1920
}
2021

22+
override func viewDidAppear() {
23+
super.viewDidAppear()
24+
searchField?.becomeFirstResponder()
25+
}
26+
27+
override func viewWillDisappear() {
28+
super.viewWillDisappear()
29+
delegate?.dismiss()
30+
}
31+
32+
func activate() {
33+
self.view.isHidden = false
34+
searchField?.becomeFirstResponder()
35+
}
36+
2137
@IBAction func performSearch(_ searchField: NSSearchField) {
38+
searchFieldDidStartSearching(searchField)
39+
}
40+
41+
@IBAction func dismissSearch(_ sender: Any) {
42+
self.view.isHidden = true
43+
}
44+
}
45+
46+
extension SearchControlViewController: NSSearchFieldDelegate {
47+
func searchFieldDidStartSearching(_ searchField: NSSearchField) {
2248
let searchTerm = searchField.stringValue
2349
.trimmingCharacters(in: .whitespacesAndNewlines)
2450
if (searchTerm.isEmpty) {
@@ -27,8 +53,8 @@ class SearchControlViewController: NSViewController {
2753
delegate?.search(term: searchTerm)
2854
}
2955

30-
@IBAction func dismissSearch(_ sender: Any) {
31-
delegate?.dismiss()
56+
func searchFieldDidEndSearching(_ sender: NSSearchField) {
57+
self.view.isHidden = true
3258
}
3359
}
3460

0 commit comments

Comments
 (0)