Skip to content

Commit fb54355

Browse files
committed
Setup search control view as child of webview
1 parent 532bb05 commit fb54355

File tree

3 files changed

+91
-32
lines changed

3 files changed

+91
-32
lines changed

devdocs-macos/DocumentationViewController.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DocumentationViewController:
2424
super.viewDidLoad()
2525
self.viewerState = .initializing
2626
setupWebView()
27+
setupSearchControlView()
2728
loadWebsite()
2829
}
2930

@@ -57,10 +58,25 @@ class DocumentationViewController:
5758
webView.wantsLayer = true
5859

5960
view.addSubview(webView)
60-
webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
61-
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
62-
webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
63-
webView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
61+
NSLayoutConstraint.activate([
62+
webView.topAnchor.constraint(equalTo: view.topAnchor),
63+
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
64+
webView.leftAnchor.constraint(equalTo: view.leftAnchor),
65+
webView.rightAnchor.constraint(equalTo: view.rightAnchor)
66+
])
67+
}
68+
69+
private func setupSearchControlView() {
70+
let searchVC = SearchControlViewController()
71+
72+
let searchView = searchVC.view
73+
searchView.translatesAutoresizingMaskIntoConstraints = false
74+
75+
webView.addSubview(searchView);
76+
NSLayoutConstraint.activate([
77+
searchView.widthAnchor.constraint(equalToConstant: 270),
78+
searchView.rightAnchor.constraint(equalTo: webView.rightAnchor)
79+
])
6480
}
6581

6682
private func loadWebsite() {

devdocs-macos/SearchControlView.xib

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,67 @@
88
<customObject id="-2" userLabel="File's Owner" customClass="SearchControlViewController" customModule="DevDocs" customModuleProvider="target">
99
<connections>
1010
<outlet property="searchField" destination="Sob-7j-rmS" id="63N-X7-5xX"/>
11+
<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="376" height="19"/>
17-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
17+
<rect key="frame" x="0.0" y="0.0" width="269" height="35"/>
18+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
1819
<subviews>
19-
<searchField wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sob-7j-rmS">
20-
<rect key="frame" x="0.0" y="0.0" width="309" height="19"/>
21-
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
22-
<searchFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" sendsSearchStringImmediately="YES" sendsWholeSearchString="YES" id="p9W-s3-2vm">
23-
<font key="font" metaFont="smallSystem"/>
24-
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
25-
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
26-
</searchFieldCell>
27-
<connections>
28-
<action selector="performSearchWithSender:" target="-2" id="qdb-CE-9Q0"/>
29-
</connections>
30-
</searchField>
31-
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NIJ-J2-h3b">
32-
<rect key="frame" x="317.5" y="0.0" width="60" height="19"/>
33-
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
34-
<buttonCell key="cell" type="roundTextured" title="Done" bezelStyle="texturedRounded" alignment="center" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="HKN-5M-iIK">
35-
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
36-
<font key="font" metaFont="smallSystem"/>
37-
</buttonCell>
38-
<connections>
39-
<action selector="dismissSearchWithSender:" target="-2" id="wRM-kj-W9W"/>
40-
</connections>
41-
</button>
20+
<stackView distribution="fill" orientation="horizontal" alignment="centerY" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j60-Tm-mzj">
21+
<rect key="frame" x="8" y="8" width="253" height="19"/>
22+
<subviews>
23+
<searchField wantsLayer="YES" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sob-7j-rmS">
24+
<rect key="frame" x="0.0" y="0.0" width="200" height="19"/>
25+
<constraints>
26+
<constraint firstAttribute="width" constant="200" id="Zms-uK-vwr"/>
27+
</constraints>
28+
<searchFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" sendsSearchStringImmediately="YES" sendsWholeSearchString="YES" id="p9W-s3-2vm">
29+
<font key="font" metaFont="smallSystem"/>
30+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
31+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
32+
</searchFieldCell>
33+
<connections>
34+
<action selector="performSearch:" target="-2" id="C7J-uG-P9I"/>
35+
</connections>
36+
</searchField>
37+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="NIJ-J2-h3b">
38+
<rect key="frame" x="208" y="1" width="45" height="17"/>
39+
<constraints>
40+
<constraint firstAttribute="width" constant="45" id="7hz-st-MQx"/>
41+
</constraints>
42+
<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">
43+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
44+
<font key="font" metaFont="smallSystem"/>
45+
</buttonCell>
46+
<connections>
47+
<action selector="dismissSearch:" target="-2" id="uF4-ir-bYe"/>
48+
</connections>
49+
</button>
50+
</subviews>
51+
<constraints>
52+
<constraint firstItem="NIJ-J2-h3b" firstAttribute="leading" secondItem="Sob-7j-rmS" secondAttribute="trailing" constant="8" id="H2z-1j-JfD"/>
53+
<constraint firstItem="Sob-7j-rmS" firstAttribute="baseline" secondItem="NIJ-J2-h3b" secondAttribute="baseline" id="wQH-wX-YLc"/>
54+
</constraints>
55+
<visibilityPriorities>
56+
<integer value="1000"/>
57+
<integer value="1000"/>
58+
</visibilityPriorities>
59+
<customSpacing>
60+
<real value="3.4028234663852886e+38"/>
61+
<real value="3.4028234663852886e+38"/>
62+
</customSpacing>
63+
</stackView>
4264
</subviews>
43-
<point key="canvasLocation" x="80" y="58"/>
65+
<constraints>
66+
<constraint firstAttribute="trailing" secondItem="j60-Tm-mzj" secondAttribute="trailing" constant="8" id="8ys-lG-1oP"/>
67+
<constraint firstItem="j60-Tm-mzj" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" constant="8" id="BlZ-p9-JuD"/>
68+
<constraint firstAttribute="bottom" secondItem="j60-Tm-mzj" secondAttribute="bottom" constant="8" id="pdA-K4-rKr"/>
69+
<constraint firstItem="j60-Tm-mzj" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" constant="8" id="uOJ-LT-T0k"/>
70+
</constraints>
71+
<point key="canvasLocation" x="42.5" y="105.5"/>
4472
</customView>
4573
</objects>
4674
</document>

devdocs-macos/SearchControlViewController.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ class SearchControlViewController: NSViewController {
44
@IBOutlet weak var searchField: NSSearchField?
55
weak var delegate: SearchControlDelegate?
66

7-
@IBAction func performSearch(sender: Any) {
7+
init() {
8+
super.init(nibName: NSNib.Name("SearchControlView"), bundle: nil)
9+
}
10+
11+
required init?(coder: NSCoder) {
12+
super.init(coder: coder)
13+
}
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
18+
view.wantsLayer = true
19+
view.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
20+
}
21+
22+
@IBAction func performSearch(_ sender: Any) {
823
let searchTerm = (searchField?.stringValue ?? "")
924
.trimmingCharacters(in: .whitespacesAndNewlines)
1025
if (searchTerm.isEmpty) {
@@ -13,7 +28,7 @@ class SearchControlViewController: NSViewController {
1328
delegate?.search(term: searchTerm)
1429
}
1530

16-
@IBAction func dismissSearch(sender: Any) {
31+
@IBAction func dismissSearch(_ sender: Any) {
1732
delegate?.dismiss()
1833
}
1934
}

0 commit comments

Comments
 (0)