Application: early UI work for the backup tree view.

This commit is contained in:
Guillaume Jacquemin 2024-07-13 11:32:13 +02:00
parent c1ad757f80
commit 165ca39e84
Signed by: williamjcm
SSH key fingerprint: SHA256:AYLOg+iTV0ElElnlu4vqM4edFazVdRiuQB0Y5LoKc4A
2 changed files with 113 additions and 38 deletions

View file

@ -115,6 +115,7 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe
void drawProfileManager();
void drawBackupListPopup();
void drawBackupFolder(const Managers::Vfs::Directory<Managers::Backup>& dir);
void drawBackupRestorePopup(std::size_t backup_index);
void drawBackupDeletePopup(std::size_t backup_index);
void drawDeleteProfilePopup(std::size_t profile_index);

View file

@ -175,48 +175,50 @@ Application::drawBackupListPopup() {
ImGui::TableSetColumnIndex(3);
ImGui::TextUnformatted("Actions");
for(std::size_t i = 0; i < _backupManager->backups().size(); ++i) {
auto& backup = _backupManager->backups()[i];
ImGui::TableNextRow();
drawBackupFolder(_backupManager->vfs());
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(backup.company.cbegin(), backup.company.cend());
if(ImGui::IsItemHovered() && ImGui::BeginTooltip()) {
for(const auto& file : backup.includedFiles) {
ImGui::TextUnformatted(file.cbegin());
}
ImGui::EndTooltip();
}
//for(std::size_t i = 0; i < _backupManager->backups().size(); ++i) {
// auto& backup = _backupManager->backups()[i];
// ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
ImGui::Text("%.4i-%.2i-%.2i %.2i:%.2i:%.2i",
backup.timestamp.year,
backup.timestamp.month,
backup.timestamp.day,
backup.timestamp.hour,
backup.timestamp.minute,
backup.timestamp.second);
// ImGui::TableSetColumnIndex(0);
// ImGui::TextUnformatted(backup.company.cbegin(), backup.company.cend());
// if(ImGui::IsItemHovered() && ImGui::BeginTooltip()) {
// for(const auto& file : backup.includedFiles) {
// ImGui::TextUnformatted(file.cbegin());
// }
// ImGui::EndTooltip();
// }
ImGui::TableSetColumnIndex(2);
ImGui::TextUnformatted(backup.demo ? "Demo" : "Full");
// ImGui::TableSetColumnIndex(1);
// ImGui::Text("%.4i-%.2i-%.2i %.2i:%.2i:%.2i",
// backup.timestamp.year,
// backup.timestamp.month,
// backup.timestamp.day,
// backup.timestamp.hour,
// backup.timestamp.minute,
// backup.timestamp.second);
ImGui::TableSetColumnIndex(3);
ImGui::PushID(int(i));
if(ImGui::SmallButton(ICON_FA_UNDO)) {
backup_index = i;
ImGui::OpenPopup("Restore backup##RestoreBackupModal");
}
drawTooltip("Restore");
drawBackupRestorePopup(backup_index);
ImGui::SameLine(0.0f, 2.0f);
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
backup_index = i;
ImGui::OpenPopup("Delete backup##DeleteBackupModal");
}
drawTooltip("Delete");
drawBackupDeletePopup(backup_index);
ImGui::PopID();
}
// ImGui::TableSetColumnIndex(2);
// ImGui::TextUnformatted(backup.demo ? "Demo" : "Full");
// ImGui::TableSetColumnIndex(3);
// ImGui::PushID(int(i));
// if(ImGui::SmallButton(ICON_FA_UNDO)) {
// backup_index = i;
// ImGui::OpenPopup("Restore backup##RestoreBackupModal");
// }
// drawTooltip("Restore");
// drawBackupRestorePopup(backup_index);
// ImGui::SameLine(0.0f, 2.0f);
// if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
// backup_index = i;
// ImGui::OpenPopup("Delete backup##DeleteBackupModal");
// }
// drawTooltip("Delete");
// drawBackupDeletePopup(backup_index);
// ImGui::PopID();
//}
ImGui::EndTable();
}
@ -241,6 +243,78 @@ Application::drawBackupListPopup() {
ImGui::EndPopup();
}
void
Application::drawBackupFolder(const Managers::Vfs::Directory<Managers::Backup>& dir) {
if(dir.files().isEmpty() && dir.subdirs().isEmpty()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextDisabled("<empty>");
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
return;
}
bool open = false;
if(dir.name() != "") {
ImGui::TableNextRow();
ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(dir.name().cbegin(), ImGuiTreeNodeFlags_SpanAllColumns);
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
ImGui::TableNextColumn();
ImGui::TextDisabled("--");
}
for(auto& subdir : dir.subdirs()) {
drawBackupFolder(subdir);
if(open) {
ImGui::TreePop();
}
}
for(auto file : dir.files()) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TreeNodeEx(file->company.cbegin(), ImGuiTreeNodeFlags_SpanAllColumns|ImGuiTreeNodeFlags_Leaf|
ImGuiTreeNodeFlags_Bullet|ImGuiTreeNodeFlags_NoTreePushOnOpen);
ImGui::TableNextColumn();
ImGui::Text("%.4i-%.2i-%.2i %.2i:%.2i:%.2i",
file->timestamp.year,
file->timestamp.month,
file->timestamp.day,
file->timestamp.hour,
file->timestamp.minute,
file->timestamp.second);
ImGui::TableNextColumn();
ImGui::TextUnformatted(file->demo ? "Demo" : "Full");
ImGui::TableNextColumn();
ImGui::PushID(file);
if(ImGui::SmallButton(ICON_FA_UNDO)) {
//ImGui::OpenPopup("Restore backup##RestoreBackupModal");
}
drawTooltip("Restore");
//drawBackupRestorePopup(backup_index);
ImGui::SameLine(0.0f, 2.0f);
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
//ImGui::OpenPopup("Delete backup##DeleteBackupModal");
}
drawTooltip("Delete");
//drawBackupDeletePopup(backup_index);
ImGui::PopID();
}
}
void
Application::drawBackupRestorePopup(std::size_t backup_index) {
if(!ImGui::BeginPopupModal("Restore backup##RestoreBackupModal", nullptr,