forked from shadowfacts/Tusker
Add compose key command
This commit is contained in:
parent
4bccbe254b
commit
72217cde51
|
@ -10,21 +10,32 @@ import UIKit
|
||||||
|
|
||||||
struct MenuController {
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func buildMainMenu(builder: UIMenuBuilder) {
|
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(
|
return UIMenu(
|
||||||
title: "",
|
title: "",
|
||||||
image: nil,
|
image: nil,
|
||||||
identifier: nil,
|
identifier: nil,
|
||||||
options: .displayInline,
|
options: .displayInline,
|
||||||
children: [
|
children: [
|
||||||
|
composeCommand(),
|
||||||
refreshCommand(discoverabilityTitle: nil),
|
refreshCommand(discoverabilityTitle: nil),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -56,6 +56,8 @@ class MainSplitViewController: UISplitViewController {
|
||||||
|
|
||||||
tabBarViewController = MainTabBarViewController(mastodonController: mastodonController)
|
tabBarViewController = MainTabBarViewController(mastodonController: mastodonController)
|
||||||
setViewController(tabBarViewController, for: .compact)
|
setViewController(tabBarViewController, for: .compact)
|
||||||
|
|
||||||
|
addKeyCommand(MenuController.composeCommand())
|
||||||
}
|
}
|
||||||
|
|
||||||
func select(item: MainSidebarViewController.Item) {
|
func select(item: MainSidebarViewController.Item) {
|
||||||
|
@ -315,7 +317,7 @@ fileprivate extension MainSidebarViewController.Item {
|
||||||
|
|
||||||
@available(iOS 14.0, *)
|
@available(iOS 14.0, *)
|
||||||
extension MainSplitViewController: TuskerRootViewController {
|
extension MainSplitViewController: TuskerRootViewController {
|
||||||
func presentCompose() {
|
@objc func presentCompose() {
|
||||||
let vc = ComposeHostingController(mastodonController: mastodonController)
|
let vc = ComposeHostingController(mastodonController: mastodonController)
|
||||||
let nav = EnhancedNavigationViewController(rootViewController: vc)
|
let nav = EnhancedNavigationViewController(rootViewController: vc)
|
||||||
nav.presentationController?.delegate = vc
|
nav.presentationController?.delegate = vc
|
||||||
|
|
|
@ -156,7 +156,7 @@ extension MainTabBarViewController: FastAccountSwitcherViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MainTabBarViewController: TuskerRootViewController {
|
extension MainTabBarViewController: TuskerRootViewController {
|
||||||
func presentCompose() {
|
@objc func presentCompose() {
|
||||||
let vc = ComposeHostingController(mastodonController: mastodonController)
|
let vc = ComposeHostingController(mastodonController: mastodonController)
|
||||||
let nav = EnhancedNavigationViewController(rootViewController: vc)
|
let nav = EnhancedNavigationViewController(rootViewController: vc)
|
||||||
nav.presentationController?.delegate = vc
|
nav.presentationController?.delegate = vc
|
||||||
|
|
Loading…
Reference in New Issue