diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp index 9cdf967c..28d1275a 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -54,7 +54,7 @@ void PaletteEditorImGui::PageRenameDialog::draw(turbine::Context &tctx) noexcept PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::StringParam path): - Editor(std::move(path)), + Editor(sctx, std::move(path)), m_sctx(sctx), m_tctx(sctx.tctx), m_pal(*keel::readObj(keelCtx(m_tctx), itemPath()).unwrapThrow()) { diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index fddf29eb..288ab3b5 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -87,7 +87,7 @@ static ox::Error toPngFile( } TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::StringParam path): - Editor(std::move(path)), + Editor(sctx, std::move(path)), m_sctx{sctx}, m_tctx{m_sctx.tctx}, m_palPicker{"Palette Chooser", keelCtx(sctx), FileExt_npal}, diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index cf7fd36d..b1c7fda7 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -329,7 +329,7 @@ void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept { m_updated = true; } -ox::Error TileSheetEditorModel::handleFileRename(ox::StringViewCR newPath, ox::UUID const&id) noexcept { +ox::Error TileSheetEditorModel::handleFileRename(ox::StringViewCR, ox::StringViewCR newPath, ox::UUID const&id) noexcept { if ((beginsWith(m_img.defaultPalette, "uuid://") && substr(m_img.defaultPalette, 7) == id.toString()) || m_img.defaultPalette == newPath) { diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index 66c75a2b..6b00e8f1 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -137,7 +137,7 @@ class TileSheetEditorModel: public ox::SignalHandler { void pushCommand(studio::UndoCommand *cmd) noexcept; - ox::Error handleFileRename(ox::StringViewCR newPath, ox::UUID const&id) noexcept; + ox::Error handleFileRename(ox::StringViewCR, ox::StringViewCR newPath, ox::UUID const&id) noexcept; }; diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index 8a7416ca..70ccc6c3 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -11,7 +11,7 @@ namespace nostalgia::scene { SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path): - Editor(path), + Editor(ctx, path), m_ctx(ctx.tctx), m_editor(m_ctx, path), m_view(m_ctx, m_editor.scene()) { diff --git a/src/olympic/studio/applib/src/clawviewer.cpp b/src/olympic/studio/applib/src/clawviewer.cpp index 65f895e5..d7b2e73b 100644 --- a/src/olympic/studio/applib/src/clawviewer.cpp +++ b/src/olympic/studio/applib/src/clawviewer.cpp @@ -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(itemPath()).unwrapThrow()) { } diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 01244728..9d4130a2 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -373,7 +373,17 @@ ox::Error StudioUI::renameFile(ox::StringViewCR path) noexcept { return m_renameFile.openPath(path); } -ox::Error StudioUI::handleMoveFile(ox::StringViewCR, ox::UUID const&) noexcept { +ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&) noexcept { + for (auto &f : m_openFiles) { + if (f == oldPath) { + f = 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(); } diff --git a/src/olympic/studio/applib/src/studioapp.hpp b/src/olympic/studio/applib/src/studioapp.hpp index 39a3e30c..06fef01e 100644 --- a/src/olympic/studio/applib/src/studioapp.hpp +++ b/src/olympic/studio/applib/src/studioapp.hpp @@ -100,7 +100,7 @@ class StudioUI: public ox::SignalHandler { ox::Error renameFile(ox::StringViewCR path) noexcept; - ox::Error handleMoveFile(ox::StringViewCR path, ox::UUID const&id) noexcept; + ox::Error handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&id) noexcept; ox::Error createOpenProject(ox::StringViewCR path) noexcept; diff --git a/src/olympic/studio/modlib/include/studio/editor.hpp b/src/olympic/studio/modlib/include/studio/editor.hpp index 14a2440a..db6db911 100644 --- a/src/olympic/studio/modlib/include/studio/editor.hpp +++ b/src/olympic/studio/modlib/include/studio/editor.hpp @@ -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; + }; diff --git a/src/olympic/studio/modlib/include/studio/project.hpp b/src/olympic/studio/modlib/include/studio/project.hpp index dc8a221a..c058281d 100644 --- a/src/olympic/studio/modlib/include/studio/project.hpp +++ b/src/olympic/studio/modlib/include/studio/project.hpp @@ -131,7 +131,7 @@ class Project: public ox::SignalHandler { ox::Signal fileRecognized; ox::Signal fileDeleted; ox::Signal fileUpdated; - ox::Signal fileMoved; + ox::Signal fileMoved; }; diff --git a/src/olympic/studio/modlib/src/editor.cpp b/src/olympic/studio/modlib/src/editor.cpp index 04917530..8aef1515 100644 --- a/src/olympic/studio/modlib/src/editor.cpp +++ b/src/olympic/studio/modlib/src/editor.cpp @@ -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 {}; +} + } diff --git a/src/olympic/studio/modlib/src/project.cpp b/src/olympic/studio/modlib/src/project.cpp index 4ec709a9..8c1f7f9a 100644 --- a/src/olympic/studio/modlib/src/project.cpp +++ b/src/olympic/studio/modlib/src/project.cpp @@ -74,7 +74,7 @@ ox::Error Project::moveItem(ox::StringViewCR src, ox::StringViewCR dest) noexcep 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(dest, uuid); + fileMoved.emit(src, dest, uuid); return {}; }