LibGUI: Add hook when a context menu is requested on a tab

This commit is contained in:
FalseHonesty 2020-05-18 18:36:02 -04:00 committed by Andreas Kling
parent ff98f55b85
commit bf2e6325a4
Notes: sideshowbarker 2024-07-19 06:16:28 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -370,4 +370,19 @@ void TabWidget::keydown_event(KeyEvent& event)
Widget::keydown_event(event);
}
void TabWidget::context_menu_event(ContextMenuEvent& context_menu_event)
{
for (size_t i = 0; i < m_tabs.size(); ++i) {
auto button_rect = this->button_rect(i);
if (!button_rect.contains(context_menu_event.position()))
continue;
auto* widget = m_tabs[i].widget;
deferred_invoke([this, widget, context_menu_event](auto&) {
if (on_context_menu_request && widget)
on_context_menu_request(*widget, context_menu_event);
});
return;
}
}
}

View file

@ -84,6 +84,7 @@ public:
Function<void(Widget&)> on_change;
Function<void(Widget&)> on_middle_click;
Function<void(Widget&, const ContextMenuEvent&)> on_context_menu_request;
protected:
TabWidget();
@ -95,6 +96,7 @@ protected:
virtual void mousemove_event(MouseEvent&) override;
virtual void leave_event(Core::Event&) override;
virtual void keydown_event(KeyEvent&) override;
virtual void context_menu_event(ContextMenuEvent&) override;
private:
Gfx::Rect child_rect_for_size(const Gfx::Size&) const;