mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 22:30:31 +00:00
Inspector+UI: Close inspector with shortcuts
This brings keyboard shortcuts for the inspector up with common convention in FF and Chrome: Ctrl+Shift+C now also opens the inspector, and F12, Ctrl+W, and Ctrl+Shift+I now close the inspector when the inspector window is focused. Resolves #972
This commit is contained in:
parent
a24718cc49
commit
5cfed4524d
Notes:
github-actions[bot]
2025-01-03 10:48:11 +00:00
Author: https://github.com/tyzoid
Commit: 5cfed4524d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2746
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 31 additions and 3 deletions
|
@ -355,7 +355,9 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
||||||
|
|
||||||
auto* inspector_action = new QAction("Open &Inspector", this);
|
auto* inspector_action = new QAction("Open &Inspector", this);
|
||||||
inspector_action->setIcon(load_icon_from_uri("resource://icons/browser/dom-tree.png"sv));
|
inspector_action->setIcon(load_icon_from_uri("resource://icons/browser/dom-tree.png"sv));
|
||||||
inspector_action->setShortcuts({ QKeySequence("Ctrl+Shift+I"), QKeySequence("F12") });
|
inspector_action->setShortcuts({ QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_I),
|
||||||
|
QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C),
|
||||||
|
QKeySequence(Qt::Key_F12) });
|
||||||
inspect_menu->addAction(inspector_action);
|
inspect_menu->addAction(inspector_action);
|
||||||
QObject::connect(inspector_action, &QAction::triggered, this, [this] {
|
QObject::connect(inspector_action, &QAction::triggered, this, [this] {
|
||||||
if (m_current_tab) {
|
if (m_current_tab) {
|
||||||
|
@ -472,7 +474,6 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* clear_cache_action = new QAction("Clear &Cache", this);
|
auto* clear_cache_action = new QAction("Clear &Cache", this);
|
||||||
clear_cache_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C));
|
|
||||||
clear_cache_action->setIcon(load_icon_from_uri("resource://icons/browser/clear-cache.png"sv));
|
clear_cache_action->setIcon(load_icon_from_uri("resource://icons/browser/clear-cache.png"sv));
|
||||||
debug_menu->addAction(clear_cache_action);
|
debug_menu->addAction(clear_cache_action);
|
||||||
QObject::connect(clear_cache_action, &QAction::triggered, this, [this] {
|
QObject::connect(clear_cache_action, &QAction::triggered, this, [this] {
|
||||||
|
|
|
@ -25,10 +25,18 @@ InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view)
|
||||||
: QWidget(tab, Qt::Window)
|
: QWidget(tab, Qt::Window)
|
||||||
{
|
{
|
||||||
m_inspector_view = new WebContentView(this);
|
m_inspector_view = new WebContentView(this);
|
||||||
|
m_inspector_view->on_close = [this] {
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
if (is_using_dark_system_theme(*this))
|
if (is_using_dark_system_theme(*this))
|
||||||
m_inspector_view->update_palette(WebContentView::PaletteMode::Dark);
|
m_inspector_view->update_palette(WebContentView::PaletteMode::Dark);
|
||||||
|
|
||||||
|
auto* inspector_close_action = new QAction("Close Inspector", this);
|
||||||
|
inspector_close_action->setShortcuts({ QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_I), QKeySequence(Qt::CTRL | Qt::Key_W), QKeySequence(Qt::Key_F12) });
|
||||||
|
addAction(inspector_close_action);
|
||||||
|
connect(inspector_close_action, &QAction::triggered, [this]() { close(); });
|
||||||
|
|
||||||
m_inspector_client = make<WebView::InspectorClient>(content_view, *m_inspector_view);
|
m_inspector_client = make<WebView::InspectorClient>(content_view, *m_inspector_view);
|
||||||
|
|
||||||
m_edit_node_action = new QAction("&Edit node", this);
|
m_edit_node_action = new QAction("&Edit node", this);
|
||||||
|
@ -206,6 +214,7 @@ void InspectorWidget::closeEvent(QCloseEvent* event)
|
||||||
{
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
m_inspector_client->clear_selection();
|
m_inspector_client->clear_selection();
|
||||||
|
emit closed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void device_pixel_ratio_changed(qreal dpi);
|
void device_pixel_ratio_changed(qreal dpi);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void closed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool event(QEvent*) override;
|
virtual bool event(QEvent*) override;
|
||||||
void closeEvent(QCloseEvent*) override;
|
void closeEvent(QCloseEvent*) override;
|
||||||
|
|
|
@ -899,10 +899,23 @@ void Tab::recreate_toolbar_icons()
|
||||||
m_hamburger_button->setIcon(create_tvg_icon_with_theme_colors("hamburger", palette()));
|
m_hamburger_button->setIcon(create_tvg_icon_with_theme_colors("hamburger", palette()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::recreate_inspector()
|
||||||
|
{
|
||||||
|
if (m_inspector_widget)
|
||||||
|
m_inspector_widget->deleteLater();
|
||||||
|
|
||||||
|
m_inspector_widget = new InspectorWidget(this, view());
|
||||||
|
|
||||||
|
QObject::connect(m_inspector_widget, &InspectorWidget::closed, [this] {
|
||||||
|
m_inspector_widget->deleteLater();
|
||||||
|
m_inspector_widget = nullptr;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Tab::show_inspector_window(InspectorTarget inspector_target)
|
void Tab::show_inspector_window(InspectorTarget inspector_target)
|
||||||
{
|
{
|
||||||
if (!m_inspector_widget)
|
if (!m_inspector_widget)
|
||||||
m_inspector_widget = new InspectorWidget(this, view());
|
recreate_inspector();
|
||||||
else
|
else
|
||||||
m_inspector_widget->inspect();
|
m_inspector_widget->inspect();
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,8 @@ private:
|
||||||
|
|
||||||
void close_sub_widgets();
|
void close_sub_widgets();
|
||||||
|
|
||||||
|
void recreate_inspector();
|
||||||
|
|
||||||
QBoxLayout* m_layout { nullptr };
|
QBoxLayout* m_layout { nullptr };
|
||||||
QToolBar* m_toolbar { nullptr };
|
QToolBar* m_toolbar { nullptr };
|
||||||
QToolButton* m_hamburger_button { nullptr };
|
QToolButton* m_hamburger_button { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue