1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:15:07 +00:00

LibGUI: Add AbstractView "edit triggers" to improve editing control

This API allows the embedder of a view to decide which actions upon
the view will begin editing the current item.

To maintain the old behavior, we will begin editing when an item is
either double-clicked, or when the "edit key" (return) is pressed.
This commit is contained in:
Andreas Kling 2020-08-28 20:27:51 +02:00
parent 383ee279ee
commit f3e4b62be9
4 changed files with 27 additions and 12 deletions

View file

@ -362,15 +362,10 @@ void AbstractView::doubleclick_event(MouseEvent& event)
else if (!m_selection.contains(index))
set_selection(index);
activate_or_edit_selected();
}
void AbstractView::activate_or_edit_selected()
{
if (is_editable())
begin_editing(selection().first());
if (is_editable() && edit_triggers() & EditTrigger::DoubleClicked)
begin_editing(cursor_index());
else
activate_selected();
activate(cursor_index());
}
void AbstractView::context_menu_event(ContextMenuEvent& event)
@ -449,4 +444,9 @@ void AbstractView::set_cursor(ModelIndex index, SelectionUpdate selection_update
}
}
void AbstractView::set_edit_triggers(unsigned triggers)
{
m_edit_triggers = triggers;
}
}