Merge commit 'ab760b064fd6a302bad13274e0e02b2b2c957b67'
This commit is contained in:
@ -9,6 +9,7 @@ add_library(
|
||||
newmenu.cpp
|
||||
newproject.cpp
|
||||
projectexplorer.cpp
|
||||
renamefile.cpp
|
||||
studioapp.cpp
|
||||
)
|
||||
target_compile_definitions(
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace studio {
|
||||
|
||||
ClawEditor::ClawEditor(StudioContext &sctx, ox::StringParam path):
|
||||
Editor(std::move(path)),
|
||||
Editor(sctx, std::move(path)),
|
||||
m_obj(sctx.project->loadObj<ox::ModelObject>(itemPath()).unwrapThrow()) {
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,22 @@ void ProjectExplorer::fileDeleted(ox::StringViewCR path) const noexcept {
|
||||
deleteItem.emit(path);
|
||||
}
|
||||
|
||||
void ProjectExplorer::fileMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept {
|
||||
moveItem.emit(src, dst);
|
||||
}
|
||||
|
||||
void ProjectExplorer::dirMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept {
|
||||
moveDir.emit(src, dst);
|
||||
}
|
||||
|
||||
void ProjectExplorer::fileContextMenu(ox::StringViewCR path) const noexcept {
|
||||
if (ImGui::BeginPopupContextItem("FileMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
||||
if (ImGui::MenuItem("Delete")) {
|
||||
deleteItem.emit(path);
|
||||
}
|
||||
if (ImGui::MenuItem("Rename")) {
|
||||
renameItem.emit(path);
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/event/signal.hpp>
|
||||
#include <ox/std/memory.hpp>
|
||||
|
||||
#include <studio/filetreemodel.hpp>
|
||||
#include <studio/widget.hpp>
|
||||
@ -20,6 +19,9 @@ class ProjectExplorer final: public FileExplorer {
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> addItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> addDir;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> deleteItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> renameItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR src, ox::StringViewCR dst)> moveDir;
|
||||
ox::Signal<ox::Error(ox::StringViewCR src, ox::StringViewCR dst)> moveItem;
|
||||
|
||||
explicit ProjectExplorer(keel::Context &kctx) noexcept;
|
||||
|
||||
@ -30,6 +32,10 @@ class ProjectExplorer final: public FileExplorer {
|
||||
|
||||
void fileDeleted(ox::StringViewCR path) const noexcept override;
|
||||
|
||||
void fileMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept override;
|
||||
|
||||
void dirMoved(ox::StringViewCR src, ox::StringViewCR dst) const noexcept override;
|
||||
|
||||
void fileContextMenu(ox::StringViewCR path) const noexcept override;
|
||||
|
||||
void dirContextMenu(ox::StringViewCR path) const noexcept override;
|
||||
|
63
src/olympic/studio/applib/src/renamefile.cpp
Normal file
63
src/olympic/studio/applib/src/renamefile.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
#include "renamefile.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
RenameFile::RenameFile() {
|
||||
setTitle("Rename File");
|
||||
}
|
||||
|
||||
ox::Error RenameFile::openPath(ox::StringParam path) noexcept {
|
||||
m_oldPath = std::move(path);
|
||||
OX_REQUIRE(idx, ox::findIdx(m_oldPath.rbegin(), m_oldPath.rend(), '/'));
|
||||
m_name = substr(m_oldPath, idx + 1);
|
||||
m_path = substr(m_oldPath, 0, idx + 1);
|
||||
open();
|
||||
return {};
|
||||
}
|
||||
|
||||
void RenameFile::open() noexcept {
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void RenameFile::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool RenameFile::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
void RenameFile::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(title().c_str());
|
||||
m_open = true;
|
||||
m_stage = Stage::Open;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
setSize({250, 0});
|
||||
drawWindow(ctx.tctx, m_open, [this] {
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
}
|
||||
ig::InputText("Name", m_name);
|
||||
ImGui::Text("%s%s", m_path.c_str(), m_name.c_str());
|
||||
if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK) {
|
||||
moveFile.emit(m_oldPath, m_path + m_name);
|
||||
close();
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
src/olympic/studio/applib/src/renamefile.hpp
Normal file
44
src/olympic/studio/applib/src/renamefile.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/popup.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class RenameFile: public Popup {
|
||||
|
||||
private:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
Open,
|
||||
};
|
||||
Stage m_stage{};
|
||||
ox::String m_oldPath;
|
||||
ox::String m_path;
|
||||
ox::IString<255> m_name;
|
||||
bool m_open{};
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(ox::StringViewCR src, ox::StringViewCR dst)> moveFile;
|
||||
|
||||
RenameFile();
|
||||
|
||||
ox::Error openPath(ox::StringParam path) noexcept;
|
||||
|
||||
void open() noexcept override;
|
||||
|
||||
void close() noexcept override;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept override;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -47,20 +47,23 @@ OX_MODEL_BEGIN(StudioConfig)
|
||||
OX_MODEL_END()
|
||||
|
||||
StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept:
|
||||
m_sctx(*this, ctx),
|
||||
m_tctx(ctx),
|
||||
m_projectDataDir(std::move(projectDataDir)),
|
||||
m_projectExplorer(keelCtx(m_tctx)),
|
||||
m_newProject(m_projectDataDir),
|
||||
m_aboutPopup(m_tctx) {
|
||||
m_sctx{*this, ctx},
|
||||
m_tctx{ctx},
|
||||
m_projectDataDir{std::move(projectDataDir)},
|
||||
m_projectExplorer{keelCtx(m_tctx)},
|
||||
m_newProject{m_projectDataDir},
|
||||
m_aboutPopup{m_tctx} {
|
||||
turbine::setApplicationData(m_tctx, &m_sctx);
|
||||
m_projectExplorer.fileChosen.connect(this, &StudioUI::openFile);
|
||||
m_projectExplorer.addDir.connect(this, &StudioUI::addDir);
|
||||
m_projectExplorer.addItem.connect(this, &StudioUI::addFile);
|
||||
m_projectExplorer.deleteItem.connect(this, &StudioUI::deleteFile);
|
||||
m_projectExplorer.renameItem.connect(this, &StudioUI::renameFile);
|
||||
m_projectExplorer.moveDir.connect(this, &StudioUI::queueDirMove);
|
||||
m_projectExplorer.moveItem.connect(this, &StudioUI::queueFileMove);
|
||||
m_renameFile.moveFile.connect(this, &StudioUI::queueFileMove);
|
||||
m_newProject.finished.connect(this, &StudioUI::createOpenProject);
|
||||
m_newMenu.finished.connect(this, &StudioUI::openFile);
|
||||
ImGui::GetIO().IniFilename = nullptr;
|
||||
loadModules();
|
||||
// open project and files
|
||||
auto const [config, err] = studio::readConfig<StudioConfig>(keelCtx(m_tctx));
|
||||
@ -135,6 +138,7 @@ void StudioUI::draw() noexcept {
|
||||
ImGui::End();
|
||||
handleKeyInput();
|
||||
m_taskRunner.update(m_tctx);
|
||||
procFileMoves();
|
||||
}
|
||||
|
||||
void StudioUI::drawMenu() noexcept {
|
||||
@ -369,6 +373,29 @@ ox::Error StudioUI::deleteFile(ox::StringViewCR path) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::renameFile(ox::StringViewCR path) noexcept {
|
||||
return m_renameFile.openPath(path);
|
||||
}
|
||||
|
||||
ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&) noexcept {
|
||||
for (auto &f : m_openFiles) {
|
||||
if (f == oldPath) {
|
||||
f = newPath;
|
||||
editConfig<StudioConfig>(keelCtx(m_sctx), [&](StudioConfig &cfg) {
|
||||
auto p = find(cfg.openFiles.begin(), cfg.openFiles.end(), oldPath);
|
||||
*p = newPath;
|
||||
cfg.activeTabItemName = newPath;
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
// needed to keep this tab open, ImGui loses track when the name changes
|
||||
if (m_activeEditor) {
|
||||
m_activeEditorUpdatePending = m_activeEditor;
|
||||
}
|
||||
return m_projectExplorer.refreshProjectTreeModel();
|
||||
}
|
||||
|
||||
ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(toStdStringView(path), ec);
|
||||
@ -390,6 +417,7 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
||||
m_project->dirAdded.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileAdded.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileDeleted.connect(&m_projectExplorer, &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileMoved.connect(this, &StudioUI::handleMoveFile);
|
||||
m_openFiles.clear();
|
||||
m_editors.clear();
|
||||
studio::editConfig<StudioConfig>(keelCtx(m_tctx), [&](StudioConfig &config) {
|
||||
@ -459,4 +487,25 @@ ox::Error StudioUI::closeFile(ox::StringViewCR path) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::queueDirMove(ox::StringParam src, ox::StringParam dst) noexcept {
|
||||
m_queuedDirMoves.emplace_back(std::move(src), std::move(dst));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::queueFileMove(ox::StringParam src, ox::StringParam dst) noexcept {
|
||||
m_queuedMoves.emplace_back(std::move(src), std::move(dst));
|
||||
return {};
|
||||
}
|
||||
|
||||
void StudioUI::procFileMoves() noexcept {
|
||||
for (auto const &m : m_queuedMoves) {
|
||||
oxLogError(m_project->moveItem(m.a, m.b));
|
||||
}
|
||||
m_queuedMoves.clear();
|
||||
for (auto const &m : m_queuedDirMoves) {
|
||||
oxLogError(m_project->moveDir(m.a, m.b));
|
||||
}
|
||||
m_queuedDirMoves.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "newmenu.hpp"
|
||||
#include "newproject.hpp"
|
||||
#include "projectexplorer.hpp"
|
||||
#include "renamefile.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
@ -39,17 +40,21 @@ class StudioUI: public ox::SignalHandler {
|
||||
BaseEditor *m_activeEditorOnLastDraw = nullptr;
|
||||
BaseEditor *m_activeEditor = nullptr;
|
||||
BaseEditor *m_activeEditorUpdatePending = nullptr;
|
||||
ox::Vector<ox::Pair<ox::String>> m_queuedMoves;
|
||||
ox::Vector<ox::Pair<ox::String>> m_queuedDirMoves;
|
||||
NewMenu m_newMenu{keelCtx(m_tctx)};
|
||||
DeleteConfirmation m_deleteConfirmation;
|
||||
NewDir m_newDirDialog;
|
||||
RenameFile m_renameFile;
|
||||
NewProject m_newProject;
|
||||
AboutPopup m_aboutPopup;
|
||||
ox::Array<Popup*, 5> const m_popups = {
|
||||
ox::Array<Popup*, 6> const m_popups = {
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
&m_aboutPopup,
|
||||
&m_deleteConfirmation,
|
||||
&m_newDirDialog,
|
||||
&m_renameFile,
|
||||
};
|
||||
bool m_showProjectExplorer = true;
|
||||
|
||||
@ -95,6 +100,10 @@ class StudioUI: public ox::SignalHandler {
|
||||
|
||||
ox::Error deleteFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error renameFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&id) noexcept;
|
||||
|
||||
ox::Error createOpenProject(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error openProjectPath(ox::StringParam path) noexcept;
|
||||
@ -104,6 +113,13 @@ class StudioUI: public ox::SignalHandler {
|
||||
ox::Error openFileActiveTab(ox::StringViewCR path, bool makeActiveTab) noexcept;
|
||||
|
||||
ox::Error closeFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error queueDirMove(ox::StringParam src, ox::StringParam dst) noexcept;
|
||||
|
||||
ox::Error queueFileMove(ox::StringParam src, ox::StringParam dst) noexcept;
|
||||
|
||||
void procFileMoves() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 {};
|
||||
}
|
||||
|
@ -107,10 +107,11 @@ UndoStack *BaseEditor::undoStack() noexcept {
|
||||
}
|
||||
|
||||
|
||||
Editor::Editor(ox::StringParam itemPath) noexcept:
|
||||
Editor::Editor(StudioContext &ctx, ox::StringParam itemPath) noexcept:
|
||||
m_itemPath(std::move(itemPath)),
|
||||
m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)) {
|
||||
m_undoStack.changeTriggered.connect(this, &Editor::markUnsavedChanges);
|
||||
ctx.project->fileMoved.connect(this, &Editor::handleRename);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -136,4 +137,12 @@ ox::Error Editor::markUnsavedChanges(UndoCommand const*) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error Editor::handleRename(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&) noexcept {
|
||||
if (m_itemPath == oldPath) {
|
||||
m_itemPath = newPath;
|
||||
m_itemName = m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ void FileExplorer::fileOpened(ox::StringViewCR) const noexcept {}
|
||||
|
||||
void FileExplorer::fileDeleted(ox::StringViewCR) const noexcept {}
|
||||
|
||||
void FileExplorer::fileMoved(ox::StringViewCR, ox::StringViewCR) const noexcept {}
|
||||
|
||||
void FileExplorer::dirMoved(ox::StringViewCR, ox::StringViewCR) const noexcept {}
|
||||
|
||||
void FileExplorer::drawFileContextMenu(ox::CStringViewCR path) const noexcept {
|
||||
ig::IDStackItem const idStackItem{path};
|
||||
fileContextMenu(path);
|
||||
@ -91,6 +95,23 @@ void FileTreeModel::draw(turbine::Context &tctx) const noexcept {
|
||||
}
|
||||
ig::IDStackItem const idStackItem{m_name};
|
||||
m_explorer.drawDirContextMenu(m_fullPath);
|
||||
if (m_explorer.fileDraggable()) {
|
||||
std::ignore = ig::dragDropSource([this] {
|
||||
ImGui::Text("%s", m_name.c_str());
|
||||
return ig::setDragDropPayload("FileRef", FileRef{ox::String{m_fullPath}, true});
|
||||
});
|
||||
}
|
||||
if (ig::DragDropTarget const dragDropTarget; dragDropTarget) {
|
||||
auto const [ref, err] = ig::getDragDropPayload<FileRef>("FileRef");
|
||||
if (!err) {
|
||||
auto const name = substr(ref.path, find(ref.path.rbegin(), ref.path.rend(), '/').offset() + 1);
|
||||
if (ref.isDir) {
|
||||
m_explorer.dirMoved(ref.path, sfmt("{}/{}", m_fullPath, name));
|
||||
} else {
|
||||
m_explorer.fileMoved(ref.path, sfmt("{}/{}", m_fullPath, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nodeOpen) {
|
||||
for (auto const&child : m_children) {
|
||||
child->draw(tctx);
|
||||
|
@ -26,16 +26,37 @@ static void generateTypes(ox::TypeStore &ts) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
static ox::Result<ox::Vector<ox::String>> listAllRecursive(ox::FileSystem &fs, ox::StringViewCR path) {
|
||||
// there really isn't much recourse if this function fails, just log it and move on
|
||||
auto [out, outErr] = fs.ls(path);
|
||||
oxLogError(outErr);
|
||||
for (auto const &p : out) {
|
||||
auto const [stat, statErr] = fs.stat(path);
|
||||
if (statErr) {
|
||||
oxLogError(statErr);
|
||||
continue;
|
||||
}
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
OX_REQUIRE_M(l, listAllRecursive(fs, sfmt("{}/{}", path, p)));
|
||||
for (auto &c : l) {
|
||||
out.emplace_back(std::move(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::move(out);
|
||||
}
|
||||
|
||||
|
||||
Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir):
|
||||
m_ctx(ctx),
|
||||
m_kctx(ctx),
|
||||
m_path(std::move(path)),
|
||||
m_projectDataDir(projectDataDir),
|
||||
m_typeDescPath(ox::sfmt("/{}/type_descriptors", m_projectDataDir)),
|
||||
m_typeStore(*m_ctx.rom, ox::sfmt("/{}/type_descriptors", projectDataDir)),
|
||||
m_fs(*m_ctx.rom) {
|
||||
m_typeStore(*m_kctx.rom, ox::sfmt("/{}/type_descriptors", projectDataDir)),
|
||||
m_fs(*m_kctx.rom) {
|
||||
oxTracef("studio", "Project: {}", m_path);
|
||||
generateTypes(m_typeStore);
|
||||
if (ox::defines::Debug) {
|
||||
if constexpr(ox::defines::Debug) {
|
||||
OX_THROW_ERROR(writeTypeStore());
|
||||
}
|
||||
buildFileIndex();
|
||||
@ -69,6 +90,29 @@ ox::Result<ox::FileStat> Project::stat(ox::StringViewCR path) const noexcept {
|
||||
return m_fs.stat(path);
|
||||
}
|
||||
|
||||
ox::Error Project::moveItem(ox::StringViewCR src, ox::StringViewCR dest) noexcept {
|
||||
OX_RETURN_ERROR(m_fs.move(src, dest));
|
||||
OX_RETURN_ERROR(keel::updatePath(m_kctx, src, dest));
|
||||
OX_REQUIRE(uuid, keel::pathToUuid(m_kctx, dest));
|
||||
fileMoved.emit(src, dest, uuid);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error Project::moveDir(ox::StringViewCR src, ox::StringViewCR dest) noexcept {
|
||||
OX_REQUIRE(files, listAllRecursive(m_fs, src));
|
||||
OX_RETURN_ERROR(m_fs.move(src, dest));
|
||||
fileMoved.emit(src, dest, ox::UUID{});
|
||||
for (auto const &op : files) {
|
||||
auto const name =
|
||||
substr(op, ox::find(op.rbegin(), op.rend(), '/').offset() + 1);
|
||||
auto const np = sfmt("{}/{}", dest, name);
|
||||
OX_RETURN_ERROR(keel::updatePath(m_kctx, op, np));
|
||||
OX_REQUIRE(uuid, keel::pathToUuid(m_kctx, dest));
|
||||
fileMoved.emit(src, dest, uuid);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error Project::deleteItem(ox::StringViewCR path) noexcept {
|
||||
OX_REQUIRE(stat, m_fs.stat(path));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
@ -142,7 +186,7 @@ ox::Error Project::writeBuff(ox::StringViewCR path, ox::BufferView const&buff) n
|
||||
ox::Buffer outBuff;
|
||||
outBuff.reserve(buff.size() + HdrSz);
|
||||
ox::BufferWriter writer(&outBuff);
|
||||
auto const [uuid, err] = pathToUuid(m_ctx, path);
|
||||
auto const [uuid, err] = pathToUuid(m_kctx, path);
|
||||
if (!err) {
|
||||
OX_RETURN_ERROR(keel::writeUuidHeader(writer, uuid));
|
||||
}
|
||||
@ -162,14 +206,14 @@ ox::Result<ox::Buffer> Project::loadBuff(ox::StringViewCR path) const noexcept {
|
||||
return m_fs.read(path);
|
||||
}
|
||||
|
||||
ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::StringViewCR path) const noexcept {
|
||||
ox::Error Project::lsProcDir(ox::Vector<ox::String> &paths, ox::StringViewCR path) const noexcept {
|
||||
OX_REQUIRE(files, m_fs.ls(path));
|
||||
for (auto const&name : files) {
|
||||
auto fullPath = ox::sfmt("{}/{}", path, name);
|
||||
OX_REQUIRE(stat, m_fs.stat(ox::StringView(fullPath)));
|
||||
switch (stat.fileType) {
|
||||
case ox::FileType::NormalFile:
|
||||
paths->emplace_back(std::move(fullPath));
|
||||
paths.emplace_back(std::move(fullPath));
|
||||
break;
|
||||
case ox::FileType::Directory:
|
||||
OX_RETURN_ERROR(lsProcDir(paths, fullPath));
|
||||
@ -183,7 +227,7 @@ ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::StringViewCR pat
|
||||
|
||||
ox::Result<ox::Vector<ox::String>> Project::listFiles(ox::StringViewCR path) const noexcept {
|
||||
ox::Vector<ox::String> paths;
|
||||
OX_RETURN_ERROR(lsProcDir(&paths, path));
|
||||
OX_RETURN_ERROR(lsProcDir(paths, path));
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user