[studio] Give MakeCopy popup an error message for files that already exist
All checks were successful
Build / build (push) Successful in 3m36s

This commit is contained in:
Gary Talent 2025-02-03 23:30:07 -06:00
parent d39d552bd9
commit 3c804bf62a
3 changed files with 27 additions and 13 deletions

View File

@ -13,6 +13,7 @@ ox::Error MakeCopyPopup::open(ox::StringViewCR path) noexcept {
m_dirPath = substr(path, 0, idx + 1);
m_title = sfmt("Copy {}", path);
m_fileName = "";
m_errMsg = "";
return {};
}
@ -25,7 +26,7 @@ bool MakeCopyPopup::isOpen() const noexcept {
return m_open;
}
void MakeCopyPopup::draw(StudioContext const &ctx, ImVec2 const &sz) noexcept {
void MakeCopyPopup::draw(StudioContext const &ctx) noexcept {
switch (m_stage) {
case Stage::Closed:
break;
@ -36,25 +37,26 @@ void MakeCopyPopup::draw(StudioContext const &ctx, ImVec2 const &sz) noexcept {
[[fallthrough]];
case Stage::Open:
ig::centerNextWindow(ctx.tctx);
ImGui::SetNextWindowSize(sz);
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
ImGui::SetNextWindowSize({250, 0});
constexpr auto modalFlags =
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
if (ImGui::IsWindowAppearing()) {
ImGui::SetKeyboardFocusHere();
}
ig::InputText("Name", m_fileName);
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
accept(ctx);
}
ImGui::Text("%s", m_errMsg.c_str());
bool open = true;
switch (ig::PopupControlsOkCancel(open)) {
case ig::PopupResponse::None:
break;
case ig::PopupResponse::OK:
{
auto const p = sfmt("{}{}", m_dirPath, m_fileName);
if (!ctx.project->exists(p)) {
makeCopy.emit(m_srcPath, p);
close();
}
}
accept(ctx);
break;
case ig::PopupResponse::Cancel:
close();
@ -66,5 +68,14 @@ void MakeCopyPopup::draw(StudioContext const &ctx, ImVec2 const &sz) noexcept {
}
}
void MakeCopyPopup::accept(StudioContext const &ctx) noexcept {
auto const p = sfmt("{}{}", m_dirPath, m_fileName);
if (!ctx.project->exists(p)) {
makeCopy.emit(m_srcPath, p);
close();
} else {
m_errMsg = sfmt("{} already exists", p);
}
}
}
}

View File

@ -20,6 +20,7 @@ class MakeCopyPopup {
};
Stage m_stage = Stage::Closed;
bool m_open{};
ox::String m_errMsg;
ox::String m_title{"Copy File"};
ox::String m_srcPath;
ox::String m_dirPath;
@ -35,8 +36,10 @@ class MakeCopyPopup {
[[nodiscard]]
bool isOpen() const noexcept;
void draw(StudioContext const &ctx, ImVec2 const &sz = {}) noexcept;
void draw(StudioContext const &ctx) noexcept;
private:
void accept(StudioContext const &ctx) noexcept;
};
}

View File

@ -137,7 +137,7 @@ void StudioUI::draw() noexcept {
p->draw(m_sctx);
}
m_closeFileConfirm.draw(m_sctx);
m_copyFilePopup.draw(m_sctx, {250, 0});
m_copyFilePopup.draw(m_sctx);
}
ImGui::End();
handleKeyInput();