mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:08:12 +00:00
FileManager: focus_dependent_delete_action is correctly enabled/disabled
The focus_dependent_delete_action that sits in the file manager's toolbar would always remain enabled, even if nothing was selected, activating it if nothing was selected would then crash the application. The action is now correctly enabled/disabled, but due to the way selection works in TreeViews, something is always selected, what really matters is if the TreeView has something selected, and it has focus. As it currently stands, there is no way to know when the TreeView's is_focused status changes. In order for this to work I added a callback to the Widget class which fires when a widget receives or looses focus. In that callback, the focus_dependent_delete_action's enabled value is recalculated.
This commit is contained in:
parent
df44ab8599
commit
dea399ff08
3 changed files with 24 additions and 5 deletions
|
@ -558,14 +558,21 @@ void Window::set_focused_widget(Widget* widget, FocusSource source)
|
|||
{
|
||||
if (m_focused_widget == widget)
|
||||
return;
|
||||
if (m_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<FocusEvent>(Event::FocusOut, source));
|
||||
m_focused_widget->update();
|
||||
}
|
||||
|
||||
WeakPtr<Widget> previously_focused_widget = m_focused_widget;
|
||||
m_focused_widget = widget;
|
||||
|
||||
if (previously_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*previously_focused_widget, make<FocusEvent>(Event::FocusOut, source));
|
||||
previously_focused_widget->update();
|
||||
if (previously_focused_widget && previously_focused_widget->on_focus_change)
|
||||
previously_focused_widget->on_focus_change(previously_focused_widget->is_focused(), source);
|
||||
}
|
||||
if (m_focused_widget) {
|
||||
Core::EventLoop::current().post_event(*m_focused_widget, make<FocusEvent>(Event::FocusIn, source));
|
||||
m_focused_widget->update();
|
||||
if (m_focused_widget && m_focused_widget->on_focus_change)
|
||||
m_focused_widget->on_focus_change(m_focused_widget->is_focused(), source);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue