1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:18:12 +00:00

Spreadsheet: Serialise Positions to URLs and add Sheet::from_uri()

This commit is contained in:
AnotherTest 2020-11-02 20:20:15 +03:30 committed by Andreas Kling
parent 6e9c6acc87
commit 821e875bc0
3 changed files with 33 additions and 0 deletions

View file

@ -32,6 +32,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/TemporaryChange.h>
#include <AK/URL.h>
#include <LibCore/File.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/Function.h>
@ -202,6 +203,24 @@ Optional<Position> 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> Sheet::from_json(const JsonObject& object, Workbook& workbook)
{
auto sheet = adopt(*new Sheet(workbook));