[tepl] TabLabel: show location in default tooltip
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] TabLabel: show location in default tooltip
- Date: Sat, 12 Aug 2017 13:17:55 +0000 (UTC)
commit b129e66d03efafccef10ce1d765cc00f3cee79ad
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 11 20:04:32 2017 +0200
TabLabel: show location in default tooltip
tepl/tepl-tab-label.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
tepl/tepl-tab-label.h | 5 +++-
2 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/tepl/tepl-tab-label.c b/tepl/tepl-tab-label.c
index f003dfe..b8d5f07 100644
--- a/tepl/tepl-tab-label.c
+++ b/tepl/tepl-tab-label.c
@@ -22,6 +22,7 @@
#include <glib/gi18n-lib.h>
#include "tepl-tab.h"
#include "tepl-buffer.h"
+#include "tepl-file.h"
#include "tepl-signal-group.h"
#include "tepl-utils.h"
@@ -36,7 +37,7 @@
* - a #GtkLabel with the #TeplBuffer:tepl-short-title.
* - a close button, when clicked the #TeplTab #TeplTab::close-request signal is
* emitted.
- * - a customizable tooltip.
+ * - a customizable tooltip, by default it shows the full #TeplFile:location.
*/
struct _TeplTabLabelPrivate
@@ -45,6 +46,7 @@ struct _TeplTabLabelPrivate
TeplTab *tab;
TeplSignalGroup *buffer_signal_group;
+ TeplSignalGroup *file_signal_group;
GtkLabel *label;
};
@@ -97,17 +99,29 @@ buffer_short_title_notify_cb (TeplBuffer *buffer,
}
static void
+file_location_notify_cb (TeplFile *file,
+ GParamSpec *pspec,
+ TeplTabLabel *tab_label)
+{
+ tepl_tab_label_update_tooltip (tab_label);
+}
+
+static void
buffer_changed (TeplTabLabel *tab_label)
{
TeplBuffer *buffer;
+ TeplFile *file;
_tepl_signal_group_clear (&tab_label->priv->buffer_signal_group);
+ _tepl_signal_group_clear (&tab_label->priv->file_signal_group);
if (tab_label->priv->tab == NULL)
{
return;
}
+ /* Buffer */
+
buffer = tepl_tab_get_buffer (tab_label->priv->tab);
tab_label->priv->buffer_signal_group = _tepl_signal_group_new (G_OBJECT (buffer));
@@ -118,6 +132,19 @@ buffer_changed (TeplTabLabel *tab_label)
tab_label));
update_label (tab_label);
+
+ /* File */
+
+ file = tepl_buffer_get_file (buffer);
+ tab_label->priv->file_signal_group = _tepl_signal_group_new (G_OBJECT (file));
+
+ _tepl_signal_group_add (tab_label->priv->file_signal_group,
+ g_signal_connect (file,
+ "notify::location",
+ G_CALLBACK (file_location_notify_cb),
+ tab_label));
+
+ tepl_tab_label_update_tooltip (tab_label);
}
static void
@@ -209,6 +236,7 @@ tepl_tab_label_dispose (GObject *object)
}
_tepl_signal_group_clear (&tab_label->priv->buffer_signal_group);
+ _tepl_signal_group_clear (&tab_label->priv->file_signal_group);
G_OBJECT_CLASS (tepl_tab_label_parent_class)->dispose (object);
}
@@ -216,7 +244,39 @@ tepl_tab_label_dispose (GObject *object)
static gchar *
tepl_tab_label_get_tooltip_markup_default (TeplTabLabel *tab_label)
{
- return NULL;
+ TeplBuffer *buffer;
+ TeplFile *file;
+ GFile *location;
+ gchar *parse_name;
+ gchar *parse_name_with_tilde;
+ gchar *tooltip_markup;
+
+ if (tab_label->priv->tab == NULL)
+ {
+ return NULL;
+ }
+
+ buffer = tepl_tab_get_buffer (tab_label->priv->tab);
+ file = tepl_buffer_get_file (buffer);
+ location = tepl_file_get_location (file);
+
+ if (location == NULL)
+ {
+ return NULL;
+ }
+
+ parse_name = g_file_get_parse_name (location);
+ parse_name_with_tilde = _tepl_utils_replace_home_dir_with_tilde (parse_name);
+
+ tooltip_markup = g_markup_printf_escaped ("<b>%s</b> %s",
+ /* Translators: location of a file. */
+ _("Location:"),
+ parse_name_with_tilde);
+
+ g_free (parse_name_with_tilde);
+ g_free (parse_name);
+
+ return tooltip_markup;
}
static void
diff --git a/tepl/tepl-tab-label.h b/tepl/tepl-tab-label.h
index ffe42af..72ff8e4 100644
--- a/tepl/tepl-tab-label.h
+++ b/tepl/tepl-tab-label.h
@@ -51,7 +51,10 @@ struct _TeplTabLabel
* @parent_class: The parent class.
* @get_tooltip_markup: Virtual function pointer to create the tooltip markup
* string. %NULL must be returned if no tooltip is wanted. The result is
- * intended to be used as an argument to gtk_widget_set_tooltip_markup().
+ * intended to be used as an argument to gtk_widget_set_tooltip_markup(). The
+ * default implementation returns the full #TeplFile:location if non-%NULL, or
+ * %NULL otherwise. The return value must be freed with g_free() when no
+ * longer needed.
*/
struct _TeplTabLabelClass
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]