[studio] Give MakeCopy popup an error message for files that already exist
All checks were successful
Build / build (push) Successful in 3m36s
All checks were successful
Build / build (push) Successful in 3m36s
This commit is contained in:
parent
d39d552bd9
commit
3c804bf62a
@ -13,6 +13,7 @@ ox::Error MakeCopyPopup::open(ox::StringViewCR path) noexcept {
|
|||||||
m_dirPath = substr(path, 0, idx + 1);
|
m_dirPath = substr(path, 0, idx + 1);
|
||||||
m_title = sfmt("Copy {}", path);
|
m_title = sfmt("Copy {}", path);
|
||||||
m_fileName = "";
|
m_fileName = "";
|
||||||
|
m_errMsg = "";
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ bool MakeCopyPopup::isOpen() const noexcept {
|
|||||||
return m_open;
|
return m_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeCopyPopup::draw(StudioContext const &ctx, ImVec2 const &sz) noexcept {
|
void MakeCopyPopup::draw(StudioContext const &ctx) noexcept {
|
||||||
switch (m_stage) {
|
switch (m_stage) {
|
||||||
case Stage::Closed:
|
case Stage::Closed:
|
||||||
break;
|
break;
|
||||||
@ -36,25 +37,26 @@ void MakeCopyPopup::draw(StudioContext const &ctx, ImVec2 const &sz) noexcept {
|
|||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case Stage::Open:
|
case Stage::Open:
|
||||||
ig::centerNextWindow(ctx.tctx);
|
ig::centerNextWindow(ctx.tctx);
|
||||||
ImGui::SetNextWindowSize(sz);
|
ImGui::SetNextWindowSize({250, 0});
|
||||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
constexpr auto modalFlags =
|
||||||
|
ImGuiWindowFlags_NoCollapse |
|
||||||
|
ImGuiWindowFlags_NoMove |
|
||||||
|
ImGuiWindowFlags_NoResize;
|
||||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||||
if (ImGui::IsWindowAppearing()) {
|
if (ImGui::IsWindowAppearing()) {
|
||||||
ImGui::SetKeyboardFocusHere();
|
ImGui::SetKeyboardFocusHere();
|
||||||
}
|
}
|
||||||
ig::InputText("Name", m_fileName);
|
ig::InputText("Name", m_fileName);
|
||||||
|
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
|
||||||
|
accept(ctx);
|
||||||
|
}
|
||||||
|
ImGui::Text("%s", m_errMsg.c_str());
|
||||||
bool open = true;
|
bool open = true;
|
||||||
switch (ig::PopupControlsOkCancel(open)) {
|
switch (ig::PopupControlsOkCancel(open)) {
|
||||||
case ig::PopupResponse::None:
|
case ig::PopupResponse::None:
|
||||||
break;
|
break;
|
||||||
case ig::PopupResponse::OK:
|
case ig::PopupResponse::OK:
|
||||||
{
|
accept(ctx);
|
||||||
auto const p = sfmt("{}{}", m_dirPath, m_fileName);
|
|
||||||
if (!ctx.project->exists(p)) {
|
|
||||||
makeCopy.emit(m_srcPath, p);
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ig::PopupResponse::Cancel:
|
case ig::PopupResponse::Cancel:
|
||||||
close();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ class MakeCopyPopup {
|
|||||||
};
|
};
|
||||||
Stage m_stage = Stage::Closed;
|
Stage m_stage = Stage::Closed;
|
||||||
bool m_open{};
|
bool m_open{};
|
||||||
|
ox::String m_errMsg;
|
||||||
ox::String m_title{"Copy File"};
|
ox::String m_title{"Copy File"};
|
||||||
ox::String m_srcPath;
|
ox::String m_srcPath;
|
||||||
ox::String m_dirPath;
|
ox::String m_dirPath;
|
||||||
@ -35,8 +36,10 @@ class MakeCopyPopup {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool isOpen() const noexcept;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ void StudioUI::draw() noexcept {
|
|||||||
p->draw(m_sctx);
|
p->draw(m_sctx);
|
||||||
}
|
}
|
||||||
m_closeFileConfirm.draw(m_sctx);
|
m_closeFileConfirm.draw(m_sctx);
|
||||||
m_copyFilePopup.draw(m_sctx, {250, 0});
|
m_copyFilePopup.draw(m_sctx);
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
handleKeyInput();
|
handleKeyInput();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user