[gedit] io-error-info-bar: use TeplInfoBar for no_backup_saving_error
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] io-error-info-bar: use TeplInfoBar for no_backup_saving_error
- Date: Tue, 24 Mar 2020 08:40:53 +0000 (UTC)
commit 8bfe0559a7dfd9979979ddfdec0557be321c0b6e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Mar 24 08:32:06 2020 +0100
io-error-info-bar: use TeplInfoBar for no_backup_saving_error
To simplify the code.
TeplInfoBar handles text wrapping well, no need to call
tepl_utils_str_middle_truncate() on the uri.
Change also the mnemonic for one of the button, because it conflicted
with the _Open button from the headerbar.
gedit/gedit-io-error-info-bar.c | 92 ++++++++++-------------------------------
1 file changed, 22 insertions(+), 70 deletions(-)
---
diff --git a/gedit/gedit-io-error-info-bar.c b/gedit/gedit-io-error-info-bar.c
index f03286f2c..0cd2d6f9e 100644
--- a/gedit/gedit-io-error-info-bar.c
+++ b/gedit/gedit-io-error-info-bar.c
@@ -743,57 +743,32 @@ GtkWidget *
gedit_no_backup_saving_error_info_bar_new (GFile *location,
const GError *error)
{
- GtkWidget *info_bar;
- GtkWidget *hbox_content;
- GtkWidget *vbox;
- gchar *primary_markup;
- gchar *secondary_markup;
- GtkWidget *primary_label;
- GtkWidget *secondary_label;
- gchar *primary_text;
- const gchar *secondary_text;
- gchar *full_formatted_uri;
- gchar *uri_for_display;
- gchar *temp_uri_for_display;
- gboolean create_backup_copy;
+ TeplInfoBar *info_bar;
GSettings *editor_settings;
+ gboolean create_backup_copy;
+ gchar *uri;
+ gchar *primary_msg;
+ const gchar *secondary_msg;
g_return_val_if_fail (G_IS_FILE (location), NULL);
- g_return_val_if_fail (error != NULL, NULL);
- g_return_val_if_fail (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_CANT_CREATE_BACKUP, NULL);
-
- full_formatted_uri = g_file_get_parse_name (location);
-
- /* Truncate the URI so it doesn't get insanely wide. Note that even
- * though the dialog uses wrapped text, if the URI doesn't contain
- * white space then the text-wrapping code is too stupid to wrap it.
- */
- temp_uri_for_display = tepl_utils_str_middle_truncate (full_formatted_uri,
- MAX_URI_IN_DIALOG_LENGTH);
- g_free (full_formatted_uri);
-
- uri_for_display = g_markup_escape_text (temp_uri_for_display, -1);
- g_free (temp_uri_for_display);
+ g_return_val_if_fail (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANT_CREATE_BACKUP), NULL);
- info_bar = gtk_info_bar_new ();
+ info_bar = tepl_info_bar_new ();
+ tepl_info_bar_set_buttons_orientation (info_bar, GTK_ORIENTATION_HORIZONTAL);
gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
_("S_ave Anyway"),
GTK_RESPONSE_YES);
+
gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
- _("D_on’t Save"),
+ _("_Don’t Save"),
GTK_RESPONSE_CANCEL);
- gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
- GTK_MESSAGE_WARNING);
- hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
+ uri = g_file_get_parse_name (location);
editor_settings = g_settings_new ("org.gnome.gedit.preferences.editor");
-
create_backup_copy = g_settings_get_boolean (editor_settings,
GEDIT_SETTINGS_CREATE_BACKUP_COPY);
g_object_unref (editor_settings);
@@ -801,46 +776,23 @@ gedit_no_backup_saving_error_info_bar_new (GFile *location,
/* FIXME: review this messages */
if (create_backup_copy)
{
- primary_text = g_strdup_printf (_("Could not create a backup file while saving “%s”"),
- uri_for_display);
+ primary_msg = g_strdup_printf (_("Could not create a backup file while saving “%s”"), uri);
}
else
{
- primary_text = g_strdup_printf (_("Could not create a temporary backup file while saving
“%s”"),
- uri_for_display);
+ primary_msg = g_strdup_printf (_("Could not create a temporary backup file while saving
“%s”"), uri);
}
- g_free (uri_for_display);
+ tepl_info_bar_add_primary_message (info_bar, primary_msg);
+ g_free (uri);
+ g_free (primary_msg);
- primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
- g_free (primary_text);
- primary_label = gtk_label_new (primary_markup);
- g_free (primary_markup);
- gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
- gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
- gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
- gtk_widget_set_halign (primary_label, GTK_ALIGN_START);
- gtk_widget_set_can_focus (primary_label, TRUE);
- gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
+ secondary_msg = _("Could not back up the old copy of the file before saving the new one. "
+ "You can ignore this warning and save the file anyway, but if an error "
+ "occurs while saving, you could lose the old copy of the file. Save anyway?");
+ tepl_info_bar_add_secondary_message (info_bar, secondary_msg);
- secondary_text = _("Could not back up the old copy of the file before saving the new one. "
- "You can ignore this warning and save the file anyway, but if an error "
- "occurs while saving, you could lose the old copy of the file. Save anyway?");
- secondary_markup = g_strdup_printf ("<small>%s</small>",
- secondary_text);
- secondary_label = gtk_label_new (secondary_markup);
- g_free (secondary_markup);
- gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
- gtk_widget_set_can_focus (secondary_label, TRUE);
- gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
- gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
- gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
- gtk_widget_set_halign (secondary_label, GTK_ALIGN_START);
-
- gtk_widget_show_all (hbox_content);
- set_contents (info_bar, hbox_content);
-
- return info_bar;
+ return GTK_WIDGET (info_bar);
}
GtkWidget *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]