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 {
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 = []
}

View File

@ -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) {

View File

@ -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 }

View File

@ -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) {