History UI improvements

This commit is contained in:
James Magahern
2023-09-26 16:23:35 -07:00
parent d9fa5adf00
commit eec57f5f31
4 changed files with 36 additions and 6 deletions

View File

@@ -470,13 +470,34 @@ class BrowserViewController: UIViewController
}
internal func showHistoryWindow() {
let historyViewController = HistoryBrowserViewController()
let historyViewController = HistoryBrowserViewController { [unowned self] url in
if tab.url == nil {
tab.beginLoadingURL(url)
} else {
createNewTab(withURL: url)
}
presentedViewController?.dismiss(animated: true)
}
historyViewController.title = "History"
historyViewController.navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: UIAction { _ in
// xxx: This is not the SwiftUI-y way to do this.
historyViewController.dismiss(animated: true)
})
historyViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Clear", primaryAction: UIAction { [unowned self] action in
let alertController = UIAlertController(title: "Clear History", message: "Are you sure you want to clear all history?", preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Clear", style: .destructive, handler: { [unowned self] _ in
BrowserHistory.shared.clearAllHistory()
presentedViewController?.dismiss(animated: true)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alertController.popoverPresentationController?.sourceItem = action.presentationSourceItem
presentedViewController?.present(alertController, animated: true)
})
let navigationController = UINavigationController(rootViewController: historyViewController)
present(navigationController, animated: true)
}