Skip to content

Commit 8d87858

Browse files
committed
Split window title into topic + doc
1 parent 0042e3d commit 8d87858

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

devdocs-macos/DocumentationViewController.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import WebKit
44
public extension Notification.Name {
55
static let DocumentTitleDidChange = Notification.Name(
66
rawValue: "DocumentationViewControllerDocumentTitleDidChangeNotification")
7+
static let DocumentCategoryDidChange = Notification.Name(
8+
rawValue: "DocumentationViewControllerDocumentCategoryDidChangeNotification")
79
static let DocumentURLDidChange = Notification.Name(
810
rawValue: "DocumentationViewControllerDocumentURLDidChangeNotification")
911
static let DocumentViewerStateDidChange = Notification.Name(
@@ -26,6 +28,11 @@ class DocumentationViewController: NSViewController {
2628
NotificationCenter.default.post(name: .DocumentTitleDidChange, object: self)
2729
}
2830
}
31+
private(set) var documentCategory: String? {
32+
didSet {
33+
NotificationCenter.default.post(name: .DocumentCategoryDidChange, object: self)
34+
}
35+
}
2936
var documentURL: URL? {
3037
didSet {
3138
NotificationCenter.default.post(name: .DocumentURLDidChange, object: self)
@@ -149,14 +156,21 @@ class DocumentationViewController: NSViewController {
149156
}
150157

151158
private func handleTitleNotification(_ args: [AnyHashable: Any]) {
152-
guard let title = args["title"] as! String? else {
153-
return
159+
if let topic = args["topic"] as! String? {
160+
self.documentTitle = topic
161+
} else if let title = args["title"] as! String? {
162+
let suffix = " — DevDocs"
163+
if title.hasSuffix(suffix) {
164+
self.documentTitle = title.replacingOccurrences(of: suffix, with: "")
165+
} else {
166+
self.documentTitle = title
167+
}
154168
}
155-
let suffix = " — DevDocs"
156-
if title.hasSuffix(suffix) {
157-
self.documentTitle = title.replacingOccurrences(of: suffix, with: "")
169+
170+
if let doc = args["doc"] as! String? {
171+
self.documentCategory = doc
158172
} else {
159-
self.documentTitle = title
173+
self.documentCategory = nil
160174
}
161175
}
162176

devdocs-macos/DocumentationWindowController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class DocumentationWindowController: NSWindowController {
3636
name: .DocumentTitleDidChange,
3737
object: dvc)
3838

39+
NotificationCenter.default.addObserver(self,
40+
selector: #selector(observeDocumentCategory),
41+
name: .DocumentCategoryDidChange,
42+
object: dvc)
43+
3944
NotificationCenter.default.addObserver(self,
4045
selector: #selector(observeDocumentURL),
4146
name: .DocumentURLDidChange,
@@ -65,6 +70,13 @@ class DocumentationWindowController: NSWindowController {
6570
self.window?.title = dvc.documentTitle ?? "DevDocs"
6671
}
6772

73+
@objc private func observeDocumentCategory() {
74+
guard let dvc = documentationViewController else { return }
75+
if #available(OSX 11.0, *) {
76+
self.window?.subtitle = dvc.documentCategory ?? ""
77+
}
78+
}
79+
6880
@objc private func observeDocumentURL() {
6981
guard let dvc = documentationViewController else { return }
7082
self.documentation.url = dvc.documentURL

0 commit comments

Comments
 (0)