From 6555b8d8e2437cfe947f7005cfedc864e0d2ffbb Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sat, 2 Sep 2017 10:48:14 +0200 Subject: [PATCH] Allow to click on heading to ellipsize it --- glade/mainWindow.glade | 19 ++++++++++++------- src/mainwindow.c | 28 ++++++++++++++++++++++++++++ src/mainwindow.h | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/glade/mainWindow.glade b/glade/mainWindow.glade index 6fb9e29..925a569 100644 --- a/glade/mainWindow.glade +++ b/glade/mainWindow.glade @@ -318,15 +318,20 @@ 2 2 - + True False - Please select an entry in the list above. - True - word-char - - - + + + True + False + Please select an entry in the list above. + True + + + + + False diff --git a/src/mainwindow.c b/src/mainwindow.c index b30eb68..13a0193 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -412,6 +412,11 @@ static void mainWindow_connect_signals(struct mainWindow *mainWindow) "clicked", (GCallback) mainWindow_decrypt_gpg_clicked, mainWindow); + + g_signal_connect(mainWindow->summaryEventBox, + "button-press-event", + (GCallback) mainWindow_toggleSummaryWrap, + mainWindow); } /** @@ -541,6 +546,7 @@ struct mainWindow *mainWindow_new() mainWindow->checkSearchSummary = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchSummary")); mainWindow->checkSearchTags = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchTags")); mainWindow->checkSearchText = GTK_WIDGET(gtk_builder_get_object(builder, "checkSearchText")); + mainWindow->summaryEventBox = GTK_WIDGET(gtk_builder_get_object(builder, "summaryEventBox")); mainWindow->labelSummary = GTK_WIDGET(gtk_builder_get_object(builder, "labelSummary")); mainWindow->buttonClearSearch = GTK_WIDGET(gtk_builder_get_object(builder, "buttonClearSearch")); mainWindow->headerBar = GTK_WIDGET(gtk_builder_get_object(builder, "headerBar")); @@ -1038,3 +1044,25 @@ void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data) g_print("ERROR: This should never happen...\n"); } } + +/** + * @brief mainWindow_toggleSummaryWrap toggles line-wrapping and ellipsize on the summary + * @param widget + * @param event + * @param user_data + * @return + */ +gboolean mainWindow_toggleSummaryWrap(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + struct mainWindow *mainWindow = (struct mainWindow *)user_data; + gboolean state; + + state = gtk_label_get_line_wrap(GTK_LABEL(mainWindow->labelSummary)); + + gtk_label_set_ellipsize(GTK_LABEL(mainWindow->labelSummary), + !state ? PANGO_ELLIPSIZE_NONE : PANGO_ELLIPSIZE_END); + + gtk_label_set_line_wrap(GTK_LABEL(mainWindow->labelSummary), !state); + + return FALSE; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index fbffc37..7337531 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -37,6 +37,7 @@ struct mainWindow { GtkWidget *checkSearchSummary; GtkWidget *checkSearchTags; GtkWidget *checkSearchText; + GtkWidget *summaryEventBox; GtkWidget *labelSummary; GtkWidget *buttonClearSearch; GtkWidget *headerBar; @@ -108,5 +109,6 @@ void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gbo void mainWindow_decrypt_gpg_clicked(GtkWidget *widget, gpointer user_data); void mainWindow_renderer_set(struct mainWindow *mainWindow, enum renderer_mode state); void mainWindow_settings_show(struct mainWindow *mainWindow); +gboolean mainWindow_toggleSummaryWrap(GtkWidget *widget, GdkEvent *event, gpointer user_data); #endif /* MAINWINDOW_H */