1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

Spreadsheet: Setup and prepare for cell types

This commit adds a generic interface for cell types and hooks it up.
There is no way to set these from the UI, and so they're not saved
anywhere yet.
Also implicitly converts numeric values (strictly integers) to numeric
javascript values, as numbery-looking + numbery-looking === string is
not very interesting. :^)
This commit is contained in:
AnotherTest 2020-08-28 17:55:06 +04:30 committed by Andreas Kling
parent 5715ed3dd6
commit 6614ee703b
13 changed files with 468 additions and 11 deletions

View file

@ -60,6 +60,45 @@ void Cell::set_data(JS::Value new_data)
evaluated_data = move(new_data);
}
void Cell::set_type(const StringView& name)
{
auto* cell_type = CellType::get_by_name(name);
if (cell_type) {
m_type = cell_type;
return;
}
ASSERT_NOT_REACHED();
}
void Cell::set_type_metadata(CellTypeMetadata&& metadata)
{
m_type_metadata = move(metadata);
}
const CellType& Cell::type() const
{
if (m_type)
return *m_type;
if (kind == LiteralString) {
if (data.to_int().has_value())
return *CellType::get_by_name("Numeric");
}
return *CellType::get_by_name("Identity");
}
String Cell::typed_display() const
{
return type().display(const_cast<Cell&>(*this), m_type_metadata);
}
JS::Value Cell::typed_js_data() const
{
return type().js_value(const_cast<Cell&>(*this), m_type_metadata);
}
void Cell::update_data()
{
TemporaryChange cell_change { sheet->current_evaluated_cell(), this };