MCPcopy Create free account
hub / github.com/dfranx/ImFileDialog / m_renderPopups

Method m_renderPopups

ImFileDialog.cpp:1203–1280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1201 }
1202 }
1203 void FileDialog::m_renderPopups()
1204 {
1205 bool openAreYouSureDlg = false, openNewFileDlg = false, openNewDirectoryDlg = false;
1206 if (ImGui::BeginPopupContextItem("##dir_context")) {
1207 if (ImGui::Selectable("New file"))
1208 openNewFileDlg = true;
1209 if (ImGui::Selectable("New directory"))
1210 openNewDirectoryDlg = true;
1211 if (m_selectedFileItem != -1 && ImGui::Selectable("Delete"))
1212 openAreYouSureDlg = true;
1213 ImGui::EndPopup();
1214 }
1215 if (openAreYouSureDlg)
1216 ImGui::OpenPopup("Are you sure?##delete");
1217 if (openNewFileDlg)
1218 ImGui::OpenPopup("Enter file name##newfile");
1219 if (openNewDirectoryDlg)
1220 ImGui::OpenPopup("Enter directory name##newdir");
1221 if (ImGui::BeginPopupModal("Are you sure?##delete")) {
1222 if (m_selectedFileItem >= static_cast<int>(m_content.size()) || m_content.size() == 0)
1223 ImGui::CloseCurrentPopup();
1224 else {
1225 const FileData& data = m_content[m_selectedFileItem];
1226 ImGui::TextWrapped("Are you sure you want to delete %s?", data.Path.filename().u8string().c_str());
1227 if (ImGui::Button("Yes")) {
1228 std::error_code ec;
1229 std::filesystem::remove_all(data.Path, ec);
1230 m_setDirectory(m_currentDirectory, false); // refresh
1231 ImGui::CloseCurrentPopup();
1232 }
1233 ImGui::SameLine();
1234 if (ImGui::Button("No"))
1235 ImGui::CloseCurrentPopup();
1236 }
1237 ImGui::EndPopup();
1238 }
1239 if (ImGui::BeginPopupModal("Enter file name##newfile")) {
1240 ImGui::PushItemWidth(250.0f);
1241 ImGui::InputText("##newfilename", m_newEntryBuffer, 1024); // TODO: remove hardcoded literals
1242 ImGui::PopItemWidth();
1243
1244 if (ImGui::Button("OK")) {
1245 std::ofstream out((m_currentDirectory / std::string(m_newEntryBuffer)).string());
1246 out << "";
1247 out.close();
1248
1249 m_setDirectory(m_currentDirectory, false); // refresh
1250 m_newEntryBuffer[0] = 0;
1251
1252 ImGui::CloseCurrentPopup();
1253 }
1254 ImGui::SameLine();
1255 if (ImGui::Button("Cancel")) {
1256 m_newEntryBuffer[0] = 0;
1257 ImGui::CloseCurrentPopup();
1258 }
1259 ImGui::EndPopup();
1260 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected