2020-11-14 16:10:20 +00:00
//
// M e n u C o n t r o l l e r . s w i f t
// T u s k e r
//
// C r e a t e d b y S h a d o w f a c t s o n 1 1 / 1 4 / 2 0 .
// C o p y r i g h t © 2 0 2 0 S h a d o w f a c t s . A l l r i g h t s r e s e r v e d .
//
import UIKit
2024-01-26 16:02:40 +00:00
@ MainActor
2020-11-14 16:10:20 +00:00
struct MenuController {
2020-11-15 03:28:52 +00:00
static let composeCommand : UIKeyCommand = {
2023-02-25 18:55:46 +00:00
return UIKeyCommand ( title : " Compose " , action : #selector ( MainSplitViewController . handleComposeKeyCommand ) , input : " n " , modifierFlags : . command )
2020-11-15 03:28:52 +00:00
} ( )
2020-11-14 16:55:19 +00:00
2020-11-14 16:10:20 +00:00
static func refreshCommand ( discoverabilityTitle : String ? ) -> UIKeyCommand {
return UIKeyCommand ( title : " Refresh " , action : #selector ( RefreshableViewController . refresh ) , input : " r " , modifierFlags : . command , discoverabilityTitle : discoverabilityTitle )
}
2023-04-04 03:25:33 +00:00
static func sidebarCommand ( item : MainSidebarViewController . Item , command : String , action : Selector ) -> UIKeyCommand {
2020-11-14 17:15:49 +00:00
return UIKeyCommand (
title : item . title ,
image : UIImage ( systemName : item . imageName ! ) ,
2023-04-04 03:25:33 +00:00
action : action ,
2020-11-14 17:15:49 +00:00
input : command ,
2023-04-04 03:25:33 +00:00
modifierFlags : . command
2020-11-14 17:15:49 +00:00
)
}
2020-11-15 03:28:52 +00:00
static let sidebarItemKeyCommands : [ UIKeyCommand ] = [
2023-04-04 03:25:33 +00:00
sidebarCommand ( item : . tab ( . timelines ) , command : " 1 " , action : #selector ( MainSplitViewController . handleSidebarCommandTimelines ) ) ,
sidebarCommand ( item : . tab ( . notifications ) , command : " 2 " , action : #selector ( MainSplitViewController . handleSidebarCommandNotifications ) ) ,
sidebarCommand ( item : . explore , command : " 3 " , action : #selector ( MainSplitViewController . handleSidebarCommandExplore ) ) ,
sidebarCommand ( item : . bookmarks , command : " 4 " , action : #selector ( MainSplitViewController . handleSidebarCommandBookmarks ) ) ,
sidebarCommand ( item : . tab ( . myProfile ) , command : " 5 " , action : #selector ( MainSplitViewController . handleSidebarCommandMyProfile ) ) ,
2020-11-15 03:28:52 +00:00
]
2020-11-14 17:15:49 +00:00
2020-11-15 03:28:52 +00:00
static let nextSubTabCommand = UIKeyCommand ( title : " Next Sub Tab " , action : #selector ( TabbedPageViewController . selectNextPage ) , input : " ] " , modifierFlags : [ . command , . shift ] )
2020-11-15 03:26:02 +00:00
2020-11-15 03:28:52 +00:00
static let prevSubTabCommand = UIKeyCommand ( title : " Previous Sub Tab " , action : #selector ( TabbedPageViewController . selectPrevPage ) , input : " [ " , modifierFlags : [ . command , . shift ] )
2020-11-15 03:26:02 +00:00
2020-11-14 16:10:20 +00:00
static func buildMainMenu ( builder : UIMenuBuilder ) {
2023-11-05 16:14:58 +00:00
builder . replace ( menu : . file , with : buildFileMenu ( builder : builder ) )
2020-11-15 03:26:02 +00:00
builder . insertChild ( buildSubTabMenu ( ) , atStartOfMenu : . view )
builder . insertChild ( buildSidebarShortcuts ( ) , atStartOfMenu : . view )
2020-11-14 16:10:20 +00:00
}
2023-11-05 16:14:58 +00:00
private static func buildFileMenu ( builder : UIMenuBuilder ) -> UIMenu {
var children : [ UIMenuElement ] = [
composeCommand ,
refreshCommand ( discoverabilityTitle : nil ) ,
]
if let close = builder . menu ( for : . close ) {
children . append ( close )
}
2020-11-14 16:10:20 +00:00
return UIMenu (
2022-05-15 14:34:24 +00:00
title : " File " ,
2020-11-14 16:10:20 +00:00
image : nil ,
identifier : nil ,
2022-05-15 14:34:24 +00:00
options : [ ] ,
2023-11-05 16:14:58 +00:00
children : children
2020-11-14 16:10:20 +00:00
)
}
2020-11-15 03:26:02 +00:00
private static func buildSubTabMenu ( ) -> UIMenu {
return UIMenu (
title : " " ,
image : nil ,
identifier : nil ,
options : . displayInline ,
children : [
2020-11-15 03:28:52 +00:00
prevSubTabCommand ,
nextSubTabCommand ,
2020-11-15 03:26:02 +00:00
]
)
}
private static func buildSidebarShortcuts ( ) -> UIMenu {
2020-11-14 17:15:49 +00:00
return UIMenu (
title : " " ,
image : nil ,
identifier : nil ,
options : . displayInline ,
2021-02-06 18:47:45 +00:00
children : sidebarItemKeyCommands
2020-11-14 17:15:49 +00:00
)
}
}