Adds history menu

This commit is contained in:
James Magahern
2023-01-27 13:46:23 -08:00
parent 6f41caff62
commit 748023d330
3 changed files with 35 additions and 12 deletions

View File

@@ -32,6 +32,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return UISceneConfiguration(name: "Browser", sessionRole: connectingSceneSession.role)
}
private func historyMenu() -> UIMenu {
let historyItems = BrowserHistory.shared.allHistory(limit: 50).map { item in
let title = (item.title.count > 0) ? item.title : item.url.absoluteString
return UIAction(title: title) { action in
UIApplication.shared.sendAction(#selector(ShortcutResponder.handleOpenURL), to: nil, from: action, for: OpenURLEvent(url: item.url))
}
}
return UIMenu(title: "History", children: [
UIKeyCommand(
modifiers: [ .command ],
input: "y",
title: "Show All History…",
action: #selector(ShortcutResponder.showHistory)
),
UIMenu(options: .displayInline, children: historyItems)
])
}
override var keyCommands: [UIKeyCommand]? {
get { KeyboardShortcuts.allKeyCommands() }
}
@@ -68,6 +88,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Go
builder.insertSibling(UIMenu(title: "Go", children: KeyboardShortcuts.menu(for: .go)), beforeMenu: .view)
// History
builder.insertSibling(historyMenu(), beforeMenu: .view)
// View
builder.replaceChildren(ofMenu: .view) { children in
KeyboardShortcuts.menu(for: .view) + children