From 165ca39e844e5973d6beeeb6d4711c367dfd639f Mon Sep 17 00:00:00 2001 From: Guillaume Jacquemin Date: Sat, 13 Jul 2024 11:32:13 +0200 Subject: [PATCH] Application: early UI work for the backup tree view. --- src/Application/Application.h | 1 + .../Application_ProfileManager.cpp | 150 +++++++++++++----- 2 files changed, 113 insertions(+), 38 deletions(-) diff --git a/src/Application/Application.h b/src/Application/Application.h index 4a6a1c8..00ce53a 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -115,6 +115,7 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe void drawProfileManager(); void drawBackupListPopup(); + void drawBackupFolder(const Managers::Vfs::Directory& dir); void drawBackupRestorePopup(std::size_t backup_index); void drawBackupDeletePopup(std::size_t backup_index); void drawDeleteProfilePopup(std::size_t profile_index); diff --git a/src/Application/Application_ProfileManager.cpp b/src/Application/Application_ProfileManager.cpp index fa55485..ec3141d 100644 --- a/src/Application/Application_ProfileManager.cpp +++ b/src/Application/Application_ProfileManager.cpp @@ -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& dir) { + if(dir.files().isEmpty() && dir.subdirs().isEmpty()) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::TextDisabled(""); + 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,