Ladybird: Add "Copy" and "Select All" actions to the Edit menu

This commit is contained in:
Andreas Kling 2023-01-11 20:09:52 +01:00
parent b79bc25a1f
commit 9c7e26b8d4
4 changed files with 45 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Matthew Costa <ucosty@gmail.com>
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
@ -18,6 +18,8 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <QAction>
#include <QActionGroup>
#include <QClipboard>
#include <QGuiApplication>
#include <QInputDialog>
#include <QPlainTextEdit>
@ -53,6 +55,18 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
menu->addAction(quit_action);
auto* edit_menu = menuBar()->addMenu("&Edit");
auto* copy_action = new QAction("&Copy", this);
copy_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Copy));
edit_menu->addAction(copy_action);
QObject::connect(copy_action, &QAction::triggered, this, &BrowserWindow::copy_selected_text);
auto* select_all_action = new QAction("Select &All", this);
select_all_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::SelectAll));
edit_menu->addAction(select_all_action);
QObject::connect(select_all_action, &QAction::triggered, this, &BrowserWindow::select_all);
auto* view_menu = menuBar()->addMenu("&View");
auto* open_next_tab_action = new QAction("Open &Next Tab", this);
@ -455,3 +469,18 @@ void BrowserWindow::reset_zoom()
if (m_current_tab)
m_current_tab->view().reset_zoom();
}
void BrowserWindow::select_all()
{
if (auto* tab = m_current_tab)
tab->view().select_all();
}
void BrowserWindow::copy_selected_text()
{
if (auto* tab = m_current_tab) {
auto text = tab->view().selected_text();
auto* clipboard = QGuiApplication::clipboard();
clipboard->setText(qstring_from_ak_deprecated_string(text));
}
}

View file

@ -46,6 +46,8 @@ public slots:
void zoom_in();
void zoom_out();
void reset_zoom();
void select_all();
void copy_selected_text();
private:
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");

View file

@ -1120,3 +1120,13 @@ void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString c
{
dbgln("TODO: support accessibility tree in Ladybird");
}
DeprecatedString WebContentView::selected_text()
{
return client().get_selected_text();
}
void WebContentView::select_all()
{
client().async_select_all();
}

View file

@ -112,6 +112,9 @@ public:
void zoom_out();
void reset_zoom();
DeprecatedString selected_text();
void select_all();
virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override;