From 1cbc57628619b342207819f1c98a6c64fe4fc635 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 19 Jan 2025 11:41:08 -0600 Subject: [PATCH] [studio] Complete drag/drop support for files --- .../studio/applib/src/projecttreemodel.cpp | 11 +++------- .../studio/applib/src/projecttreemodel.hpp | 8 ++++++- .../studio/modlib/include/studio/dragdrop.hpp | 22 +++++++++++++++++++ .../modlib/include/studio/imguiutil.hpp | 1 + .../studio/modlib/include/studio/studio.hpp | 1 + 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 src/olympic/studio/modlib/include/studio/dragdrop.hpp diff --git a/src/olympic/studio/applib/src/projecttreemodel.cpp b/src/olympic/studio/applib/src/projecttreemodel.cpp index 51e945ef..cc7afd1a 100644 --- a/src/olympic/studio/applib/src/projecttreemodel.cpp +++ b/src/olympic/studio/applib/src/projecttreemodel.cpp @@ -4,6 +4,7 @@ #include +#include #include #include "projectexplorer.hpp" @@ -54,8 +55,9 @@ void ProjectTreeModel::draw(turbine::Context &tctx) const noexcept { ImGui::EndPopup(); } ImGui::TreePop(); - ig::dragDropSource([this] { + std::ignore = ig::dragDropSource([this] { ImGui::Text("%s", m_name.c_str()); + return ig::setDragDropPayload("FileRef", FileRef{fullPath()}); }); } } @@ -80,11 +82,4 @@ void ProjectTreeModel::drawDirContextMenu() const noexcept { } } -ox::BasicString<255> ProjectTreeModel::fullPath() const noexcept { - if (m_parent) { - return m_parent->fullPath() + "/" + m_name; - } - return {}; -} - } diff --git a/src/olympic/studio/applib/src/projecttreemodel.hpp b/src/olympic/studio/applib/src/projecttreemodel.hpp index e7060d4e..fdfc1fae 100644 --- a/src/olympic/studio/applib/src/projecttreemodel.hpp +++ b/src/olympic/studio/applib/src/projecttreemodel.hpp @@ -32,8 +32,14 @@ class ProjectTreeModel { private: void drawDirContextMenu() const noexcept; + template> [[nodiscard]] - ox::BasicString<255> fullPath() const noexcept; + Str fullPath() const noexcept { + if (m_parent) { + return m_parent->fullPath() + "/" + m_name; + } + return {}; + } }; diff --git a/src/olympic/studio/modlib/include/studio/dragdrop.hpp b/src/olympic/studio/modlib/include/studio/dragdrop.hpp new file mode 100644 index 00000000..e75bb040 --- /dev/null +++ b/src/olympic/studio/modlib/include/studio/dragdrop.hpp @@ -0,0 +1,22 @@ +/* + * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include +#include + +namespace studio { + +struct FileRef { + static constexpr auto TypeName = "net.drinkingtea.studio.FileRef"; + static constexpr auto TypeVersion = 1; + ox::String path; +}; + +OX_MODEL_BEGIN(FileRef) + OX_MODEL_FIELD(path) +OX_MODEL_END() + +} diff --git a/src/olympic/studio/modlib/include/studio/imguiutil.hpp b/src/olympic/studio/modlib/include/studio/imguiutil.hpp index c82f32e8..60bff752 100644 --- a/src/olympic/studio/modlib/include/studio/imguiutil.hpp +++ b/src/olympic/studio/modlib/include/studio/imguiutil.hpp @@ -63,6 +63,7 @@ auto dragDropSource(auto const&cb) noexcept { if (ig::DragDropSource const tgt; tgt) [[unlikely]] { return cb(); } + return ox::Error{}; } else { if (ig::DragDropSource const tgt; tgt) [[unlikely]] { cb(); diff --git a/src/olympic/studio/modlib/include/studio/studio.hpp b/src/olympic/studio/modlib/include/studio/studio.hpp index b18e8263..cd747473 100644 --- a/src/olympic/studio/modlib/include/studio/studio.hpp +++ b/src/olympic/studio/modlib/include/studio/studio.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include