Compare commits

...

3 Commits

Author SHA1 Message Date
8eb1ac215b [studio] Fix not to try moving a parent directory to its child
All checks were successful
Build / build (push) Successful in 3m34s
2025-01-27 00:10:25 -06:00
e132f2fd1b [studio] Make file move do nothing if the file already exists 2025-01-26 23:59:13 -06:00
12f6b22c8b [nostalgia/gfx/studio/palette] Cleanup 2025-01-26 23:35:03 -06:00
4 changed files with 30 additions and 17 deletions

View File

@@ -1,19 +1,6 @@
target_sources(
NostalgiaCore-Studio PRIVATE
commands/addcolorcommand.cpp
commands/addpagecommand.cpp
commands/applycolorallpagescommand.cpp
commands/duplicatepagecommand.cpp
commands/movecolorcommand.cpp
commands/movepagecommand.cpp
commands/removecolorcommand.cpp
commands/removepagecommand.cpp
commands/renamepagecommand.cpp
commands/updatecolorcommand.cpp
commands/updatecolorinfocommand.cpp
)
target_sources( target_sources(
NostalgiaCore-Studio-ImGui PRIVATE NostalgiaCore-Studio-ImGui PRIVATE
paletteeditor-imgui.cpp paletteeditor-imgui.cpp
) )
add_subdirectory(commands)

View File

@@ -0,0 +1,15 @@
target_sources(
NostalgiaCore-Studio PRIVATE
addcolorcommand.cpp
addpagecommand.cpp
applycolorallpagescommand.cpp
duplicatepagecommand.cpp
movecolorcommand.cpp
movepagecommand.cpp
removecolorcommand.cpp
removepagecommand.cpp
renamepagecommand.cpp
updatecolorcommand.cpp
updatecolorinfocommand.cpp
)

View File

@@ -495,11 +495,15 @@ ox::Error StudioUI::queueFileMove(ox::StringParam src, ox::StringParam dst) noex
void StudioUI::procFileMoves() noexcept { void StudioUI::procFileMoves() noexcept {
for (auto const &m : m_queuedMoves) { for (auto const &m : m_queuedMoves) {
oxLogError(m_project->moveItem(m.a, m.b)); if (!m_project->exists(m.b)) {
oxLogError(m_project->moveItem(m.a, m.b));
}
} }
m_queuedMoves.clear(); m_queuedMoves.clear();
for (auto const &m : m_queuedDirMoves) { for (auto const &m : m_queuedDirMoves) {
oxLogError(m_project->moveDir(m.a, m.b)); if (!m_project->exists(m.b)) {
oxLogError(m_project->moveDir(m.a, m.b));
}
} }
m_queuedDirMoves.clear(); m_queuedDirMoves.clear();
} }

View File

@@ -46,6 +46,10 @@ static ox::Result<ox::Vector<ox::String>> listAllRecursive(ox::FileSystem &fs, o
return std::move(out); return std::move(out);
} }
[[nodiscard]]
static constexpr bool isParentOf(ox::StringViewCR parent, ox::StringViewCR child) noexcept {
return beginsWith(child, parent);
}
Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir): Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir):
m_kctx(ctx), m_kctx(ctx),
@@ -99,6 +103,9 @@ ox::Error Project::moveItem(ox::StringViewCR src, ox::StringViewCR dest) noexcep
} }
ox::Error Project::moveDir(ox::StringViewCR src, ox::StringViewCR dest) noexcept { ox::Error Project::moveDir(ox::StringViewCR src, ox::StringViewCR dest) noexcept {
if (isParentOf(src, dest)) {
return ox::Error{1, "cannot move parent to a child directory"};
}
OX_REQUIRE(files, listAllRecursive(m_fs, src)); OX_REQUIRE(files, listAllRecursive(m_fs, src));
OX_RETURN_ERROR(m_fs.move(src, dest)); OX_RETURN_ERROR(m_fs.move(src, dest));
fileMoved.emit(src, dest, ox::UUID{}); fileMoved.emit(src, dest, ox::UUID{});