diff --git a/src/localization.c b/src/localization.c index 44bd002..2d31f2d 100644 --- a/src/localization.c +++ b/src/localization.c @@ -19,7 +19,8 @@ const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] = [LS_OPEN] = "Öffnen", [LS_SAVE] = "Speichern", [LS_SAVE_AS] = "Speichern unter", - [LS_CLOSE_CALENDAR] = "Kalender schließen", + [LS_CLOSE_CALENDAR] = "Kalender schließen###CloseCalendar", + [LS_CLOSE_AND_LOAD_CALENDAR] = "Kalender schließen und laden###CloseLoadCalendar", [LS_EXIT] = "Beenden###Close", [LS_VIEW] = "Ansicht", [LS_LEGEND] = "Legende", @@ -42,7 +43,8 @@ const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] = [LS_OK] = "Ok", [LS_CANCEL] = "Abbrechen", [LS_TITLE_OPEN_PASSWORD] = "Passwort eingeben###Open", - [LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT] = "Möchten Sie wirklich beenden?", + [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", }, @@ -64,7 +66,8 @@ const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] = [LS_OPEN] = "Open", [LS_SAVE] = "Save", [LS_SAVE_AS] = "Save as", - [LS_CLOSE_CALENDAR] = "Close Calendar", + [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", @@ -87,7 +90,8 @@ const char *localized_strings_storage[LANGUAGE_COUNT][LOCALIZED_STRING_COUNT] = [LS_OK] = "Ok", [LS_CANCEL] = "Cancel", [LS_TITLE_OPEN_PASSWORD] = "Enter Password###Open", - [LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT] = "Do you really want to quit?", + [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", }, diff --git a/src/localization.h b/src/localization.h index fa0c2be..96b4262 100644 --- a/src/localization.h +++ b/src/localization.h @@ -19,6 +19,7 @@ enum Localized_String { LS_SAVE, LS_SAVE_AS, LS_CLOSE_CALENDAR, + LS_CLOSE_AND_LOAD_CALENDAR, LS_EXIT, LS_VIEW, LS_LEGEND, @@ -41,7 +42,9 @@ enum Localized_String { LS_OK, LS_CANCEL, LS_TITLE_OPEN_PASSWORD, + //Questions LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT, + LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR, LS_YES, LS_NO, LOCALIZED_STRING_COUNT diff --git a/src/work-calendar.cpp b/src/work-calendar.cpp index bfc9bf7..afb31d0 100644 --- a/src/work-calendar.cpp +++ b/src/work-calendar.cpp @@ -265,6 +265,18 @@ void load(){ unsaved_changes = false; } +void close_calendar(){ + if (save_file_path) free(save_file_path); + save_file_path = (char *)calloc(1, 1); + num_categories = 0; + num_categorized_days = 0; + hydro_memzero(categories, sizeof(categories)); + hydro_memzero(categorized_days, sizeof(categorized_days)); + hydro_memzero(derived_key, sizeof(derived_key)); + set_window_title("Work Calendar"); + unsaved_changes = false; +} + void per_frame(){ current_language = selected_language; @@ -299,19 +311,25 @@ void per_frame(){ ImGui::DockBuilderFinish(main_viewport_dock); } ImGui::DockSpaceOverViewport(main_viewport_dock, ImGui::GetMainViewport(), ImGuiDockNodeFlags_NoTabBar); - - ImGuiID close_popup = ImGui::GetID("###Close"); - ImGuiID save_password_popup = ImGui::GetID("###Save"); - ImGuiID open_password_popup = ImGui::GetID("###Open"); + + ImGuiID close_popup = ImGui::GetID("###Close"); + ImGuiID close_calendar_popup = ImGui::GetID("###CloseCalendar"); + ImGuiID close_and_load_calendar_popup = ImGui::GetID("###CloseLoadCalendar"); + ImGuiID save_password_popup = ImGui::GetID("###Save"); + ImGuiID open_password_popup = ImGui::GetID("###Open"); if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu(get_localized_string(LS_FILE))) { if (ImGui::MenuItem(get_localized_string(LS_OPEN), "Ctrl + O")) { - char *new_save_file_path = open_file_dialog(); - if (new_save_file_path) { - if (save_file_path) free(save_file_path); - save_file_path = new_save_file_path; - ImGui::OpenPopup(open_password_popup); + if(unsaved_changes) { + ImGui::OpenPopup(close_and_load_calendar_popup); + } else { + char *new_save_file_path = open_file_dialog(); + if (new_save_file_path) { + if (save_file_path) free(save_file_path); + save_file_path = new_save_file_path; + ImGui::OpenPopup(open_password_popup); + } } } if (ImGui::MenuItem(get_localized_string(LS_SAVE), "Ctrl + S", false, !!save_file_path)) { @@ -327,26 +345,22 @@ void per_frame(){ } } - //TODO ImGui::Separator(); if (ImGui::MenuItem(get_localized_string(LS_CLOSE_CALENDAR), "Ctrl + X")) { - //TODO if calendar is opened warning - - if (save_file_path) free(save_file_path); - save_file_path = (char *)calloc(1, 1); - num_categories = 0; - num_categorized_days = 0; - hydro_memzero(categories, sizeof(categories)); - hydro_memzero(categorized_days, sizeof(categorized_days)); - hydro_memzero(derived_key, sizeof(derived_key)); - set_window_title("Work Calendar"); + if(unsaved_changes) { + ImGui::OpenPopup(close_calendar_popup); + } else { + close_calendar(); + } } ImGui::Separator(); if (ImGui::MenuItem(get_localized_string(LS_EXIT), NULL)) { - if(unsaved_changes) + if(unsaved_changes) { ImGui::OpenPopup(close_popup); - should_exit = true; + } else { + should_exit = true; + } } ImGui::EndMenu(); } @@ -441,8 +455,7 @@ void per_frame(){ ImGui::SameLine(); if (ImGui::Button(get_localized_string(LS_CANCEL), ImVec2(120, 0))) { - if (save_file_path) free(save_file_path); - save_file_path = (char *)calloc(1, 1); + close_calendar(); ImGui::CloseCurrentPopup(); hydro_memzero(password_input_buffer, sizeof(password_input_buffer)); } @@ -450,8 +463,53 @@ void per_frame(){ ImGui::EndPopup(); } + // 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)) { + ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR)); + + ImGui::SetItemDefaultFocus(); + if (ImGui::Button(get_localized_string(LS_YES), ImVec2(120, 0))) { + ImGui::CloseCurrentPopup(); + close_calendar(); + + char *new_save_file_path = open_file_dialog(); + if (new_save_file_path) { + if (save_file_path) free(save_file_path); + save_file_path = new_save_file_path; + ImGui::OpenPopup(open_password_popup); + } + } + + ImGui::SameLine(); + if (ImGui::Button(get_localized_string(LS_NO), ImVec2(120, 0))) { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + // 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)) { + ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_CLOSE_THE_CALENDAR)); + + ImGui::SetItemDefaultFocus(); + if (ImGui::Button(get_localized_string(LS_YES), ImVec2(120, 0))) { + close_calendar(); + ImGui::CloseCurrentPopup(); + } + + ImGui::SameLine(); + if (ImGui::Button(get_localized_string(LS_NO), ImVec2(120, 0))) { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + + // 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)) { ImGui::Text("%s", get_localized_string(LS_QUESTION_DO_YOU_REALLY_WANT_TO_QUIT)); @@ -527,11 +585,11 @@ void per_frame(){ ImGui::TableSetColumnIndex(0); //if first week has 3 or less days, last week from previous year - int calender_week = calendar_week_from_day(year, month, day); - if (calender_week == 0) { + int calendar_week = calendar_week_from_day(year, month, day); + if (calendar_week == 0) { ImGui::TextAligned(0.5, -FLT_MIN, "%d", 53); } else { - ImGui::TextAligned(0.5, -FLT_MIN, "%d", calender_week); + ImGui::TextAligned(0.5, -FLT_MIN, "%d", calendar_week); } } }