mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
Spreadsheet: Serialise Positions to URLs and add Sheet::from_uri()
This commit is contained in:
parent
6e9c6acc87
commit
821e875bc0
3 changed files with 33 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <AK/URL.h>
|
||||||
|
|
||||||
namespace Spreadsheet {
|
namespace Spreadsheet {
|
||||||
|
|
||||||
|
@ -44,6 +45,16 @@ struct Position {
|
||||||
{
|
{
|
||||||
return !(other == *this);
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonParser.h>
|
#include <AK/JsonParser.h>
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
|
#include <AK/URL.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibJS/Parser.h>
|
#include <LibJS/Parser.h>
|
||||||
#include <LibJS/Runtime/Function.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() };
|
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)
|
RefPtr<Sheet> Sheet::from_json(const JsonObject& object, Workbook& workbook)
|
||||||
{
|
{
|
||||||
auto sheet = adopt(*new Sheet(workbook));
|
auto sheet = adopt(*new Sheet(workbook));
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
|
|
||||||
static Optional<Position> parse_cell_name(const StringView&);
|
static Optional<Position> parse_cell_name(const StringView&);
|
||||||
|
|
||||||
|
Cell* from_url(const URL&);
|
||||||
|
const Cell* from_url(const URL& url) const { return const_cast<Sheet*>(this)->from_url(url); }
|
||||||
|
|
||||||
JsonObject to_json() const;
|
JsonObject to_json() const;
|
||||||
static RefPtr<Sheet> from_json(const JsonObject&, Workbook&);
|
static RefPtr<Sheet> from_json(const JsonObject&, Workbook&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue