Compare commits

..

No commits in common. "e9fad7600be0437b28533881e632f0b6632022ef" and "0b46403ededb6a9a59572aef99e5a2d4a32e9f05" have entirely different histories.

4 changed files with 117 additions and 117 deletions

View file

@ -402,7 +402,8 @@ Application::drawHelpMarker(Containers::StringView text, float wrap_pos) {
void
Application::drawTooltip(Containers::StringView text, float wrap_pos) {
if(ImGui::IsItemHovered() && ImGui::BeginTooltip()) {
if(ImGui::IsItemHovered()){
ImGui::BeginTooltip();
if(wrap_pos > 0.0f) {
ImGui::PushTextWrapPos(wrap_pos);
}

View file

@ -113,11 +113,9 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe
void drawInitialisation();
void drawProfileManager();
void drawBackupListPopup();
void drawBackupRestorePopup(std::size_t backup_index);
void drawBackupDeletePopup(std::size_t backup_index);
void drawBackupProfilePopup(std::size_t profile_index);
void drawDeleteProfilePopup(std::size_t profile_index);
auto drawBackupListPopup() -> ImGuiID;
auto drawBackupProfilePopup(std::size_t profile_index) -> ImGuiID;
auto drawDeleteProfilePopup(std::size_t profile_index) -> ImGuiID;
void drawManager();
bool drawIntEditPopup(int* value_to_edit, int max);

View file

@ -40,6 +40,10 @@ Application::drawProfileManager() {
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)) {
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
@ -59,9 +63,8 @@ Application::drawProfileManager() {
ImGui::SameLine();
if(ImGui::SmallButton("Backups")) {
_profileManager->refreshBackups();
ImGui::OpenPopup("Backups##BackupsModal");
ImGui::OpenPopup(backup_list_popup_id);
}
drawBackupListPopup();
ImGui::EndTable();
}
@ -101,17 +104,15 @@ Application::drawProfileManager() {
ImGui::TableSetColumnIndex(2);
if(ImGui::SmallButton(ICON_FA_FILE_ARCHIVE)) {
profile_index = i;
ImGui::OpenPopup("Include builds ?##IncludeBuildsDialog");
ImGui::OpenPopup(backup_popup_id);
}
drawTooltip("Backup");
drawBackupProfilePopup(profile_index);
ImGui::SameLine(0.0f, 2.0f);
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_TRASH_ALT)) {
profile_index = i;
ImGui::OpenPopup("Confirmation##DeleteProfileConfirmation");
ImGui::OpenPopup(delete_popup_id);
}
drawTooltip("Delete");
drawDeleteProfilePopup(profile_index);
ImGui::PopID();
}
ImGui::EndTable();
@ -120,20 +121,108 @@ Application::drawProfileManager() {
ImGui::TextUnformatted("Click a profile to manage it.");
}
drawBackupListPopup();
drawBackupProfilePopup(profile_index);
drawDeleteProfilePopup(profile_index);
ImGui::End();
}
void
ImGuiID
Application::drawBackupListPopup() {
ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot);
if(!ImGui::BeginPopupModal("Backups##BackupsModal", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return;
return ImGui::GetID("Backups##BackupsModal");
}
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)) {
ImGui::TableSetupColumn("##Label", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##Refresh", ImGuiTableColumnFlags_WidthFixed);
@ -178,7 +267,8 @@ Application::drawBackupListPopup() {
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(backup.company.cbegin(), backup.company.cend());
if(ImGui::IsItemHovered() && ImGui::BeginTooltip()) {
if(ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
for(const auto& file : backup.includedFiles) {
ImGui::TextUnformatted(file.cbegin());
}
@ -201,17 +291,15 @@ Application::drawBackupListPopup() {
ImGui::PushID(int(i));
if(ImGui::SmallButton(ICON_FA_UNDO)) {
backup_index = i;
ImGui::OpenPopup("Restore backup##RestoreBackupModal");
ImGui::OpenPopup(restore_backup_popup_id);
}
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");
ImGui::OpenPopup(delete_backup_popup_id);
}
drawTooltip("Delete");
drawBackupDeletePopup(backup_index);
ImGui::PopID();
}
ImGui::EndTable();
@ -236,107 +324,16 @@ Application::drawBackupListPopup() {
}
ImGui::EndPopup();
return 0;
}
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
ImGuiID
Application::drawBackupProfilePopup(std::size_t profile_index) {
if(!ImGui::BeginPopupModal("Include builds ?##IncludeBuildsDialog", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return;
return ImGui::GetID("Include builds ?##IncludeBuildsDialog");
}
ImGui::TextUnformatted("Should builds be added to the backup ?");
@ -372,14 +369,16 @@ Application::drawBackupProfilePopup(std::size_t profile_index) {
}
ImGui::EndPopup();
return 0;
}
void
ImGuiID
Application::drawDeleteProfilePopup(std::size_t profile_index) {
if(!ImGui::BeginPopupModal("Confirmation##DeleteProfileConfirmation", nullptr,
ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove))
{
return;
return ImGui::GetID("Confirmation##DeleteProfileConfirmation");
}
static bool delete_builds = false;
@ -417,6 +416,8 @@ Application::drawDeleteProfilePopup(std::size_t profile_index) {
}
ImGui::EndPopup();
return 0;
}
}

View file

@ -73,7 +73,7 @@ Application::drawMainMenu() {
openUri(Utility::Path::toNativeSeparators(conf().directories().armours));
}
if(ImGui::MenuItem(ICON_FA_HAMMER " Weapons", nullptr, false,
if(ImGui::MenuItem(ICON_FA_ROCKET " Weapons", nullptr, false,
Utility::Path::exists(conf().directories().weapons)))
{
openUri(Utility::Path::toNativeSeparators(conf().directories().weapons));