Adds history menu
This commit is contained in:
@@ -32,6 +32,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
return UISceneConfiguration(name: "Browser", sessionRole: connectingSceneSession.role)
|
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]? {
|
override var keyCommands: [UIKeyCommand]? {
|
||||||
get { KeyboardShortcuts.allKeyCommands() }
|
get { KeyboardShortcuts.allKeyCommands() }
|
||||||
}
|
}
|
||||||
@@ -68,6 +88,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
// Go
|
// Go
|
||||||
builder.insertSibling(UIMenu(title: "Go", children: KeyboardShortcuts.menu(for: .go)), beforeMenu: .view)
|
builder.insertSibling(UIMenu(title: "Go", children: KeyboardShortcuts.menu(for: .go)), beforeMenu: .view)
|
||||||
|
|
||||||
|
// History
|
||||||
|
builder.insertSibling(historyMenu(), beforeMenu: .view)
|
||||||
|
|
||||||
// View
|
// View
|
||||||
builder.replaceChildren(ofMenu: .view) { children in
|
builder.replaceChildren(ofMenu: .view) { children in
|
||||||
KeyboardShortcuts.menu(for: .view) + children
|
KeyboardShortcuts.menu(for: .view) + children
|
||||||
|
|||||||
@@ -168,13 +168,13 @@ extension BrowserViewController: ShortcutResponder
|
|||||||
showReaderWindow()
|
showReaderWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleOpenURL(_ sender: Any?, url: URL?) {
|
func handleOpenURL(_ sender: Any?, forEvent event: OpenURLEvent?) {
|
||||||
guard let url else { return }
|
guard let event else { return }
|
||||||
|
|
||||||
if tab.url == nil {
|
if tab.url == nil {
|
||||||
tab.beginLoadingURL(url)
|
tab.beginLoadingURL(event.url)
|
||||||
} else {
|
} else {
|
||||||
createNewTab(withURL: url)
|
createNewTab(withURL: event.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,14 @@ protocol ShortcutResponder: AnyObject {
|
|||||||
optional func showHistory(_ sender: Any?)
|
optional func showHistory(_ sender: Any?)
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
optional func handleOpenURL(_ sender: Any?, url: URL?)
|
optional func handleOpenURL(_ sender: Any?, forEvent event: OpenURLEvent?)
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OpenURLEvent: UIEvent {
|
||||||
|
let url: URL
|
||||||
|
public init(url: URL) {
|
||||||
|
self.url = url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate extension Array {
|
fileprivate extension Array {
|
||||||
@@ -172,13 +179,6 @@ public class KeyboardShortcuts {
|
|||||||
title: "Go Forward",
|
title: "Go Forward",
|
||||||
action: #selector(ShortcutResponder.goForward)
|
action: #selector(ShortcutResponder.goForward)
|
||||||
),
|
),
|
||||||
|
|
||||||
UIKeyCommand(
|
|
||||||
modifiers: [.command, .shift],
|
|
||||||
input: "h",
|
|
||||||
title: "Show History…",
|
|
||||||
action: #selector(ShortcutResponder.showHistory)
|
|
||||||
),
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
// Tab Navigation
|
// Tab Navigation
|
||||||
|
|||||||
Reference in New Issue
Block a user