From 72217cde51598d51dabff48c29d305f70fe32e0f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 14 Nov 2020 11:55:19 -0500 Subject: [PATCH] Add compose key command --- Tusker/Controllers/MenuController.swift | 15 +++++++++++++-- Tusker/Screens/Main/MainSplitViewController.swift | 4 +++- .../Screens/Main/MainTabBarViewController.swift | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Tusker/Controllers/MenuController.swift b/Tusker/Controllers/MenuController.swift index 8502aac9..e979c1dc 100644 --- a/Tusker/Controllers/MenuController.swift +++ b/Tusker/Controllers/MenuController.swift @@ -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), ] ) diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index 7a6fd28f..f13415be 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -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 diff --git a/Tusker/Screens/Main/MainTabBarViewController.swift b/Tusker/Screens/Main/MainTabBarViewController.swift index 390dcc5c..7aea1fd3 100644 --- a/Tusker/Screens/Main/MainTabBarViewController.swift +++ b/Tusker/Screens/Main/MainTabBarViewController.swift @@ -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