[libgda] GdaBrowser: allow notebook's tab label changes
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] GdaBrowser: allow notebook's tab label changes
- Date: Sun, 23 Aug 2009 20:20:17 +0000 (UTC)
commit cfd8491b22461e208340ceb2619cba3fd8506de9
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Aug 21 15:05:21 2009 +0200
GdaBrowser: allow notebook's tab label changes
tools/browser/browser-page.c | 52 ++++++++--
tools/browser/browser-page.h | 10 ++-
tools/browser/browser-perspective.c | 11 ++
tools/browser/browser-perspective.h | 3 +
tools/browser/schema-browser/relations-diagram.c | 106 ++++++++++++++++---
.../schema-browser/schema-browser-perspective.c | 59 +++++++----
tools/browser/schema-browser/table-info.c | 17 +++
tools/browser/support.c | 2 +-
8 files changed, 208 insertions(+), 52 deletions(-)
---
diff --git a/tools/browser/browser-page.c b/tools/browser/browser-page.c
index 1867ae4..c29ac9b 100644
--- a/tools/browser/browser-page.c
+++ b/tools/browser/browser-page.c
@@ -21,6 +21,7 @@
*/
#include "browser-page.h"
+#include "browser-perspective.h"
static GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
static void browser_page_class_init (gpointer g_class);
@@ -67,18 +68,18 @@ browser_page_class_init (gpointer g_class)
/**
* browser_page_get_actions_group
- * @pers:
+ * @page:
* @instance: a GtkWidget which has been returned by a previous call to browser_page_create()
*
* Returns: a new #GtkActionGroup
*/
GtkActionGroup *
-browser_page_get_actions_group (BrowserPage *pers)
+browser_page_get_actions_group (BrowserPage *page)
{
- g_return_val_if_fail (IS_BROWSER_PAGE (pers), NULL);
+ g_return_val_if_fail (IS_BROWSER_PAGE (page), NULL);
- if (BROWSER_PAGE_GET_CLASS (pers)->i_get_actions_group)
- return (BROWSER_PAGE_GET_CLASS (pers)->i_get_actions_group) (pers);
+ if (BROWSER_PAGE_GET_CLASS (page)->i_get_actions_group)
+ return (BROWSER_PAGE_GET_CLASS (page)->i_get_actions_group) (page);
else
return NULL;
}
@@ -88,12 +89,45 @@ browser_page_get_actions_group (BrowserPage *pers)
*
*/
const gchar *
-browser_page_get_actions_ui (BrowserPage *pers)
+browser_page_get_actions_ui (BrowserPage *page)
{
- g_return_val_if_fail (IS_BROWSER_PAGE (pers), NULL);
+ g_return_val_if_fail (IS_BROWSER_PAGE (page), NULL);
- if (BROWSER_PAGE_GET_CLASS (pers)->i_get_actions_ui)
- return (BROWSER_PAGE_GET_CLASS (pers)->i_get_actions_ui) (pers);
+ if (BROWSER_PAGE_GET_CLASS (page)->i_get_actions_ui)
+ return (BROWSER_PAGE_GET_CLASS (page)->i_get_actions_ui) (page);
else
return NULL;
}
+
+/**
+ * browser_page_get_perspective
+ *
+ * Finds the BrowserPerspective in which @page is.
+ */
+BrowserPerspective *
+browser_page_get_perspective (BrowserPage *page)
+{
+ GtkWidget *wid;
+ for (wid = gtk_widget_get_parent (GTK_WIDGET (page)); wid; wid = gtk_widget_get_parent (wid))
+ if (IS_BROWSER_PERSPECTIVE (wid))
+ return BROWSER_PERSPECTIVE (wid);
+ return NULL;
+}
+
+/**
+ * browser_page_get_tab_label
+ *
+ * Returns: a new #GtkWidget, or %NULL
+ */
+GtkWidget *
+browser_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button)
+{
+ g_return_val_if_fail (IS_BROWSER_PAGE (page), NULL);
+
+ if (out_close_button)
+ *out_close_button = NULL;
+ if (BROWSER_PAGE_GET_CLASS (page)->i_get_tab_label)
+ return (BROWSER_PAGE_GET_CLASS (page)->i_get_tab_label) (page, out_close_button);
+ else
+ return NULL;
+}
diff --git a/tools/browser/browser-page.h b/tools/browser/browser-page.h
index ce507fa..937ea26 100644
--- a/tools/browser/browser-page.h
+++ b/tools/browser/browser-page.h
@@ -40,12 +40,16 @@ struct _BrowserPageIface {
/* virtual table */
GtkActionGroup *(* i_get_actions_group) (BrowserPage *page);
const gchar *(* i_get_actions_ui) (BrowserPage *page);
+ GtkWidget *(* i_get_tab_label) (BrowserPage *page, GtkWidget **out_close_button);
};
-GType browser_page_get_type (void) G_GNUC_CONST;
+GType browser_page_get_type (void) G_GNUC_CONST;
-GtkActionGroup *browser_page_get_actions_group (BrowserPage *page);
-const gchar *browser_page_get_actions_ui (BrowserPage *page);
+GtkActionGroup *browser_page_get_actions_group (BrowserPage *page);
+const gchar *browser_page_get_actions_ui (BrowserPage *page);
+
+BrowserPerspective *browser_page_get_perspective (BrowserPage *page);
+GtkWidget *browser_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button);
G_END_DECLS
diff --git a/tools/browser/browser-perspective.c b/tools/browser/browser-perspective.c
index 6b8db6d..55f0eae 100644
--- a/tools/browser/browser-perspective.c
+++ b/tools/browser/browser-perspective.c
@@ -21,6 +21,7 @@
*/
#include "browser-perspective.h"
+#include "browser-page.h"
static GStaticRecMutex init_mutex = G_STATIC_REC_MUTEX_INIT;
static void browser_perspective_class_init (gpointer g_class);
@@ -97,3 +98,13 @@ browser_perspective_get_actions_ui (BrowserPerspective *pers)
else
return NULL;
}
+
+void
+browser_perspective_page_tab_label_change (BrowserPerspective *pers, BrowserPage *page)
+{
+ g_return_if_fail (IS_BROWSER_PERSPECTIVE (pers));
+ g_return_if_fail (IS_BROWSER_PAGE (page));
+
+ if (BROWSER_PERSPECTIVE_GET_CLASS (pers)->i_page_tab_label_change)
+ (BROWSER_PERSPECTIVE_GET_CLASS (pers)->i_page_tab_label_change) (pers, page);
+}
diff --git a/tools/browser/browser-perspective.h b/tools/browser/browser-perspective.h
index 9c44e37..824c757 100644
--- a/tools/browser/browser-perspective.h
+++ b/tools/browser/browser-perspective.h
@@ -40,12 +40,15 @@ struct _BrowserPerspectiveIface {
/* virtual table */
GtkActionGroup *(* i_get_actions_group) (BrowserPerspective *perspective);
const gchar *(* i_get_actions_ui) (BrowserPerspective *perspective);
+ void (* i_page_tab_label_change) (BrowserPerspective *perspective, BrowserPage *page);
};
GType browser_perspective_get_type (void) G_GNUC_CONST;
GtkActionGroup *browser_perspective_get_actions_group (BrowserPerspective *perspective);
const gchar *browser_perspective_get_actions_ui (BrowserPerspective *perspective);
+void browser_perspective_page_tab_label_change (BrowserPerspective *perspective,
+ BrowserPage *page);
G_END_DECLS
diff --git a/tools/browser/schema-browser/relations-diagram.c b/tools/browser/schema-browser/relations-diagram.c
index da2533c..c26507d 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -29,6 +29,8 @@
#include "../canvas/browser-canvas-db-relations.h"
#include <gdk/gdkkeysyms.h>
#include "../common/popup-container.h"
+#include "../browser-page.h"
+#include "../browser-perspective.h"
struct _RelationsDiagramPrivate {
BrowserConnection *bcnc;
@@ -55,7 +57,12 @@ static void relations_diagram_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
+/* BrowserPage interface */
+static void relations_diagram_page_init (BrowserPageIface *iface);
+static GtkWidget *relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button);
+
static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram);
+static void favorites_changed_cb (BrowserConnection *bcnc, RelationsDiagram *diagram);
static void relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **error);
/* properties */
@@ -90,6 +97,13 @@ relations_diagram_class_init (RelationsDiagramClass *klass)
object_class->dispose = relations_diagram_dispose;
}
+static void
+relations_diagram_page_init (BrowserPageIface *iface)
+{
+ iface->i_get_actions_group = NULL;
+ iface->i_get_actions_ui = NULL;
+ iface->i_get_tab_label = relations_diagram_page_get_tab_label;
+}
static void
relations_diagram_init (RelationsDiagram *diagram, RelationsDiagramClass *klass)
@@ -109,6 +123,8 @@ relations_diagram_dispose (GObject *object)
if (diagram->priv->bcnc) {
g_signal_handlers_disconnect_by_func (diagram->priv->bcnc,
G_CALLBACK (meta_changed_cb), diagram);
+ g_signal_handlers_disconnect_by_func (diagram->priv->bcnc,
+ G_CALLBACK (favorites_changed_cb), diagram);
g_object_unref (diagram->priv->bcnc);
}
@@ -139,7 +155,14 @@ relations_diagram_get_type (void)
0,
(GInstanceInitFunc) relations_diagram_init
};
+ static GInterfaceInfo page_info = {
+ (GInterfaceInitFunc) relations_diagram_page_init,
+ NULL,
+ NULL
+ };
+
type = g_type_register_static (GTK_TYPE_VBOX, "RelationsDiagram", &info, 0);
+ g_type_add_interface_static (type, BROWSER_PAGE_TYPE, &page_info);
}
return type;
}
@@ -174,6 +197,13 @@ meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, RelationsDiagr
g_object_set (G_OBJECT (diagram->priv->canvas), "meta-struct", mstruct, NULL);
}
+static void
+favorites_changed_cb (BrowserConnection *bcnc, RelationsDiagram *diagram)
+{
+ if (diagram->priv->fav_id >= 0)
+ relations_diagram_set_fav_id (diagram, diagram->priv->fav_id, NULL);
+}
+
/*
* POPUP
*/
@@ -194,7 +224,7 @@ real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
fav.name = gtk_editable_get_chars (GTK_EDITABLE (diagram->priv->name_entry), 0, -1);
if (!*fav.name) {
g_free (fav.name);
- fav.name = g_strdup ("Diagram #0");
+ fav.name = g_strdup (_("Diagram"));
}
fav.contents = str;
@@ -280,6 +310,9 @@ relations_diagram_new (BrowserConnection *bcnc)
diagram->priv->bcnc = g_object_ref (bcnc);
g_signal_connect (diagram->priv->bcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), diagram);
+ g_signal_connect (bcnc, "favorites-changed",
+ G_CALLBACK (favorites_changed_cb), diagram);
+
/* header */
GtkWidget *hbox, *wid;
@@ -316,7 +349,7 @@ relations_diagram_new (BrowserConnection *bcnc)
mstruct = browser_connection_get_meta_struct (diagram->priv->bcnc);
if (mstruct)
meta_changed_cb (diagram->priv->bcnc, mstruct, diagram);
-
+
return (GtkWidget*) diagram;
}
@@ -420,22 +453,33 @@ relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **e
g_return_if_fail (IS_RELATIONS_DIAGRAM (diagram));
BrowserFavoritesAttributes fav;
- if (! browser_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
- fav_id, &fav, error))
- return;
-
- gchar *str, *tmp;
- tmp = g_markup_printf_escaped (_("'%s' diagram"), fav.name);
- str = g_strdup_printf ("<b>%s</b>\n%s", _("Relations diagram"), tmp);
- g_free (tmp);
- cc_gray_bar_set_text (diagram->priv->header, str);
- g_free (str);
-
- diagram->priv->fav_id = fav.id;
+ if ((fav_id >=0) &&
+ browser_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ fav_id, &fav, error)) {
+ gchar *str, *tmp;
+ tmp = g_markup_printf_escaped (_("'%s' diagram"), fav.name);
+ str = g_strdup_printf ("<b>%s</b>\n%s", _("Relations diagram"), tmp);
+ g_free (tmp);
+ cc_gray_bar_set_text (diagram->priv->header, str);
+ g_free (str);
+
+ diagram->priv->fav_id = fav.id;
+
+ browser_favorites_reset_attributes (&fav);
+ }
+ else {
+ gchar *str;
+ str = g_strdup_printf ("<b>%s</b>\n%s", _("Relations diagram"), _("Unsaved diagram"));
+ cc_gray_bar_set_text (diagram->priv->header, str);
+ g_free (str);
+ diagram->priv->fav_id = -1;
+ }
- g_free (fav.name);
- g_free (fav.descr);
- g_free (fav.contents);
+ /* update notebook's tab label */
+ BrowserPerspective *pers;
+ pers = browser_page_get_perspective (BROWSER_PAGE (diagram));
+ if (pers)
+ browser_perspective_page_tab_label_change (pers, BROWSER_PAGE (diagram));
}
/**
@@ -448,3 +492,31 @@ relations_diagram_get_fav_id (RelationsDiagram *diagram)
g_return_val_if_fail (IS_RELATIONS_DIAGRAM (diagram), -1);
return diagram->priv->fav_id;
}
+
+static GtkWidget *
+relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button)
+{
+ GtkWidget *wid;
+ RelationsDiagram *diagram;
+ gchar *tab_name = NULL;
+ GdkPixbuf *table_pixbuf;
+
+ diagram = RELATIONS_DIAGRAM (page);
+ if (diagram->priv->fav_id > 0) {
+ BrowserFavoritesAttributes fav;
+ if (browser_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ diagram->priv->fav_id, &fav, NULL)) {
+ tab_name = g_strdup (fav.name);
+ browser_favorites_reset_attributes (&fav);
+ }
+ }
+ if (!tab_name)
+ tab_name = g_strdup (_("Diagram"));
+
+ table_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_DIAGRAM);
+ wid = browser_make_tab_label_with_pixbuf (tab_name,
+ table_pixbuf,
+ out_close_button ? TRUE : FALSE, out_close_button);
+ g_free (tab_name);
+ return wid;
+}
diff --git a/tools/browser/schema-browser/schema-browser-perspective.c b/tools/browser/schema-browser/schema-browser-perspective.c
index 6fcb1f0..c18dbb2 100644
--- a/tools/browser/schema-browser/schema-browser-perspective.c
+++ b/tools/browser/schema-browser/schema-browser-perspective.c
@@ -41,6 +41,8 @@ static void schema_browser_perspective_dispose (GObject *object);
static void schema_browser_perspective_perspective_init (BrowserPerspectiveIface *iface);
static GtkActionGroup *schema_browser_perspective_get_actions_group (BrowserPerspective *perspective);
static const gchar *schema_browser_perspective_get_actions_ui (BrowserPerspective *perspective);
+static void schema_browser_perspective_page_tab_label_change (BrowserPerspective *perspective, BrowserPage *page);
+
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
@@ -98,6 +100,7 @@ schema_browser_perspective_perspective_init (BrowserPerspectiveIface *iface)
{
iface->i_get_actions_group = schema_browser_perspective_get_actions_group;
iface->i_get_actions_ui = schema_browser_perspective_get_actions_ui;
+ iface->i_page_tab_label_change = schema_browser_perspective_page_tab_label_change;
}
@@ -326,6 +329,25 @@ schema_browser_perspective_get_actions_ui (BrowserPerspective *bpers)
return ui_actions_info;
}
+static void
+schema_browser_perspective_page_tab_label_change (BrowserPerspective *perspective, BrowserPage *page)
+{
+ SchemaBrowserPerspective *bpers;
+ GtkWidget *tab_label;
+ GtkWidget *close_btn;
+
+ bpers = SCHEMA_BROWSER_PERSPECTIVE (perspective);
+ tab_label = browser_page_get_tab_label (page, &close_btn);
+ if (tab_label) {
+ gtk_notebook_set_tab_label (bpers->priv->notebook, GTK_WIDGET (page), tab_label);
+ g_signal_connect (close_btn, "clicked",
+ G_CALLBACK (close_button_clicked_cb), page);
+
+ tab_label = browser_page_get_tab_label (page, NULL);
+ gtk_notebook_set_menu_label (bpers->priv->notebook, GTK_WIDGET (page), tab_label);
+ }
+}
+
#ifdef HAVE_GOOCANVAS
/**
* schema_browser_perspective_display_diagram
@@ -366,22 +388,19 @@ schema_browser_perspective_display_diagram (SchemaBrowserPerspective *bpers, gin
if (diagram) {
GtkWidget *close_btn;
- GdkPixbuf *diagram_pixbuf;
+ GtkWidget *tab_label;
gint i;
- diagram_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_DIAGRAM);
- i = gtk_notebook_append_page (GTK_NOTEBOOK (bpers->priv->notebook), diagram,
- browser_make_tab_label_with_pixbuf (_("Diagram"),
- diagram_pixbuf,
- TRUE, &close_btn));
+ tab_label = browser_page_get_tab_label (BROWSER_PAGE (diagram), &close_btn);
+ i = gtk_notebook_append_page (GTK_NOTEBOOK (bpers->priv->notebook), diagram, tab_label);
g_signal_connect (close_btn, "clicked",
G_CALLBACK (close_button_clicked_cb), diagram);
gtk_widget_show (diagram);
- gtk_notebook_set_menu_label (GTK_NOTEBOOK (bpers->priv->notebook), diagram,
- browser_make_tab_label_with_pixbuf (_("Diagram"),
- diagram_pixbuf,
- FALSE, NULL));
+
+ tab_label = browser_page_get_tab_label (BROWSER_PAGE (diagram), NULL);
+ gtk_notebook_set_menu_label (GTK_NOTEBOOK (bpers->priv->notebook), diagram, tab_label);
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (bpers->priv->notebook), diagram,
TRUE);
@@ -423,23 +442,19 @@ schema_browser_perspective_display_table_info (SchemaBrowserPerspective *bpers,
ti = table_info_new (browser_window_get_connection (bpers->priv->bwin), table_schema, table_name);
if (ti) {
GtkWidget *close_btn;
- const gchar *tab_name;
- GdkPixbuf *table_pixbuf;
+ GtkWidget *tab_label;
+ gint i;
- table_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
- tab_name = table_short_name ? table_short_name : table_name;
- i = gtk_notebook_append_page (GTK_NOTEBOOK (bpers->priv->notebook), ti,
- browser_make_tab_label_with_pixbuf (tab_name,
- table_pixbuf,
- TRUE, &close_btn));
+ tab_label = browser_page_get_tab_label (BROWSER_PAGE (ti), &close_btn);
+ i = gtk_notebook_append_page (GTK_NOTEBOOK (bpers->priv->notebook), ti, tab_label);
g_signal_connect (close_btn, "clicked",
G_CALLBACK (close_button_clicked_cb), ti);
gtk_widget_show (ti);
- gtk_notebook_set_menu_label (GTK_NOTEBOOK (bpers->priv->notebook), ti,
- browser_make_tab_label_with_pixbuf (tab_name,
- table_pixbuf,
- FALSE, NULL));
+
+ tab_label = browser_page_get_tab_label (BROWSER_PAGE (ti), NULL);
+ gtk_notebook_set_menu_label (GTK_NOTEBOOK (bpers->priv->notebook), ti, tab_label);
+
gtk_notebook_set_current_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (bpers->priv->notebook), ti,
TRUE);
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index 042edfe..515de8b 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -62,6 +62,7 @@ static void table_info_get_property (GObject *object,
static void table_info_page_init (BrowserPageIface *iface);
static GtkActionGroup *table_info_page_get_actions_group (BrowserPage *page);
static const gchar *table_info_page_get_actions_ui (BrowserPage *page);
+static GtkWidget *table_info_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button);
static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableInfo *tinfo);
@@ -102,6 +103,7 @@ table_info_page_init (BrowserPageIface *iface)
{
iface->i_get_actions_group = table_info_page_get_actions_group;
iface->i_get_actions_ui = table_info_page_get_actions_ui;
+ iface->i_get_tab_label = table_info_page_get_tab_label;
}
static void
@@ -467,3 +469,18 @@ table_info_page_get_actions_ui (BrowserPage *page)
{
return ui_actions_info;
}
+
+static GtkWidget *
+table_info_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button)
+{
+ TableInfo *tinfo;
+ const gchar *tab_name;
+ GdkPixbuf *table_pixbuf;
+
+ tinfo = TABLE_INFO (page);
+ table_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ tab_name = tinfo->priv->table_short_name ? tinfo->priv->table_short_name : tinfo->priv->table_name;
+ return browser_make_tab_label_with_pixbuf (tab_name,
+ table_pixbuf,
+ out_close_button ? TRUE : FALSE, out_close_button);
+}
diff --git a/tools/browser/support.c b/tools/browser/support.c
index be0556c..9548c62 100644
--- a/tools/browser/support.c
+++ b/tools/browser/support.c
@@ -215,7 +215,7 @@ browser_make_tab_label_with_pixbuf (const gchar *label,
*
* Get a pointer to an internal #GdkPixbuf for the requested @type. Don't unref it!
*
- * Returns: a #GdkPixbuf, or %NULL if the icon was not found
+ * Returns: an already existing #GdkPixbuf, or %NULL if the icon was not found
*/
GdkPixbuf *
browser_get_pixbuf_icon (BrowserIconType type)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]