Calendar now selects the appropriate date before displayed

This commit is contained in:
Markus Koch 2017-02-03 19:14:42 +01:00
parent a02a4b1614
commit 1fa1a10a10
2 changed files with 32 additions and 7 deletions

View File

@ -52,8 +52,8 @@
<object class="GtkEntry" id="dateStart"> <object class="GtkEntry" id="dateStart">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="max_length">10</property>
<property name="width_chars">10</property> <property name="width_chars">10</property>
<property name="text" translatable="yes">0000-00-00</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
@ -77,8 +77,8 @@
<object class="GtkEntry" id="dateEnd"> <object class="GtkEntry" id="dateEnd">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="max_length">10</property>
<property name="width_chars">10</property> <property name="width_chars">10</property>
<property name="text" translatable="yes">0000-00-00</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>

View File

@ -347,6 +347,12 @@ struct mainWindow *mainWindow_new()
mainWindow_configure_treeView(mainWindow); mainWindow_configure_treeView(mainWindow);
mainWindow_connect_signals(mainWindow); mainWindow_connect_signals(mainWindow);
/**
* These need to be set to oldest and newest after indexing date
*/
gtk_entry_set_text(mainWindow->dateStart, "2016-01-01");
gtk_entry_set_text(mainWindow->dateEnd, "2017-01-01");
return mainWindow; return mainWindow;
} }
@ -356,10 +362,27 @@ void mainWindow_chooseWorkspaceClicked(GtkWidget *widget, gint event, gpointer u
fflush(stdout); fflush(stdout);
} }
void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data) void mainWindow_showPopover(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{ {
struct mainWindow *mainWindow = (struct mainWindow *)user_data; struct mainWindow *mainWindow = (struct mainWindow *)user_data;
GDateTime *datetime;
mainWindow->selectedDateEntry = NULL;
datetime = g_date_time_new_from_unix_local((widget == mainWindow->dateStart
? mainWindow->filterSettings.time_start
: mainWindow->filterSettings.time_end));
if (datetime) {
gtk_calendar_select_month(GTK_CALENDAR(mainWindow->calendarRange),
g_date_time_get_month(datetime) - 1,
g_date_time_get_year(datetime));
gtk_calendar_select_day(GTK_CALENDAR(mainWindow->calendarRange),
g_date_time_get_day_of_month(datetime));
g_date_time_unref(datetime);
}
/* gtk_editable_select_region(GTK_EDITABLE(widget), 0, 255); */
mainWindow->selectedDateEntry = widget; mainWindow->selectedDateEntry = widget;
if (!gtk_widget_get_visible(mainWindow->popoverDate)) if (!gtk_widget_get_visible(mainWindow->popoverDate))
@ -373,10 +396,12 @@ void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
guint year, month, day; guint year, month, day;
gchar *text; gchar *text;
gtk_calendar_get_date(GTK_CALENDAR(mainWindow->calendarRange), &year, &month, &day); if (mainWindow->selectedDateEntry) {
text = g_strdup_printf("%d-%02d-%02d", year, month, day); gtk_calendar_get_date(GTK_CALENDAR(mainWindow->calendarRange), &year, &month, &day);
gtk_entry_set_text(GTK_ENTRY(mainWindow->selectedDateEntry), text); text = g_strdup_printf("%d-%02d-%02d", year, month + 1, day);
g_free(text); gtk_entry_set_text(GTK_ENTRY(mainWindow->selectedDateEntry), text);
g_free(text);
}
} }
void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data) void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)