Add compose key command

This commit is contained in:
Shadowfacts 2020-11-14 11:55:19 -05:00
parent 4bccbe254b
commit 72217cde51
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 17 additions and 4 deletions

View File

@ -10,21 +10,32 @@ import UIKit
struct MenuController {
static func composeCommand() -> UIKeyCommand {
let selector: Selector
if #available(iOS 14.0, *) {
selector = #selector(MainSplitViewController.presentCompose)
} else {
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)
}
static func buildMainMenu(builder: UIMenuBuilder) {
builder.insertChild(buildViewMenu(), atEndOfMenu: .view)
builder.insertChild(buildFileMenu(), atStartOfMenu: .file)
}
private static func buildViewMenu() -> UIMenu {
private static func buildFileMenu() -> UIMenu {
return UIMenu(
title: "",
image: nil,
identifier: nil,
options: .displayInline,
children: [
composeCommand(),
refreshCommand(discoverabilityTitle: nil),
]
)

View File

@ -56,6 +56,8 @@ class MainSplitViewController: UISplitViewController {
tabBarViewController = MainTabBarViewController(mastodonController: mastodonController)
setViewController(tabBarViewController, for: .compact)
addKeyCommand(MenuController.composeCommand())
}
func select(item: MainSidebarViewController.Item) {
@ -315,7 +317,7 @@ fileprivate extension MainSidebarViewController.Item {
@available(iOS 14.0, *)
extension MainSplitViewController: TuskerRootViewController {
func presentCompose() {
@objc func presentCompose() {
let vc = ComposeHostingController(mastodonController: mastodonController)
let nav = EnhancedNavigationViewController(rootViewController: vc)
nav.presentationController?.delegate = vc

View File

@ -156,7 +156,7 @@ extension MainTabBarViewController: FastAccountSwitcherViewControllerDelegate {
}
extension MainTabBarViewController: TuskerRootViewController {
func presentCompose() {
@objc func presentCompose() {
let vc = ComposeHostingController(mastodonController: mastodonController)
let nav = EnhancedNavigationViewController(rootViewController: vc)
nav.presentationController?.delegate = vc