[balsa] Unify wrapped label creation
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Unify wrapped label creation
- Date: Mon, 27 Jan 2020 21:13:53 +0000 (UTC)
commit 7b042b0b82477c65668f4135c1e47e68d74210a4
Author: Albrecht Dreß <albrecht dress arcor de>
Date: Mon Jan 27 16:06:14 2020 -0500
Unify wrapped label creation
* libbalsa/misc.[ch]: add new helper libbalsa_create_wrap_label()
for creating a label with word wrap and with or without markup;
libbalsa_create_grid_label(): add missing xalign
* libbalsa/html.c, libbalsa/libbalsa-gpgme-cb.c,
libbalsa/libbalsa-gpgme-widgets.c,
src/balsa-mime-widget-message.c, src/balsa-mime-widget-text.c,
src/balsa-mime-widget-vcalendar.c, src/folder-conf.c,
src/sendmsg-window.c: use libbalsa_create_wrap_label()
* src/pref-manager.c: use libbalsa_create_wrap_label(); remove
redundant calls to set default value
* src/print-gtk.c: add_font_button(), add_margin_spinbtn(): add
missing xalign, remove default justify; add_margin_spinbtn():
do not wrap the (short) units string; create_options_group():
use libbalsa_create_wrap_label()
ChangeLog | 19 +++++++++++++++++++
libbalsa/html.c | 3 +--
libbalsa/libbalsa-gpgme-cb.c | 4 +---
libbalsa/libbalsa-gpgme-widgets.c | 16 +++-------------
libbalsa/misc.c | 28 ++++++++++++++++++++++++++++
libbalsa/misc.h | 2 ++
src/balsa-mime-widget-message.c | 11 ++---------
src/balsa-mime-widget-text.c | 8 +++-----
src/balsa-mime-widget-vcalendar.c | 4 +---
src/folder-conf.c | 4 +---
src/pref-manager.c | 12 ++----------
src/print-gtk.c | 11 +++--------
src/sendmsg-window.c | 22 ++++++++--------------
13 files changed, 74 insertions(+), 70 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a314b3242..0ad5441a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2020-01-27 Albrecht Dreß <albrecht dress arcor de>
+
+ Unify wrapped label creation
+
+ * libbalsa/misc.[ch]: add new helper libbalsa_create_wrap_label()
+ for creating a label with word wrap and with or without markup;
+ libbalsa_create_grid_label(): add missing xalign
+ * libbalsa/html.c, libbalsa/libbalsa-gpgme-cb.c,
+ libbalsa/libbalsa-gpgme-widgets.c,
+ src/balsa-mime-widget-message.c, src/balsa-mime-widget-text.c,
+ src/balsa-mime-widget-vcalendar.c, src/folder-conf.c,
+ src/sendmsg-window.c: use libbalsa_create_wrap_label()
+ * src/pref-manager.c: use libbalsa_create_wrap_label(); remove
+ redundant calls to set default value
+ * src/print-gtk.c: add_font_button(), add_margin_spinbtn(): add
+ missing xalign, remove default justify; add_margin_spinbtn():
+ do not wrap the (short) units string; create_options_group():
+ use libbalsa_create_wrap_label()
+
2020-01-27 Peter Bloomfield <pbloomfield bellsouth net>
mailbox-local: Drop a redundant auxiliary structure
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 3f2f746b7..20e6b25ea 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -429,8 +429,7 @@ lbh_info_bar(LibBalsaWebKitInfo * info)
(gtk_info_bar_get_action_area
(info_bar)), GTK_ORIENTATION_VERTICAL);
- label = gtk_label_new(_(text));
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ label = libbalsa_create_wrap_label(text, FALSE);
content_area = gtk_info_bar_get_content_area(info_bar);
gtk_container_add(GTK_CONTAINER(content_area), label);
diff --git a/libbalsa/libbalsa-gpgme-cb.c b/libbalsa/libbalsa-gpgme-cb.c
index fed16b269..06bf763c2 100644
--- a/libbalsa/libbalsa-gpgme-cb.c
+++ b/libbalsa/libbalsa-gpgme-cb.c
@@ -229,9 +229,7 @@ lb_gpgme_select_key(const gchar * user_name, lb_key_sel_md_t mode, GList * keys,
default:
g_assert_not_reached();
}
- label = gtk_label_new(prompt);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
+ label = libbalsa_create_wrap_label(prompt, FALSE);
g_free(prompt);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
diff --git a/libbalsa/libbalsa-gpgme-widgets.c b/libbalsa/libbalsa-gpgme-widgets.c
index 0bdff701a..ac2736a65 100644
--- a/libbalsa/libbalsa-gpgme-widgets.c
+++ b/libbalsa/libbalsa-gpgme-widgets.c
@@ -423,14 +423,11 @@ libbalsa_key_dialog(GtkWindow *parent,
gtk_label_set_markup(GTK_LABEL(label), markup);
g_free(markup);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_label_set_line_wrap(GTK_LABEL(label), FALSE);
}
if (message2 != NULL) {
- label = gtk_label_new(message2);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
+ label = libbalsa_create_wrap_label(message2, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
}
scrolledw = gtk_scrolled_window_new(NULL, NULL);
@@ -605,22 +602,15 @@ create_key_label_with_warn(const gchar *text,
icon = gtk_image_new_from_icon_name("gtk-dialog-warning", GTK_ICON_SIZE_MENU);
gtk_box_pack_start(GTK_BOX(result), icon, FALSE, FALSE, 0U);
buf = g_markup_printf_escaped("<span fgcolor=\"red\">%s</span>", text);
- label = gtk_label_new(NULL);
- gtk_label_set_markup(GTK_LABEL(label), buf);
+ label = libbalsa_create_wrap_label(buf, TRUE);
g_free(buf);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_widget_set_hexpand(label, TRUE);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
- gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
gtk_box_pack_start(GTK_BOX(result), label, FALSE, TRUE, 0U);
} else {
- result = gtk_label_new(text);
- gtk_widget_set_halign(result, GTK_ALIGN_START);
+ result = libbalsa_create_wrap_label(text, FALSE);
gtk_widget_set_hexpand(result, TRUE);
gtk_label_set_selectable(GTK_LABEL(result), TRUE);
- gtk_label_set_line_wrap(GTK_LABEL(result), TRUE);
- gtk_label_set_xalign(GTK_LABEL(result), 0.0F);
}
return result;
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index e93324050..d46407536 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -904,12 +904,40 @@ libbalsa_create_grid_label(const gchar * text, GtkWidget * grid, gint row)
label = gtk_label_new_with_mnemonic(text);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_halign(label, GTK_ALIGN_START);
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
gtk_grid_attach(GTK_GRID(grid), label, 0, row, 1, 1);
return label;
}
+/** \brief Create a properly aligned label with line wrap
+ *
+ * \param text label text
+ * \param markup TRUE if the label text contains markup
+ * \return the new label widget
+ *
+ * Create a new label, enable word wrap, and set set xalign property.
+ */
+GtkWidget *
+libbalsa_create_wrap_label(const gchar *text,
+ gboolean markup)
+{
+ GtkWidget *label;
+
+ if (markup) {
+ label = gtk_label_new(NULL);
+ gtk_label_set_markup(GTK_LABEL(label), text);
+ } else {
+ label = gtk_label_new(text);
+ }
+
+ gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
+
+ return label;
+}
+
/* create_check:
creates a checkbox with a given label and places them in given array.
*/
diff --git a/libbalsa/misc.h b/libbalsa/misc.h
index b2639e6d1..145c11dbd 100644
--- a/libbalsa/misc.h
+++ b/libbalsa/misc.h
@@ -143,6 +143,8 @@ GtkWidget *libbalsa_create_grid_entry(GtkWidget * grid, GCallback func,
GtkWidget *libbalsa_create_grid_check(const gchar * label, GtkWidget * grid,
gint row, gboolean initval);
GtkSizeGroup *libbalsa_create_size_group(GtkWidget * chooser);
+GtkWidget *libbalsa_create_wrap_label(const gchar *text,
+ gboolean markup);
void libbalsa_assure_balsa_dir(void);
gchar *libbalsa_guess_ldap_base(void);
diff --git a/src/balsa-mime-widget-message.c b/src/balsa-mime-widget-message.c
index 9e39a588a..5743fe466 100644
--- a/src/balsa-mime-widget-message.c
+++ b/src/balsa-mime-widget-message.c
@@ -630,7 +630,7 @@ add_header_gchar(GtkGrid * grid, const gchar * header, const gchar * label,
libbalsa_utf8_sanitize(&sanitized,
balsa_app.convert_unknown_8bit, NULL);
g_strdelimit(sanitized, "\r\n", ' ');
- value_label = gtk_label_new(sanitized);
+ value_label = libbalsa_create_wrap_label(sanitized, FALSE);
g_free(sanitized);
gtk_widget_set_name(value_label, BALSA_MESSAGE_HEADER);
@@ -638,11 +638,8 @@ add_header_gchar(GtkGrid * grid, const gchar * header, const gchar * label,
GTK_STYLE_PROVIDER(css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- gtk_label_set_line_wrap(GTK_LABEL(value_label), TRUE);
gtk_label_set_line_wrap_mode(GTK_LABEL(value_label), PANGO_WRAP_WORD_CHAR);
gtk_label_set_selectable(GTK_LABEL(value_label), TRUE);
- gtk_label_set_xalign(GTK_LABEL(value_label), 0.0F);
- gtk_widget_set_halign(value_label, GTK_ALIGN_START);
gtk_widget_set_hexpand(value_label, TRUE);
expander = gtk_expander_new(NULL);
@@ -865,12 +862,8 @@ add_header_sigstate(GtkGrid * grid, GMimeGpgmeSigstat * siginfo)
msg = g_markup_printf_escaped(format, info_str);
g_free(info_str);
- label = gtk_label_new(NULL);
- gtk_label_set_markup(GTK_LABEL(label), msg);
+ label = libbalsa_create_wrap_label(msg, TRUE);
g_free(msg);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
gtk_widget_show(label);
gtk_grid_attach_next_to(grid, label, NULL, GTK_POS_BOTTOM, 2, 1);
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 262020dc4..70f97c810 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1200,13 +1200,11 @@ bm_widget_new_html(BalsaMessage * bm, LibBalsaMessageBody * mime_body)
#endif /* defined HAVE_HTML_WIDGET */
#define GRID_ATTACH(g,str,label) \
- if (str) { GtkWidget *lbl; \
+ if (str) { GtkWidget *lbl; \
lbl = gtk_label_new(label); \
- gtk_widget_set_halign(lbl, GTK_ALIGN_START); \
- gtk_grid_attach(g, lbl, 0, row, 1, 1); \
- lbl = gtk_label_new(str); \
- gtk_label_set_line_wrap(GTK_LABEL(lbl), TRUE); \
gtk_widget_set_halign(lbl, GTK_ALIGN_START); \
+ gtk_grid_attach(g, lbl, 0, row, 1, 1); \
+ lbl = libbalsa_create_wrap_label(str, FALSE); \
gtk_grid_attach(g, lbl, 1, row, 1, 1); \
row++; \
}
diff --git a/src/balsa-mime-widget-vcalendar.c b/src/balsa-mime-widget-vcalendar.c
index c9fbf0d62..d1410c25e 100644
--- a/src/balsa-mime-widget-vcalendar.c
+++ b/src/balsa-mime-widget-vcalendar.c
@@ -120,9 +120,7 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
gtk_widget_set_halign(lbl, GTK_ALIGN_START); \
gtk_widget_set_valign(lbl, GTK_ALIGN_START); \
gtk_grid_attach(g, lbl, 0, row, 1, 1); \
- lbl = gtk_label_new(str); \
- gtk_label_set_line_wrap(GTK_LABEL(lbl), TRUE); \
- gtk_widget_set_halign(lbl, GTK_ALIGN_START); \
+ lbl = libbalsa_create_wrap_label(str, FALSE); \
gtk_widget_set_valign(lbl, GTK_ALIGN_START); \
gtk_widget_set_hexpand(lbl, TRUE); \
gtk_widget_set_vexpand(lbl, TRUE); \
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 52118b7f1..1fb7c0fea 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -361,9 +361,7 @@ create_imap_folder_dialog(LibBalsaServer *server,
gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox);
gtk_widget_set_vexpand(vbox, TRUE);
- label = gtk_label_new(message);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
+ label = libbalsa_create_wrap_label(message, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0);
scrolled_wind = gtk_scrolled_window_new(NULL,NULL);
diff --git a/src/pref-manager.c b/src/pref-manager.c
index 2f90a542d..766c9817b 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -1260,15 +1260,10 @@ pm_group_label(const gchar * text)
GtkWidget *label;
gchar *markup;
- label = gtk_label_new(NULL);
-
markup = g_strdup_printf("<b>%s</b>", text);
- gtk_label_set_markup(GTK_LABEL(label), markup);
+ label = libbalsa_create_wrap_label(markup, TRUE);
g_free(markup);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
-
return label;
}
@@ -1298,11 +1293,8 @@ pm_grid_attach_label(GtkGrid * grid,
{
GtkWidget *label;
- label = gtk_label_new(text);
- gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ label = libbalsa_create_wrap_label(text, FALSE);
gtk_label_set_max_width_chars(GTK_LABEL(label), BALSA_MAX_WIDTH_CHARS);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
pm_grid_attach(grid, label, left, top, width, height);
diff --git a/src/print-gtk.c b/src/print-gtk.c
index 57e11dc41..374944813 100644
--- a/src/print-gtk.c
+++ b/src/print-gtk.c
@@ -476,9 +476,9 @@ add_font_button(const gchar * text, const gchar * font, GtkGrid * grid,
GtkWidget *font_button;
label = gtk_label_new_with_mnemonic(text);
- gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_halign(label, GTK_ALIGN_START);
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
gtk_grid_attach(grid, label, 1, row, 1, 1);
font_button = gtk_font_button_new_with_font(font);
@@ -499,9 +499,9 @@ add_margin_spinbtn(const gchar * text, gdouble min, gdouble max, gdouble dflt,
const gchar *unit;
label = gtk_label_new_with_mnemonic(text);
- gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_halign(label, GTK_ALIGN_START);
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0F);
gtk_grid_attach(grid, label, 1, row, 1, 1);
if (get_default_user_units() == GTK_UNIT_INCH) {
@@ -524,8 +524,6 @@ add_margin_spinbtn(const gchar * text, gdouble min, gdouble max, gdouble dflt,
gtk_grid_attach(grid, spinbtn, 2, row, 1, 1);
label = gtk_label_new(unit);
- gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_grid_attach(grid, label, 3, row, 1, 1);
@@ -554,12 +552,9 @@ create_options_group(const gchar *label_str, GtkWidget *parent_grid, gint parent
group = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
gtk_grid_attach(GTK_GRID(parent_grid), group, parent_col, parent_row, parent_width, 1);
- label = gtk_label_new(NULL);
markup = g_strdup_printf("<b>%s</b>", label_str);
- gtk_label_set_markup(GTK_LABEL(label), markup);
+ label = libbalsa_create_wrap_label(markup, TRUE);
g_free(markup);
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_box_pack_start(GTK_BOX(group), label, FALSE, FALSE, 0);
grid = gtk_grid_new();
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 096724f29..11f184fa0 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -3372,10 +3372,8 @@ quote_parts_select_dlg(GtkTreeStore *tree_store,
#endif
geometry_manager_attach(GTK_WINDOW(dialog), "SelectReplyParts");
- label = gtk_label_new(_("Select the parts of the message"
- " which shall be quoted in the reply"));
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
+ label = libbalsa_create_wrap_label(_("Select the parts of the message"
+ " which shall be quoted in the reply"), FALSE);
gtk_widget_set_valign(label, GTK_ALIGN_START);
image = gtk_image_new_from_icon_name("dialog-question",
@@ -3397,20 +3395,19 @@ quote_parts_select_dlg(GtkTreeStore *tree_store,
if (stats->decrypted != stats->parts) {
warning = gtk_label_new(NULL);
- gtk_label_set_markup(GTK_LABEL(warning),
+ warning = libbalsa_create_wrap_label(
_("<b>Warning:</b> The original message contains an abnormal "
"mixture of encrypted and unencrypted parts. This "
"<i>might</i> indicate an attack.\nDouble-check the contents "
- "of the reply before sending."));
+ "of the reply before sending."), TRUE);
gtk_tree_model_foreach(GTK_TREE_MODEL(tree_store), unselect_decrypted, NULL);
} else {
- warning = gtk_label_new(_("You reply to an encrypted message. The reply will contain "
+ warning = libbalsa_create_wrap_label(
+ _("You reply to an encrypted message. The reply will contain "
"the decrypted contents of the original message.\n"
"Consider to encrypt the reply, and verify that you do not "
- "unintentionally leak sensitive information."));
+ "unintentionally leak sensitive information."), FALSE);
}
- gtk_label_set_line_wrap(GTK_LABEL(warning), TRUE);
- gtk_widget_set_halign(warning, GTK_ALIGN_START);
gtk_widget_set_valign(warning, GTK_ALIGN_START);
gtk_box_pack_start(GTK_BOX(vbox), warning, FALSE, FALSE, 0);
}
@@ -5132,12 +5129,9 @@ subject_not_empty(BalsaSendmsg * bsmsg)
text_str = g_strdup_printf("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("You did not specify a subject for this message"),
_("If you would like to provide one, enter it below."));
- label = gtk_label_new (text_str);
+ label = libbalsa_create_wrap_label(text_str, TRUE);
g_free(text_str);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_widget_set_valign(label, GTK_ALIGN_START);
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]