Skip to content

Commit e3d62cd

Browse files
committed
Remove unnecessary NSToolbarItem subclass
1 parent 16f9de8 commit e3d62cd

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

DevDocs.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
06B5A73921D3665C007823B2 /* DefaultsKit.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 06B5A73821D3665C007823B2 /* DefaultsKit.framework.dSYM */; };
2323
06B5A73B21D36680007823B2 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B5A73A21D36680007823B2 /* Storage.swift */; };
2424
06CAA897223E6ACB00B296AC /* URLEventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CAA896223E6ACB00B296AC /* URLEventHandler.swift */; };
25-
06CFC3B8256CE31B00330C5D /* NavigationToolbarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CFC3B7256CE31B00330C5D /* NavigationToolbarItem.swift */; };
2625
06EAE7ED21D0CB3D00F7C921 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06EAE7EC21D0CB3D00F7C921 /* AppDelegate.swift */; };
2726
06EAE7EF21D0CB3E00F7C921 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 06EAE7EE21D0CB3E00F7C921 /* Assets.xcassets */; };
2827
06EAE7F221D0CB3E00F7C921 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 06EAE7F021D0CB3E00F7C921 /* MainMenu.xib */; };
@@ -72,7 +71,6 @@
7271
06B5A73821D3665C007823B2 /* DefaultsKit.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = DefaultsKit.framework.dSYM; path = Carthage/Build/Mac/DefaultsKit.framework.dSYM; sourceTree = "<group>"; };
7372
06B5A73A21D36680007823B2 /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
7473
06CAA896223E6ACB00B296AC /* URLEventHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLEventHandler.swift; sourceTree = "<group>"; };
75-
06CFC3B7256CE31B00330C5D /* NavigationToolbarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationToolbarItem.swift; sourceTree = "<group>"; };
7674
06EAE7E921D0CB3D00F7C921 /* DevDocs.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DevDocs.app; sourceTree = BUILT_PRODUCTS_DIR; };
7775
06EAE7EC21D0CB3D00F7C921 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7876
06EAE7EE21D0CB3E00F7C921 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -140,7 +138,6 @@
140138
06B5A73021D354FC007823B2 /* DocumentationWindows.swift */,
141139
061A0544246E275200CCFC1A /* GeneralPreferences.swift */,
142140
06EAE7F021D0CB3E00F7C921 /* MainMenu.xib */,
143-
06CFC3B7256CE31B00330C5D /* NavigationToolbarItem.swift */,
144141
06996D3A223DEF54001507AD /* PreferencesWindowController.swift */,
145142
06996D3B223DEF54001507AD /* PreferencesWindowController.xib */,
146143
06B5A73A21D36680007823B2 /* Storage.swift */,
@@ -230,7 +227,6 @@
230227
buildActionMask = 2147483647;
231228
files = (
232229
06996D2D223DDBEB001507AD /* Summoner.swift in Sources */,
233-
06CFC3B8256CE31B00330C5D /* NavigationToolbarItem.swift in Sources */,
234230
06EAE7FF21D0FA4000F7C921 /* DocumentationViewController.swift in Sources */,
235231
06996D3C223DEF54001507AD /* PreferencesWindowController.swift in Sources */,
236232
06B5A73121D354FC007823B2 /* DocumentationWindows.swift in Sources */,

devdocs-macos/DocumentationViewController.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ class DocumentationViewController: NSViewController {
105105

106106
// MARK:- Navigation
107107

108+
func canGoBack() -> Bool {
109+
return webView.backForwardList.backItem.map { _ in true } ?? false
110+
}
111+
112+
func canGoForward() -> Bool {
113+
return webView.backForwardList.forwardItem.map { _ in true } ?? false
114+
}
115+
108116
@objc func goBack() {
109117
webView.evaluateJavaScript("window.history.back();");
110118
}
@@ -291,16 +299,15 @@ extension DocumentationViewController: NSSearchFieldDelegate {
291299
}
292300
}
293301

294-
// MARK:- NavigationToolbarItemDelegate
295-
extension DocumentationViewController: NavigationToolbarItemDelegate {
296-
func canNavigate(_ item: NavigationToolbarItem) -> Bool {
297-
switch item.itemIdentifier {
298-
case .navigateBack:
299-
return webView.backForwardList.backItem.map { _ in true } ?? false
300-
case .navigateForward:
301-
return webView.backForwardList.forwardItem.map { _ in true } ?? false
302-
default:
303-
return false;
302+
// MARK:- NSUserInterfaceValidations
303+
extension DocumentationViewController: NSUserInterfaceValidations {
304+
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
305+
if item.action == #selector(goBack) {
306+
return canGoBack()
307+
}
308+
if item.action == #selector(goForward) {
309+
return canGoForward()
304310
}
311+
return false
305312
}
306313
}

devdocs-macos/DocumentationWindowController.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extension DocumentationWindowController: NSToolbarDelegate {
173173
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
174174
switch itemIdentifier {
175175
case .historyNavigation:
176-
let backItem = NavigationToolbarItem(itemIdentifier: .navigateBack)
176+
let backItem = NSToolbarItem(itemIdentifier: .navigateBack)
177177
do {
178178
backItem.label = NSLocalizedString("Back", comment: "Navigate back")
179179
backItem.toolTip = backItem.label
@@ -183,7 +183,7 @@ extension DocumentationWindowController: NSToolbarDelegate {
183183
backItem.autovalidates = true
184184
}
185185

186-
let forwardItem = NavigationToolbarItem(itemIdentifier: .navigateForward)
186+
let forwardItem = NSToolbarItem(itemIdentifier: .navigateForward)
187187
do {
188188
forwardItem.label = NSLocalizedString("Forward", comment: "Navigate forward")
189189
forwardItem.toolTip = forwardItem.label
@@ -216,14 +216,12 @@ extension DocumentationWindowController: NSToolbarDelegate {
216216
case .historyNavigation:
217217
let itemGroup = item as! NSToolbarItemGroup
218218
for subitem in itemGroup.subitems {
219-
let navigationItem = subitem as! NavigationToolbarItem
220-
navigationItem.navigationDelegate = documentationViewController
221-
navigationItem.target = documentationViewController
222-
switch navigationItem.itemIdentifier {
219+
subitem.target = documentationViewController
220+
switch subitem.itemIdentifier {
223221
case .navigateBack:
224-
navigationItem.action = #selector(DocumentationViewController.goBack)
222+
subitem.action = #selector(DocumentationViewController.goBack)
225223
case .navigateForward:
226-
navigationItem.action = #selector(DocumentationViewController.goForward)
224+
subitem.action = #selector(DocumentationViewController.goForward)
227225
default:
228226
break
229227
}
@@ -248,10 +246,8 @@ extension DocumentationWindowController: NSToolbarDelegate {
248246
case .historyNavigation:
249247
let itemGroup = item as! NSToolbarItemGroup
250248
for subitem in itemGroup.subitems {
251-
let navigationItem = subitem as! NavigationToolbarItem
252-
navigationItem.navigationDelegate = nil
253-
navigationItem.target = nil
254-
navigationItem.action = nil
249+
subitem.target = nil
250+
subitem.action = nil
255251
}
256252
case .contentSearch:
257253
contentSearchField = nil

devdocs-macos/NavigationToolbarItem.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)