Ladybird: Add "Open File..." to menu

This commit is contained in:
Xexxa 2023-05-25 23:47:12 +02:00 committed by Linus Groh
parent e8af912e30
commit 5f39a3f911
Notes: sideshowbarker 2024-07-17 04:49:48 +09:00
4 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -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();

View File

@ -16,6 +16,7 @@
#include <QClipboard>
#include <QCoreApplication>
#include <QCursor>
#include <QFileDialog>
#include <QFont>
#include <QFontMetrics>
#include <QGuiApplication>
@ -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);

View File

@ -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 {