[studio,nostalgia] Update tab name when corresponding file's name changes
All checks were successful
Build / build (push) Successful in 3m30s

This commit is contained in:
Gary Talent 2025-01-26 00:52:11 -06:00
parent f840240aac
commit 046834c2b9
12 changed files with 34 additions and 12 deletions

View File

@ -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<Palette>(keelCtx(m_tctx), itemPath()).unwrapThrow()) {

View File

@ -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},

View File

@ -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) {

View File

@ -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;
};

View File

@ -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()) {

View File

@ -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()) {
}

View File

@ -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();
}

View File

@ -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;

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

@ -131,7 +131,7 @@ class Project: public ox::SignalHandler {
ox::Signal<ox::Error(ox::StringViewCR)> fileRecognized;
ox::Signal<ox::Error(ox::StringViewCR)> fileDeleted;
ox::Signal<ox::Error(ox::StringViewCR path, ox::UUID const&id)> fileUpdated;
ox::Signal<ox::Error(ox::StringViewCR newPath, ox::UUID const&id)> fileMoved;
ox::Signal<ox::Error(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const&id)> fileMoved;
};

View File

@ -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 {};
}
}

View File

@ -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 {};
}