From 80c0d08ec6bc16566ffcfcae7dc97bfd0640ef32 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 14 Nov 2020 22:28:52 -0500 Subject: [PATCH] Tweak MenuController --- Tusker/Controllers/MenuController.swift | 36 ++++++++----------- .../Main/MainSplitViewController.swift | 4 +-- .../Profile/ProfileViewController.swift | 4 +-- .../SegmentedPageViewController.swift | 4 +-- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Tusker/Controllers/MenuController.swift b/Tusker/Controllers/MenuController.swift index 9a26a09487..4b61b701e1 100644 --- a/Tusker/Controllers/MenuController.swift +++ b/Tusker/Controllers/MenuController.swift @@ -10,7 +10,7 @@ import UIKit struct MenuController { - static func composeCommand() -> UIKeyCommand { + static let composeCommand: UIKeyCommand = { let selector: Selector if #available(iOS 14.0, *) { selector = #selector(MainSplitViewController.presentCompose) @@ -18,7 +18,7 @@ struct MenuController { selector = #selector(MainTabBarViewController.presentCompose) } return UIKeyCommand(title: "Compose", action: selector, input: "n", modifierFlags: .command) - } + }() static func refreshCommand(discoverabilityTitle: String?) -> UIKeyCommand { return UIKeyCommand(title: "Refresh", action: #selector(RefreshableViewController.refresh), input: "r", modifierFlags: .command, discoverabilityTitle: discoverabilityTitle) @@ -47,23 +47,17 @@ struct MenuController { } @available(iOS 14.0, *) - static func sidebarItemKeyCommands() -> [UIKeyCommand] { - return [ - sidebarCommand(item: .tab(.timelines), command: "1"), - sidebarCommand(item: .tab(.notifications), command: "2"), - sidebarCommand(item: .search, command: "3"), - sidebarCommand(item: .bookmarks, command: "4"), - sidebarCommand(item: .tab(.myProfile), command: "5"), - ] - } + static let sidebarItemKeyCommands: [UIKeyCommand] = [ + sidebarCommand(item: .tab(.timelines), command: "1"), + sidebarCommand(item: .tab(.notifications), command: "2"), + sidebarCommand(item: .search, command: "3"), + sidebarCommand(item: .bookmarks, command: "4"), + sidebarCommand(item: .tab(.myProfile), command: "5"), + ] - static func nextSubTabCommand() -> UIKeyCommand { - return UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift]) - } + static let nextSubTabCommand = UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift]) - static func prevSubTabCommand() -> UIKeyCommand { - return UIKeyCommand(title: "Previous Sub Tab", action: #selector(TabbedPageViewController.selectPrevPage), input: "[", modifierFlags: [.command, .shift]) - } + static let prevSubTabCommand = UIKeyCommand(title: "Previous Sub Tab", action: #selector(TabbedPageViewController.selectPrevPage), input: "[", modifierFlags: [.command, .shift]) static func buildMainMenu(builder: UIMenuBuilder) { builder.insertChild(buildFileMenu(), atStartOfMenu: .file) @@ -78,7 +72,7 @@ struct MenuController { identifier: nil, options: .displayInline, children: [ - composeCommand(), + composeCommand, refreshCommand(discoverabilityTitle: nil), ] ) @@ -91,8 +85,8 @@ struct MenuController { identifier: nil, options: .displayInline, children: [ - prevSubTabCommand(), - nextSubTabCommand(), + prevSubTabCommand, + nextSubTabCommand, ] ) } @@ -100,7 +94,7 @@ struct MenuController { private static func buildSidebarShortcuts() -> UIMenu { let children: [UIMenuElement] if #available(iOS 14.0, *) { - children = sidebarItemKeyCommands() + children = sidebarItemKeyCommands } else { children = [] } diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index d9ccf89e8b..cc9555235b 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -58,9 +58,9 @@ class MainSplitViewController: UISplitViewController { tabBarViewController = MainTabBarViewController(mastodonController: mastodonController) setViewController(tabBarViewController, for: .compact) - addKeyCommand(MenuController.composeCommand()) + addKeyCommand(MenuController.composeCommand) - MenuController.sidebarItemKeyCommands().forEach(addKeyCommand(_:)) + MenuController.sidebarItemKeyCommands.forEach(addKeyCommand(_:)) } func select(item: MainSidebarViewController.Item) { diff --git a/Tusker/Screens/Profile/ProfileViewController.swift b/Tusker/Screens/Profile/ProfileViewController.swift index 0d5f417f8f..e60c7aa90c 100644 --- a/Tusker/Screens/Profile/ProfileViewController.swift +++ b/Tusker/Screens/Profile/ProfileViewController.swift @@ -89,8 +89,8 @@ class ProfileViewController: UIPageViewController { headerView.widthAnchor.constraint(equalTo: view.widthAnchor), ]) - addKeyCommand(MenuController.prevSubTabCommand()) - addKeyCommand(MenuController.nextSubTabCommand()) + addKeyCommand(MenuController.prevSubTabCommand) + addKeyCommand(MenuController.nextSubTabCommand) accountUpdater = mastodonController.persistentContainer.accountSubject .filter { [weak self] in $0 == self?.accountID } diff --git a/Tusker/Screens/Utilities/SegmentedPageViewController.swift b/Tusker/Screens/Utilities/SegmentedPageViewController.swift index 0fd2ce03d6..a9457976c1 100644 --- a/Tusker/Screens/Utilities/SegmentedPageViewController.swift +++ b/Tusker/Screens/Utilities/SegmentedPageViewController.swift @@ -42,8 +42,8 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel segmentedControl.selectedSegmentIndex = 0 selectPage(at: 0, animated: false) - addKeyCommand(MenuController.prevSubTabCommand()) - addKeyCommand(MenuController.nextSubTabCommand()) + addKeyCommand(MenuController.prevSubTabCommand) + addKeyCommand(MenuController.nextSubTabCommand) } func selectPage(at index: Int, animated: Bool) {