diff --git a/src/olympic/studio/applib/src/renamefile.cpp b/src/olympic/studio/applib/src/renamefile.cpp index 24053fc4..73a2ff19 100644 --- a/src/olympic/studio/applib/src/renamefile.cpp +++ b/src/olympic/studio/applib/src/renamefile.cpp @@ -41,20 +41,35 @@ void RenameFile::draw(StudioContext &ctx) noexcept { case Stage::Opening: ImGui::OpenPopup(title().c_str()); m_open = true; + m_fileExists = false; m_stage = Stage::Open; [[fallthrough]]; case Stage::Open: setSize({250, 0}); - drawWindow(ctx.tctx, m_open, [this] { + drawWindow(ctx.tctx, m_open, [this, &ctx] { if (ImGui::IsWindowAppearing()) { ImGui::SetKeyboardFocusHere(); } - ig::InputText("Name", m_name); + m_fileExists = !ig::InputText("Name", m_name) && m_fileExists; auto const nameInputFocused = ImGui::IsItemFocused(); - ImGui::Text("%s%s", m_path.c_str(), m_name.c_str()); - if (ig::PopupControlsOkCancel(m_open) == ig::PopupResponse::OK || + if (m_fileExists) { + ImGui::Text("File %s already exists.", m_name.c_str()); + } else { + ImGui::Text("%s%s", m_path.c_str(), m_name.c_str()); + } + bool b{}; + auto const response = ig::PopupControlsOkCancel(b); + if (response == ig::PopupResponse::OK || (nameInputFocused && ImGui::IsKeyPressed(ImGuiKey_Enter))) { - moveFile.emit(m_oldPath, m_path + m_name); + auto const newPath = m_path + m_name; + if (!ctx.project->exists(newPath)) { + moveFile.emit(m_oldPath, newPath); + close(); + } else { + m_open = true; + m_fileExists = true; + } + } else if (response == ig::PopupResponse::Cancel) { close(); } }); diff --git a/src/olympic/studio/applib/src/renamefile.hpp b/src/olympic/studio/applib/src/renamefile.hpp index 2af0326d..4625118f 100644 --- a/src/olympic/studio/applib/src/renamefile.hpp +++ b/src/olympic/studio/applib/src/renamefile.hpp @@ -21,6 +21,7 @@ class RenameFile: public Popup { ox::String m_oldPath; ox::String m_path; ox::IString<255> m_name; + bool m_fileExists{}; bool m_open{}; public: diff --git a/src/olympic/studio/modlib/src/imguiutil.cpp b/src/olympic/studio/modlib/src/imguiutil.cpp index d3af2aaf..12549785 100644 --- a/src/olympic/studio/modlib/src/imguiutil.cpp +++ b/src/olympic/studio/modlib/src/imguiutil.cpp @@ -64,13 +64,11 @@ PopupResponse PopupControlsOkCancel( ImGui::Separator(); ImGui::SetCursorPosX(popupWidth - 118); if (ImGui::Button(ok.c_str(), btnSz)) { - ImGui::CloseCurrentPopup(); popupOpen = false; out = PopupResponse::OK; } ImGui::SameLine(); if (ImGui::IsKeyDown(ImGuiKey_Escape) || ImGui::Button(cancel.c_str(), btnSz)) { - ImGui::CloseCurrentPopup(); popupOpen = false; out = PopupResponse::Cancel; }