Re: [gedit-list] close buttons on tabs



Hi James,
	I have applied your patch.
Great work!!!
I have changed it a bit in order to be able to call gedit_file_close to
close the right view.
Like you, I cannot figure how to reduce the size of the tab.
I'm attaching my patch here.
Could you please give a look at it (you are the responsible for this
task ;-).

Ciao,
Paolo

P.S. Since I'm lazy, the patch lacks a ChangeLog entry. I'm giving the
bad example.


-- 
Paolo Maggi                      E-mail: maggi athena polito it
Dip. Automatica e Informatica    Tel.  : + 39 011 564 7078 
Politecnico di Torino            Fax   : + 39 011 564 7099

A Bugless Program is an Abstract Theoretical Concept.


? gedit_jwillcox_close_buttons_v2.diff
? gedit_paolo_close_buttons_v3.diff
? src/.gedit-mdi-child.c.swp
? src/prova.txt
Index: src/bonobo-mdi-child.c
===================================================================
RCS file: /cvs/gnome/gedit/src/bonobo-mdi-child.c,v
retrieving revision 1.6
diff -u -r1.6 bonobo-mdi-child.c
--- src/bonobo-mdi-child.c	18 Mar 2002 15:21:49 -0000	1.6
+++ src/bonobo-mdi-child.c	28 Aug 2002 09:56:12 -0000
@@ -40,7 +40,7 @@
 static void       bonobo_mdi_child_instance_init    (BonoboMDIChild *);
 static void       bonobo_mdi_child_finalize         (GObject *);
 
-static GtkWidget *bonobo_mdi_child_set_label        (BonoboMDIChild *, GtkWidget *, gpointer);
+static GtkWidget *bonobo_mdi_child_set_label        (BonoboMDIChild *, GtkWidget *, GtkWidget *, gpointer);
 static GtkWidget *bonobo_mdi_child_create_view      (BonoboMDIChild *);
 
 static void bonobo_mdi_child_real_name_changed (BonoboMDIChild *child, gchar* old_name);
@@ -125,10 +125,11 @@
  * should (obviously) NOT call the parent class handler!
  */
 static GtkWidget *
-bonobo_mdi_child_set_label (BonoboMDIChild *child, GtkWidget *old_label, gpointer data)
+bonobo_mdi_child_set_label (BonoboMDIChild *child, GtkWidget *view, GtkWidget *old_label, gpointer data)
 {
 	g_return_val_if_fail (BONOBO_IS_MDI_CHILD (child), NULL);
 	g_return_val_if_fail (child->priv != NULL, NULL);
+	g_return_val_if_fail (view != NULL, NULL);
 
 	if (old_label != NULL) 
 	{
Index: src/bonobo-mdi-child.h
===================================================================
RCS file: /cvs/gnome/gedit/src/bonobo-mdi-child.h,v
retrieving revision 1.2
diff -u -r1.2 bonobo-mdi-child.h
--- src/bonobo-mdi-child.h	18 Mar 2002 15:21:49 -0000	1.2
+++ src/bonobo-mdi-child.h	28 Aug 2002 09:56:12 -0000
@@ -55,7 +55,7 @@
 typedef GtkWidget *(*BonoboMDIChildViewCreator) (BonoboMDIChild *, gpointer);
 typedef GList     *(*BonoboMDIChildMenuCreator) (BonoboMDIChild *, GtkWidget *, gpointer);
 typedef gchar     *(*BonoboMDIChildConfigFunc)  (BonoboMDIChild *, gpointer);
-typedef GtkWidget *(*BonoboMDIChildLabelFunc)   (BonoboMDIChild *, GtkWidget *, gpointer);
+typedef GtkWidget *(*BonoboMDIChildLabelFunc)   (BonoboMDIChild *, GtkWidget *, GtkWidget *, gpointer);
 
 /* 
  * Note that if you override the set_label virtual function, it should return
Index: src/bonobo-mdi.c
===================================================================
RCS file: /cvs/gnome/gedit/src/bonobo-mdi.c,v
retrieving revision 1.24
diff -u -r1.24 bonobo-mdi.c
--- src/bonobo-mdi.c	16 Aug 2002 21:30:46 -0000	1.24
+++ src/bonobo-mdi.c	28 Aug 2002 09:56:12 -0000
@@ -86,7 +86,7 @@
 static void            set_active_view          (BonoboMDI *, GtkWidget *);
 
 /* convenience functions that call child's "virtual" functions */
-static GtkWidget      *child_set_label         (BonoboMDIChild *, GtkWidget *);
+static GtkWidget      *child_set_label         (BonoboMDIChild *, GtkWidget *, GtkWidget *);
 
 static void 	       child_name_changed 	(BonoboMDIChild *mdi_child, 
 						 gchar* old_name, 
@@ -408,10 +408,10 @@
 }
 
 static GtkWidget *
-child_set_label (BonoboMDIChild *child, GtkWidget *label)
+child_set_label (BonoboMDIChild *child, GtkWidget *view, GtkWidget *label)
 {
 	GtkWidget *w;
-	w = BONOBO_MDI_CHILD_GET_CLASS (child)->set_label (child, label, NULL);
+	w = BONOBO_MDI_CHILD_GET_CLASS (child)->set_label (child, view, label, NULL);
 	
 	return w;
 }
@@ -875,7 +875,7 @@
 
 	child = bonobo_mdi_get_child_from_view (view);
 
-	title = child_set_label (child, NULL);
+	title = child_set_label (child, view, NULL);
 
 	gtk_notebook_append_page (book, view, title);
 
@@ -1834,7 +1834,7 @@
 	{
 		view = GTK_WIDGET (view_node->data);
 
-		title = child_set_label (child, NULL);
+		title = child_set_label (child, view, NULL);
 		
 		gtk_notebook_set_tab_label (GTK_NOTEBOOK (view->parent), view, title);
 		
Index: src/gedit-mdi-child.c
===================================================================
RCS file: /cvs/gnome/gedit/src/gedit-mdi-child.c,v
retrieving revision 1.6
diff -u -r1.6 gedit-mdi-child.c
--- src/gedit-mdi-child.c	14 May 2002 09:46:38 -0000	1.6
+++ src/gedit-mdi-child.c	28 Aug 2002 09:56:16 -0000
@@ -32,6 +32,8 @@
 #include "gedit-debug.h"
 #include "gedit-view.h"
 #include "gedit-marshal.h"
+#include "gedit-file.h"
+
 
 struct _GeditMDIChildPrivate
 {
@@ -61,7 +63,13 @@
 						gboolean can, GeditMDIChild* child);
 
 static gchar* gedit_mdi_child_get_config_string (BonoboMDIChild *child, gpointer data);
-		
+
+
+static GtkWidget * gedit_mdi_child_set_label (BonoboMDIChild *child,
+					      GtkWidget *view,					
+                                              GtkWidget *old_label,
+					      gpointer data);
+
 static BonoboMDIChildClass *parent_class = NULL;
 static guint mdi_child_signals[LAST_SIGNAL] = { 0 };
 
@@ -132,6 +140,10 @@
 
 	BONOBO_MDI_CHILD_CLASS (klass)->get_config_string = 
 		(BonoboMDIChildConfigFunc)(gedit_mdi_child_get_config_string);
+
+	BONOBO_MDI_CHILD_CLASS (klass)->set_label = 
+		(BonoboMDIChildLabelFunc)(gedit_mdi_child_set_label);
+
 }
 
 static void 
@@ -352,4 +364,72 @@
 	c = GEDIT_MDI_CHILD (child);
 	
 	return gedit_document_get_raw_uri (c->document);
+}
+
+static void
+gedit_mdi_child_tab_close_clicked (GtkWidget *button, GtkWidget *view)
+{
+	gedit_debug (DEBUG_MDI, "");
+
+	g_return_if_fail (GEDIT_IS_VIEW (view));
+
+	gedit_file_close (view);
+}
+
+static GtkWidget *
+gedit_mdi_child_set_label (BonoboMDIChild *child, GtkWidget *view,  GtkWidget *old_hbox,
+                           gpointer data)
+{
+	GtkWidget *ret;
+	gchar *name;
+	
+	gedit_debug (DEBUG_MDI, "");
+
+	g_return_val_if_fail (child != NULL, NULL);
+	g_return_val_if_fail (GEDIT_IS_MDI_CHILD (child), NULL);
+	g_return_val_if_fail (GEDIT_IS_VIEW (view), NULL);
+
+	name = bonobo_mdi_child_get_name (child);
+
+	if (old_hbox != NULL) 
+	{
+		GtkWidget *label = g_object_get_data (G_OBJECT (old_hbox),
+				"label");
+		gtk_label_set_text (GTK_LABEL (label), name);
+		ret = old_hbox;
+	} 
+	else 
+	{
+		GtkWidget *hbox;
+		GtkWidget *label;
+		GtkWidget *button;
+		GtkWidget *image;
+
+		label = gtk_label_new (name);
+		gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+
+		button = gtk_button_new ();
+		gtk_container_set_border_width (GTK_CONTAINER (button), 0);
+
+		g_signal_connect (button, "clicked",
+				  G_CALLBACK (gedit_mdi_child_tab_close_clicked),
+				  view);
+		
+		gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+		image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+		gtk_container_add (GTK_CONTAINER (button), image);
+
+		hbox = gtk_hbox_new (FALSE, 2);
+		gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0);
+		gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+		
+		g_object_set_data (G_OBJECT (hbox), "label", label);
+
+		gtk_widget_show_all (hbox);
+		ret = hbox;
+	}
+
+	g_free (name);
+
+	return ret;
 }
Index: src/gedit-ui.xml
===================================================================
RCS file: /cvs/gnome/gedit/src/gedit-ui.xml,v
retrieving revision 1.29
diff -u -r1.29 gedit-ui.xml
--- src/gedit-ui.xml	9 Jul 2002 12:07:26 -0000	1.29
+++ src/gedit-ui.xml	28 Aug 2002 09:56:21 -0000
@@ -299,7 +299,6 @@
 	<toolitem name="FileNew" verb=""/>
 	<toolitem name="FileOpen" verb=""/>
 	<toolitem name="FileSave" verb=""/>
-	<toolitem name="FileClose" verb=""/>
 
 	<separator/>
 


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