mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
Ladybird/Qt: Remove the standalone JavaScript console
This commit is contained in:
parent
b385a44f6f
commit
c4daaa9902
7 changed files with 2 additions and 223 deletions
|
@ -115,7 +115,6 @@ if (ENABLE_QT)
|
|||
target_sources(ladybird PRIVATE
|
||||
Qt/AutoComplete.cpp
|
||||
Qt/BrowserWindow.cpp
|
||||
Qt/ConsoleWidget.cpp
|
||||
Qt/EventLoopImplementationQt.cpp
|
||||
Qt/EventLoopImplementationQtEventTarget.cpp
|
||||
Qt/Icon.cpp
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
|
||||
#include "BrowserWindow.h"
|
||||
#include "ConsoleWidget.h"
|
||||
#include "Icon.h"
|
||||
#include "Settings.h"
|
||||
#include "SettingsDialog.h"
|
||||
|
@ -174,16 +173,6 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
|||
}
|
||||
});
|
||||
|
||||
auto* js_console_action = new QAction("Show &JS Console", this);
|
||||
js_console_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-javascript.png"sv));
|
||||
js_console_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_J));
|
||||
inspect_menu->addAction(js_console_action);
|
||||
QObject::connect(js_console_action, &QAction::triggered, this, [this] {
|
||||
if (m_current_tab) {
|
||||
m_current_tab->show_console_window();
|
||||
}
|
||||
});
|
||||
|
||||
auto* inspector_action = new QAction("Open &Inspector", this);
|
||||
inspector_action->setIcon(load_icon_from_uri("resource://icons/browser/dom-tree.png"sv));
|
||||
inspector_action->setShortcut(QKeySequence("Ctrl+Shift+I"));
|
||||
|
@ -658,9 +647,6 @@ void BrowserWindow::select_all()
|
|||
if (!m_current_tab)
|
||||
return;
|
||||
|
||||
if (auto* console = m_current_tab->console(); console && console->isActiveWindow())
|
||||
console->view().select_all();
|
||||
else
|
||||
m_current_tab->view().select_all();
|
||||
}
|
||||
|
||||
|
@ -676,12 +662,7 @@ void BrowserWindow::copy_selected_text()
|
|||
if (!m_current_tab)
|
||||
return;
|
||||
|
||||
DeprecatedString text;
|
||||
|
||||
if (auto* console = m_current_tab->console(); console && console->isActiveWindow())
|
||||
text = console->view().selected_text();
|
||||
else
|
||||
text = m_current_tab->view().selected_text();
|
||||
auto text = m_current_tab->view().selected_text();
|
||||
|
||||
auto* clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(qstring_from_ak_deprecated_string(text));
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ConsoleWidget.h"
|
||||
#include "StringUtils.h"
|
||||
#include "WebContentView.h"
|
||||
#include <LibWebView/ConsoleClient.h>
|
||||
#include <QFontDatabase>
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
bool is_using_dark_system_theme(QWidget&);
|
||||
|
||||
ConsoleWidget::ConsoleWidget(WebContentView& content_view)
|
||||
{
|
||||
setLayout(new QVBoxLayout);
|
||||
|
||||
m_output_view = new WebContentView({}, {});
|
||||
if (is_using_dark_system_theme(*this))
|
||||
m_output_view->update_palette(WebContentView::PaletteMode::Dark);
|
||||
|
||||
m_console_client = make<WebView::ConsoleClient>(content_view, *m_output_view);
|
||||
|
||||
layout()->addWidget(m_output_view);
|
||||
|
||||
auto* bottom_container = new QWidget(this);
|
||||
bottom_container->setLayout(new QHBoxLayout);
|
||||
|
||||
layout()->addWidget(bottom_container);
|
||||
|
||||
m_input = new ConsoleInputEdit(bottom_container, *this);
|
||||
m_input->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
||||
bottom_container->layout()->addWidget(m_input);
|
||||
|
||||
setFocusProxy(m_input);
|
||||
|
||||
auto* clear_button = new QPushButton(bottom_container);
|
||||
bottom_container->layout()->addWidget(clear_button);
|
||||
clear_button->setFixedSize(22, 22);
|
||||
clear_button->setText("X");
|
||||
clear_button->setToolTip("Clear the console output");
|
||||
QObject::connect(clear_button, &QPushButton::pressed, [this] {
|
||||
client().clear();
|
||||
});
|
||||
|
||||
m_input->setFocus();
|
||||
}
|
||||
|
||||
ConsoleWidget::~ConsoleWidget() = default;
|
||||
|
||||
Optional<String> ConsoleWidget::previous_history_item()
|
||||
{
|
||||
return m_console_client->previous_history_item();
|
||||
}
|
||||
|
||||
Optional<String> ConsoleWidget::next_history_item()
|
||||
{
|
||||
return m_console_client->next_history_item();
|
||||
}
|
||||
|
||||
void ConsoleWidget::reset()
|
||||
{
|
||||
m_console_client->reset();
|
||||
}
|
||||
|
||||
void ConsoleInputEdit::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Up:
|
||||
if (auto script = m_console_widget.previous_history_item(); script.has_value())
|
||||
setText(qstring_from_ak_string(*script));
|
||||
break;
|
||||
|
||||
case Qt::Key_Down:
|
||||
if (auto script = m_console_widget.next_history_item(); script.has_value())
|
||||
setText(qstring_from_ak_string(*script));
|
||||
break;
|
||||
|
||||
case Qt::Key_Return: {
|
||||
auto js_source = MUST(ak_string_from_qstring(text()));
|
||||
if (js_source.bytes_as_string_view().is_whitespace())
|
||||
return;
|
||||
|
||||
m_console_widget.client().execute(std::move(js_source));
|
||||
clear();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibWebView/Forward.h>
|
||||
#include <QLineEdit>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ladybird {
|
||||
|
||||
class WebContentView;
|
||||
|
||||
class ConsoleWidget final : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConsoleWidget(WebContentView& content_view);
|
||||
virtual ~ConsoleWidget();
|
||||
|
||||
Optional<String> previous_history_item();
|
||||
Optional<String> next_history_item();
|
||||
|
||||
WebView::ConsoleClient& client() { return *m_console_client; }
|
||||
WebContentView& view() { return *m_output_view; }
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
OwnPtr<WebView::ConsoleClient> m_console_client;
|
||||
|
||||
WebContentView* m_output_view { nullptr };
|
||||
QLineEdit* m_input { nullptr };
|
||||
};
|
||||
|
||||
class ConsoleInputEdit final : public QLineEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ConsoleInputEdit(QWidget* q_widget, ConsoleWidget& console_widget)
|
||||
: QLineEdit(q_widget)
|
||||
, m_console_widget(console_widget)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
ConsoleWidget& m_console_widget;
|
||||
};
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
#include "BrowserWindow.h"
|
||||
#include "ConsoleWidget.h"
|
||||
#include "Icon.h"
|
||||
#include "InspectorWidget.h"
|
||||
#include "Settings.h"
|
||||
|
@ -139,9 +138,6 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
|
||||
if (m_inspector_widget)
|
||||
m_inspector_widget->reset();
|
||||
|
||||
if (m_console_widget)
|
||||
m_console_widget->reset();
|
||||
};
|
||||
|
||||
view().on_load_finish = [this](auto&) {
|
||||
|
@ -706,31 +702,6 @@ void Tab::show_inspector_window(InspectorTarget inspector_target)
|
|||
m_inspector_widget->select_default_node();
|
||||
}
|
||||
|
||||
void Tab::show_console_window()
|
||||
{
|
||||
if (!m_console_widget) {
|
||||
m_console_widget = new Ladybird::ConsoleWidget(view());
|
||||
m_console_widget->setWindowTitle("JS Console");
|
||||
m_console_widget->resize(640, 480);
|
||||
|
||||
// Make these actions available on the window itself. Adding them to the context menu alone
|
||||
// does not enable activattion via keyboard shortcuts.
|
||||
m_console_widget->addAction(&m_window->copy_selection_action());
|
||||
m_console_widget->addAction(&m_window->select_all_action());
|
||||
|
||||
m_console_context_menu = make<QMenu>("Context menu", m_console_widget);
|
||||
m_console_context_menu->addAction(&m_window->copy_selection_action());
|
||||
m_console_context_menu->addAction(&m_window->select_all_action());
|
||||
|
||||
m_console_widget->view().on_context_menu_request = [this](Gfx::IntPoint) {
|
||||
auto screen_position = QCursor::pos();
|
||||
m_console_context_menu->exec(screen_position);
|
||||
};
|
||||
}
|
||||
|
||||
m_console_widget->show();
|
||||
}
|
||||
|
||||
void Tab::close_sub_widgets()
|
||||
{
|
||||
auto close_widget_window = [](auto* widget) {
|
||||
|
@ -738,7 +709,6 @@ void Tab::close_sub_widgets()
|
|||
widget->close();
|
||||
};
|
||||
|
||||
close_widget_window(m_console_widget);
|
||||
close_widget_window(m_inspector_widget);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace Ladybird {
|
||||
|
||||
class BrowserWindow;
|
||||
class ConsoleWidget;
|
||||
class InspectorWidget;
|
||||
|
||||
class Tab final : public QWidget {
|
||||
|
@ -51,9 +50,6 @@ public:
|
|||
HoveredElement
|
||||
};
|
||||
void show_inspector_window(InspectorTarget = InspectorTarget::Document);
|
||||
void show_console_window();
|
||||
|
||||
Ladybird::ConsoleWidget* console() { return m_console_widget; }
|
||||
|
||||
public slots:
|
||||
void focus_location_editor();
|
||||
|
@ -113,8 +109,6 @@ private:
|
|||
|
||||
bool m_is_history_navigation { false };
|
||||
|
||||
Ladybird::ConsoleWidget* m_console_widget { nullptr };
|
||||
OwnPtr<QMenu> m_console_context_menu;
|
||||
Ladybird::InspectorWidget* m_inspector_widget { nullptr };
|
||||
|
||||
QPointer<QDialog> m_dialog;
|
||||
|
|
|
@ -19,7 +19,6 @@ moc_qt_objects("generate_moc") {
|
|||
sources = [
|
||||
"Qt/AutoComplete.h",
|
||||
"Qt/BrowserWindow.h",
|
||||
"Qt/ConsoleWidget.h",
|
||||
"Qt/EventLoopImplementationQtEventTarget.h",
|
||||
"Qt/InspectorWidget.h",
|
||||
"Qt/LocationEdit.h",
|
||||
|
@ -89,7 +88,6 @@ executable("ladybird_executable") {
|
|||
sources += [
|
||||
"Qt/AutoComplete.cpp",
|
||||
"Qt/BrowserWindow.cpp",
|
||||
"Qt/ConsoleWidget.cpp",
|
||||
"Qt/EventLoopImplementationQt.cpp",
|
||||
"Qt/EventLoopImplementationQtEventTarget.cpp",
|
||||
"Qt/Icon.cpp",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue