diff --git a/Applications/Spreadsheet/Position.h b/Applications/Spreadsheet/Position.h index 358ab9c1f6..af7d7f70a9 100644 --- a/Applications/Spreadsheet/Position.h +++ b/Applications/Spreadsheet/Position.h @@ -28,6 +28,7 @@ #include #include +#include namespace Spreadsheet { @@ -44,6 +45,16 @@ struct Position { { return !(other == *this); } + + URL to_url() const + { + URL url; + url.set_protocol("spreadsheet"); + url.set_host("cell"); + url.set_path(String::formatted("/{}", getpid())); + url.set_fragment(String::formatted("{}{}", column, row)); + return url; + } }; } diff --git a/Applications/Spreadsheet/Spreadsheet.cpp b/Applications/Spreadsheet/Spreadsheet.cpp index e306a0fbc6..309b9c10c8 100644 --- a/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Applications/Spreadsheet/Spreadsheet.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -202,6 +203,24 @@ Optional Sheet::parse_cell_name(const StringView& name) return Position { col, row.to_uint().value() }; } +Cell* Sheet::from_url(const URL& url) +{ + if (!url.is_valid()) { + dbgln("Invalid url: {}", url.to_string()); + return nullptr; + } + + if (url.protocol() != "spreadsheet" || url.host() != "cell") { + dbgln("Bad url: {}", url.to_string()); + return nullptr; + } + + // FIXME: Figure out a way to do this cross-process. + ASSERT(url.path() == String::formatted("/{}", getpid())); + + return at(url.fragment()); +} + RefPtr Sheet::from_json(const JsonObject& object, Workbook& workbook) { auto sheet = adopt(*new Sheet(workbook)); diff --git a/Applications/Spreadsheet/Spreadsheet.h b/Applications/Spreadsheet/Spreadsheet.h index c210f40bc3..4f1c3f2110 100644 --- a/Applications/Spreadsheet/Spreadsheet.h +++ b/Applications/Spreadsheet/Spreadsheet.h @@ -49,6 +49,9 @@ public: static Optional parse_cell_name(const StringView&); + Cell* from_url(const URL&); + const Cell* from_url(const URL& url) const { return const_cast(this)->from_url(url); } + JsonObject to_json() const; static RefPtr from_json(const JsonObject&, Workbook&);