From 5f39a3f911cca0ef39cb18c93311fa88c66c8b6f Mon Sep 17 00:00:00 2001 From: Xexxa <93391300+Xexxa@users.noreply.github.com> Date: Thu, 25 May 2023 23:47:12 +0200 Subject: [PATCH] Ladybird: Add "Open File..." to menu --- Ladybird/BrowserWindow.cpp | 11 +++++++++++ Ladybird/BrowserWindow.h | 1 + Ladybird/Tab.cpp | 8 ++++++++ Ladybird/Tab.h | 1 + 4 files changed, 21 insertions(+) diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index 977e8a0cf92..5cd141f24e4 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -65,6 +65,11 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive close_current_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Close)); menu->addAction(close_current_tab_action); + auto* open_file_action = new QAction("&Open File...", this); + open_file_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-folder-open.png").arg(s_serenity_resource_root.characters()))); + open_file_action->setShortcut(QKeySequence(QKeySequence::StandardKey::Open)); + menu->addAction(open_file_action); + menu->addSeparator(); auto* quit_action = new QAction("&Quit", this); @@ -349,6 +354,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive QObject::connect(new_tab_action, &QAction::triggered, this, [this] { new_tab(s_settings->new_tab_page(), Web::HTML::ActivateTab::Yes); }); + QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); QObject::connect(settings_action, &QAction::triggered, this, [this] { new SettingsDialog(this); }); @@ -504,6 +510,11 @@ void BrowserWindow::close_tab(int index) }); } +void BrowserWindow::open_file() +{ + m_current_tab->open_file(); +} + void BrowserWindow::close_current_tab() { auto count = m_tabs_container->count() - 1; diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 0724addbe1c..e1ddf74de95 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -76,6 +76,7 @@ public slots: void close_current_tab(); void open_next_tab(); void open_previous_tab(); + void open_file(); void enable_auto_color_scheme(); void enable_light_color_scheme(); void enable_dark_color_scheme(); diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index 50286be1cad..eea62d26963 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -523,6 +524,13 @@ void Tab::location_edit_return_pressed() navigate(m_location_edit->text()); } +void Tab::open_file() +{ + auto filename = QFileDialog::getOpenFileName(this, "Open file", QDir::homePath(), "All Files (*.*)"); + if (!filename.isNull()) + navigate("file://" + filename); +} + int Tab::tab_index() { return m_window->tab_index(this); diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index c05e10bb5dc..8072bdb2918 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -43,6 +43,7 @@ public: void debug_request(DeprecatedString const& request, DeprecatedString const& argument); + void open_file(); void update_reset_zoom_button(); enum class InspectorTarget {