add popups

- close calendar
- close calendar and load a new one
- close application

#16
This commit is contained in:
2026-05-23 16:12:12 +02:00
parent 8b1ed44bc9
commit 943b45bcb7
3 changed files with 96 additions and 31 deletions
+85 -27
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;
@@ -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);
}
}
}