gnome-terminal r3207 - in trunk: po src
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-terminal r3207 - in trunk: po src
- Date: Mon, 10 Nov 2008 21:10:48 +0000 (UTC)
Author: chpe
Date: Mon Nov 10 21:10:48 2008
New Revision: 3207
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=3207&view=rev
Log:
Create a tab label class, and use it in TerminalWindow.
Added:
trunk/src/terminal-tab-label.c
trunk/src/terminal-tab-label.h
Modified:
trunk/po/POTFILES.in
trunk/src/Makefile.am
trunk/src/terminal-window.c
Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in (original)
+++ trunk/po/POTFILES.in Mon Nov 10 21:10:48 2008
@@ -19,6 +19,7 @@
src/terminal-options.c
src/terminal-profile.c
src/terminal-screen.c
+src/terminal-tab-label.c
src/terminal-tabs-menu.c
src/terminal-util.c
src/terminal-window.c
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Nov 10 21:10:48 2008
@@ -31,6 +31,8 @@
terminal-screen.h \
terminal-screen-container.c \
terminal-screen-container.h \
+ terminal-tab-label.c \
+ terminal-tab-label.h \
terminal-tabs-menu.c \
terminal-tabs-menu.h \
terminal-type-builtins.c \
Added: trunk/src/terminal-tab-label.c
==============================================================================
--- (empty file)
+++ trunk/src/terminal-tab-label.c Mon Nov 10 21:10:48 2008
@@ -0,0 +1,234 @@
+/*
+ * 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 2, 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "terminal-tab-label.h"
+
+#define TERMINAL_TAB_LABEL_GET_PRIVATE(tab_label)(G_TYPE_INSTANCE_GET_PRIVATE ((tab_label), TERMINAL_TYPE_TAB_LABEL, TerminalTabLabelPrivate))
+
+#define SPACING (4)
+
+struct _TerminalTabLabelPrivate
+{
+ TerminalScreen *screen;
+ GtkWidget *label;
+ GtkWidget *close_button;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SCREEN
+};
+
+enum
+{
+ CLOSE_BUTTON_CLICKED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+G_DEFINE_TYPE (TerminalTabLabel, terminal_tab_label, GTK_TYPE_HBOX);
+
+/* helper functions */
+
+static void
+close_button_clicked_cb (GtkWidget *widget,
+ TerminalTabLabel *tab_label)
+{
+ g_signal_emit (tab_label, signals[CLOSE_BUTTON_CLICKED], 0);
+}
+
+static void
+sync_tab_label (TerminalScreen *screen,
+ GParamSpec *pspec,
+ GtkWidget *label)
+{
+ GtkWidget *hbox;
+ const char *title;
+
+ title = terminal_screen_get_title (screen);
+ hbox = gtk_widget_get_parent (label);
+
+ gtk_label_set_text (GTK_LABEL (label), title);
+
+ gtk_widget_set_tooltip_text (hbox, title);
+}
+
+/* public functions */
+
+/* Class implementation */
+
+static void
+terminal_tab_label_parent_set (GtkWidget *widget,
+ GtkWidget *old_parent)
+{
+ void (* parent_set) (GtkWidget *, GtkWidget *) = GTK_WIDGET_CLASS (terminal_tab_label_parent_class)->parent_set;
+
+ if (parent_set)
+ parent_set (widget, old_parent);
+}
+
+static void
+terminal_tab_label_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
+{
+ TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (widget);
+ TerminalTabLabelPrivate *priv = tab_label->priv;
+ void (* style_set) (GtkWidget *, GtkStyle *) = GTK_WIDGET_CLASS (terminal_tab_label_parent_class)->style_set;
+ int h, w;
+
+ if (style_set)
+ style_set (widget, previous_style);
+
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
+ GTK_ICON_SIZE_MENU, &w, &h);
+ gtk_widget_set_size_request (priv->close_button, w + 2, h + 2);
+}
+
+static void
+terminal_tab_label_init (TerminalTabLabel *tab_label)
+{
+ tab_label->priv = TERMINAL_TAB_LABEL_GET_PRIVATE (tab_label);
+}
+
+static GObject *
+terminal_tab_label_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+ TerminalTabLabel *tab_label;
+ TerminalTabLabelPrivate *priv;
+ GtkWidget *hbox, *label, *close_button, *image;
+
+ object = G_OBJECT_CLASS (terminal_tab_label_parent_class)->constructor
+ (type, n_construct_properties, construct_params);
+
+ tab_label = TERMINAL_TAB_LABEL (object);
+ hbox = GTK_WIDGET (tab_label);
+ priv = tab_label->priv;
+
+ g_assert (priv->screen != NULL);
+
+ gtk_box_set_spacing (GTK_BOX (hbox), SPACING);
+
+ priv->label = label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_misc_set_padding (GTK_MISC (label), 0, 0);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
+
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ priv->close_button = close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ gtk_widget_set_name (close_button, "gnome-terminal-tab-close-button");
+ gtk_widget_set_tooltip_text (close_button, _("Close tab"));
+
+ image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+ gtk_container_add (GTK_CONTAINER (close_button), image);
+ gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+
+ sync_tab_label (priv->screen, NULL, label);
+ g_signal_connect (priv->screen, "notify::title",
+ G_CALLBACK (sync_tab_label), label);
+
+ g_signal_connect (close_button, "clicked",
+ G_CALLBACK (close_button_clicked_cb), tab_label);
+
+ gtk_widget_show_all (hbox);
+
+ return object;
+}
+
+static void
+terminal_tab_label_finalize (GObject *object)
+{
+// TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
+
+ G_OBJECT_CLASS (terminal_tab_label_parent_class)->finalize (object);
+}
+
+static void
+terminal_tab_label_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (object);
+ TerminalTabLabelPrivate *priv = tab_label->priv;
+
+ switch (prop_id) {
+ case PROP_SCREEN:
+ priv->screen = g_value_get_object (value);
+ break;
+ }
+}
+
+static void
+terminal_tab_label_class_init (TerminalTabLabelClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gobject_class->constructor = terminal_tab_label_constructor;
+ 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;
+ widget_class->style_set = terminal_tab_label_style_set;
+
+ signals[CLOSE_BUTTON_CLICKED] =
+ g_signal_new ("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));
+
+ g_type_class_add_private (gobject_class, sizeof (TerminalTabLabelPrivate));
+}
+
+/* public API */
+
+GtkWidget *
+terminal_tab_label_new (TerminalScreen *screen)
+{
+ return g_object_new (TERMINAL_TYPE_TAB_LABEL,
+ "screen", screen,
+ NULL);
+}
Added: trunk/src/terminal-tab-label.h
==============================================================================
--- (empty file)
+++ trunk/src/terminal-tab-label.h Mon Nov 10 21:10:48 2008
@@ -0,0 +1,61 @@
+/*
+ * Copyright  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 2, 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef TERMINAL_TAB_LABEL_H
+#define TERMINAL_TAB_LABEL_H
+
+#include <gtk/gtk.h>
+
+#include "terminal-screen.h"
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_TAB_LABEL (terminal_tab_label_get_type ())
+#define TERMINAL_TAB_LABEL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TERMINAL_TYPE_TAB_LABEL, TerminalTabLabel))
+#define TERMINAL_TAB_LABEL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TERMINAL_TYPE_TAB_LABEL, TerminalTabLabelClass))
+#define TERMINAL_IS_TAB_LABEL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TERMINAL_TYPE_TAB_LABEL))
+#define TERMINAL_IS_TAB_LABEL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TERMINAL_TYPE_TAB_LABEL))
+#define TERMINAL_TAB_LABEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TERMINAL_TYPE_TAB_LABEL, TerminalTabLabelClass))
+
+typedef struct _TerminalTabLabel TerminalTabLabel;
+typedef struct _TerminalTabLabelClass TerminalTabLabelClass;
+typedef struct _TerminalTabLabelPrivate TerminalTabLabelPrivate;
+
+struct _TerminalTabLabel
+{
+ GtkHBox parent_instance;
+
+ /*< private >*/
+ TerminalTabLabelPrivate *priv;
+};
+
+struct _TerminalTabLabelClass
+{
+ GtkHBoxClass parent_class;
+
+ /* Signals */
+ void (* close_button_clicked) (TerminalTabLabel *tab_label);
+};
+
+GType terminal_tab_label_get_type (void);
+
+GtkWidget *terminal_tab_label_new (TerminalScreen *screen);
+
+G_END_DECLS
+
+#endif /* !TERMINAL_TAB_LABEL_H */
Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c (original)
+++ trunk/src/terminal-window.c Mon Nov 10 21:10:48 2008
@@ -32,6 +32,7 @@
#include "terminal-encoding.h"
#include "terminal-intl.h"
#include "terminal-screen-container.h"
+#include "terminal-tab-label.h"
#include "terminal-tabs-menu.h"
#include "terminal-util.h"
#include "terminal-window.h"
@@ -1358,7 +1359,6 @@
if (g_str_has_prefix (accel_path, "<Actions>/Main/"))
{
- TerminalWindowPrivate *priv = window->priv;
const char *action_name;
/* We want to always consume these accelerators, even if the corresponding
@@ -2045,7 +2045,7 @@
/* Notebook callbacks */
static void
-close_button_clicked_cb (GtkWidget *widget,
+close_button_clicked_cb (GtkWidget *tab_label,
GtkWidget *screen_container)
{
GtkWidget *notebook;
@@ -2056,75 +2056,6 @@
gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
}
-static void
-sync_tab_label (TerminalScreen *screen,
- GParamSpec *pspec,
- GtkWidget *label)
-{
- GtkWidget *hbox;
- const char *title;
-
- title = terminal_screen_get_title (screen);
- hbox = gtk_widget_get_parent (label);
-
- gtk_label_set_text (GTK_LABEL (label), title);
-
- gtk_widget_set_tooltip_text (hbox, title);
-}
-
-static void
-tab_label_style_set_cb (GtkWidget *hbox,
- GtkStyle *previous_style,
- GtkWidget *button)
-{
- int h, w;
-
- gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
- GTK_ICON_SIZE_MENU, &w, &h);
- gtk_widget_set_size_request (button, w + 2, h + 2);
-}
-
-static GtkWidget *
-construct_tab_label (TerminalScreen *screen, GtkWidget *screen_container)
-{
- GtkWidget *hbox, *label, *close_button, *image;
-
- hbox = gtk_hbox_new (FALSE, 4);
-
- label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_misc_set_padding (GTK_MISC (label), 0, 0);
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
-
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-
- close_button = gtk_button_new ();
- gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
- gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
- gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
- gtk_widget_set_name (close_button, "gnome-terminal-tab-close-button");
- gtk_widget_set_tooltip_text (close_button, _("Close tab"));
-
- image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
- gtk_container_add (GTK_CONTAINER (close_button), image);
- gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
-
- sync_tab_label (screen, NULL, label);
- g_signal_connect (screen, "notify::title",
- G_CALLBACK (sync_tab_label), label);
-
- g_signal_connect (close_button, "clicked",
- G_CALLBACK (close_button_clicked_cb), screen_container);
-
- g_signal_connect (hbox, "style-set",
- G_CALLBACK (tab_label_style_set_cb), close_button);
-
- gtk_widget_show_all (hbox);
-
- return hbox;
-}
-
void
terminal_window_add_screen (TerminalWindow *window,
TerminalScreen *screen,
@@ -2148,7 +2079,9 @@
update_tab_visibility (window, +1);
- tab_label = construct_tab_label (screen, screen_container);
+ tab_label = terminal_tab_label_new (screen);
+ g_signal_connect (tab_label, "close-button-clicked",
+ G_CALLBACK (close_button_clicked_cb), screen_container);
gtk_notebook_insert_page (GTK_NOTEBOOK (priv->notebook),
screen_container,
@@ -2184,7 +2117,6 @@
gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), num_page);
}
-
void
terminal_window_move_screen (TerminalWindow *source_window,
TerminalWindow *dest_window,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]