mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
Browser: Add "New tab" action (Ctrl+T) :^)
This also introduces a WindowActions collection of actions that are not specific to the currently open tab, but nevertheless part of its menus.
This commit is contained in:
parent
4e8b6e48fd
commit
476a4475e5
5 changed files with 62 additions and 1 deletions
|
@ -2,6 +2,7 @@ OBJS = \
|
|||
BookmarksBarWidget.o \
|
||||
InspectorWidget.o \
|
||||
Tab.o \
|
||||
WindowActions.o \
|
||||
main.o
|
||||
|
||||
PROGRAM = Browser
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "Tab.h"
|
||||
#include "BookmarksBarWidget.h"
|
||||
#include "WindowActions.h"
|
||||
#include "History.h"
|
||||
#include "InspectorWidget.h"
|
||||
#include <LibGUI/AboutDialog.h>
|
||||
|
@ -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<bool> change(m_should_push_loads_to_history, false);
|
||||
m_html_widget->reload();
|
||||
|
|
26
Applications/Browser/WindowActions.cpp
Normal file
26
Applications/Browser/WindowActions.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "WindowActions.h"
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
21
Applications/Browser/WindowActions.h
Normal file
21
Applications/Browser/WindowActions.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/Action.h>
|
||||
|
||||
namespace Browser {
|
||||
|
||||
class WindowActions {
|
||||
public:
|
||||
static WindowActions& the();
|
||||
|
||||
WindowActions(GUI::Window&);
|
||||
|
||||
Function<void()> on_create_new_tab;
|
||||
|
||||
GUI::Action& create_new_tab_action() { return *m_create_new_tab_action; }
|
||||
|
||||
private:
|
||||
RefPtr<GUI::Action> m_create_new_tab_action;
|
||||
};
|
||||
|
||||
}
|
|
@ -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 <LibCore/File.h>
|
||||
|
@ -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<Browser::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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue