From 181ffbf6f41780feefa90bb63ceab1e0a2bd8aa1 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Thu, 27 Jul 2023 07:53:33 +0200 Subject: [PATCH] CompEditor: Show source full name for existing components The source combo box is disabled when editing existing component, which makes it hard to recognize which calendar is selected, especially when there are configured more calendar of the same name. Let's show the full source name in such case. Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/1180 --- src/calendar/gui/e-comp-editor-page-general.c | 8 ++- src/e-util/e-source-combo-box.c | 55 ++++++++++++++++++- src/e-util/e-source-combo-box.h | 5 ++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/calendar/gui/e-comp-editor-page-general.c b/src/calendar/gui/e-comp-editor-page-general.c index eef49caa5a..ca3e36e2e9 100644 --- a/src/calendar/gui/e-comp-editor-page-general.c +++ b/src/calendar/gui/e-comp-editor-page-general.c @@ -602,12 +602,16 @@ ecep_general_editor_flags_notify_cb (ECompEditor *comp_editor, GParamSpec *param, ECompEditorPageGeneral *page_general) { + gboolean is_new_component; + g_return_if_fail (E_IS_COMP_EDITOR (comp_editor)); g_return_if_fail (E_IS_COMP_EDITOR_PAGE_GENERAL (page_general)); + is_new_component = (e_comp_editor_get_flags (comp_editor) & E_COMP_EDITOR_FLAG_IS_NEW) != 0; + /* Allow changing target client only for new components */ - gtk_widget_set_sensitive (page_general->priv->source_combo_box, - (e_comp_editor_get_flags (comp_editor) & E_COMP_EDITOR_FLAG_IS_NEW) != 0); + gtk_widget_set_sensitive (page_general->priv->source_combo_box, is_new_component); + e_source_combo_box_set_show_full_name (E_SOURCE_COMBO_BOX (page_general->priv->source_combo_box), !is_new_component); } static gboolean diff --git a/src/e-util/e-source-combo-box.c b/src/e-util/e-source-combo-box.c index 84af308353..978a925d32 100644 --- a/src/e-util/e-source-combo-box.c +++ b/src/e-util/e-source-combo-box.c @@ -39,6 +39,7 @@ struct _ESourceComboBoxPrivate { gboolean show_colors; gint max_natural_width; + gboolean show_full_name; }; enum { @@ -52,6 +53,7 @@ enum { enum { COLUMN_COLOR, /* GDK_TYPE_RGBA */ COLUMN_NAME, /* G_TYPE_STRING */ + COLUMN_FULL_NAME, /* G_TYPE_STRING */ COLUMN_SENSITIVE, /* G_TYPE_BOOLEAN */ COLUMN_UID, /* G_TYPE_STRING */ NUM_COLUMNS @@ -72,6 +74,7 @@ source_combo_box_traverse (GNode *node, const gchar *ext_name; const gchar *display_name; const gchar *uid; + gchar *full_name; gboolean sensitive = FALSE; gboolean use_color = FALSE; guint depth; @@ -106,6 +109,7 @@ source_combo_box_traverse (GNode *node, } display_name = e_source_get_display_name (source); + full_name = e_util_get_source_full_name (combo_box->priv->registry, source); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); gtk_list_store_append (GTK_LIST_STORE (model), &iter); @@ -130,11 +134,13 @@ source_combo_box_traverse (GNode *node, GTK_LIST_STORE (model), &iter, COLUMN_COLOR, use_color ? &rgba : NULL, COLUMN_NAME, indented->str, + COLUMN_FULL_NAME, full_name && *full_name ? full_name : display_name, COLUMN_SENSITIVE, sensitive, COLUMN_UID, uid, -1); g_string_free (indented, TRUE); + g_free (full_name); return FALSE; } @@ -404,6 +410,7 @@ source_combo_box_constructed (GObject *object) NUM_COLUMNS, GDK_TYPE_RGBA, /* COLUMN_COLOR */ G_TYPE_STRING, /* COLUMN_NAME */ + G_TYPE_STRING, /* COLUMN_FULL_NAME */ G_TYPE_BOOLEAN, /* COLUMN_SENSITIVE */ G_TYPE_STRING); /* COLUMN_UID */ gtk_combo_box_set_model ( @@ -432,7 +439,7 @@ source_combo_box_constructed (GObject *object) gtk_cell_layout_pack_start (layout, renderer, TRUE); gtk_cell_layout_set_attributes ( layout, renderer, - "text", COLUMN_NAME, + "text", combo_box->priv->show_full_name ? COLUMN_FULL_NAME : COLUMN_NAME, "sensitive", COLUMN_SENSITIVE, NULL); @@ -887,3 +894,49 @@ e_source_combo_box_set_max_natural_width (ESourceComboBox *combo_box, g_object_notify (G_OBJECT (combo_box), "max-natural-width"); } + +/** + * e_source_combo_box_get_show_full_name: + * @combo_box: an #ESourceComboBox + * + * Returns whether should show full name of the sources. + * + * Returns: whether should show full name of the sources + * + * Since: 3.50 + **/ +gboolean +e_source_combo_box_get_show_full_name (ESourceComboBox *combo_box) +{ + g_return_val_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box), FALSE); + + return combo_box->priv->show_full_name; +} + +/** + * e_source_combo_box_set_show_full_name: + * @combo_box: an #ESourceComboBox + * @show_full_name: value to set + * + * Sets whether should show full name of the sources. + * + * Since: 3.50 + **/ +void +e_source_combo_box_set_show_full_name (ESourceComboBox *combo_box, + gboolean show_full_name) +{ + g_return_if_fail (E_IS_SOURCE_COMBO_BOX (combo_box)); + + if ((combo_box->priv->show_full_name ? 1 : 0) == (show_full_name ? 1 : 0)) + return; + + combo_box->priv->show_full_name = show_full_name; + + if (combo_box->priv->name_renderer) { + gtk_cell_layout_set_attributes ( + GTK_CELL_LAYOUT (combo_box), combo_box->priv->name_renderer, + "text", combo_box->priv->show_full_name ? COLUMN_FULL_NAME : COLUMN_NAME, + NULL); + } +} diff --git a/src/e-util/e-source-combo-box.h b/src/e-util/e-source-combo-box.h index 345b23dd1c..41aa34194f 100644 --- a/src/e-util/e-source-combo-box.h +++ b/src/e-util/e-source-combo-box.h @@ -89,6 +89,11 @@ gint e_source_combo_box_get_max_natural_width void e_source_combo_box_set_max_natural_width (ESourceComboBox *combo_box, gint value); +gboolean e_source_combo_box_get_show_full_name + (ESourceComboBox *combo_box); +void e_source_combo_box_set_show_full_name + (ESourceComboBox *combo_box, + gboolean show_full_name); G_END_DECLS