Automatically fill current date and time when creating a new entry

This commit is contained in:
Markus Koch 2018-03-17 12:47:52 +01:00
parent 247ea6977f
commit 871669f904

View File

@ -1,13 +1,14 @@
#include "mainwindow.h"
#include "mdiary.h"
const gchar *default_template = "\
# Title\n\
Date: 01.01.2000 00:00\n\
Summary: \n\
Tags: \n\
\n\
Text";
const gchar *default_template[] = {"# Title\n"
"Date: ", "\0",
"\n"
"Summary: \n"
"Tags: \n"
"\n"
"Text",
NULL};
static gboolean mainWindow_workspace_entry_visible(GtkTreeModel *model,
GtkTreeIter *iter,
@ -1072,6 +1073,7 @@ void mainWindow_new_entry_clicked(GtkWidget *widget, gpointer user_data)
FILE *fd;
gchar *default_path;
GDateTime *datetime;
int i;
dialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow->mainWindow),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@ -1082,7 +1084,6 @@ void mainWindow_new_entry_clicked(GtkWidget *widget, gpointer user_data)
default_path = g_date_time_format(datetime, "%Y/%Y-%m-%d");
gtk_entry_set_text(GTK_ENTRY(textInput), default_path);
g_free(default_path);
g_date_time_unref(datetime);
gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), textInput, true, true, 4);
g_signal_connect(textInput,
"activate",
@ -1104,7 +1105,15 @@ void mainWindow_new_entry_clicked(GtkWidget *widget, gpointer user_data)
} else {
fd = fopen(path, "w");
if (fd) {
fwrite(default_template, sizeof(char), strlen(default_template), fd);
for (i = 0; default_template[i] != NULL; ++i) {
if (default_template[i][0] == '\0') {
default_path = g_date_time_format(datetime, "%d.%m.%Y %H:%M");
fwrite(default_path, sizeof(char), strlen(default_path), fd);
g_free(default_path);
} else {
fwrite(default_template[i], sizeof(char), strlen(default_template[i]), fd);
}
}
fclose(fd);
mainWindow_openExternalEditor(path);
} else {
@ -1114,6 +1123,8 @@ void mainWindow_new_entry_clicked(GtkWidget *widget, gpointer user_data)
}
}
g_date_time_unref(datetime);
gtk_widget_destroy(GTK_WIDGET(dialog));
// Get ws path
// Ask user for filename