Merge commit 'ab760b064fd6a302bad13274e0e02b2b2c957b67'

This commit is contained in:
2025-01-26 15:42:50 -06:00
40 changed files with 810 additions and 193 deletions

View File

@@ -13,10 +13,12 @@ struct FileRef {
static constexpr auto TypeName = "net.drinkingtea.studio.FileRef";
static constexpr auto TypeVersion = 1;
ox::String path;
bool isDir{};
};
OX_MODEL_BEGIN(FileRef)
OX_MODEL_FIELD(path)
OX_MODEL_FIELD(isDir)
OX_MODEL_END()
}

View File

@@ -119,7 +119,7 @@ class Editor: public studio::BaseEditor {
ox::String m_itemName;
public:
Editor(ox::StringParam itemPath) noexcept;
Editor(StudioContext &ctx, ox::StringParam itemPath) noexcept;
[[nodiscard]]
ox::CStringView itemPath() const noexcept final;
@@ -143,6 +143,9 @@ class Editor: public studio::BaseEditor {
private:
ox::Error markUnsavedChanges(UndoCommand const*) noexcept;
ox::Error handleRename(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&id) noexcept;
};

View File

@@ -45,6 +45,10 @@ class FileExplorer: public ox::SignalHandler {
virtual void fileDeleted(ox::StringViewCR path) const noexcept;
virtual void fileMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept;
virtual void dirMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept;
void drawFileContextMenu(ox::CStringViewCR path) const noexcept;
void drawDirContextMenu(ox::CStringViewCR path) const noexcept;

View File

@@ -34,19 +34,37 @@ ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
static_cast<size_t>(payload->DataSize)});
}
template<typename T>
ox::Result<T> getDragDropPayload() noexcept {
auto const payload = ImGui::AcceptDragDropPayload(ox::ModelTypeName_v<T>);
if (!payload) {
return ox::Error(1, "No drag/drop payload");
}
return ox::readClaw<T>({
reinterpret_cast<char const*>(payload->Data),
static_cast<size_t>(payload->DataSize)});
}
ox::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept {
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
return {};
}
template<typename T>
ox::Error setDragDropPayload(T const&obj) noexcept {
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ImGui::SetDragDropPayload(ox::ModelTypeName_v<T>, buff.data(), buff.size());
return {};
}
class DragDropSource {
private:
bool const m_active{};
public:
DragDropSource() noexcept:
m_active(ImGui::BeginDragDropSource()) {
DragDropSource(ImGuiDragDropFlags const flags = 0) noexcept:
m_active(ImGui::BeginDragDropSource(flags)) {
}
~DragDropSource() noexcept {
if (m_active) {
@@ -58,14 +76,14 @@ class DragDropSource {
}
};
auto dragDropSource(auto const&cb) noexcept {
auto dragDropSource(auto const&cb, ImGuiDragDropFlags const flags = 0) noexcept {
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
if (ig::DragDropSource const tgt{flags}; tgt) [[unlikely]] {
return cb();
}
return ox::Error{};
} else {
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
if (ig::DragDropSource const tgt{flags}; tgt) [[unlikely]] {
cb();
}
}

View File

@@ -8,7 +8,6 @@
#include <ox/claw/write.hpp>
#include <ox/event/signal.hpp>
#include <ox/fs/fs.hpp>
#include <ox/mc/mc.hpp>
#include <ox/model/descwrite.hpp>
#include <ox/std/hashmap.hpp>
@@ -26,6 +25,7 @@ enum class ProjectEvent {
FileRecognized,
FileDeleted,
FileUpdated,
FileMoved,
};
[[nodiscard]]
@@ -49,7 +49,7 @@ constexpr ox::StringView parentDir(ox::StringView path) noexcept {
class Project: public ox::SignalHandler {
private:
ox::SmallMap<ox::String, ox::Optional<ox::ClawFormat>> m_typeFmt;
keel::Context &m_ctx;
keel::Context &m_kctx;
ox::String m_path;
ox::String m_projectDataDir;
ox::String m_typeDescPath;
@@ -92,6 +92,10 @@ class Project: public ox::SignalHandler {
ox::Result<ox::FileStat> stat(ox::StringViewCR path) const noexcept;
ox::Error moveItem(ox::StringViewCR src, ox::StringViewCR dest) noexcept;
ox::Error moveDir(ox::StringViewCR src, ox::StringViewCR dest) noexcept;
ox::Error deleteItem(ox::StringViewCR path) noexcept;
[[nodiscard]]
@@ -114,7 +118,7 @@ class Project: public ox::SignalHandler {
ox::Result<ox::Buffer> loadBuff(ox::StringViewCR path) const noexcept;
ox::Error lsProcDir(ox::Vector<ox::String> *paths, ox::StringViewCR path) const noexcept;
ox::Error lsProcDir(ox::Vector<ox::String> &paths, ox::StringViewCR path) const noexcept;
ox::Result<ox::Vector<ox::String>> listFiles(ox::StringViewCR path = "") const noexcept;
@@ -128,7 +132,8 @@ class Project: public ox::SignalHandler {
// file.
ox::Signal<ox::Error(ox::StringViewCR)> fileRecognized;
ox::Signal<ox::Error(ox::StringViewCR)> fileDeleted;
ox::Signal<ox::Error(ox::StringView, ox::UUID)> fileUpdated;
ox::Signal<ox::Error(ox::StringViewCR path, ox::UUID const&id)> fileUpdated;
ox::Signal<ox::Error(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&id)> fileMoved;
};
@@ -151,8 +156,8 @@ ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat f
if (!descExists) {
OX_RETURN_ERROR(writeTypeStore());
}
OX_RETURN_ERROR(keel::reloadAsset(m_ctx, path));
OX_REQUIRE(uuid, pathToUuid(m_ctx, path));
OX_RETURN_ERROR(keel::reloadAsset(m_kctx, path));
OX_REQUIRE(uuid, pathToUuid(m_kctx, path));
fileUpdated.emit(path, uuid);
return {};
}
@@ -200,6 +205,9 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
case ProjectEvent::FileUpdated:
connect(this, &Project::fileUpdated, tgt, slot);
break;
case ProjectEvent::FileMoved:
connect(this, &Project::fileMoved, tgt, slot);
break;
}
return {};
}