Tweak MenuController

This commit is contained in:
Shadowfacts 2020-11-14 22:28:52 -05:00
parent 2b5ab90cd8
commit 80c0d08ec6
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 21 additions and 27 deletions

View File

@ -10,7 +10,7 @@ import UIKit
struct MenuController { struct MenuController {
static func composeCommand() -> UIKeyCommand { static let composeCommand: UIKeyCommand = {
let selector: Selector let selector: Selector
if #available(iOS 14.0, *) { if #available(iOS 14.0, *) {
selector = #selector(MainSplitViewController.presentCompose) selector = #selector(MainSplitViewController.presentCompose)
@ -18,7 +18,7 @@ struct MenuController {
selector = #selector(MainTabBarViewController.presentCompose) selector = #selector(MainTabBarViewController.presentCompose)
} }
return UIKeyCommand(title: "Compose", action: selector, input: "n", modifierFlags: .command) return UIKeyCommand(title: "Compose", action: selector, input: "n", modifierFlags: .command)
} }()
static func refreshCommand(discoverabilityTitle: String?) -> UIKeyCommand { static func refreshCommand(discoverabilityTitle: String?) -> UIKeyCommand {
return UIKeyCommand(title: "Refresh", action: #selector(RefreshableViewController.refresh), input: "r", modifierFlags: .command, discoverabilityTitle: discoverabilityTitle) return UIKeyCommand(title: "Refresh", action: #selector(RefreshableViewController.refresh), input: "r", modifierFlags: .command, discoverabilityTitle: discoverabilityTitle)
@ -47,23 +47,17 @@ struct MenuController {
} }
@available(iOS 14.0, *) @available(iOS 14.0, *)
static func sidebarItemKeyCommands() -> [UIKeyCommand] { static let sidebarItemKeyCommands: [UIKeyCommand] = [
return [
sidebarCommand(item: .tab(.timelines), command: "1"), sidebarCommand(item: .tab(.timelines), command: "1"),
sidebarCommand(item: .tab(.notifications), command: "2"), sidebarCommand(item: .tab(.notifications), command: "2"),
sidebarCommand(item: .search, command: "3"), sidebarCommand(item: .search, command: "3"),
sidebarCommand(item: .bookmarks, command: "4"), sidebarCommand(item: .bookmarks, command: "4"),
sidebarCommand(item: .tab(.myProfile), command: "5"), sidebarCommand(item: .tab(.myProfile), command: "5"),
] ]
}
static func nextSubTabCommand() -> UIKeyCommand { static let nextSubTabCommand = UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift])
return UIKeyCommand(title: "Next Sub Tab", action: #selector(TabbedPageViewController.selectNextPage), input: "]", modifierFlags: [.command, .shift])
}
static func prevSubTabCommand() -> UIKeyCommand { static let prevSubTabCommand = UIKeyCommand(title: "Previous Sub Tab", action: #selector(TabbedPageViewController.selectPrevPage), input: "[", modifierFlags: [.command, .shift])
return UIKeyCommand(title: "Previous Sub Tab", action: #selector(TabbedPageViewController.selectPrevPage), input: "[", modifierFlags: [.command, .shift])
}
static func buildMainMenu(builder: UIMenuBuilder) { static func buildMainMenu(builder: UIMenuBuilder) {
builder.insertChild(buildFileMenu(), atStartOfMenu: .file) builder.insertChild(buildFileMenu(), atStartOfMenu: .file)
@ -78,7 +72,7 @@ struct MenuController {
identifier: nil, identifier: nil,
options: .displayInline, options: .displayInline,
children: [ children: [
composeCommand(), composeCommand,
refreshCommand(discoverabilityTitle: nil), refreshCommand(discoverabilityTitle: nil),
] ]
) )
@ -91,8 +85,8 @@ struct MenuController {
identifier: nil, identifier: nil,
options: .displayInline, options: .displayInline,
children: [ children: [
prevSubTabCommand(), prevSubTabCommand,
nextSubTabCommand(), nextSubTabCommand,
] ]
) )
} }
@ -100,7 +94,7 @@ struct MenuController {
private static func buildSidebarShortcuts() -> UIMenu { private static func buildSidebarShortcuts() -> UIMenu {
let children: [UIMenuElement] let children: [UIMenuElement]
if #available(iOS 14.0, *) { if #available(iOS 14.0, *) {
children = sidebarItemKeyCommands() children = sidebarItemKeyCommands
} else { } else {
children = [] children = []
} }

View File

@ -58,9 +58,9 @@ class MainSplitViewController: UISplitViewController {
tabBarViewController = MainTabBarViewController(mastodonController: mastodonController) tabBarViewController = MainTabBarViewController(mastodonController: mastodonController)
setViewController(tabBarViewController, for: .compact) setViewController(tabBarViewController, for: .compact)
addKeyCommand(MenuController.composeCommand()) addKeyCommand(MenuController.composeCommand)
MenuController.sidebarItemKeyCommands().forEach(addKeyCommand(_:)) MenuController.sidebarItemKeyCommands.forEach(addKeyCommand(_:))
} }
func select(item: MainSidebarViewController.Item) { func select(item: MainSidebarViewController.Item) {

View File

@ -89,8 +89,8 @@ class ProfileViewController: UIPageViewController {
headerView.widthAnchor.constraint(equalTo: view.widthAnchor), headerView.widthAnchor.constraint(equalTo: view.widthAnchor),
]) ])
addKeyCommand(MenuController.prevSubTabCommand()) addKeyCommand(MenuController.prevSubTabCommand)
addKeyCommand(MenuController.nextSubTabCommand()) addKeyCommand(MenuController.nextSubTabCommand)
accountUpdater = mastodonController.persistentContainer.accountSubject accountUpdater = mastodonController.persistentContainer.accountSubject
.filter { [weak self] in $0 == self?.accountID } .filter { [weak self] in $0 == self?.accountID }

View File

@ -42,8 +42,8 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
segmentedControl.selectedSegmentIndex = 0 segmentedControl.selectedSegmentIndex = 0
selectPage(at: 0, animated: false) selectPage(at: 0, animated: false)
addKeyCommand(MenuController.prevSubTabCommand()) addKeyCommand(MenuController.prevSubTabCommand)
addKeyCommand(MenuController.nextSubTabCommand()) addKeyCommand(MenuController.nextSubTabCommand)
} }
func selectPage(at index: Int, animated: Bool) { func selectPage(at index: Int, animated: Bool) {