Skip to content

Commit 054638c

Browse files
alimpfardawesomekling
authored andcommitted
Spreadsheet: Add (limited) support for custom cell formatting
1 parent e75247a commit 054638c

File tree

10 files changed

+466
-4
lines changed

10 files changed

+466
-4
lines changed

Applications/Spreadsheet/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(SOURCES
55
CellType/Numeric.cpp
66
CellType/String.cpp
77
CellType/Type.cpp
8+
CellTypeDialog.cpp
89
HelpWindow.cpp
910
JSIntegration.cpp
1011
Spreadsheet.cpp

Applications/Spreadsheet/Cell.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ void Cell::set_data(JS::Value new_data)
6060
evaluated_data = move(new_data);
6161
}
6262

63+
void Cell::set_type(const CellType* type)
64+
{
65+
m_type = type;
66+
}
67+
6368
void Cell::set_type(const StringView& name)
6469
{
6570
auto* cell_type = CellType::get_by_name(name);
6671
if (cell_type) {
67-
m_type = cell_type;
68-
return;
72+
return set_type(cell_type);
6973
}
7074

7175
ASSERT_NOT_REACHED();

Applications/Spreadsheet/Cell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct Cell : public Weakable<Cell> {
5959
void set_data(JS::Value new_data);
6060

6161
void set_type(const StringView& name);
62+
void set_type(const CellType*);
6263
void set_type_metadata(CellTypeMetadata&&);
6364

6465
String typed_display() const;

Applications/Spreadsheet/CellType/Type.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ const CellType* CellType::get_by_name(const StringView& name)
4343
return s_cell_types.get(name).value_or(nullptr);
4444
}
4545

46+
Vector<StringView> CellType::names()
47+
{
48+
Vector<StringView> names;
49+
for (auto& it : s_cell_types)
50+
names.append(it.key);
51+
return names;
52+
}
53+
4654
CellType::CellType(const StringView& name)
4755
{
4856
ASSERT(!s_cell_types.contains(name));

Applications/Spreadsheet/CellType/Type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@
2929
#include "../Forward.h"
3030
#include <AK/Forward.h>
3131
#include <AK/String.h>
32+
#include <LibGfx/TextAlignment.h>
3233
#include <LibJS/Forward.h>
3334

3435
namespace Spreadsheet {
3536

3637
struct CellTypeMetadata {
3738
int length { -1 };
3839
String format;
40+
Gfx::TextAlignment alignment { Gfx::TextAlignment::CenterRight };
3941
};
4042

4143
class CellType {
4244
public:
4345
static const CellType* get_by_name(const StringView&);
46+
static Vector<StringView> names();
4447

4548
virtual String display(Cell&, const CellTypeMetadata&) const = 0;
4649
virtual JS::Value js_value(Cell&, const CellTypeMetadata&) const = 0;

0 commit comments

Comments
 (0)