summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Spreadsheet/Position.h11
-rw-r--r--Applications/Spreadsheet/Spreadsheet.cpp19
-rw-r--r--Applications/Spreadsheet/Spreadsheet.h3
3 files changed, 33 insertions, 0 deletions
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 <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;
+ }
};
}
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 <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));
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<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&);