Factor out the tab label.

Borrowed the close-button and tab-label widgets from gedit
and factor it out from gtr-notebook.
parent d4cce14d
......@@ -52,6 +52,7 @@ src/plugin-system/gtr-plugin-manager.c
src/gtr-prefs-manager.c
src/gtr-statusbar.c
src/gtr-tab.c
src/gtr-tab-label.c
src/toolbareditor/egg-editable-toolbar.c
src/toolbareditor/egg-toolbar-editor.c
src/translation-memory/berkeley/gtr-db-base.c
......
......@@ -12,23 +12,21 @@
# First Version: 2000-09-13 20:39+0200
#
# Jesús Bravo Álvarez <jba@pobox.com>, 2000.
# Ignacio Casal Quinteiro <nacho.resa@gmail.com>, 2005, 2006.
# Ignacio Casal Quinteiro <icq@cvs.gnome.org>, 2007.
# Ignacio Casal Quinteiro <icq@svn.gnome.org>, 2008.
# Ignacio Casal Quinteiro <nacho.resa@gmail.com>, 2008.
# Fran Diéguez <frandieguez@ubuntu.com>, 2010.
# Francisco Diéguez <frandieguez@ubuntu.com>, 2009, 2010.
# Ignacio Casal Quinteiro <icq@gnome.org>, 2005, 2006, 2007, 2008, 2010.
#
msgid ""
msgstr ""
"Project-Id-Version: gl\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-04-09 19:08+0200\n"
"PO-Revision-Date: 2010-03-06 23:32+0100\n"
"Last-Translator: Francisco Diéguez <frandieguez@ubuntu.com>\n"
"PO-Revision-Date: 2010-04-17 13:22+0200\n"
"Last-Translator: Ignacio Casal Quinteiro <icq@gnome.org>\n"
"Language-Team: Galician <proxecto@trasno.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Content-Transfer-Encoding: 8bits\n"
"X-Generator: Lokalize 0.3\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
......
......@@ -97,6 +97,10 @@ libgtranslator_la_SOURCES = \
gtr-message-table-model.h \
gtr-notebook.c \
gtr-tab.c \
gtr-tab-label.h \
gtr-tab-label.c \
gtr-close-button.h \
gtr-close-button.c \
gtr-view.c \
gtr-window.c \
gtr-po.c \
......
/*
* gtr-close-button.c
* This file is part of gtr
*
* Copyright (C) 2010 - Paolo Borelli
*
* 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 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that 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 "gtr-close-button.h"
G_DEFINE_TYPE (GtrCloseButton, gtr_close_button, GTK_TYPE_BUTTON)
static void
gtr_close_button_style_set (GtkWidget *button,
GtkStyle *previous_style)
{
gint 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);
GTK_WIDGET_CLASS (gtr_close_button_parent_class)->style_set (button, previous_style);
}
static void
gtr_close_button_class_init (GtrCloseButtonClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->style_set = gtr_close_button_style_set;
}
static void
gtr_close_button_init (GtrCloseButton *button)
{
GtkRcStyle *rcstyle;
GtkWidget *image;
/* make it as small as possible */
rcstyle = gtk_rc_style_new ();
rcstyle->xthickness = rcstyle->ythickness = 0;
gtk_widget_modify_style (GTK_WIDGET (button), rcstyle);
g_object_unref (rcstyle);
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
GTK_ICON_SIZE_MENU);
gtk_widget_show (image);
gtk_container_add (GTK_CONTAINER (button), image);
}
GtkWidget *
gtr_close_button_new ()
{
GtrCloseButton *button;
button = g_object_new (GTR_TYPE_CLOSE_BUTTON,
"relief", GTK_RELIEF_NONE,
"focus-on-click", FALSE,
NULL);
return GTK_WIDGET (button);
}
/*
* gtr-close-button.h
* This file is part of gtr
*
* Copyright (C) 2010 - Paolo Borelli
*
* 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 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that 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 __GTR_CLOSE_BUTTON_H__
#define __GTR_CLOSE_BUTTON_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GTR_TYPE_CLOSE_BUTTON (gtr_close_button_get_type ())
#define GTR_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTR_TYPE_CLOSE_BUTTON, GtrCloseButton))
#define GTR_CLOSE_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTR_TYPE_CLOSE_BUTTON, GtrCloseButton const))
#define GTR_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTR_TYPE_CLOSE_BUTTON, GtrCloseButtonClass))
#define GTR_IS_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTR_TYPE_CLOSE_BUTTON))
#define GTR_IS_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTR_TYPE_CLOSE_BUTTON))
#define GTR_CLOSE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTR_TYPE_CLOSE_BUTTON, GtrCloseButtonClass))
typedef struct _GtrCloseButton GtrCloseButton;
typedef struct _GtrCloseButtonClass GtrCloseButtonClass;
typedef struct _GtrCloseButtonPrivate GtrCloseButtonPrivate;
struct _GtrCloseButton {
GtkButton parent;
};
struct _GtrCloseButtonClass {
GtkButtonClass parent_class;
};
GType gtr_close_button_get_type (void) G_GNUC_CONST;
GtkWidget *gtr_close_button_new (void);
G_END_DECLS
#endif /* __GTR_CLOSE_BUTTON_H__ */
......@@ -22,179 +22,97 @@
#include "gtr-notebook.h"
#include "gtr-tab.h"
#include "gtr-tab-label.h"
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#define GTR_NOTEBOOK_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
(object), \
GTR_TYPE_NOTEBOOK, \
GtrNotebookPrivate))
#define GTR_NOTEBOOK_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
(object), \
GTR_TYPE_NOTEBOOK, \
GtrNotebookPrivate))
G_DEFINE_TYPE (GtrNotebook, gtr_notebook, GTK_TYPE_NOTEBOOK)
struct _GtrNotebookPrivate
{
GList *pages;
};
struct _GtrNotebookPrivate
{
};
/* Signals */
enum
{
TAB_CLOSE_REQUEST,
LAST_SIGNAL
};
enum
{
TAB_CLOSE_REQUEST,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static guint signals[LAST_SIGNAL] = { 0 };
static void
tab_label_style_set_cb (GtkWidget * hbox,
GtkStyle * previous_style, gpointer user_data)
close_button_clicked_cb (GtrTabLabel *tab_label, GtrNotebook *notebook)
{
GtkWidget *button;
gint h, w;
gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (hbox),
GTK_ICON_SIZE_MENU, &w, &h);
GtrTab *tab;
button = g_object_get_data (G_OBJECT (hbox), "close-button");
gtk_widget_set_size_request (button, w + 2, h + 2);
tab = gtr_tab_label_get_tab (tab_label);
g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab);
}
static void
sync_name (GtrPo * po, GParamSpec * pspec, GtkWidget * hbox)
static GtkWidget *
create_tab_label (GtrNotebook *nb,
GtrTab *tab)
{
gchar *str;
GtkWidget *label;
GtkWidget *ebox;
gchar *tooltip;
GtrTab *tab;
GFile *location;
gchar *path;
GtkWidget *tab_label;
label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
ebox = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label-ebox"));
tab = gtr_tab_get_from_document (po);
tab_label = gtr_tab_label_new (tab);
str = gtr_tab_get_name (tab);
g_return_if_fail (str != NULL);
g_signal_connect (tab_label,
"close-clicked",
G_CALLBACK (close_button_clicked_cb),
nb);
gtk_label_set_text (GTK_LABEL (label), str);
g_object_set_data (G_OBJECT (tab), "tab-label", tab_label);
location = gtr_po_get_location (po);
path = g_file_get_path (location);
g_object_unref (location);
return tab_label;
}
static void
remove_tab_label (GtrNotebook *nb,
GtrTab *tab)
{
GtkWidget *tab_label;
tooltip = g_strdup_printf (_("<b>Path:</b> %s"), path);
tab_label = gtr_tab_label_new (tab);
gtk_widget_set_tooltip_markup (ebox, tooltip);
g_signal_handlers_disconnect_by_func (tab_label,
G_CALLBACK (close_button_clicked_cb),
nb);
g_free (path);
g_free (tooltip);
g_free (str);
g_object_set_data (G_OBJECT (tab), "tab-label", NULL);
}
static void
close_button_clicked_cb (GtkWidget * widget, GtkWidget * tab)
update_tabs_visibility (GtrNotebook *nb)
{
GtrNotebook *notebook;
gboolean show_tabs;
guint num;
notebook = GTR_NOTEBOOK (gtk_widget_get_parent (tab));
g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab);
}
num = gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb));
static GtkWidget *
build_tab_label (GtrNotebook * nb, GtrTab * tab)
{
GtkWidget *hbox, *label_hbox, *label_ebox;
GtkWidget *label, *dummy_label;
GtkWidget *close_button;
GtkRcStyle *rcstyle;
GtkWidget *image;
GtkWidget *icon;
hbox = gtk_hbox_new (FALSE, 4);
label_ebox = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (label_ebox), FALSE);
gtk_box_pack_start (GTK_BOX (hbox), label_ebox, TRUE, TRUE, 0);
label_hbox = gtk_hbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (label_ebox), label_hbox);
/* setup close button */
close_button = gtk_button_new ();
gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
/* don't allow focus on the close button */
gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
/* make it as small as possible */
rcstyle = gtk_rc_style_new ();
rcstyle->xthickness = rcstyle->ythickness = 0;
gtk_widget_modify_style (close_button, rcstyle);
g_object_unref (G_OBJECT (rcstyle)),
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (close_button), image);
gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text (close_button, _("Close document"));
g_signal_connect (close_button,
"clicked", G_CALLBACK (close_button_clicked_cb), tab);
/* setup site icon, empty by default */
icon = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (label_hbox), icon, FALSE, FALSE, 0);
/* setup label */
label = gtk_label_new ("");
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_misc_set_padding (GTK_MISC (label), 0, 0);
gtk_box_pack_start (GTK_BOX (label_hbox), label, FALSE, FALSE, 0);
dummy_label = gtk_label_new ("");
gtk_box_pack_start (GTK_BOX (label_hbox), dummy_label, TRUE, TRUE, 0);
/* Set minimal size */
g_signal_connect (hbox, "style-set",
G_CALLBACK (tab_label_style_set_cb), NULL);
gtk_widget_show (hbox);
gtk_widget_show (label_ebox);
gtk_widget_show (label_hbox);
gtk_widget_show (label);
gtk_widget_show (dummy_label);
gtk_widget_show (image);
gtk_widget_show (close_button);
gtk_widget_show (icon);
g_object_set_data (G_OBJECT (hbox), "label", label);
g_object_set_data (G_OBJECT (hbox), "label-ebox", label_ebox);
g_object_set_data (G_OBJECT (hbox), "close-button", close_button);
g_object_set_data (G_OBJECT (tab), "close-button", close_button);
return hbox;
show_tabs = (num > 1);
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs);
}
static void
gtr_notebook_init (GtrNotebook * notebook)
{
notebook->priv = GTR_NOTEBOOK_GET_PRIVATE (notebook);
GtrNotebookPrivate *priv = notebook->priv;
priv->pages = NULL;
}
static void
gtr_notebook_finalize (GObject * object)
{
GtrNotebook *notebook = GTR_NOTEBOOK (object);
if (notebook->priv->pages)
g_list_free (notebook->priv->pages);
G_OBJECT_CLASS (gtr_notebook_parent_class)->finalize (object);
}
......@@ -203,7 +121,7 @@ gtr_notebook_class_init (GtrNotebookClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (GtrNotebookPrivate));
//g_type_class_add_private (klass, sizeof (GtrNotebookPrivate));
object_class->finalize = gtr_notebook_finalize;
......@@ -242,7 +160,6 @@ gtr_notebook_new ()
void
gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab)
{
GtrNotebookPrivate *priv = notebook->priv;
GtrPo *po;
GtkWidget *label;
......@@ -251,20 +168,11 @@ gtr_notebook_add_page (GtrNotebook * notebook, GtrTab * tab)
po = gtr_tab_get_po (tab);
label = build_tab_label (notebook, tab);
sync_name (po, NULL, label);
g_signal_connect_object (po,
"notify::state", G_CALLBACK (sync_name), label, 0);
label = create_tab_label (notebook, tab);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), GTK_WIDGET (tab), label);
priv->pages = g_list_append (priv->pages, tab);
if (g_list_length (notebook->priv->pages) == 1)
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
else
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), TRUE);
update_tabs_visibility (notebook);
}
/**
......@@ -284,12 +192,12 @@ gtr_notebook_remove_page (GtrNotebook * notebook, gint page_num)
tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page_num);
if (page_num != -1)
gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
notebook->priv->pages = g_list_remove (notebook->priv->pages, tab);
{
remove_tab_label (notebook, GTR_TAB (tab));
gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), page_num);
}
if (g_list_length (notebook->priv->pages) == 1)
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
update_tabs_visibility (notebook);
}
/**
......
......@@ -58,65 +58,89 @@
G_DEFINE_TYPE (GtrPo, gtr_po, G_TYPE_OBJECT)
struct _GtrPoPrivate
{
GFile *location;
/* Gettext's file handle */
po_file_t gettext_po_file;
struct _GtrPoPrivate
{
GFile *location;
/* Gettext's file handle */
po_file_t gettext_po_file;
/* Message iter */
po_message_iterator_t iter;
/* Message iter */
po_message_iterator_t iter;
/* The message domains in this file */
GList *domains;
/* The message domains in this file */
GList *domains;
/* Parsed list of GtrMsgs for the current domains' messagelist */
GList *messages;
/* Parsed list of GtrMsgs for the current domains' messagelist */
GList *messages;
/* A pointer to the currently displayed message */
GList *current;
/* A pointer to the currently displayed message */
GList *current;
/* The obsolete messages are stored within this gchar. */
gchar *obsolete;
/* The obsolete messages are stored within this gchar. */
gchar *obsolete;
/* Is the file write-permitted? (read-only) */
gboolean no_write_perms;
/* Is the file write-permitted? (read-only) */
gboolean no_write_perms;
/* Translated entries count */
guint translated;
/* Translated entries count */
guint translated;
/* Fuzzy entries count */
guint fuzzy;
/* Fuzzy entries count */
guint fuzzy;
/* Autosave timeout timer */
guint autosave_timeout;
/* Autosave timeout timer */
guint autosave_timeout;
/* Header object */
GtrHeader *header;
/* Header object */
GtrHeader *header;
GtrPoState state;
GtrPoState state;
/* Marks if the file was changed; */
guint file_changed:1;
};
/* Marks if the file was changed; */
guint file_changed : 1;
};
enum
{
PROP_0,
PROP_STATE
};
enum
{
PROP_0,
PROP_LOCATION,
PROP_STATE
};
static gchar *message_error = NULL;
static gchar *message_error = NULL;
static void
gtr_po_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
static void
gtr_po_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtrPo *po = GTR_PO (object);
switch (prop_id)
{
case PROP_LOCATION:
gtr_po_set_location (po, G_FILE (g_value_get_object (value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtr_po_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
{
GtrPo *po = GTR_PO (object);
switch (prop_id)
{
case PROP_LOCATION:
g_value_take_object (value, gtr_po_get_location (po));
break;
case PROP_STATE:
g_value_set_enum (value, gtr_po_get_state (po));
break;
......@@ -208,6 +232,15 @@ gtr_po_class_init (GtrPoClass * klass)
object_class->finalize = gtr_po_finalize;
object_class->dispose = gtr_po_dispose;
object_class->get_property = gtr_po_get_property;
object_class->set_property = gtr_po_set_property;
g_object_class_install_property (object_class,
PROP_LOCATION,
g_param_spec_object ("location",
"Location",
"The po's location",
G_TYPE_FILE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STATE,
......@@ -623,9 +656,15 @@ gtr_po_set_location (GtrPo * po, GFile * location)
g_return_if_fail (GTR_IS_PO (po));
if (po->priv->location)
g_object_unref (po->priv->location);
{
if (g_file_equal (po->priv->location, location))
return;
g_object_unref (po->priv->location);
}
po->priv->location = g_file_dup (location);
g_object_notify (G_OBJECT (po), "location");
}
/**
......
/*
* gtr-tab-label.c
* This file is part of gtranslator
*
* Copyright (C) 2010 - Paolo Borelli
*
* 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 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "gtr-tab-label.h"
#include "gtr-close-button.h"
#define GTR_TAB_LABEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GTR_TYPE_TAB_LABEL, GtrTabLabelPrivate))
/* Signals */
enum
{
CLOSE_CLICKED,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_TAB
};
struct _GtrTabLabelPrivate
{
GtrTab *tab;
GtkWidget *ebox;
GtkWidget *close_button;
GtkWidget *spinner;
GtkWidget *icon;
GtkWidget *label;
gboolean close_button_sensitive;
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GtrTabLabel, gtr_tab_label, GTK_TYPE_HBOX)
static void
gtr_tab_label_finalize (GObject *object)
{
G_OBJECT_CLASS (gtr_tab_label_parent_class)->finalize (object);
}
static void
gtr_tab_label_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtrTabLabel *tab_label = GTR_TAB_LABEL (object);
switch (prop_id)
{
case PROP_TAB:
tab_label->priv->tab = GTR_TAB (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtr_tab_label_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtrTabLabel *tab_label = GTR_TAB_LABEL (object);
switch (prop_id)
{
case PROP_TAB:
g_value_set_object (value, tab_label->priv->tab);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
close_button_clicked_cb (GtkWidget *widget,
GtrTabLabel *tab_label)
{
g_signal_emit (tab_label, signals[CLOSE_CLICKED], 0, NULL);
}
static void
sync_tip (GtrTab *tab, GtrTabLabel *tab_label)
{
gchar *str;
str = _gtr_tab_get_tooltips (tab);
g_return_if_fail (str != NULL);
gtk_widget_set_tooltip_markup (tab_label->priv->ebox, str);