mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
Ladybird: Add "View Source" menu action (Ctrl+U)
This commit is contained in:
parent
1400a160bc
commit
74c71804c7
Notes:
sideshowbarker
2024-07-17 06:24:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/74c71804c7 Pull-request: https://github.com/SerenityOS/serenity/pull/16583 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
3 changed files with 29 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "WebView.h"
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <QAction>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QStatusBar>
|
||||
|
||||
extern String s_serenity_resource_root;
|
||||
|
@ -31,6 +32,24 @@ BrowserWindow::BrowserWindow(Core::EventLoop& event_loop)
|
|||
quit_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
|
||||
menu->addAction(quit_action);
|
||||
|
||||
auto* inspect_menu = menuBar()->addMenu("&Inspect");
|
||||
|
||||
auto* view_source_action = new QAction("View &Source");
|
||||
view_source_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-html.png").arg(s_serenity_resource_root.characters())));
|
||||
view_source_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
|
||||
inspect_menu->addAction(view_source_action);
|
||||
QObject::connect(view_source_action, &QAction::triggered, this, [this] {
|
||||
if (m_current_tab) {
|
||||
auto source = m_current_tab->view().source();
|
||||
|
||||
auto* text_edit = new QPlainTextEdit;
|
||||
text_edit->setFont(QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont));
|
||||
text_edit->resize(800, 600);
|
||||
text_edit->setPlainText(source.characters());
|
||||
text_edit->show();
|
||||
}
|
||||
});
|
||||
|
||||
auto* debug_menu = menuBar()->addMenu("&Debug");
|
||||
|
||||
auto* dump_dom_tree_action = new QAction("Dump DOM Tree");
|
||||
|
|
|
@ -664,3 +664,11 @@ void WebView::debug_request(String const& request, String const& argument)
|
|||
doc->window().local_storage()->dump();
|
||||
}
|
||||
}
|
||||
|
||||
String WebView::source() const
|
||||
{
|
||||
auto* document = m_page_client->page().top_level_browsing_context().active_document();
|
||||
if (!document)
|
||||
return String::empty();
|
||||
return document->source();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
|
||||
void debug_request(String const& request, String const& argument);
|
||||
|
||||
String source() const;
|
||||
|
||||
signals:
|
||||
void linkHovered(QString, int timeout = 0);
|
||||
void linkUnhovered();
|
||||
|
|
Loading…
Reference in a new issue