mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Spreadsheet: Serialise Positions to URLs and add Sheet::from_uri()
This commit is contained in:
parent
6e9c6acc87
commit
821e875bc0
Notes:
sideshowbarker
2024-07-19 01:34:25 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/821e875bc0f Pull-request: https://github.com/SerenityOS/serenity/pull/3920 Reviewed-by: https://github.com/awesomekling
3 changed files with 33 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/URL.h>
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -49,6 +49,9 @@ public:
|
|||
|
||||
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;
|
||||
static RefPtr<Sheet> from_json(const JsonObject&, Workbook&);
|
||||
|
||||
|
|
Loading…
Reference in a new issue