2011-11-06 14:13:49 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2001 Havoc Pennington
|
|
|
|
* Copyright © 2007, 2008 Christian Persch
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope tab_label it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-10-11 18:34:18 -05:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-11-06 14:13:49 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "terminal-intl.h"
|
|
|
|
#include "terminal-tab-label.h"
|
2016-06-11 11:03:09 -05:00
|
|
|
#include "terminal-close-button.h"
|
2011-11-06 14:13:49 -06:00
|
|
|
|
|
|
|
#define SPACING (4)
|
|
|
|
|
|
|
|
struct _TerminalTabLabelPrivate
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
TerminalScreen *screen;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *close_button;
|
|
|
|
gboolean bold;
|
2011-11-06 14:13:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
PROP_0,
|
|
|
|
PROP_SCREEN
|
2011-11-06 14:13:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
CLOSE_BUTTON_CLICKED,
|
|
|
|
LAST_SIGNAL
|
2011-11-06 14:13:49 -06:00
|
|
|
};
|
|
|
|
|
2014-10-28 08:46:34 -06:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2019-08-24 21:26:46 -05:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (TerminalTabLabel, terminal_tab_label, GTK_TYPE_BOX);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
|
|
|
/* helper functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_button_clicked_cb (GtkWidget *widget,
|
|
|
|
TerminalTabLabel *tab_label)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
g_signal_emit (tab_label, signals[CLOSE_BUTTON_CLICKED], 0);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_tab_label (TerminalScreen *screen,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkWidget *label)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
GtkWidget *hbox;
|
|
|
|
const char *title;
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
title = terminal_screen_get_title (screen);
|
|
|
|
hbox = gtk_widget_get_parent (label);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_label_set_text (GTK_LABEL (label), title);
|
|
|
|
|
|
|
|
gtk_widget_set_tooltip_text (hbox, title);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
/* Class implementation */
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminal_tab_label_parent_set (GtkWidget *widget,
|
|
|
|
GtkWidget *old_parent)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
void (* parent_set) (GtkWidget *, GtkWidget *) = GTK_WIDGET_CLASS (terminal_tab_label_parent_class)->parent_set;
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
if (parent_set)
|
|
|
|
parent_set (widget, old_parent);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminal_tab_label_init (TerminalTabLabel *tab_label)
|
|
|
|
{
|
2019-08-24 21:26:46 -05:00
|
|
|
tab_label->priv = terminal_tab_label_get_instance_private (tab_label);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
terminal_tab_label_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_params)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
GObject *object;
|
|
|
|
TerminalTabLabel *tab_label;
|
|
|
|
TerminalTabLabelPrivate *priv;
|
2016-06-11 11:03:09 -05:00
|
|
|
GtkWidget *hbox, *label, *close_button;
|
2011-11-06 16:14:03 -06:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (terminal_tab_label_parent_class)->constructor
|
|
|
|
(type, n_construct_properties, construct_params);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
tab_label = TERMINAL_TAB_LABEL (object);
|
|
|
|
hbox = GTK_WIDGET (tab_label);
|
|
|
|
priv = tab_label->priv;
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
g_assert (priv->screen != NULL);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_box_set_spacing (GTK_BOX (hbox), SPACING);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
priv->label = label = gtk_label_new (NULL);
|
2016-01-20 02:23:36 -06:00
|
|
|
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_label_set_yalign (GTK_LABEL (label), 0.5);
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2016-06-11 11:03:09 -05:00
|
|
|
priv->close_button = close_button = terminal_close_button_new ();
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_widget_set_tooltip_text (close_button, _("Close tab"));
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
sync_tab_label (priv->screen, NULL, label);
|
|
|
|
g_signal_connect (priv->screen, "notify::title",
|
|
|
|
G_CALLBACK (sync_tab_label), label);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
g_signal_connect (close_button, "clicked",
|
|
|
|
G_CALLBACK (close_button_clicked_cb), tab_label);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
gtk_widget_show_all (hbox);
|
2011-11-06 14:13:49 -06:00
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
return object;
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
2016-09-28 13:05:46 -05:00
|
|
|
static void
|
|
|
|
terminal_tab_label_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
|
|
|
|
TerminalTabLabelPrivate *priv = tab_label->priv;
|
|
|
|
|
|
|
|
if (priv->screen != NULL) {
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->screen,
|
|
|
|
G_CALLBACK (sync_tab_label),
|
|
|
|
priv->label);
|
|
|
|
g_object_unref (priv->screen);
|
|
|
|
priv->screen = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (terminal_tab_label_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2011-11-06 14:13:49 -06:00
|
|
|
static void
|
|
|
|
terminal_tab_label_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
// TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
|
|
|
|
|
2011-11-06 16:14:03 -06:00
|
|
|
G_OBJECT_CLASS (terminal_tab_label_parent_class)->finalize (object);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminal_tab_label_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
|
|
|
|
TerminalTabLabelPrivate *priv = tab_label->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_SCREEN:
|
2016-09-28 13:05:46 -05:00
|
|
|
priv->screen = g_value_dup_object (value);
|
2011-11-06 16:14:03 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminal_tab_label_class_init (TerminalTabLabelClass *klass)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->constructor = terminal_tab_label_constructor;
|
2016-09-28 13:05:46 -05:00
|
|
|
gobject_class->dispose = terminal_tab_label_dispose;
|
2011-11-06 16:14:03 -06:00
|
|
|
gobject_class->finalize = terminal_tab_label_finalize;
|
|
|
|
gobject_class->set_property = terminal_tab_label_set_property;
|
|
|
|
|
|
|
|
widget_class->parent_set = terminal_tab_label_parent_set;
|
|
|
|
|
|
|
|
signals[CLOSE_BUTTON_CLICKED] =
|
|
|
|
g_signal_new (I_("close-button-clicked"),
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (TerminalTabLabelClass, close_button_clicked),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
0);
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_SCREEN,
|
|
|
|
g_param_spec_object ("screen", NULL, NULL,
|
|
|
|
TERMINAL_TYPE_SCREEN,
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* public API */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* terminal_tab_label_new:
|
|
|
|
* @screen: a #TerminalScreen
|
|
|
|
*
|
|
|
|
* Returns: a new #TerminalTabLabel for @screen
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
terminal_tab_label_new (TerminalScreen *screen)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
return g_object_new (TERMINAL_TYPE_TAB_LABEL,
|
|
|
|
"screen", screen,
|
|
|
|
NULL);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* terminal_tab_label_set_bold:
|
|
|
|
* @tab_label: a #TerminalTabLabel
|
|
|
|
* @bold: whether to enable label bolding
|
|
|
|
*
|
|
|
|
* Sets the tab label text bold, or unbolds it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
terminal_tab_label_set_bold (TerminalTabLabel *tab_label,
|
|
|
|
gboolean bold)
|
|
|
|
{
|
2011-11-06 16:14:03 -06:00
|
|
|
TerminalTabLabelPrivate *priv = tab_label->priv;
|
|
|
|
PangoAttrList *attr_list;
|
|
|
|
PangoAttribute *weight_attr;
|
|
|
|
gboolean free_list = FALSE;
|
|
|
|
|
|
|
|
bold = bold != FALSE;
|
|
|
|
if (priv->bold == bold)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->bold = bold;
|
|
|
|
|
|
|
|
attr_list = gtk_label_get_attributes (GTK_LABEL (priv->label));
|
|
|
|
if (!attr_list)
|
|
|
|
{
|
|
|
|
attr_list = pango_attr_list_new ();
|
|
|
|
free_list = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bold)
|
|
|
|
weight_attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
|
|
|
|
else
|
|
|
|
weight_attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL);
|
|
|
|
|
|
|
|
/* gtk_label_get_attributes() returns the label's internal list,
|
|
|
|
* which we're probably not supposed to modify directly.
|
|
|
|
* It seems to work ok however.
|
|
|
|
*/
|
|
|
|
pango_attr_list_change (attr_list, weight_attr);
|
|
|
|
|
|
|
|
gtk_label_set_attributes (GTK_LABEL (priv->label), attr_list);
|
|
|
|
|
|
|
|
if (free_list)
|
|
|
|
pango_attr_list_unref (attr_list);
|
2011-11-06 14:13:49 -06:00
|
|
|
}
|