Allow custom date formats
This commit is contained in:
parent
c4809f29b2
commit
aa4d74f603
@ -461,11 +461,12 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="buttonNew">
|
||||
<property name="label" translatable="yes">New Entry</property>
|
||||
<property name="visible">True</property>
|
||||
<object class="GtkButton" id="buttonDecrypt">
|
||||
<property name="label" translatable="yes">Decrypt GPG</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">imageDecrypt</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -474,12 +475,11 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="buttonDecrypt">
|
||||
<property name="label" translatable="yes">Decrypt GPG</property>
|
||||
<object class="GtkButton" id="buttonNew">
|
||||
<property name="label" translatable="yes">New Entry</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">imageDecrypt</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -559,11 +559,57 @@
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkStack" id="stackNewDateFormat">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="comboNewDateFormat">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">page0</property>
|
||||
<property name="title" translatable="yes">page0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="entryNewDateFormat">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">page1</property>
|
||||
<property name="title" translatable="yes">page1</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="buttonCustomNewFileDateFormat">
|
||||
<property name="label" translatable="yes">...</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Use custom format</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
|
@ -505,19 +505,50 @@ static void mainWindow_settings_comboNewDateFormat_changed(GtkComboBox *widget,
|
||||
mainWindow_set_new_file_date_format(mainWindow, gtk_combo_box_get_active_id(GTK_COMBO_BOX(mainWindow->settingsDialog.comboNewDateFormat)));
|
||||
}
|
||||
|
||||
|
||||
static void mainWindow_settings_buttonCustomNewFileDateFormat_clicked(GtkComboBox *widget, gpointer user_data)
|
||||
{
|
||||
struct mainWindow *mainWindow = (struct mainWindow *)user_data;
|
||||
|
||||
if (gtk_stack_get_visible_child(GTK_STACK(mainWindow->settingsDialog.stackNewDateFormat)) == mainWindow->settingsDialog.entryNewDateFormat) {
|
||||
mainWindow_set_new_file_date_format(mainWindow, gtk_entry_get_text(mainWindow->settingsDialog.entryNewDateFormat));
|
||||
gtk_stack_set_visible_child(GTK_STACK(mainWindow->settingsDialog.stackNewDateFormat),
|
||||
mainWindow->settingsDialog.comboNewDateFormat);
|
||||
gtk_button_set_label(GTK_BUTTON(mainWindow->settingsDialog.buttonCustomNewFileDateFormat), "...");
|
||||
} else {
|
||||
gtk_stack_set_visible_child(GTK_STACK(mainWindow->settingsDialog.stackNewDateFormat),
|
||||
mainWindow->settingsDialog.entryNewDateFormat);
|
||||
gtk_button_set_label(GTK_BUTTON(mainWindow->settingsDialog.buttonCustomNewFileDateFormat), "OK");
|
||||
}
|
||||
}
|
||||
|
||||
const gchar *newDateFormats[] = {"%d.%m.%Y %H:%M",
|
||||
"%Y-%m-%d %H:%M",
|
||||
NULL};
|
||||
|
||||
void mainWindow_set_new_file_date_format(struct mainWindow *mainWindow, gchar *fmt)
|
||||
{
|
||||
GDateTime *datetime;
|
||||
gchar *text;
|
||||
|
||||
if (!fmt) {
|
||||
fmt = newDateFormats[0];
|
||||
}
|
||||
g_free(mainWindow->newFileDateFormat);
|
||||
mainWindow->newFileDateFormat = g_strdup(fmt);
|
||||
|
||||
gtk_entry_set_text(mainWindow->settingsDialog.entryNewDateFormat, fmt);
|
||||
|
||||
/* Custom format -> Add to list for this session */
|
||||
if (!gtk_combo_box_set_active_id(mainWindow->settingsDialog.comboNewDateFormat, fmt)) {
|
||||
datetime = g_date_time_new_now_local();
|
||||
text = g_date_time_format(datetime, fmt);
|
||||
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mainWindow->settingsDialog.comboNewDateFormat),
|
||||
fmt, text);
|
||||
g_free(text);
|
||||
g_date_time_unref(datetime);
|
||||
gtk_combo_box_set_active_id(mainWindow->settingsDialog.comboNewDateFormat, fmt);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean mainWindow_settings_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
|
||||
@ -564,6 +595,11 @@ static void mainWindow_configure_settings_dialog(struct mainWindow *mainWindow)
|
||||
(GCallback) mainWindow_settings_comboNewDateFormat_changed,
|
||||
mainWindow);
|
||||
|
||||
g_signal_connect(mainWindow->settingsDialog.buttonCustomNewFileDateFormat,
|
||||
"clicked",
|
||||
(GCallback) mainWindow_settings_buttonCustomNewFileDateFormat_clicked,
|
||||
mainWindow);
|
||||
|
||||
g_signal_connect(mainWindow->settingsDialog.settingsDialog,
|
||||
"delete-event",
|
||||
(GCallback) mainWindow_settings_delete_event,
|
||||
@ -619,6 +655,9 @@ struct mainWindow *mainWindow_new()
|
||||
mainWindow->settingsDialog.settingsDialog = GTK_WIDGET(gtk_builder_get_object(builder, "settingsDialog"));
|
||||
mainWindow->settingsDialog.comboDisplayMode = GTK_WIDGET(gtk_builder_get_object(builder, "comboDisplayMode"));
|
||||
mainWindow->settingsDialog.comboNewDateFormat = GTK_WIDGET(gtk_builder_get_object(builder, "comboNewDateFormat"));
|
||||
mainWindow->settingsDialog.stackNewDateFormat = GTK_WIDGET(gtk_builder_get_object(builder, "stackNewDateFormat"));
|
||||
mainWindow->settingsDialog.entryNewDateFormat = GTK_WIDGET(gtk_builder_get_object(builder, "entryNewDateFormat"));
|
||||
mainWindow->settingsDialog.buttonCustomNewFileDateFormat = GTK_WIDGET(gtk_builder_get_object(builder, "buttonCustomNewFileDateFormat"));
|
||||
|
||||
mainWindow->filterSettings.time_start = 0;
|
||||
mainWindow->filterSettings.time_end = -1;
|
||||
|
@ -86,7 +86,10 @@ struct mainWindow {
|
||||
struct settingsDialog {
|
||||
GtkWidget *settingsDialog;
|
||||
GtkWidget *comboDisplayMode;
|
||||
GtkWidget *stackNewDateFormat;
|
||||
GtkWidget *comboNewDateFormat;
|
||||
GtkWidget *buttonCustomNewFileDateFormat;
|
||||
GtkWidget *entryNewDateFormat;
|
||||
} settingsDialog;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user