From 7d84e62be3bc8fd1a347269a70130f3b56d28fe6 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 03 Oct 2018 18:52:03 -0400 Subject: MqTabLabel: Keep or revert custom title --- (limited to 'src') diff --git a/src/tab-label.c b/src/tab-label.c index 35f1c91..e3b7ee3 100644 --- a/src/tab-label.c +++ b/src/tab-label.c @@ -40,6 +40,7 @@ struct _MqTabLabel { GtkWidget *label; guint position; gchar *title; + gchar *custom_title; gboolean scrolling; gchar *scrolled_title; gchar *scrolled_markup; @@ -179,13 +180,22 @@ update_label(MqTabLabel *tab_label) gtk_label_set_markup(GTK_LABEL(tab_label->label), label); } else { label = g_strdup_printf("%u. %s", tab_label->position, - tab_label->title); + (tab_label->custom_title && tab_label->custom_title[0]) + ? tab_label->custom_title : tab_label->title); gtk_label_set_text(GTK_LABEL(tab_label->label), label); gtk_label_set_use_markup(GTK_LABEL(tab_label->label), FALSE); } g_free(label); } +/* + * Title setting logic: + * !custom && title: set normal title and use normal title + * !custom && !title: set normal title and use normal title + * custom && title: set custom title and use custom title + * custom && !title: unset custom title and use normal title + */ + static void set_title(MqTabLabel *tab_label, const gchar *title) { @@ -201,10 +211,26 @@ set_title(MqTabLabel *tab_label, const gchar *title) static void set_custom_title(MqTabLabel *tab_label, const gchar *title) { - /* TODO: Handle empty string. Set custom title instead of overriding - * (temporarily) regular title. */ - mq_tab_page_set_title(tab_label->tab_page, title); - set_title(tab_label, title); + if (title && title[0]) { + g_free(tab_label->custom_title); + tab_label->custom_title = g_strdup(title); + if (tab_label->scrolling) { + mq_tab_label_begin_scrolling(tab_label); + } + update_label(tab_label); + gtk_widget_set_tooltip_text(GTK_WIDGET(tab_label), title); + mq_tab_page_set_title(tab_label->tab_page, title); + } else { + g_free(tab_label->custom_title); + tab_label->custom_title = NULL; + if (tab_label->scrolling) { + mq_tab_label_begin_scrolling(tab_label); + } + update_label(tab_label); + gtk_widget_set_tooltip_text(GTK_WIDGET(tab_label), + tab_label->title); + mq_tab_page_set_title(tab_label->tab_page, NULL); + } } static void @@ -324,7 +350,9 @@ create_name_popover(MqTabLabel *tab_label) G_CALLBACK(name_entry_changed_cb), NULL); g_signal_connect(GTK_ENTRY(tab_label->name_entry), "icon-press", G_CALLBACK(name_entry_icon_press_cb), NULL); - gtk_entry_set_text(GTK_ENTRY(tab_label->name_entry), tab_label->title); + gtk_entry_set_text(GTK_ENTRY(tab_label->name_entry), + (tab_label->custom_title && tab_label->custom_title[0]) ? + tab_label->custom_title : tab_label->title); /* Close button */ close_button = gtk_button_new_from_icon_name("window-close", @@ -511,7 +539,9 @@ mq_tab_label_begin_scrolling(MqTabLabel *tab_label) tab_label->scrolling = TRUE; g_free(tab_label->scrolled_title); g_free(tab_label->scrolled_markup); - tab_label->scrolled_title = g_strdup_printf("%s ", tab_label->title); + tab_label->scrolled_title = g_strdup_printf("%s ", + (tab_label->custom_title && tab_label->custom_title[0]) ? + tab_label->custom_title : tab_label->title); tab_label->scrolled_markup = g_markup_printf_escaped(SCROLLED_TITLE_FMT, tab_label->scrolled_title); } -- cgit v0.9.1