LibGUI: Allow double-clicking PathBreadcrumbbar buttons to edit path

When viewing a deeply nested path, there may be very little of the
PathBreadcrumbbar itself visible to double-click on. This solves that
by allowing double-clicks on its segment buttons to behave the same.
(With the caveat that it first selects the double-clicked segment.)

In order to make this work, `on_double_click` now takes the modifiers
instead of the MouseEvent. In this case we don't use it so that's fine,
but maybe we should make all mouse callbacks consistently take the
MouseEvent& as a parameter.
This commit is contained in:
Sam Atkins 2023-02-17 11:20:12 +00:00 committed by Linus Groh
parent 8f717927f2
commit 5b77346f53
Notes: sideshowbarker 2024-07-17 07:48:42 +09:00
3 changed files with 7 additions and 3 deletions

View file

@ -86,6 +86,10 @@ void Breadcrumbbar::append_segment(DeprecatedString text, Gfx::Bitmap const* ico
if (on_segment_change && m_selected_segment != index)
on_segment_change(index);
};
button.on_double_click = [this](auto modifiers) {
if (on_doubleclick)
on_doubleclick(modifiers);
};
button.on_focus_change = [this, index = m_segments.size()](auto has_focus, auto) {
if (has_focus && on_segment_change && m_selected_segment != index)
on_segment_change(index);
@ -154,7 +158,7 @@ void Breadcrumbbar::set_selected_segment(Optional<size_t> index)
void Breadcrumbbar::doubleclick_event(MouseEvent& event)
{
if (on_doubleclick)
on_doubleclick(event);
on_doubleclick(event.modifiers());
}
void Breadcrumbbar::resize_event(ResizeEvent&)

View file

@ -37,7 +37,7 @@ public:
Function<void(size_t index)> on_segment_click;
Function<void(size_t index, DropEvent&)> on_segment_drop;
Function<void(size_t index, DragEvent&)> on_segment_drag_enter;
Function<void(MouseEvent& event)> on_doubleclick;
Function<void(unsigned modifiers)> on_doubleclick;
protected:
virtual void did_change_font() override;

View file

@ -80,7 +80,7 @@ PathBreadcrumbbar::PathBreadcrumbbar(NonnullRefPtr<GUI::TextBox> location_text_b
on_paths_drop(m_breadcrumbbar->segment_data(segment_index), event);
};
m_breadcrumbbar->on_doubleclick = [&](GUI::MouseEvent const&) {
m_breadcrumbbar->on_doubleclick = [&](auto) {
show_location_text_box();
};
}