Application: reorganise profile manager UI code.
This commit is contained in:
parent
387647669f
commit
e9fad7600b
2 changed files with 114 additions and 112 deletions
|
@ -113,9 +113,11 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe
|
||||||
void drawInitialisation();
|
void drawInitialisation();
|
||||||
|
|
||||||
void drawProfileManager();
|
void drawProfileManager();
|
||||||
auto drawBackupListPopup() -> ImGuiID;
|
void drawBackupListPopup();
|
||||||
auto drawBackupProfilePopup(std::size_t profile_index) -> ImGuiID;
|
void drawBackupRestorePopup(std::size_t backup_index);
|
||||||
auto drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID;
|
void drawBackupDeletePopup(std::size_t backup_index);
|
||||||
|
void drawBackupProfilePopup(std::size_t profile_index);
|
||||||
|
void drawDeleteProfilePopup(std::size_t profile_index);
|
||||||
|
|
||||||
void drawManager();
|
void drawManager();
|
||||||
bool drawIntEditPopup(int* value_to_edit, int max);
|
bool drawIntEditPopup(int* value_to_edit, int max);
|
||||||
|
|
|
@ -40,10 +40,6 @@ Application::drawProfileManager() {
|
||||||
ImGui::EndMenuBar();
|
ImGui::EndMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImGuiID backup_list_popup_id = drawBackupListPopup();
|
|
||||||
static ImGuiID backup_popup_id = drawBackupProfilePopup(profile_index);
|
|
||||||
static ImGuiID delete_popup_id = drawDeleteProfilePopup(profile_index);
|
|
||||||
|
|
||||||
if(ImGui::BeginTable("##ManagerLayout", 2)) {
|
if(ImGui::BeginTable("##ManagerLayout", 2)) {
|
||||||
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
|
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
|
||||||
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
@ -63,8 +59,9 @@ Application::drawProfileManager() {
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if(ImGui::SmallButton("Backups")) {
|
if(ImGui::SmallButton("Backups")) {
|
||||||
_profileManager->refreshBackups();
|
_profileManager->refreshBackups();
|
||||||
ImGui::OpenPopup(backup_list_popup_id);
|
ImGui::OpenPopup("Backups##BackupsModal");
|
||||||
}
|
}
|
||||||
|
drawBackupListPopup();
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
@ -104,15 +101,17 @@ Application::drawProfileManager() {
|
||||||
ImGui::TableSetColumnIndex(2);
|
ImGui::TableSetColumnIndex(2);
|
||||||
if(ImGui::SmallButton(ICON_FA_FILE_ARCHIVE)) {
|
if(ImGui::SmallButton(ICON_FA_FILE_ARCHIVE)) {
|
||||||
profile_index = i;
|
profile_index = i;
|
||||||
ImGui::OpenPopup(backup_popup_id);
|
ImGui::OpenPopup("Include builds ?##IncludeBuildsDialog");
|
||||||
}
|
}
|
||||||
drawTooltip("Backup");
|
drawTooltip("Backup");
|
||||||
|
drawBackupProfilePopup(profile_index);
|
||||||
ImGui::SameLine(0.0f, 2.0f);
|
ImGui::SameLine(0.0f, 2.0f);
|
||||||
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
|
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
|
||||||
profile_index = i;
|
profile_index = i;
|
||||||
ImGui::OpenPopup(delete_popup_id);
|
ImGui::OpenPopup("Confirmation##DeleteProfileConfirmation");
|
||||||
}
|
}
|
||||||
drawTooltip("Delete");
|
drawTooltip("Delete");
|
||||||
|
drawDeleteProfilePopup(profile_index);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
|
@ -121,108 +120,20 @@ Application::drawProfileManager() {
|
||||||
ImGui::TextUnformatted("Click a profile to manage it.");
|
ImGui::TextUnformatted("Click a profile to manage it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
drawBackupListPopup();
|
|
||||||
drawBackupProfilePopup(profile_index);
|
|
||||||
drawDeleteProfilePopup(profile_index);
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiID
|
void
|
||||||
Application::drawBackupListPopup() {
|
Application::drawBackupListPopup() {
|
||||||
ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot);
|
ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot);
|
||||||
if(!ImGui::BeginPopupModal("Backups##BackupsModal", nullptr,
|
if(!ImGui::BeginPopupModal("Backups##BackupsModal", nullptr,
|
||||||
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
||||||
{
|
{
|
||||||
return ImGui::GetID("Backups##BackupsModal");
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::size_t backup_index;
|
static std::size_t backup_index;
|
||||||
|
|
||||||
if(ImGui::BeginPopupModal("Restore backup", nullptr,
|
|
||||||
ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize))
|
|
||||||
{
|
|
||||||
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.40f);
|
|
||||||
ImGui::Text("Are you sure you want to restore the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? Any existing data will be overwritten.",
|
|
||||||
_profileManager->backups()[backup_index].company.data(),
|
|
||||||
_profileManager->backups()[backup_index].timestamp.year,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.month,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.day,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.hour,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.minute,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.second);
|
|
||||||
ImGui::PopTextWrapPos();
|
|
||||||
|
|
||||||
if(ImGui::BeginTable("##RestoreBackupLayout", 2)) {
|
|
||||||
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
|
|
||||||
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
|
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
|
||||||
if(ImGui::Button("Yes")) {
|
|
||||||
if(!_profileManager->restoreBackup(backup_index)) {
|
|
||||||
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
|
|
||||||
}
|
|
||||||
if(!_profileManager->refreshProfiles()) {
|
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
|
||||||
_profileManager->lastError().data(), window());
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ImGui::BeginPopupModal("Delete backup", nullptr,
|
|
||||||
ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize))
|
|
||||||
{
|
|
||||||
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.40f);
|
|
||||||
ImGui::Text("Are you sure you want to delete the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ? This operation is irreversible.",
|
|
||||||
_profileManager->backups()[backup_index].company.data(),
|
|
||||||
_profileManager->backups()[backup_index].timestamp.year,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.month,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.day,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.hour,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.minute,
|
|
||||||
_profileManager->backups()[backup_index].timestamp.second);
|
|
||||||
ImGui::PopTextWrapPos();
|
|
||||||
|
|
||||||
if(ImGui::BeginTable("##DeleteBackupLayout", 2)) {
|
|
||||||
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
|
|
||||||
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
|
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
|
||||||
if(ImGui::Button("Yes")) {
|
|
||||||
if(!_profileManager->deleteBackup(backup_index)) {
|
|
||||||
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
|
|
||||||
}
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
|
|
||||||
ImGui::CloseCurrentPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImGuiID restore_backup_popup_id = ImGui::GetID("Restore backup");
|
|
||||||
static ImGuiID delete_backup_popup_id = ImGui::GetID("Delete backup");
|
|
||||||
|
|
||||||
if(ImGui::BeginTable("##BackupsLabelLayout", 2)) {
|
if(ImGui::BeginTable("##BackupsLabelLayout", 2)) {
|
||||||
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
|
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
|
||||||
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
@ -290,15 +201,17 @@ Application::drawBackupListPopup() {
|
||||||
ImGui::PushID(int(i));
|
ImGui::PushID(int(i));
|
||||||
if(ImGui::SmallButton(ICON_FA_UNDO)) {
|
if(ImGui::SmallButton(ICON_FA_UNDO)) {
|
||||||
backup_index = i;
|
backup_index = i;
|
||||||
ImGui::OpenPopup(restore_backup_popup_id);
|
ImGui::OpenPopup("Restore backup##RestoreBackupModal");
|
||||||
}
|
}
|
||||||
drawTooltip("Restore");
|
drawTooltip("Restore");
|
||||||
|
drawBackupRestorePopup(backup_index);
|
||||||
ImGui::SameLine(0.0f, 2.0f);
|
ImGui::SameLine(0.0f, 2.0f);
|
||||||
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
|
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
|
||||||
backup_index = i;
|
backup_index = i;
|
||||||
ImGui::OpenPopup(delete_backup_popup_id);
|
ImGui::OpenPopup("Delete backup##DeleteBackupModal");
|
||||||
}
|
}
|
||||||
drawTooltip("Delete");
|
drawTooltip("Delete");
|
||||||
|
drawBackupDeletePopup(backup_index);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
|
@ -323,16 +236,107 @@ Application::drawBackupListPopup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiID
|
void
|
||||||
|
Application::drawBackupRestorePopup(std::size_t backup_index) {
|
||||||
|
if(!ImGui::BeginPopupModal("Restore backup##RestoreBackupModal", nullptr,
|
||||||
|
ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.50f);
|
||||||
|
ImGui::Text("Are you sure you want to restore the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ?\n\n"
|
||||||
|
"Any existing data will be overwritten.",
|
||||||
|
_profileManager->backups()[backup_index].company.data(),
|
||||||
|
_profileManager->backups()[backup_index].timestamp.year,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.month,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.day,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.hour,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.minute,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.second);
|
||||||
|
ImGui::PopTextWrapPos();
|
||||||
|
|
||||||
|
if(ImGui::BeginTable("##RestoreBackupLayout", 2)) {
|
||||||
|
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
|
||||||
|
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
if(ImGui::Button("Yes")) {
|
||||||
|
if(!_profileManager->restoreBackup(backup_index)) {
|
||||||
|
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
|
||||||
|
}
|
||||||
|
if(!_profileManager->refreshProfiles()) {
|
||||||
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
||||||
|
_profileManager->lastError().data(), window());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Application::drawBackupDeletePopup(std::size_t backup_index) {
|
||||||
|
if(!ImGui::BeginPopupModal("Delete backup##DeleteBackupModal", nullptr,
|
||||||
|
ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.50f);
|
||||||
|
ImGui::Text("Are you sure you want to delete the %s backup from %.4i-%.2i-%.2i %.2i:%.2i:%.2i ?\n\n"
|
||||||
|
"This operation is irreversible.",
|
||||||
|
_profileManager->backups()[backup_index].company.data(),
|
||||||
|
_profileManager->backups()[backup_index].timestamp.year,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.month,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.day,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.hour,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.minute,
|
||||||
|
_profileManager->backups()[backup_index].timestamp.second);
|
||||||
|
ImGui::PopTextWrapPos();
|
||||||
|
|
||||||
|
if(ImGui::BeginTable("##DeleteBackupLayout", 2)) {
|
||||||
|
ImGui::TableSetupColumn("##Dummy", ImGuiTableColumnFlags_WidthStretch);
|
||||||
|
ImGui::TableSetupColumn("##YesNo", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
if(ImGui::Button("Yes")) {
|
||||||
|
if(!_profileManager->deleteBackup(backup_index)) {
|
||||||
|
_queue.addToast(Toast::Type::Error, _profileManager->lastError());
|
||||||
|
}
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if(ImGui::Button("No", ImGui::GetItemRectSize())) {
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
Application::drawBackupProfilePopup(std::size_t profile_index) {
|
Application::drawBackupProfilePopup(std::size_t profile_index) {
|
||||||
if(!ImGui::BeginPopupModal("Include builds ?##IncludeBuildsDialog", nullptr,
|
if(!ImGui::BeginPopupModal("Include builds ?##IncludeBuildsDialog", nullptr,
|
||||||
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
||||||
{
|
{
|
||||||
return ImGui::GetID("Include builds ?##IncludeBuildsDialog");
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TextUnformatted("Should builds be added to the backup ?");
|
ImGui::TextUnformatted("Should builds be added to the backup ?");
|
||||||
|
@ -368,16 +372,14 @@ Application::drawBackupProfilePopup(std::size_t profile_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiID
|
void
|
||||||
Application::drawDeleteProfilePopup(std::size_t profile_index) {
|
Application::drawDeleteProfilePopup(std::size_t profile_index) {
|
||||||
if(!ImGui::BeginPopupModal("Confirmation##DeleteProfileConfirmation", nullptr,
|
if(!ImGui::BeginPopupModal("Confirmation##DeleteProfileConfirmation", nullptr,
|
||||||
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
|
||||||
{
|
{
|
||||||
return ImGui::GetID("Confirmation##DeleteProfileConfirmation");
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delete_builds = false;
|
static bool delete_builds = false;
|
||||||
|
@ -415,8 +417,6 @@ Application::drawDeleteProfilePopup(std::size_t profile_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue