Compare commits

...

2 Commits

Author SHA1 Message Date
Ammerhai 943b45bcb7 add popups
- close calendar
- close calendar and load a new one
- close application

#16
2026-05-23 16:12:12 +02:00
Ammerhai 8b1ed44bc9 fix save_file_path allocation when open calendar is canceled
remove LS_CLOSE

#9
2026-05-23 15:23:57 +02:00
3 changed files with 99 additions and 35 deletions
+9 -7
View File
@@ -19,8 +19,9 @@ 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_EXIT] = "Beenden",
[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",
[LS_LANGUAGE] = "Sprache",
@@ -42,8 +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_CLOSE] = "Schließen",
[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",
},
@@ -65,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",
@@ -88,8 +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_CLOSE] = "Close",
[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",
},
+3 -1
View File
@@ -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,8 +42,9 @@ enum Localized_String {
LS_OK,
LS_CANCEL,
LS_TITLE_OPEN_PASSWORD,
LS_CLOSE,
//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
+78 -18
View File
@@ -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;
@@ -300,13 +312,18 @@ void per_frame(){
}
ImGui::DockSpaceOverViewport(main_viewport_dock, ImGui::GetMainViewport(), ImGuiDockNodeFlags_NoTabBar);
ImGuiID close_popup = ImGui::GetID("Close");
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")) {
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);
@@ -314,6 +331,7 @@ void per_frame(){
ImGui::OpenPopup(open_password_popup);
}
}
}
if (ImGui::MenuItem(get_localized_string(LS_SAVE), "Ctrl + S", false, !!save_file_path)) {
save();
}
@@ -327,24 +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 = NULL;
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) {
ImGui::OpenPopup(close_popup);
} else {
should_exit = true;
}
}
ImGui::EndMenu();
}
@@ -439,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 = NULL;
close_calendar();
ImGui::CloseCurrentPopup();
hydro_memzero(password_input_buffer, sizeof(password_input_buffer));
}
@@ -448,9 +463,54 @@ 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_CLOSE), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize)) {
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));
ImGui::SetItemDefaultFocus();
@@ -525,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);
}
}
}