[studio] Make rename file give error message if the file already exists
All checks were successful
Build / build (push) Successful in 3m32s
All checks were successful
Build / build (push) Successful in 3m32s
This commit is contained in:
parent
2286238abc
commit
95256a9a0d
@ -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();
|
||||
}
|
||||
});
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user