mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:27:45 +00:00
Userland: Turn all application menus into window menus :^)
This commit is contained in:
parent
fcc8e3484f
commit
78b12e1521
47 changed files with 100 additions and 110 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -125,15 +125,6 @@ void Application::quit(int exit_code)
|
|||
m_event_loop->quit(exit_code);
|
||||
}
|
||||
|
||||
void Application::set_menubar(RefPtr<MenuBar> menubar)
|
||||
{
|
||||
if (m_menubar)
|
||||
m_menubar->notify_removed_from_application({});
|
||||
m_menubar = move(menubar);
|
||||
if (m_menubar)
|
||||
m_menubar->notify_added_to_application({});
|
||||
}
|
||||
|
||||
void Application::register_global_shortcut_action(Badge<Action>, Action& action)
|
||||
{
|
||||
m_global_shortcut_actions.set(action.shortcut(), &action);
|
||||
|
|
|
@ -49,7 +49,6 @@ public:
|
|||
int exec();
|
||||
void quit(int = 0);
|
||||
|
||||
void set_menubar(RefPtr<MenuBar>);
|
||||
Action* action_for_key_event(const KeyEvent&);
|
||||
|
||||
void register_global_shortcut_action(Badge<Action>, Action&);
|
||||
|
@ -106,7 +105,6 @@ private:
|
|||
void set_pending_drop_widget(Widget*);
|
||||
|
||||
OwnPtr<Core::EventLoop> m_event_loop;
|
||||
RefPtr<MenuBar> m_menubar;
|
||||
RefPtr<Gfx::PaletteImpl> m_palette;
|
||||
RefPtr<Gfx::PaletteImpl> m_system_palette;
|
||||
HashMap<Shortcut, Action*> m_global_shortcut_actions;
|
||||
|
|
|
@ -61,7 +61,7 @@ void MenuBar::unrealize_menubar()
|
|||
m_menubar_id = -1;
|
||||
}
|
||||
|
||||
void MenuBar::notify_added_to_application(Badge<Application>)
|
||||
void MenuBar::notify_added_to_window(Badge<Window>)
|
||||
{
|
||||
VERIFY(m_menubar_id == -1);
|
||||
m_menubar_id = realize_menubar();
|
||||
|
@ -71,10 +71,9 @@ void MenuBar::notify_added_to_application(Badge<Application>)
|
|||
VERIFY(menu_id != -1);
|
||||
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id);
|
||||
}
|
||||
WindowServerConnection::the().send_sync<Messages::WindowServer::SetApplicationMenubar>(m_menubar_id);
|
||||
}
|
||||
|
||||
void MenuBar::notify_removed_from_application(Badge<Application>)
|
||||
void MenuBar::notify_removed_from_window(Badge<Window>)
|
||||
{
|
||||
unrealize_menubar();
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ public:
|
|||
|
||||
Menu& add_menu(String name);
|
||||
|
||||
void notify_added_to_application(Badge<Application>);
|
||||
void notify_removed_from_application(Badge<Application>);
|
||||
void notify_added_to_window(Badge<Window>);
|
||||
void notify_removed_from_window(Badge<Window>);
|
||||
|
||||
int menubar_id() const { return m_menubar_id; }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -110,6 +110,8 @@ Window::Window(Core::Object* parent)
|
|||
|
||||
Window::~Window()
|
||||
{
|
||||
if (m_menubar)
|
||||
m_menubar->notify_removed_from_window({});
|
||||
all_windows->remove(this);
|
||||
hide();
|
||||
}
|
||||
|
@ -161,6 +163,12 @@ void Window::show()
|
|||
|
||||
apply_icon();
|
||||
|
||||
if (m_menubar) {
|
||||
// This little dance makes us create a server-side menubar.
|
||||
auto menubar = move(m_menubar);
|
||||
set_menubar(menubar);
|
||||
}
|
||||
|
||||
reified_windows->set(m_window_id, this);
|
||||
Application::the()->did_create_window({});
|
||||
update();
|
||||
|
@ -1057,9 +1065,13 @@ void Window::set_menubar(RefPtr<MenuBar> menubar)
|
|||
{
|
||||
if (m_menubar == menubar)
|
||||
return;
|
||||
if (m_menubar)
|
||||
m_menubar->notify_removed_from_window({});
|
||||
m_menubar = move(menubar);
|
||||
if (m_window_id && m_menubar)
|
||||
if (m_window_id && m_menubar) {
|
||||
m_menubar->notify_added_to_window({});
|
||||
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowMenubar>(m_window_id, m_menubar->menubar_id());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue