add Open, Save calendar functionality

add path information to window title

#9
This commit is contained in:
2026-03-21 13:08:09 +01:00
parent 01a1187b3c
commit 234e056965
2 changed files with 118 additions and 10 deletions
+36 -9
View File
@@ -22,6 +22,10 @@ static int current_day = 1;
static ImFont *inter_regular;
static ImFont *inter_bold;
char *open_file_dialog();
char *save_file_dialog();
void set_window_title(const char *title);
int get_current_year(){
time_t t = time(NULL);
struct tm tm = *localtime(&t);
@@ -69,7 +73,7 @@ void init(){
year = get_current_year();
}
static const char *savefile_path = "./calendar";
static char *save_file_path = NULL;
static const char *wiki_url = "https://gitea.ammerhai.com/Ammerhai/work-calendar/wiki";
static const char *month_names[] = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
@@ -106,8 +110,10 @@ ImVec4 table_sunday_bg = ImVec4(0.0f, 0.0f, 0.0f, 0.2f);
ImVec4 table_hover_color = ImVec4(0.0f, 0.3f, 0.6f, 0.2f);
void save(){
if(!save_file_path) return;
uint32_t version = 1;
FILE *save_file = fopen(savefile_path, "wb");
FILE *save_file = fopen(save_file_path, "wb");
fwrite(&version, sizeof(version), 1, save_file);
fwrite(&num_categories, sizeof(num_categories), 1, save_file);
fwrite(&num_categorized_days, sizeof(num_categorized_days), 1, save_file);
@@ -128,7 +134,7 @@ void save(){
}
void load(){
FILE *save_file = fopen(savefile_path, "rb");
FILE *save_file = fopen(save_file_path, "rb");
uint32_t version = 0;
fread(&version, sizeof(version), 1, save_file);
if(version != 1) {
@@ -184,16 +190,37 @@ void per_frame(){
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("Datei")) {
if (ImGui::MenuItem("Kalender öffnen", NULL)) {
//TODO popup + filepicker
load();
if (ImGui::MenuItem("Öffnen", "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;
load();
char *title = (char *)calloc(1, strlen("Work Calendar - ") + strlen(save_file_path) + 1);
memcpy(title, "Work Calendar - ", strlen("Work Calendar - "));
memcpy(title + strlen("Work Calendar - "), save_file_path, strlen(save_file_path));
set_window_title(title);
free(title);
}
}
if (ImGui::MenuItem("Kalender speichern", NULL)) {
if (ImGui::MenuItem("Speichern", "Ctrl + S", false, !!save_file_path)) {
save();
}
if (ImGui::MenuItem("Speichern unter", "Ctrl + Shift + S")) {
char *new_save_file_path = save_file_dialog();
if(new_save_file_path) {
if(save_file_path) free(save_file_path);
save_file_path = new_save_file_path;
save();
}
}
//TODO
ImGui::Separator();
ImGui::MenuItem("Abmelden", NULL);
ImGui::MenuItem("Kalender Schließen", "Ctrl + X");
ImGui::Separator();
if (ImGui::MenuItem("Beenden", NULL)) {
@@ -213,7 +240,7 @@ void per_frame(){
ImGui::GetPlatformIO().Platform_OpenInShellFn(ImGui::GetCurrentContext(), wiki_url);
}
ImGui::Separator();
ImGui::MenuItem("Über", NULL);
ImGui::MenuItem("Über", NULL); //TODO
ImGui::EndMenu();
}