Settings View: SwiftUI wrapper

This commit is contained in:
James Magahern
2021-03-03 16:17:54 -08:00
parent 225761473d
commit fb9ec47833
8 changed files with 167 additions and 13 deletions

View File

@@ -22,6 +22,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
static func appMenuShortcuts() -> [UIKeyCommand] {
[
// Preferences
UIKeyCommand(
modifiers: .command,
input: ",",
title: "Preferences",
action: #selector(ShortcutResponder.showPreferences)
)
]
}
static func fileMenuShortcuts() -> [UIKeyCommand] {
[
// Open Location...
@@ -90,13 +102,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
override var keyCommands: [UIKeyCommand]? {
get { return Self.fileMenuShortcuts() }
get { return Self.fileMenuShortcuts() + Self.appMenuShortcuts() }
}
override func buildMenu(with builder: UIMenuBuilder) {
builder.replaceChildren(ofMenu: .file) { children in
return Self.fileMenuShortcuts() + children
}
builder.replaceChildren(ofMenu: .application, from: { children in
let index = children.firstIndex(where: { elem in
if let elem = elem as? UIMenu {
return elem.identifier == .about
}
return false
})
var newChildren = children
if let index = index {
newChildren.insert(contentsOf: Self.appMenuShortcuts(), at: index + 1)
} else {
newChildren.append(contentsOf: Self.appMenuShortcuts())
}
return newChildren
})
}
}