add popup when loading failed

add ImGuiWindowFlags_NoSavedSettings flag for all popups

#18
This commit is contained in:
2026-07-05 14:12:37 +02:00
parent bd0409d15b
commit 5dadadc94d
3 changed files with 88 additions and 61 deletions
+52 -48
View File
@@ -1,6 +1,56 @@
#include "localization.h"
const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] = {
[L_ENGLISH] = { //Default language
[LS_LANGUAGE_NAME] = "English",
[LS_JANUARY] = "January",
[LS_FEBRUARY] = "February",
[LS_MARCH] = "March",
[LS_APRIL] = "April",
[LS_MAY] = "May",
[LS_JUNE] = "June",
[LS_JULY] = "July",
[LS_AUGUST] = "August",
[LS_SEPTEMBER] = "September",
[LS_OCTOBER] = "October",
[LS_NOVEMBER] = "November",
[LS_DECEMBER] = "December",
[LS_FILE] = "File",
[LS_OPEN] = "Open",
[LS_SAVE] = "Save",
[LS_SAVE_AS] = "Save as",
[LS_CLOSE_CALENDAR] = "Close Calendar###CloseCalendar",
[LS_CLOSE_AND_LOAD_CALENDAR] = "Close and Load Calendar###CloseLoadCalendar",
[LS_EXIT] = "Exit",
[LS_VIEW] = "View",
[LS_LEGEND] = "Legend",
[LS_LANGUAGE] = "Language",
[LS_HELP] = "Help",
[LS_DEMO] = "Demo",
[LS_WIKI] = "Wiki",
[LS_ABOUT] = "About###About",
[LS_CALENDAR_WEEK_SHORT] = "No.",
[LS_MONDAY_SHORT] = "Mo",
[LS_TUESDAY_SHORT] = "Tu",
[LS_WEDNESDAY_SHORT] = "We",
[LS_THURSDAY_SHORT] = "Th",
[LS_FRIDAY_SHORT] = "Fr",
[LS_SATURDAY_SHORT] = "Sa",
[LS_SUNDAY_SHORT] = "Su",
[LS_TITLE_ENTER_PASSWORD] = "Enter Password###Save",
[LS_PASSWORD] = "Password",
[LS_CONFIRM_PASSWORD] = "Confirm Password",
[LS_OK] = "Ok",
[LS_CANCEL] = "Cancel",
[LS_TITLE_OPEN_PASSWORD] = "Enter Password###Open",
[LS_TITLE_LOAD_ERROR] = "Error###LoadError",
[LS_LOAD_ERROR] = "Failed to load the calendar file: '%s'",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT] = "There are unsaved changes.\nDo you really want to quit?",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR] = "There are unsaved changes.\nDo you really want to close the calendar?",
[LS_YES] = "Yes",
[LS_NO] = "No",
[LS_CLOSE] = "Close",
},
[L_GERMAN] = {
[LS_LANGUAGE_NAME] = "Deutsch",
[LS_JANUARY] = "Januar",
@@ -43,60 +93,14 @@ const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] =
[LS_OK] = "Ok",
[LS_CANCEL] = "Abbrechen",
[LS_TITLE_OPEN_PASSWORD] = "Passwort eingeben###Open",
[LS_TITLE_LOAD_ERROR] = "Fehler###LoadError",
[LS_LOAD_ERROR] = "Datei konnte nicht geladen werden: '%s'",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT] = "Es gibt noch offene Änderungen.\nMöchten Sie wirklich beenden?",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR] = "Es gibt noch offene Änderungen.\nMöchten Sie wirklich den Kalender schließen?",
[LS_YES] = "Ja",
[LS_NO] = "Nein",
[LS_CLOSE] = "Schließen",
},
[L_ENGLISH] = {
[LS_LANGUAGE_NAME] = "English",
[LS_JANUARY] = "January",
[LS_FEBRUARY] = "February",
[LS_MARCH] = "March",
[LS_APRIL] = "April",
[LS_MAY] = "May",
[LS_JUNE] = "June",
[LS_JULY] = "July",
[LS_AUGUST] = "August",
[LS_SEPTEMBER] = "September",
[LS_OCTOBER] = "October",
[LS_NOVEMBER] = "November",
[LS_DECEMBER] = "December",
[LS_FILE] = "File",
[LS_OPEN] = "Open",
[LS_SAVE] = "Save",
[LS_SAVE_AS] = "Save as",
[LS_CLOSE_CALENDAR] = "Close Calendar###CloseCalendar",
[LS_CLOSE_AND_LOAD_CALENDAR] = "Close and Load Calendar###CloseLoadCalendar",
[LS_EXIT] = "Exit",
[LS_VIEW] = "View",
[LS_LEGEND] = "Legend",
[LS_LANGUAGE] = "Language",
[LS_HELP] = "Help",
[LS_DEMO] = "Demo",
[LS_WIKI] = "Wiki",
[LS_ABOUT] = "About###About",
[LS_CALENDAR_WEEK_SHORT] = "No.",
[LS_MONDAY_SHORT] = "Mo",
[LS_TUESDAY_SHORT] = "Tu",
[LS_WEDNESDAY_SHORT] = "We",
[LS_THURSDAY_SHORT] = "Th",
[LS_FRIDAY_SHORT] = "Fr",
[LS_SATURDAY_SHORT] = "Sa",
[LS_SUNDAY_SHORT] = "Su",
[LS_TITLE_ENTER_PASSWORD] = "Enter Password###Save",
[LS_PASSWORD] = "Password",
[LS_CONFIRM_PASSWORD] = "Confirm Password",
[LS_OK] = "Ok",
[LS_CANCEL] = "Cancel",
[LS_TITLE_OPEN_PASSWORD] = "Enter Password###Open",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT] = "There are unsaved changes.\nDo you really want to quit?",
[LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR] = "There are unsaved changes.\nDo you really want to close the calendar?",
[LS_YES] = "Yes",
[LS_NO] = "No",
[LS_CLOSE] = "Close",
},
[L_FRENCH] = {
[LS_LANGUAGE_NAME] = "Français",
[LS_JANUARY] = "Janvier",
+2
View File
@@ -42,6 +42,8 @@ enum Localized_String {
LS_OK,
LS_CANCEL,
LS_TITLE_OPEN_PASSWORD,
LS_TITLE_LOAD_ERROR,
LS_LOAD_ERROR,
//Questions
LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT,
LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR,
+34 -13
View File
@@ -103,6 +103,7 @@ static ImGuiID close_and_load_calendar_popup;
static ImGuiID save_password_popup;
static ImGuiID open_password_popup;
static ImGuiID about_popup;
static ImGuiID load_error_popup;
void init() {
hydro_init();
@@ -234,12 +235,14 @@ void load(){
size_t num_bytes = fread(encrypted_buffer, 1, sizeof(encrypted_buffer), save_file);
fclose (save_file);
if ( num_bytes <= 0) {
return; //TODO Popup warning
if (num_bytes <= 0) {
ImGui::OpenPopup(load_error_popup);
return;
}
if (hydro_secretbox_decrypt(plaintext_buffer, (uint8_t *)encrypted_buffer, num_bytes, 0, HYDROGEN_CONTEXT, derived_key) != 0){
return; //TODO Popup warning
ImGui::OpenPopup(load_error_popup);
return;
}
hydro_memzero(encrypted_buffer, sizeof(encrypted_buffer));
@@ -249,14 +252,18 @@ void load(){
uint32_t version = 0;
read_from_buffer(version);
if (version != 1) {
return; //TODO Popup warning
ImGui::OpenPopup(load_error_popup);
return;
}
read_from_buffer(num_categories);
read_from_buffer(num_categorized_days);
if (num_categories > IM_ARRAYSIZE(categories) || num_categorized_days > IM_ARRAYSIZE(categorized_days)){
return; //TODO Popup warning
ImGui::OpenPopup(load_error_popup);
num_categories = 0;
num_categorized_days = 0;
return;
}
for (int i = 0; i < num_categories; i++) {
@@ -317,8 +324,6 @@ void interaction_close_calendar() {
}
}
void per_frame(){
current_language = selected_language;
@@ -328,6 +333,7 @@ void per_frame(){
save_password_popup = ImGui::GetID("###Save");
open_password_popup = ImGui::GetID("###Open");
about_popup = ImGui::GetID("###About");
load_error_popup = ImGui::GetID("###LoadError");
if (ImGui::IsKeyDown(ImGuiMod_Ctrl) && ImGui::IsKeyPressed(ImGuiKey_S, false)) {
if (ImGui::IsKeyDown(ImGuiMod_Shift)) {
@@ -436,7 +442,7 @@ void per_frame(){
// save calendar file with password modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_ENTER_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_ENTER_PASSWORD), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
ImGui::AlignTextToFramePadding();
@@ -477,7 +483,7 @@ void per_frame(){
// open calendar file with password modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_OPEN_PASSWORD), NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_OPEN_PASSWORD), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
ImGui::AlignTextToFramePadding();
@@ -493,8 +499,8 @@ void per_frame(){
master_key, HYDROGEN_OPSLIMIT, HYDROGEN_MEMLIMIT, HYDROGEN_THREADS);
hydro_memzero(password_input_buffer, sizeof(password_input_buffer));
load();
ImGui::CloseCurrentPopup();
load();
}
ImGui::SameLine();
@@ -509,7 +515,7 @@ void per_frame(){
// close and load calendar modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE_AND_LOAD_CALENDAR), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE_AND_LOAD_CALENDAR), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR));
ImGui::SetItemDefaultFocus();
@@ -535,7 +541,7 @@ void per_frame(){
// close calendar modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE_CALENDAR), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal(get_localized_string(LS_CLOSE_CALENDAR), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR));
ImGui::SetItemDefaultFocus();
@@ -554,7 +560,7 @@ void per_frame(){
// close application modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal(get_localized_string(LS_EXIT), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal(get_localized_string(LS_EXIT), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT));
ImGui::SetItemDefaultFocus();
@@ -580,6 +586,21 @@ void per_frame(){
ImGui::EndPopup();
}
// load error modal dialogue
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(640.0f, 0), ImGuiCond_Appearing);
if (ImGui::BeginPopupModal(get_localized_string(LS_TITLE_LOAD_ERROR), NULL, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped(get_localized_string(LS_LOAD_ERROR), save_file_path);
if (ImGui::Button(get_localized_string(LS_OK), ImVec2(120, 0))) {
free(save_file_path);
save_file_path = (char *)calloc(1, 1);
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
if (ImGui::Begin("Work Calendar", 0)) {
ImGui::PushStyleColor(ImGuiCol_TableHeaderBg, {0,0,0,0});
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, {0,0,0,0});