LibGUI: Allow rollback of model editing delegate input

In the StringModelEditingDelegate convenience class, we simply hook up
the escape key to editor rollback. This means you can cancel an ongoing
cell edit by pressing escape. :^)
This commit is contained in:
Andreas Kling 2020-08-28 20:50:12 +02:00
commit 12dfeb9845
Notes: sideshowbarker 2024-07-19 03:03:45 +09:00
2 changed files with 13 additions and 0 deletions

View file

@ -49,6 +49,7 @@ public:
const Widget* widget() const { return m_widget; }
Function<void()> on_commit;
Function<void()> on_rollback;
virtual Variant value() const = 0;
virtual void set_value(const Variant&) = 0;
@ -64,6 +65,11 @@ protected:
if (on_commit)
on_commit();
}
void rollback()
{
if (on_rollback)
on_rollback();
}
const ModelIndex& index() const { return m_index; }
@ -84,6 +90,9 @@ public:
textbox->on_return_pressed = [this] {
commit();
};
textbox->on_escape_pressed = [this] {
rollback();
};
return textbox;
}
virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); }