mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
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.
This commit is contained in:
parent
eabb7b563a
commit
2c14714ee0
1 changed files with 10 additions and 16 deletions
|
@ -218,23 +218,17 @@ Tab::Tab()
|
||||||
auto& inspect_menu = m_menubar->add_menu("Inspect");
|
auto& inspect_menu = m_menubar->add_menu("Inspect");
|
||||||
inspect_menu.add_action(GUI::Action::create(
|
inspect_menu.add_action(GUI::Action::create(
|
||||||
"View source", { Mod_Ctrl, Key_U }, [this](auto&) {
|
"View source", { Mod_Ctrl, Key_U }, [this](auto&) {
|
||||||
String filename_to_open;
|
|
||||||
char tmp_filename[] = "/tmp/view-source.XXXXXX";
|
|
||||||
ASSERT(m_html_widget->document());
|
ASSERT(m_html_widget->document());
|
||||||
if (m_html_widget->document()->url().protocol() == "file") {
|
auto url = m_html_widget->document()->url().to_string();
|
||||||
filename_to_open = m_html_widget->document()->url().path();
|
auto source = m_html_widget->document()->source();
|
||||||
} else {
|
auto window = GUI::Window::construct();
|
||||||
int fd = mkstemp(tmp_filename);
|
auto& editor = window->set_main_widget<GUI::TextEditor>();
|
||||||
ASSERT(fd >= 0);
|
editor.set_text(source);
|
||||||
auto source = m_html_widget->document()->source();
|
editor.set_readonly(true);
|
||||||
write(fd, source.characters(), source.length());
|
window->set_rect(150, 150, 640, 480);
|
||||||
close(fd);
|
window->set_title(url);
|
||||||
filename_to_open = tmp_filename;
|
window->show();
|
||||||
}
|
(void)window.leak_ref();
|
||||||
if (fork() == 0) {
|
|
||||||
execl("/bin/TextEditor", "TextEditor", filename_to_open.characters(), nullptr);
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
this));
|
this));
|
||||||
inspect_menu.add_action(GUI::Action::create(
|
inspect_menu.add_action(GUI::Action::create(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue