mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-20 23:19:44 +00:00
LibWebView+UI: Extract some UI-specific displays to Application helpers
This is preparation for moving application menus to LibWebView. We will need a way to display these dialogs from outside of the UI layer.
This commit is contained in:
parent
95dca6c787
commit
2632b1375b
Notes:
github-actions[bot]
2025-09-11 18:25:30 +00:00
Author: https://github.com/trflynn89
Commit: 2632b1375b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6062
10 changed files with 134 additions and 54 deletions
|
@ -11,8 +11,10 @@
|
|||
#include <UI/Qt/Settings.h>
|
||||
#include <UI/Qt/StringUtils.h>
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QFileOpenEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
|
@ -88,6 +90,13 @@ BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, Bro
|
|||
return *window;
|
||||
}
|
||||
|
||||
Optional<WebView::ViewImplementation&> Application::active_web_view() const
|
||||
{
|
||||
if (auto* active_tab = this->active_tab())
|
||||
return active_tab->view();
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<ByteString> Application::ask_user_for_download_folder() const
|
||||
{
|
||||
auto path = QFileDialog::getExistingDirectory(nullptr, "Select download directory", QDir::homePath());
|
||||
|
@ -97,4 +106,26 @@ Optional<ByteString> Application::ask_user_for_download_folder() const
|
|||
return ak_byte_string_from_qstring(path);
|
||||
}
|
||||
|
||||
void Application::display_download_confirmation_dialog(StringView download_name, LexicalPath const& path) const
|
||||
{
|
||||
auto message = MUST(String::formatted("{} saved to: {}", download_name, path));
|
||||
|
||||
QMessageBox dialog(active_tab());
|
||||
dialog.setWindowTitle("Ladybird");
|
||||
dialog.setIcon(QMessageBox::Information);
|
||||
dialog.setText(qstring_from_ak_string(message));
|
||||
dialog.addButton(QMessageBox::Ok);
|
||||
dialog.addButton(QMessageBox::Open)->setText("Open folder");
|
||||
|
||||
if (dialog.exec() == QMessageBox::Open) {
|
||||
auto path_url = QUrl::fromLocalFile(qstring_from_ak_string(path.dirname()));
|
||||
QDesktopServices::openUrl(path_url);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::display_error_dialog(StringView error_message) const
|
||||
{
|
||||
QMessageBox::warning(active_tab(), "Ladybird", qstring_from_ak_string(error_message));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue