mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
Browser: Move show_console_window()
to Tab
Having the BrowserWindow assigning Tab's internals felt a bit wrong. This is also a step towards removing BrowserWindow as a friend class. While I was at it, changed the Tab to having a pointer to the ConsoleWidget instead of the Window, since that is usually what we want to use, and it's awkward having to static_cast the main-widget repeatedly.
This commit is contained in:
parent
931f462b6e
commit
2b2158595f
3 changed files with 28 additions and 21 deletions
|
@ -211,22 +211,7 @@ void BrowserWindow::build_menus()
|
||||||
|
|
||||||
auto js_console_action = GUI::Action::create(
|
auto js_console_action = GUI::Action::create(
|
||||||
"Open &JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
|
"Open &JS Console", { Mod_Ctrl, Key_I }, [this](auto&) {
|
||||||
auto& tab = active_tab();
|
active_tab().show_console_window();
|
||||||
if (!tab.m_console_window) {
|
|
||||||
tab.m_console_window = GUI::Window::construct(this);
|
|
||||||
tab.m_console_window->resize(500, 300);
|
|
||||||
tab.m_console_window->set_title("JS Console");
|
|
||||||
tab.m_console_window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-javascript.png"));
|
|
||||||
tab.m_console_window->set_main_widget<ConsoleWidget>();
|
|
||||||
}
|
|
||||||
auto* console_widget = static_cast<ConsoleWidget*>(tab.m_console_window->main_widget());
|
|
||||||
console_widget->on_js_input = [&tab](const String& js_source) {
|
|
||||||
tab.m_web_content_view->js_console_input(js_source);
|
|
||||||
};
|
|
||||||
console_widget->clear_output();
|
|
||||||
tab.m_web_content_view->js_console_initialize();
|
|
||||||
tab.m_console_window->show();
|
|
||||||
tab.m_console_window->move_to_front();
|
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
js_console_action->set_status_tip("Open JavaScript console for this page");
|
js_console_action->set_status_tip("Open JavaScript console for this page");
|
||||||
|
|
|
@ -294,10 +294,8 @@ Tab::Tab(BrowserWindow& window)
|
||||||
};
|
};
|
||||||
|
|
||||||
hooks().on_js_console_output = [this](auto& method, auto& line) {
|
hooks().on_js_console_output = [this](auto& method, auto& line) {
|
||||||
if (m_console_window) {
|
if (m_console_widget)
|
||||||
auto* console_widget = static_cast<ConsoleWidget*>(m_console_window->main_widget());
|
m_console_widget->handle_js_console_output(method, line);
|
||||||
console_widget->handle_js_console_output(method, line);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto focus_location_box_action = GUI::Action::create(
|
auto focus_location_box_action = GUI::Action::create(
|
||||||
|
@ -503,4 +501,25 @@ void Tab::show_inspector_window(Browser::Tab::InspectorTarget inspector_target)
|
||||||
window->move_to_front();
|
window->move_to_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::show_console_window()
|
||||||
|
{
|
||||||
|
if (!m_console_widget) {
|
||||||
|
auto console_window = GUI::Window::construct(&window());
|
||||||
|
console_window->resize(500, 300);
|
||||||
|
console_window->set_title("JS Console");
|
||||||
|
console_window->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-javascript.png"));
|
||||||
|
m_console_widget = console_window->set_main_widget<ConsoleWidget>();
|
||||||
|
m_console_widget->on_js_input = [this](String const& js_source) {
|
||||||
|
m_web_content_view->js_console_input(js_source);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
m_console_widget->clear_output();
|
||||||
|
m_web_content_view->js_console_initialize();
|
||||||
|
|
||||||
|
auto* window = m_console_widget->window();
|
||||||
|
window->show();
|
||||||
|
window->move_to_front();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Browser {
|
||||||
|
|
||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
class InspectorWidget;
|
class InspectorWidget;
|
||||||
|
class ConsoleWidget;
|
||||||
|
|
||||||
class Tab final : public GUI::Widget {
|
class Tab final : public GUI::Widget {
|
||||||
C_OBJECT(Tab);
|
C_OBJECT(Tab);
|
||||||
|
@ -66,6 +67,8 @@ public:
|
||||||
};
|
};
|
||||||
void show_inspector_window(InspectorTarget);
|
void show_inspector_window(InspectorTarget);
|
||||||
|
|
||||||
|
void show_console_window();
|
||||||
|
|
||||||
const String& title() const { return m_title; }
|
const String& title() const { return m_title; }
|
||||||
const Gfx::Bitmap* icon() const { return m_icon; }
|
const Gfx::Bitmap* icon() const { return m_icon; }
|
||||||
|
|
||||||
|
@ -91,7 +94,7 @@ private:
|
||||||
RefPtr<GUI::UrlBox> m_location_box;
|
RefPtr<GUI::UrlBox> m_location_box;
|
||||||
RefPtr<GUI::Button> m_bookmark_button;
|
RefPtr<GUI::Button> m_bookmark_button;
|
||||||
RefPtr<InspectorWidget> m_dom_inspector_widget;
|
RefPtr<InspectorWidget> m_dom_inspector_widget;
|
||||||
RefPtr<GUI::Window> m_console_window;
|
RefPtr<ConsoleWidget> m_console_widget;
|
||||||
RefPtr<GUI::Statusbar> m_statusbar;
|
RefPtr<GUI::Statusbar> m_statusbar;
|
||||||
RefPtr<GUI::ToolbarContainer> m_toolbar_container;
|
RefPtr<GUI::ToolbarContainer> m_toolbar_container;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue