mirror of
https://github.com/RGBCube/serenity
synced 2025-07-05 07:27:35 +00:00
LibGUI: Refactor context menus to be event-driven instead of declarative.
The declarative approach had way too many limitations. This patch adds a context menu event that can be hooked to prepare a custom context menu on demand just-in-time. :^)
This commit is contained in:
parent
e74b5bc054
commit
a747a10eab
5 changed files with 37 additions and 27 deletions
|
@ -178,18 +178,14 @@ void GWidget::handle_mousedown_event(GMouseEvent& event)
|
|||
{
|
||||
if (accepts_focus())
|
||||
set_focus(true);
|
||||
if (event.button() == GMouseButton::Right) {
|
||||
if (m_context_menu) {
|
||||
if (m_context_menu_mode == ContextMenuMode::PassthroughMouseEvent)
|
||||
mousedown_event(event);
|
||||
m_context_menu->popup(screen_relative_rect().location().translated(event.position()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// FIXME: Maybe the click clock should be per-button.
|
||||
if (!m_click_clock.is_valid())
|
||||
m_click_clock.start();
|
||||
mousedown_event(event);
|
||||
if (event.button() == GMouseButton::Right) {
|
||||
GContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position()));
|
||||
context_menu_event(c_event);
|
||||
}
|
||||
}
|
||||
|
||||
void GWidget::handle_enter_event(CEvent& event)
|
||||
|
@ -253,6 +249,10 @@ void GWidget::mousemove_event(GMouseEvent&)
|
|||
{
|
||||
}
|
||||
|
||||
void GWidget::context_menu_event(GContextMenuEvent&)
|
||||
{
|
||||
}
|
||||
|
||||
void GWidget::focusin_event(CEvent&)
|
||||
{
|
||||
}
|
||||
|
@ -437,14 +437,6 @@ void GWidget::set_enabled(bool enabled)
|
|||
update();
|
||||
}
|
||||
|
||||
void GWidget::set_context_menu(OwnPtr<GMenu>&& context_menu, ContextMenuMode mode)
|
||||
{
|
||||
// FIXME: Support switching context menus.
|
||||
ASSERT(!m_context_menu);
|
||||
m_context_menu = move(context_menu);
|
||||
m_context_menu_mode = mode;
|
||||
}
|
||||
|
||||
void GWidget::move_to_front()
|
||||
{
|
||||
auto* parent = parent_widget();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue