Skip to content

Commit fe70f00

Browse files
committed
Refactor DocumentationWindows class
1 parent 63f5e5c commit fe70f00

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

devdocs-macos/DocumentationViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extension DocumentationViewController: WKUIDelegate {
180180
}
181181

182182
if let host = requestURL.host, host == "devdocs.io" {
183-
DocumentationWindows.shared.newWindowFor(url: requestURL)
183+
DocumentationWindows.shared.newWindow(forURL: requestURL)
184184
return nil
185185
}
186186

devdocs-macos/DocumentationWindows.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Cocoa
22

3-
class DocumentationWindows: NSObject, NSWindowDelegate {
3+
class DocumentationWindows: NSObject {
44
private var windowControllers: Set<DocumentationWindowController>
55

66
static let shared = DocumentationWindows()
@@ -10,11 +10,11 @@ class DocumentationWindows: NSObject, NSWindowDelegate {
1010
}
1111

1212
func newWindow() {
13-
newWindowFor(documentation: Documentation.init())
13+
newWindow(forDoc: Documentation.init())
1414
}
1515

16-
func newWindowFor(url: URL) {
17-
newWindowFor(documentation: Documentation.init(withURL: url))
16+
func newWindow(forURL url: URL) {
17+
newWindow(forDoc: Documentation.init(withURL: url))
1818
}
1919

2020
func newWindowIfNoWindow() {
@@ -23,15 +23,7 @@ class DocumentationWindows: NSObject, NSWindowDelegate {
2323
}
2424
}
2525

26-
func windowWillClose(_ notification: Notification) {
27-
guard let window = notification.object as! NSWindow? else { return }
28-
guard let dwc = window.windowController as! DocumentationWindowController? else {
29-
return
30-
}
31-
windowControllers.remove(dwc)
32-
}
33-
34-
private func newWindowFor(documentation: Documentation) {
26+
private func newWindow(forDoc documentation: Documentation) {
3527
let dwc = DocumentationWindowController.init(window: nil)
3628
dwc.documentation = documentation
3729
dwc.window?.delegate = self
@@ -60,11 +52,21 @@ class DocumentationWindows: NSObject, NSWindowDelegate {
6052
return false
6153
}
6254
}.forEach { url in
63-
newWindowFor(url: url)
55+
newWindow(forURL: url)
6456
}
6557
} else {
6658
newWindow()
6759
}
6860
}
61+
}
6962

63+
// MARK:- NSWindowDelegate
64+
extension DocumentationWindows: NSWindowDelegate {
65+
func windowWillClose(_ notification: Notification) {
66+
guard let window = notification.object as! NSWindow? else { return }
67+
guard let dwc = window.windowController as! DocumentationWindowController? else {
68+
return
69+
}
70+
windowControllers.remove(dwc)
71+
}
7072
}

devdocs-macos/URLEventHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class URLEventHandler {
4141
}
4242

4343
NSApp.activate(ignoringOtherApps: true)
44-
DocumentationWindows.shared.newWindowFor(url: searchURL)
44+
DocumentationWindows.shared.newWindow(forURL: searchURL)
4545
case "newWindow":
4646
NSApp.activate(ignoringOtherApps: true)
4747
DocumentationWindows.shared.newWindow()
4848
case "devdocs.io":
4949
NSApp.activate(ignoringOtherApps: true)
50-
DocumentationWindows.shared.newWindowFor(url: url!)
50+
DocumentationWindows.shared.newWindow(forURL: url!)
5151
default:
5252
return
5353
}

0 commit comments

Comments
 (0)