diff --git a/Applications/Browser/Makefile b/Applications/Browser/Makefile index dd8d297395..91cc60aff2 100755 --- a/Applications/Browser/Makefile +++ b/Applications/Browser/Makefile @@ -2,6 +2,7 @@ OBJS = \ BookmarksBarWidget.o \ InspectorWidget.o \ Tab.o \ + WindowActions.o \ main.o PROGRAM = Browser diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index b48cfdc1bd..7743ca48ba 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -26,6 +26,7 @@ #include "Tab.h" #include "BookmarksBarWidget.h" +#include "WindowActions.h" #include "History.h" #include "InspectorWidget.h" #include @@ -176,6 +177,8 @@ Tab::Tab() m_menubar = GUI::MenuBar::construct(); auto& app_menu = m_menubar->add_menu("Browser"); + app_menu.add_action(WindowActions::the().create_new_tab_action()); + app_menu.add_action(GUI::Action::create("Reload", { Mod_None, Key_F5 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), [this](auto&) { TemporaryChange change(m_should_push_loads_to_history, false); m_html_widget->reload(); diff --git a/Applications/Browser/WindowActions.cpp b/Applications/Browser/WindowActions.cpp new file mode 100644 index 0000000000..e5169ea7b8 --- /dev/null +++ b/Applications/Browser/WindowActions.cpp @@ -0,0 +1,26 @@ +#include "WindowActions.h" +#include + +namespace Browser { + +static WindowActions* s_the; + +WindowActions& WindowActions::the() +{ + ASSERT(s_the); + return *s_the; +} + +WindowActions::WindowActions(GUI::Window& window) +{ + ASSERT(!s_the); + s_the = this; + m_create_new_tab_action = GUI::Action::create( + "New tab", { Mod_Ctrl, Key_T }, [this](auto&) { + if (on_create_new_tab) + on_create_new_tab(); + }, + &window); +} + +} diff --git a/Applications/Browser/WindowActions.h b/Applications/Browser/WindowActions.h new file mode 100644 index 0000000000..8b64fa2fe9 --- /dev/null +++ b/Applications/Browser/WindowActions.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace Browser { + +class WindowActions { +public: + static WindowActions& the(); + + WindowActions(GUI::Window&); + + Function on_create_new_tab; + + GUI::Action& create_new_tab_action() { return *m_create_new_tab_action; } + +private: + RefPtr m_create_new_tab_action; +}; + +} diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index c2ab84b539..13ca696d17 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "WindowActions.h" #include "InspectorWidget.h" #include "Tab.h" #include @@ -88,7 +89,9 @@ int main(int argc, char** argv) tab.did_become_active(); }; - auto create_new_tab = [&] { + Browser::WindowActions window_actions(*window); + + auto create_new_tab = [&](bool activate = true) { auto& new_tab = tab_widget.add_tab("New tab"); new_tab.on_title_change = [&](auto title) { @@ -111,6 +114,13 @@ int main(int argc, char** argv) new_tab.load(url_to_load); dbg() << "Added new tab " << &new_tab << ", loading " << url_to_load; + + if (activate) + tab_widget.set_active_widget(&new_tab); + }; + + window_actions.on_create_new_tab = [&] { + create_new_tab(); }; create_new_tab();