mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
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:
parent
c43f0f012d
commit
12dfeb9845
2 changed files with 13 additions and 0 deletions
|
@ -147,6 +147,10 @@ void AbstractView::begin_editing(const ModelIndex& index)
|
||||||
model()->set_data(m_edit_index, m_editing_delegate->value());
|
model()->set_data(m_edit_index, m_editing_delegate->value());
|
||||||
stop_editing();
|
stop_editing();
|
||||||
};
|
};
|
||||||
|
m_editing_delegate->on_rollback = [this] {
|
||||||
|
ASSERT(model());
|
||||||
|
stop_editing();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractView::stop_editing()
|
void AbstractView::stop_editing()
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
const Widget* widget() const { return m_widget; }
|
const Widget* widget() const { return m_widget; }
|
||||||
|
|
||||||
Function<void()> on_commit;
|
Function<void()> on_commit;
|
||||||
|
Function<void()> on_rollback;
|
||||||
|
|
||||||
virtual Variant value() const = 0;
|
virtual Variant value() const = 0;
|
||||||
virtual void set_value(const Variant&) = 0;
|
virtual void set_value(const Variant&) = 0;
|
||||||
|
@ -64,6 +65,11 @@ protected:
|
||||||
if (on_commit)
|
if (on_commit)
|
||||||
on_commit();
|
on_commit();
|
||||||
}
|
}
|
||||||
|
void rollback()
|
||||||
|
{
|
||||||
|
if (on_rollback)
|
||||||
|
on_rollback();
|
||||||
|
}
|
||||||
|
|
||||||
const ModelIndex& index() const { return m_index; }
|
const ModelIndex& index() const { return m_index; }
|
||||||
|
|
||||||
|
@ -84,6 +90,9 @@ public:
|
||||||
textbox->on_return_pressed = [this] {
|
textbox->on_return_pressed = [this] {
|
||||||
commit();
|
commit();
|
||||||
};
|
};
|
||||||
|
textbox->on_escape_pressed = [this] {
|
||||||
|
rollback();
|
||||||
|
};
|
||||||
return textbox;
|
return textbox;
|
||||||
}
|
}
|
||||||
virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); }
|
virtual Variant value() const override { return static_cast<const TextBox*>(widget())->text(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue