summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-06 16:01:04 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-06 17:14:51 +0200
commit2c14714ee0dca15c7747d162c4a9753a3cd275d5 (patch)
tree00556eb4ba5b696e3fd20ba4793e777e0afab46b
parenteabb7b563ac4d7363fecabc0a3d5fdfa58058f87 (diff)
downloadserenity-2c14714ee0dca15c7747d162c4a9753a3cd275d5.zip
Browser: Add dedicated "view source" window
Basically a window containing a read-only GUI::TextEditor containing the source code of the current webpage. No temporary file needed :^) Fixes #1103.
-rw-r--r--Applications/Browser/Tab.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index 3b8f6f4ea9..9de3288f2d 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -218,23 +218,17 @@ Tab::Tab()
auto& inspect_menu = m_menubar->add_menu("Inspect");
inspect_menu.add_action(GUI::Action::create(
"View source", { Mod_Ctrl, Key_U }, [this](auto&) {
- String filename_to_open;
- char tmp_filename[] = "/tmp/view-source.XXXXXX";
ASSERT(m_html_widget->document());
- if (m_html_widget->document()->url().protocol() == "file") {
- filename_to_open = m_html_widget->document()->url().path();
- } else {
- int fd = mkstemp(tmp_filename);
- ASSERT(fd >= 0);
- auto source = m_html_widget->document()->source();
- write(fd, source.characters(), source.length());
- close(fd);
- filename_to_open = tmp_filename;
- }
- if (fork() == 0) {
- execl("/bin/TextEditor", "TextEditor", filename_to_open.characters(), nullptr);
- ASSERT_NOT_REACHED();
- }
+ auto url = m_html_widget->document()->url().to_string();
+ auto source = m_html_widget->document()->source();
+ auto window = GUI::Window::construct();
+ auto& editor = window->set_main_widget<GUI::TextEditor>();
+ editor.set_text(source);
+ editor.set_readonly(true);
+ window->set_rect(150, 150, 640, 480);
+ window->set_title(url);
+ window->show();
+ (void)window.leak_ref();
},
this));
inspect_menu.add_action(GUI::Action::create(