[gedit] Add a close buttons to GeditDocumentsPanel



commit 078cb4bf82f32393b65ea8f598300217e80a2b61
Author: Garrett Regier <alias301 gmail com>
Date:   Sat Mar 19 13:12:19 2011 -0700

    Add a close buttons to GeditDocumentsPanel

 gedit/Makefile.am                  |    6 ++-
 gedit/gedit-cell-renderer-button.c |  104 ++++++++++++++++++++++++++++++++++++
 gedit/gedit-cell-renderer-button.h |   61 +++++++++++++++++++++
 gedit/gedit-documents-panel.c      |   43 +++++++++++++++
 4 files changed, 212 insertions(+), 2 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 914aa61..430a416 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -102,7 +102,8 @@ BUILT_SOURCES = 			\
 
 NOINST_H_FILES =			\
 	gedit-animatable.h		\
-	gedit-animated-overlay.h	\
+	gedit-animated-overlay.h        \
+	gedit-cell-renderer-button.h	\
 	gedit-close-button.h		\
 	gedit-command-line.h		\
 	gedit-dbus.h			\
@@ -173,7 +174,8 @@ libgedit_private_la_SOURCES =		\
 libgedit_c_files =			\
 	gedit-animatable.c		\
 	gedit-animated-overlay.c	\
-	gedit-app.c			\
+	gedit-app.c               	\
+	gedit-cell-renderer-button.c	\
 	gedit-close-button.c		\
 	gedit-command-line.c		\
 	gedit-commands-documents.c	\
diff --git a/gedit/gedit-cell-renderer-button.c b/gedit/gedit-cell-renderer-button.c
new file mode 100644
index 0000000..60cada4
--- /dev/null
+++ b/gedit/gedit-cell-renderer-button.c
@@ -0,0 +1,104 @@
+/*
+ * gedit-cell-renderer-button.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ * 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 "gedit-cell-renderer-button.h"
+
+G_DEFINE_TYPE (GeditCellRendererButton, gedit_cell_renderer_button, GTK_TYPE_CELL_RENDERER_PIXBUF)
+
+enum
+{
+	CLICKED,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static void
+gedit_cell_renderer_button_render (GtkCellRenderer      *cell,
+                                   cairo_t              *cr,
+                                   GtkWidget            *widget,
+                                   const GdkRectangle   *background_area,
+                                   const GdkRectangle   *cell_area,
+                                   GtkCellRendererState  flags)
+{
+  	if ((flags & GTK_CELL_RENDERER_PRELIT) == 0)
+  	{
+		return;
+	}
+
+	GTK_CELL_RENDERER_CLASS (gedit_cell_renderer_button_parent_class)->render (cell, cr, widget,
+	                                                                           background_area,
+	                                                                           cell_area,
+	                                                                           flags);
+}
+
+static gboolean
+gedit_cell_renderer_button_activate (GtkCellRenderer      *cell,
+                                     GdkEvent             *event,
+                                     GtkWidget            *widget,
+                                     const gchar          *path,
+                                     const GdkRectangle   *background_area,
+                                     const GdkRectangle   *cell_area,
+                                     GtkCellRendererState  flags)
+{
+	if (event != NULL && event->type == GDK_BUTTON_PRESS)
+	{
+		g_signal_emit (cell, signals[CLICKED], 0, path);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static void
+gedit_cell_renderer_button_class_init (GeditCellRendererButtonClass *klass)
+{
+	GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
+
+	cell_class->render = gedit_cell_renderer_button_render;
+	cell_class->activate = gedit_cell_renderer_button_activate;
+
+	signals[CLICKED] = g_signal_new ("clicked",
+		                         G_OBJECT_CLASS_TYPE (klass),
+		                         G_SIGNAL_RUN_LAST,
+		                         G_STRUCT_OFFSET (GeditCellRendererButtonClass, clicked),
+		                         NULL, NULL,
+		                         g_cclosure_marshal_VOID__STRING,
+		                         G_TYPE_NONE, 1,
+		                         G_TYPE_STRING);
+}
+
+static void
+gedit_cell_renderer_button_init (GeditCellRendererButton *button)
+{
+	g_object_set (button, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
+}
+
+GtkCellRenderer *
+gedit_cell_renderer_button_new (void)
+{
+	return g_object_new (GEDIT_TYPE_CELL_RENDERER_BUTTON, NULL);
+}
diff --git a/gedit/gedit-cell-renderer-button.h b/gedit/gedit-cell-renderer-button.h
new file mode 100644
index 0000000..2019042
--- /dev/null
+++ b/gedit/gedit-cell-renderer-button.h
@@ -0,0 +1,61 @@
+/*
+ * gedit-cell-renderer-button.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2011 - Garrett Regier
+ *
+ * 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 __GEDIT_CELL_RENDERER_BUTTON_H__
+#define __GEDIT_CELL_RENDERER_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_CELL_RENDERER_BUTTON            (gedit_cell_renderer_button_get_type ())
+#define GEDIT_CELL_RENDERER_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_CELL_RENDERER_BUTTON, GeditCellRendererButton))
+#define GEDIT_CELL_RENDERER_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_CELL_RENDERER_BUTTON, GeditCellRendererButtonClass))
+#define GEDIT_IS_CELL_RENDERER_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_CELL_RENDERER_BUTTON))
+#define GEDIT_IS_CELL_RENDERER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_CELL_RENDERER_BUTTON))
+#define GEDIT_CELL_RENDERER_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_CELL_RENDERER_BUTTON, GeditCellRendererButtonClass))
+
+typedef struct _GeditCellRendererButton      GeditCellRendererButton;
+typedef struct _GeditCellRendererButtonClass GeditCellRendererButtonClass;
+
+struct _GeditCellRendererButton
+{
+	GtkCellRendererPixbuf  parent_instance;
+};
+
+struct _GeditCellRendererButtonClass
+{
+	GtkCellRendererPixbufClass  parent_class;
+
+	void (* clicked) (GeditCellRendererButton *cell,
+	                  const gchar             *path);
+};
+
+
+GType            gedit_cell_renderer_button_get_type (void) G_GNUC_CONST;
+
+GtkCellRenderer *gedit_cell_renderer_button_new      (void);
+
+
+G_END_DECLS
+
+#endif /* __GEDIT_CELL_RENDERER_BUTTON_H__ */
diff --git a/gedit/gedit-documents-panel.c b/gedit/gedit-documents-panel.c
index 7609b83..f0b338a 100644
--- a/gedit/gedit-documents-panel.c
+++ b/gedit/gedit-documents-panel.c
@@ -37,6 +37,7 @@
 #include "gedit-utils.h"
 #include "gedit-multi-notebook.h"
 #include "gedit-notebook.h"
+#include "gedit-cell-renderer-button.h"
 
 #include <glib/gi18n.h>
 
@@ -1010,6 +1011,40 @@ treeview_row_inserted (GtkTreeModel        *tree_model,
 */
 
 static void
+close_button_clicked (GtkCellRenderer     *cell,
+                      const gchar         *path,
+                      GeditDocumentsPanel *panel)
+{
+        GtkTreeIter iter;
+        GeditTab *tab;
+        GeditNotebook *notebook;
+
+        if (!gtk_tree_model_get_iter_from_string (panel->priv->model,
+                                                  &iter, path))
+        {
+                return;
+        }
+
+        gtk_tree_model_get (panel->priv->model,
+		            &iter,
+		            NOTEBOOK_COLUMN, &notebook,
+		            TAB_COLUMN, &tab,
+		            -1);
+
+	if (tab == NULL)
+	{
+		gedit_notebook_remove_all_tabs (notebook);
+	}
+	else
+	{
+		gedit_notebook_remove_tab (notebook, tab);
+		g_object_unref (tab);
+	}
+
+	g_object_unref (notebook);
+}
+
+static void
 pixbuf_data_func (GtkTreeViewColumn   *column,
 		  GtkCellRenderer     *cell,
 		  GtkTreeModel        *model,
@@ -1101,6 +1136,14 @@ gedit_documents_panel_init (GeditDocumentsPanel *panel)
 	gtk_tree_view_append_column (GTK_TREE_VIEW (panel->priv->treeview),
 				     column);
 
+	cell = gedit_cell_renderer_button_new ();
+	g_object_set (cell, "stock-id", GTK_STOCK_CLOSE, NULL);
+	gtk_tree_view_column_pack_end (column, cell, FALSE);
+	g_signal_connect (cell,
+	                  "clicked",
+	                  G_CALLBACK (close_button_clicked),
+	                  panel);
+
 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
 
 	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);



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