[glade3] * src/Makefile.am, src/glade-close-button.[ch]: Using Paolo Borelli's close button code for noteboo



commit fa97bcf9951310697cc51c364285fd05229bf7c7
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Wed Mar 31 21:46:38 2010 -0400

    	* src/Makefile.am, src/glade-close-button.[ch]: Using Paolo Borelli's close button code for notebook
    	  tab close buttons.
    
    	* src/glade-window.c:
    	  - Added option to disable toolbar in View menu and session data (bug 586194).
    	  - Added option to show notebook tabs for open projects also in the View menu and session data.
    
    	* gladeui/glade-palette.c: Made "both" mode use text horizontally again, still get alot of unwanted
    	  ellipsize here.
    
    	* gladeui/glade-project.c: Added the targets-changed signal to refresh views with data about
    	  target project versions (notebook tabs).

 ChangeLog                     |   19 +++
 gladeui/glade-palette.c       |    6 +-
 gladeui/glade-project.c       |   56 +++++++++
 gladeui/glade-project.h       |    3 +
 gladeui/glade-signal-editor.c |   18 ++-
 gladeui/glade-utils.c         |   46 ++++++++
 gladeui/glade-utils.h         |    2 +
 src/Makefile.am               |    2 +
 src/glade-close-button.c      |   80 +++++++++++++
 src/glade-close-button.h      |   56 +++++++++
 src/glade-window.c            |  254 ++++++++++++++++++++++++++++++++++++++--
 11 files changed, 519 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a738303..4b8e323 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2010-03-31  Tristan Van Berkom <tvb gnome org>
+
+	* gladeui/glade-signal-editor.c: Moved unrefs from finalize --> dispose, unload the loaded
+	  widget and disconnect from support-changed signal, avoid clearing liststore when its owning
+	  view is destroyed and we're unsetting the widget in ->dispose.
+
+	* src/Makefile.am, src/glade-close-button.[ch]: Using Paolo Borelli's close button code for notebook
+	  tab close buttons.
+
+	* src/glade-window.c: 
+	  - Added option to disable toolbar in View menu and session data (bug 586194).
+	  - Added option to show notebook tabs for open projects also in the View menu and session data.
+
+	* gladeui/glade-palette.c: Made "both" mode use text horizontally again, still get alot of unwanted 
+	  ellipsize here.
+
+	* gladeui/glade-project.c: Added the targets-changed signal to refresh views with data about 
+	  target project versions (notebook tabs).
+
 2010-03-30  Tristan Van Berkom <tvb gnome org>
 
 	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Block the glade_gtk_text_buffer_changed()
diff --git a/gladeui/glade-palette.c b/gladeui/glade-palette.c
index 3d9b5ff..d3b3a96 100644
--- a/gladeui/glade-palette.c
+++ b/gladeui/glade-palette.c
@@ -658,9 +658,9 @@ glade_palette_update_appearance (GladePalette *palette)
 
 	switch (priv->item_appearance)
        	{
-	case GLADE_ITEM_ICON_AND_LABEL: style = GTK_TOOLBAR_BOTH;   break;
-	case GLADE_ITEM_ICON_ONLY:      style = GTK_TOOLBAR_ICONS;  break;
-	case GLADE_ITEM_LABEL_ONLY:     style = GTK_TOOLBAR_TEXT;   break;
+	case GLADE_ITEM_ICON_AND_LABEL: style = GTK_TOOLBAR_BOTH_HORIZ; break;
+	case GLADE_ITEM_ICON_ONLY:      style = GTK_TOOLBAR_ICONS;      break;
+	case GLADE_ITEM_LABEL_ONLY:     style = GTK_TOOLBAR_TEXT;       break;
 	default:
 		g_assert_not_reached ();
 		break;
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 3e97d6a..5778b13 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -62,6 +62,7 @@ enum
 	CHANGED,
 	PARSE_FINISHED,
 	CONVERT_FINISHED,
+	TARGETS_CHANGED,
 	LAST_SIGNAL
 };
 
@@ -802,6 +803,22 @@ glade_project_class_init (GladeProjectClass *klass)
 			      G_TYPE_NONE,
 			      0);
 
+
+	/**
+	 * GladeProject::targets-changed:
+	 * @gladeproject: the #GladeProject which received the signal.
+	 *
+	 * Emitted when @gladeproject target versions change.
+	 */
+	glade_project_signals[TARGETS_CHANGED] =
+		g_signal_new ("targets-changed",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_FIRST,
+			      0, NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE,
+			      0);
+
 	g_object_class_install_property (object_class,
 					 PROP_MODIFIED,
 					 g_param_spec_boolean ("modified",
@@ -2861,6 +2878,8 @@ glade_project_set_target_version (GladeProject *project,
 	}
 
 	glade_project_verify_project_for_ui (project);
+
+	g_signal_emit (project, glade_project_signals [TARGETS_CHANGED], 0);
 }
 
 static void
@@ -4146,3 +4165,40 @@ glade_project_preferences (GladeProject *project)
 
 	gtk_window_present (GTK_WINDOW (project->priv->prefs_dialog));
 }
+
+
+gchar *
+glade_project_display_dependencies (GladeProject *project)
+{
+	GList *catalogs, *l;
+	GString *string;
+
+	g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
+
+	string = g_string_new ("");
+
+	catalogs = glade_project_required_libs (project);
+	for (l = catalogs; l; l = l->next)
+	{
+		gchar *catalog = l->data;
+		gint   major = 0, minor = 0;
+
+		glade_project_get_target_version (project, catalog, &major, &minor);
+
+		if (l != catalogs)
+			g_string_append (string, ", ");
+
+		/* Capitalize GTK+ */
+		if (strcmp (catalog, "gtk+") == 0)
+			g_string_append_printf (string, "GTK+ >= %d.%d", major, minor);
+		else if (major && minor)
+			g_string_append_printf (string, "%s >= %d.%d", catalog, major, minor);
+		else
+			g_string_append_printf (string, "%s", catalog);
+
+		g_free (catalog);
+	}
+	g_list_free (catalogs);
+
+	return g_string_free (string, FALSE);
+}
diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h
index f389465..f76ce6c 100644
--- a/gladeui/glade-project.h
+++ b/gladeui/glade-project.h
@@ -193,6 +193,9 @@ void          glade_project_get_target_version     (GladeProject       *project,
 void          glade_project_update_signal_support_warning (GladeWidget  *widget,
 							   GladeSignal  *signal);
 
+
+gchar        *glade_project_display_dependencies (GladeProject *project);
+
 G_END_DECLS
 
 #endif /* __GLADE_PROJECT_H__ */
diff --git a/gladeui/glade-signal-editor.c b/gladeui/glade-signal-editor.c
index dc7a41a..be6fd58 100644
--- a/gladeui/glade-signal-editor.c
+++ b/gladeui/glade-signal-editor.c
@@ -1115,8 +1115,6 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
 	g_return_if_fail (GLADE_IS_SIGNAL_EDITOR (editor));
 	g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
 
-	gtk_tree_store_clear (editor->model);
-
 	if (editor->widget != widget)
 	{
 		if (editor->widget)
@@ -1141,6 +1139,8 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
 	if (!widget)
 		return;
 
+	gtk_tree_store_clear (editor->model);
+
 	if (glade_project_get_format (glade_widget_get_project (widget)) == GLADE_PROJECT_FORMAT_GTKBUILDER)
 		gtk_tree_view_column_set_visible (editor->swapped_column_ptr, TRUE);
 	else
@@ -1362,14 +1362,18 @@ glade_signal_editor_set_property  (GObject      *object,
 }
 
 static void
-glade_signal_editor_finalize (GObject *object)
+glade_signal_editor_dispose (GObject *object)
 {
 	GladeSignalEditor *self = GLADE_SIGNAL_EDITOR (object);
+	
+	glade_signal_editor_load_widget (self, NULL);
 
-	g_object_unref (self->handler_store);
-	g_object_unref (self->userdata_store);
+	if (self->handler_store)
+		g_object_unref (self->handler_store);
+	if (self->userdata_store)
+		g_object_unref (self->userdata_store);
 
-	G_OBJECT_CLASS (glade_signal_editor_parent_class)->finalize (object);
+	G_OBJECT_CLASS (glade_signal_editor_parent_class)->dispose (object);
 }
 
 static void
@@ -1391,7 +1395,7 @@ glade_signal_editor_class_init (GladeSignalEditorClass *klass)
 	object_class->constructor = glade_signal_editor_constructor;
 	object_class->get_property = glade_signal_editor_get_property;
 	object_class->set_property = glade_signal_editor_set_property;
-	object_class->finalize = glade_signal_editor_finalize;
+	object_class->dispose = glade_signal_editor_dispose;
 	klass->handler_editing_done = glade_signal_editor_handler_editing_done_impl;
 	klass->userdata_editing_done = glade_signal_editor_userdata_editing_done_impl;
 	klass->handler_editing_started = NULL;
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index af4abad..80b5bb2 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -2346,3 +2346,49 @@ glade_utils_hijack_key_press (GtkWindow          *win,
 	return FALSE;
 }
 
+
+/* copied from gedit */
+gchar *
+glade_utils_replace_home_dir_with_tilde (const gchar *uri)
+{
+	gchar *tmp;
+	gchar *home;
+
+	g_return_val_if_fail (uri != NULL, NULL);
+
+	/* Note that g_get_home_dir returns a const string */
+	tmp = (gchar *)g_get_home_dir ();
+
+	if (tmp == NULL)
+		return g_strdup (uri);
+
+	home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
+	if (home == NULL)
+		return g_strdup (uri);
+
+	if (strcmp (uri, home) == 0)
+	{
+		g_free (home);
+		
+		return g_strdup ("~");
+	}
+
+	tmp = home;
+	home = g_strdup_printf ("%s/", tmp);
+	g_free (tmp);
+
+	if (g_str_has_prefix (uri, home))
+	{
+		gchar *res;
+
+		res = g_strdup_printf ("~/%s", uri + strlen (home));
+
+		g_free (home);
+		
+		return res;		
+	}
+
+	g_free (home);
+
+	return g_strdup (uri);
+}
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index b584688..edbf8ad 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -159,6 +159,8 @@ gint              glade_utils_hijack_key_press (GtkWindow          *win,
 						gpointer            user_data);
 	
 
+gchar           *glade_utils_replace_home_dir_with_tilde (const gchar *uri);
+
 G_END_DECLS
 
 #endif /* __GLADE_UTILS_H__ */
diff --git a/src/Makefile.am b/src/Makefile.am
index 4202205..ed147b0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,8 @@ glade_3_LDADD = $(top_builddir)/gladeui/libgladeui-1.la $(IGE_MAC_LIBS)
 glade_3_SOURCES = \
 	glade-window.c \
 	glade-window.h \
+	glade-close-button.c \
+	glade-close-button.h \
 	main.c
 
 if NATIVE_WIN32
diff --git a/src/glade-close-button.c b/src/glade-close-button.c
new file mode 100644
index 0000000..7977283
--- /dev/null
+++ b/src/glade-close-button.c
@@ -0,0 +1,80 @@
+/*
+ * glade-close-button.c
+ * This file was taken from gedit
+ *
+ * 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 "glade-close-button.h"
+
+G_DEFINE_TYPE (GladeCloseButton, glade_close_button, GTK_TYPE_BUTTON)
+
+static void
+glade_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 (glade_close_button_parent_class)->style_set (button, previous_style);
+}
+
+static void
+glade_close_button_class_init (GladeCloseButtonClass *klass)
+{
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	widget_class->style_set = glade_close_button_style_set;
+}
+
+static void
+glade_close_button_init (GladeCloseButton *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 *
+glade_close_button_new ()
+{
+	GladeCloseButton *button;
+
+	button = g_object_new (GLADE_TYPE_CLOSE_BUTTON,
+			       "relief", GTK_RELIEF_NONE,
+			       "focus-on-click", FALSE,
+			       NULL);
+
+	return GTK_WIDGET (button);
+}
+
diff --git a/src/glade-close-button.h b/src/glade-close-button.h
new file mode 100644
index 0000000..bd1195d
--- /dev/null
+++ b/src/glade-close-button.h
@@ -0,0 +1,56 @@
+/*
+ * glade-close-button.h
+ * This file was taken from gedit
+ *
+ * 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 __GLADE_CLOSE_BUTTON_H__
+#define __GLADE_CLOSE_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_CLOSE_BUTTON			(glade_close_button_get_type ())
+#define GLADE_CLOSE_BUTTON(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CLOSE_BUTTON, GladeCloseButton))
+#define GLADE_CLOSE_BUTTON_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CLOSE_BUTTON, GladeCloseButton const))
+#define GLADE_CLOSE_BUTTON_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_CLOSE_BUTTON, GladeCloseButtonClass))
+#define GLADE_IS_CLOSE_BUTTON(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CLOSE_BUTTON))
+#define GLADE_IS_CLOSE_BUTTON_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CLOSE_BUTTON))
+#define GLADE_CLOSE_BUTTON_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CLOSE_BUTTON, GladeCloseButtonClass))
+
+typedef struct _GladeCloseButton	GladeCloseButton;
+typedef struct _GladeCloseButtonClass	GladeCloseButtonClass;
+typedef struct _GladeCloseButtonPrivate	GladeCloseButtonPrivate;
+
+struct _GladeCloseButton {
+	GtkButton parent;
+};
+
+struct _GladeCloseButtonClass {
+	GtkButtonClass parent_class;
+};
+
+GType		  glade_close_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget	 *glade_close_button_new (void);
+
+G_END_DECLS
+
+#endif /* __GLADE_CLOSE_BUTTON_H__ */
diff --git a/src/glade-window.c b/src/glade-window.c
index 138a648..67f9272 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -26,6 +26,7 @@
 #include <config.h>
 
 #include "glade-window.h"
+#include "glade-close-button.h"
 
 #include <gladeui/glade.h>
 #include <gladeui/glade-design-view.h>
@@ -61,6 +62,8 @@
 #define CONFIG_KEY_HEIGHT           "height"
 #define CONFIG_KEY_DETACHED         "detached"
 #define CONFIG_KEY_MAXIMIZED        "maximized"
+#define CONFIG_KEY_SHOW_TOOLBAR     "show-toolbar"
+#define CONFIG_KEY_SHOW_TABS        "show-tabs"
 
 #define GLADE_WINDOW_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object),  \
 					  GLADE_TYPE_WINDOW,                      \
@@ -673,6 +676,77 @@ format_project_list_item_tooltip (GladeProject *project)
 }
 
 static void
+refresh_notebook_tab_for_project (GladeWindow *window, GladeProject *project)
+{
+	GtkWidget *tab_label, *label, *view, *eventbox;
+	GList     *children, *l;
+	gchar     *str;
+
+	children = gtk_container_get_children (GTK_CONTAINER (window->priv->notebook));
+	for (l = children; l; l = l->next)
+	{
+		view = l->data;
+
+		if (project == glade_design_view_get_project (GLADE_DESIGN_VIEW (view)))
+		{
+			GladeProjectFormat fmt = glade_project_get_format (project);
+			gchar *path, *deps;
+
+			tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (window->priv->notebook), view);
+			label     = g_object_get_data (G_OBJECT (tab_label), "tab-label");
+			eventbox  = g_object_get_data (G_OBJECT (tab_label), "tab-event-box");
+
+			str   = get_formatted_project_name_for_display (project, 
+									FORMAT_NAME_MARK_UNSAVED | 
+									FORMAT_NAME_MIDDLE_TRUNCATE);
+			gtk_label_set_text (GTK_LABEL (label), str);
+			g_free (str);
+
+			if (glade_project_get_path (project))
+				path = glade_utils_replace_home_dir_with_tilde (glade_project_get_path (project));
+			else
+				path = glade_project_get_name (project);
+
+
+			deps = glade_project_display_dependencies (project);
+			str =  g_markup_printf_escaped (" <b>%s</b> %s \n"
+							" %s \n"
+						        " <b>%s</b> %s \n"
+						        " <b>%s</b> %s ",
+						        _("Name:"), path,
+							glade_project_get_readonly (project) ? READONLY_INDICATOR : "",
+						        _("Format:"), 
+							fmt == GLADE_PROJECT_FORMAT_GTKBUILDER ? "GtkBuilder" : "Libglade",
+						        _("Requires:"), deps);
+
+			gtk_widget_set_tooltip_markup (eventbox, str);
+			
+			g_free (path);
+			g_free (deps);
+			g_free (str);
+
+			break;
+		}
+	}
+	g_list_free (children);
+}
+
+static void
+refresh_notebook_tabs (GladeWindow *window)
+{
+	GList *list;
+	
+	for (list = glade_app_get_projects (); list; list = list->next)
+		refresh_notebook_tab_for_project (window, GLADE_PROJECT (list->data));
+}
+
+static void
+project_targets_changed_cb (GladeProject *project, GladeWindow *window)
+{
+	refresh_notebook_tab_for_project (window, project);
+}
+
+static void
 refresh_projects_list_item (GladeWindow *window, GladeProject *project)
 {
 	GtkAction *action;
@@ -740,18 +814,24 @@ project_notify_handler_cb (GladeProject *project, GParamSpec *spec, GladeWindow
 {
 	GtkAction *action;
 
-	if (strcmp (spec->name, "modified") == 0)	
+	if (strcmp (spec->name, "path")   == 0 ||
+	    strcmp (spec->name, "format") == 0)	
+		refresh_notebook_tab_for_project (window, project);
+	else if (strcmp (spec->name, "modified") == 0)	
 	{
 		refresh_title (window);
 		refresh_projects_list_item (window, project);
 	}
 	else if (strcmp (spec->name, "read-only") == 0)	
 	{
+		refresh_notebook_tab_for_project (window, project);
+
 		action = gtk_action_group_get_action (window->priv->project_actions, "Save");
 		gtk_action_set_sensitive (action,
 				  	  !glade_project_get_readonly (project));
 	}
-	else if (strcmp (spec->name, "has-selection") == 0)	
+	else if (strcmp (spec->name, "has-selection") == 0 &&
+		 (project == glade_app_get_project ()))	
 	{
 		action = gtk_action_group_get_action (window->priv->project_actions, "Cut");
 		gtk_action_set_sensitive (action,
@@ -1166,6 +1246,7 @@ save (GladeWindow *window, GladeProject *project, const gchar *path)
 	/* refresh names */
 	refresh_title (window);
 	refresh_projects_list_item (window, project);
+	refresh_notebook_tab_for_project (window, project);
 
 	glade_util_flash_message (window->priv->statusbar,
 				  window->priv->statusbar_actions_context_id,
@@ -1631,14 +1712,24 @@ notebook_tab_added_cb (GtkNotebook *notebook,
 	g_signal_connect (G_OBJECT (project), "notify::modified",
 			  G_CALLBACK (project_notify_handler_cb),
 			  window);	
-	g_signal_connect (G_OBJECT (project), "selection-changed",
-			  G_CALLBACK (project_selection_changed_cb), window);
+	g_signal_connect (G_OBJECT (project), "notify::path",
+			  G_CALLBACK (project_notify_handler_cb),
+			  window);	
+	g_signal_connect (G_OBJECT (project), "notify::format",
+			  G_CALLBACK (project_notify_handler_cb),
+			  window);	
 	g_signal_connect (G_OBJECT (project), "notify::has-selection",
 			  G_CALLBACK (project_notify_handler_cb),
 			  window);
 	g_signal_connect (G_OBJECT (project), "notify::read-only",
 			  G_CALLBACK (project_notify_handler_cb),
 			  window);
+	g_signal_connect (G_OBJECT (project), "selection-changed",
+			  G_CALLBACK (project_selection_changed_cb), 
+			  window);
+	g_signal_connect (G_OBJECT (project), "targets-changed",
+			  G_CALLBACK (project_targets_changed_cb), 
+			  window);
 
 	/* create inspector */
 	inspector = glade_inspector_new ();
@@ -1682,6 +1773,9 @@ notebook_tab_removed_cb (GtkNotebook *notebook,
 	g_signal_handlers_disconnect_by_func (G_OBJECT (project),
 					      G_CALLBACK (project_selection_changed_cb),
 					      window);
+	g_signal_handlers_disconnect_by_func (G_OBJECT (project),
+					      G_CALLBACK (project_targets_changed_cb),
+					      window);
 
 
 	gtk_notebook_remove_page (GTK_NOTEBOOK (window->priv->inspectors_notebook), page_num);
@@ -1852,6 +1946,25 @@ toggle_dock_cb (GtkAction *action, GladeWindow *window)
 	}
 }
 
+
+static void
+toggle_toolbar_cb (GtkAction *action, GladeWindow *window)
+{
+	if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+		gtk_widget_show (window->priv->toolbar);
+	else
+		gtk_widget_hide (window->priv->toolbar);
+}
+
+static void
+toggle_tabs_cb (GtkAction *action, GladeWindow *window)
+{
+	if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
+		gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), TRUE);
+	else
+		gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), FALSE);
+}
+
 static void
 show_help_cb (GtkAction *action, GladeWindow *window)
 {
@@ -1970,7 +2083,7 @@ about_cb (GtkAction *action, GladeWindow *window)
 	static const gchar copyright[] =
 		"Copyright \xc2\xa9 2001-2006 Ximian, Inc.\n"
 		"Copyright \xc2\xa9 2001-2006 Joaquin Cuenca Abela, Paolo Borelli, et al.\n"
-		"Copyright \xc2\xa9 2001-2008 Tristan Van Berkom, Juan Pablo Ugarte, et al.";
+		"Copyright \xc2\xa9 2001-2010 Tristan Van Berkom, Juan Pablo Ugarte, et al.";
 	
 	gtk_show_about_dialog (GTK_WINDOW (window),
 			       "name", g_get_application_name (),
@@ -2014,6 +2127,8 @@ static const gchar ui_info[] =
 "      <menuitem action='Preferences'/>"
 "    </menu>"
 "    <menu action='ViewMenu'>"
+"      <menuitem action='ToolbarVisible'/>"
+"      <menuitem action='ProjectTabsVisible'/>"
 "      <menu action='PaletteAppearance'>"
 "        <menuitem action='IconsAndLabels'/>"
 "        <menuitem action='IconsOnly'/>"
@@ -2150,6 +2265,14 @@ static GtkToggleActionEntry view_entries[] = {
 	  N_("Dock the editor into the main window"),
 	  G_CALLBACK (toggle_dock_cb), TRUE },
 
+	{ "ToolbarVisible", NULL, N_("Toolbar"), NULL,
+	  N_("Show the main toolbar"),
+	  G_CALLBACK (toggle_toolbar_cb), TRUE },
+
+	{ "ProjectTabsVisible", NULL, N_("Project Tabs"), NULL,
+	  N_("Show notebook tabs for loaded projects"),
+	  G_CALLBACK (toggle_tabs_cb), TRUE },
+
 };
 static guint n_view_entries = G_N_ELEMENTS (view_entries);
 
@@ -2389,10 +2512,72 @@ create_drag_resize_tool_button (GtkToolbar *toolbar)
 	return GTK_WIDGET (button);
 }
 
+static void 
+tab_close_button_clicked_cb (GtkWidget    *close_button,
+			     GladeProject *project)
+{
+	GladeDesignView *view;
+	GladeWindow *window = GLADE_WINDOW (glade_app_get_window ());
+	gboolean close;
+
+	view = glade_design_view_get_from_project (project);
+
+	if (glade_project_get_modified (project))
+	{
+		close = confirm_close_project (window, project);
+			if (!close)
+				return;
+	}
+	do_close (window, view);
+}
+
+static GtkWidget *
+create_notebook_tab (GladeWindow *window, GladeProject *project)
+{
+	GtkWidget *tab_label, *ebox, *hbox, *close_button, *label, *dummy_label;
+
+	tab_label = gtk_hbox_new (FALSE, 4);
+	
+	ebox = gtk_event_box_new ();
+	gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
+	gtk_box_pack_start (GTK_BOX (tab_label), ebox, TRUE, TRUE, 0);
+
+	hbox = gtk_hbox_new (FALSE, 4);
+	gtk_container_add (GTK_CONTAINER (ebox), hbox);
+
+	close_button = glade_close_button_new ();
+	gtk_widget_set_tooltip_text (close_button, _("Close document"));
+	gtk_box_pack_start (GTK_BOX (tab_label), close_button, FALSE, FALSE, 0);
+
+	g_signal_connect (close_button,
+			  "clicked",
+			  G_CALLBACK (tab_close_button_clicked_cb),
+			  project);
+
+	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 (hbox), label, FALSE, FALSE, 0);
+
+	dummy_label = gtk_label_new ("");
+	gtk_box_pack_start (GTK_BOX (hbox), dummy_label, TRUE, TRUE, 0);
+
+	gtk_widget_show (ebox);
+	gtk_widget_show (hbox);
+	gtk_widget_show (close_button);
+	gtk_widget_show (label);
+	gtk_widget_show (dummy_label);
+
+	g_object_set_data (G_OBJECT (tab_label), "tab-event-box", ebox);
+	g_object_set_data (G_OBJECT (tab_label), "tab-label", label);
+
+	return tab_label;
+}
+
 static void
 add_project (GladeWindow *window, GladeProject *project)
 {
-	GtkWidget *view;
+	GtkWidget *view, *label;
 
  	g_return_if_fail (GLADE_IS_PROJECT (project));
  	
@@ -2403,9 +2588,14 @@ add_project (GladeWindow *window, GladeProject *project)
 	glade_app_add_project (project);
 	g_object_unref (project);
 
-	gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->notebook), GTK_WIDGET (view), NULL);
+	/* Custom notebook tab label (will be refreshed later) */
+	label = create_notebook_tab (window, project);
+
+	gtk_notebook_append_page (GTK_NOTEBOOK (window->priv->notebook), GTK_WIDGET (view), label);
 	gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook), -1);	
 
+	refresh_notebook_tab_for_project (window, project);
+
 	/* Kick the inspector in the balls here... */
 	glade_project_selection_changed (project);
 }
@@ -2570,9 +2760,9 @@ glade_window_open_project (GladeWindow *window,
 
 static void
 change_menu_label (GladeWindow *window,
-					const gchar *path,
-					const gchar *action_label,
-					const gchar *action_description)
+		   const gchar *path,
+		   const gchar *action_label,
+		   const gchar *action_description)
 {
 	GtkBin *bin;
 	GtkLabel *label;
@@ -2651,6 +2841,8 @@ update_ui (GladeApp *app, GladeWindow *window)
 		gtk_widget_queue_draw (GTK_WIDGET (window->priv->active_view));
 
 	refresh_undo_redo (window);
+
+	refresh_notebook_tabs (window);
 }
 
 static void
@@ -2765,6 +2957,8 @@ static void
 save_windows_config (GladeWindow *window, GKeyFile *config)
 {
 	guint i;
+	GdkWindow *gdk_window;
+	gboolean   maximized;
 
 	for (i = 0; i < N_DOCKS; ++i)
 	{
@@ -2773,11 +2967,21 @@ save_windows_config (GladeWindow *window, GKeyFile *config)
 					      dock->detached, TRUE, dock->maximized);
 	}
 
-	GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
-	gboolean maximized = gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED;
+	gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+	maximized  = gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED;
 
 	key_file_set_window_position (config, &window->priv->position, 
 				      "main", FALSE, FALSE, maximized);
+
+	g_key_file_set_boolean (config, 
+				CONFIG_GROUP_WINDOWS,
+				CONFIG_KEY_SHOW_TOOLBAR, 
+				gtk_widget_get_visible (window->priv->toolbar));
+
+	g_key_file_set_boolean (config, 
+				CONFIG_GROUP_WINDOWS,
+				CONFIG_KEY_SHOW_TABS, 
+				gtk_notebook_get_show_tabs (GTK_NOTEBOOK (window->priv->notebook)));
 }
 
 static void 
@@ -2880,6 +3084,7 @@ glade_window_set_initial_size (GladeWindow *window, GKeyFile *config)
 	};
 
 	gboolean maximized;
+
 	key_file_get_window_position (config, "main", &position, NULL, &maximized);
 	if (maximized)
 	{
@@ -2903,9 +3108,30 @@ static void
 glade_window_config_load (GladeWindow *window)
 {
 	GKeyFile *config = glade_app_get_config ();
+	gboolean show_toolbar, show_tabs;
+	GtkAction *action;
 
+	/* Initial main dimensions */
 	glade_window_set_initial_size (window, config);	
 
+	/* toolbar and tabs */
+	show_toolbar = g_key_file_get_boolean (config, CONFIG_GROUP_WINDOWS, CONFIG_KEY_SHOW_TOOLBAR, NULL);
+	show_tabs    = g_key_file_get_boolean (config, CONFIG_GROUP_WINDOWS, CONFIG_KEY_SHOW_TABS, NULL);
+
+	if (show_toolbar)
+		gtk_widget_show (window->priv->toolbar);
+	else
+		gtk_widget_hide (window->priv->toolbar);
+
+	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (window->priv->notebook), show_tabs);
+
+	action = gtk_action_group_get_action (window->priv->static_actions, "ToolbarVisible");
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_toolbar);
+
+	action = gtk_action_group_get_action (window->priv->static_actions, "ProjectTabsVisible");
+	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), show_tabs);
+
+	/* Paned positions */
 	load_paned_position (config, window->priv->left_pane, "left_pane", 200);
 	load_paned_position (config, window->priv->center_pane, "center_pane", 400);
 	load_paned_position (config, window->priv->right_pane, "right_pane", 220);
@@ -3068,7 +3294,9 @@ glade_window_init (GladeWindow *window)
 
 	/* notebook */
 	priv->notebook = gtk_notebook_new ();
-	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
+
+	/* Show tabs (user preference) */
+	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), TRUE);
 	gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
 	gtk_paned_pack2 (GTK_PANED (hpaned2), priv->notebook, TRUE, FALSE);
 	gtk_widget_show (priv->notebook);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]