[anjuta/git-shell] libanjuta: Add AnjutaColumnTextView



commit ec6f5b0be05061664f12850e9e1c6557a55dcfd3
Author: James Liggett <jrliggett cox net>
Date:   Wed Jul 21 16:05:37 2010 -0700

    libanjuta: Add AnjutaColumnTextView
    
    This composite widget consists of a text view and a label that shows the
    current column location of the cursor.

 libanjuta/Makefile.am               |    7 +-
 libanjuta/anjuta-column-text-view.c |  145 +++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-column-text-view.h |   58 ++++++++++++++
 libanjuta/anjuta-glade-catalog.c    |    1 +
 libanjuta/anjuta-glade.xml          |    4 +
 5 files changed, 213 insertions(+), 2 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index 7227030..44bbe04 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -106,7 +106,9 @@ libanjuta_la_SOURCES= \
 	anjuta-file-list.c \
 	anjuta-file-list.h \
 	anjuta-pkg-config-chooser.h \
-	anjuta-pkg-config-chooser.c
+	anjuta-pkg-config-chooser.c \
+	anjuta-column-text-view.h \
+	anjuta-column-text-view.c
 
 
 
@@ -174,7 +176,8 @@ libanjuta_include = \
 	anjuta-dock.h \
 	anjuta-dock-pane.h \
 	anjuta-file-list.h \
-	anjuta-pkg-config-chooser.h
+	anjuta-pkg-config-chooser.h \
+	anjuta-column-text-view.h
 
 libanjutainclude_HEADERS = \
 	$(libanjuta_include) \
diff --git a/libanjuta/anjuta-column-text-view.c b/libanjuta/anjuta-column-text-view.c
new file mode 100644
index 0000000..a8be903
--- /dev/null
+++ b/libanjuta/anjuta-column-text-view.c
@@ -0,0 +1,145 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "anjuta-column-text-view.h"
+
+struct _AnjutaColumnTextViewPriv
+{
+	GtkWidget *text_view;
+	GtkWidget *column_label;
+};
+
+G_DEFINE_TYPE (AnjutaColumnTextView, anjuta_column_text_view, GTK_TYPE_VBOX);
+
+static void
+set_text_view_column_label (GtkTextBuffer *buffer, 
+                            GtkTextIter *location,
+                            GtkTextMark *mark,
+                            GtkLabel *column_label)
+{
+	gint column;
+	gchar *text;
+
+	column = gtk_text_iter_get_line_offset (location) + 1;
+	text = g_strdup_printf (_("Column %i"), column);
+
+	gtk_label_set_text (column_label, text);
+
+	g_free (text);
+}
+
+static void
+anjuta_column_text_view_init (AnjutaColumnTextView *self)
+{
+	GtkWidget *scrolled_window;
+	GtkTextBuffer *text_buffer;
+
+	self->priv = g_new0 (AnjutaColumnTextViewPriv, 1);
+
+	/* Text view */
+	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
+	                                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
+	                                     GTK_SHADOW_IN);
+
+	self->priv->text_view = gtk_text_view_new ();
+
+	gtk_container_add (GTK_CONTAINER (scrolled_window), self->priv->text_view);
+	gtk_box_pack_start (GTK_BOX (self), scrolled_window, TRUE, TRUE, 0);
+
+	/* Column label */
+	self->priv->column_label = gtk_label_new (_("Column 1"));
+
+	/* Right justify the label text */
+	g_object_set (G_OBJECT (self->priv->column_label), "xalign", 1.0, NULL);
+
+	/* Column change handling */
+	text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->text_view));
+
+	g_signal_connect (G_OBJECT (text_buffer), "mark-set",
+	                  G_CALLBACK (set_text_view_column_label),
+	                  self->priv->column_label);
+
+	gtk_box_pack_start (GTK_BOX (self), self->priv->column_label, FALSE, FALSE,
+	                    0);
+
+	/* Allow focusing */
+	gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
+
+	gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+anjuta_column_text_view_finalize (GObject *object)
+{
+	AnjutaColumnTextView *self;
+
+	self = ANJUTA_COLUMN_TEXT_VIEW (object);
+
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (anjuta_column_text_view_parent_class)->finalize (object);
+}
+
+static void
+anjuta_column_text_view_grab_focus (GtkWidget *widget)
+{
+	AnjutaColumnTextView *self;
+
+	self = ANJUTA_COLUMN_TEXT_VIEW (widget);
+
+	gtk_widget_grab_focus (self->priv->text_view);
+}
+
+static void
+anjuta_column_text_view_class_init (AnjutaColumnTextViewClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	object_class->finalize = anjuta_column_text_view_finalize;
+	widget_class->grab_focus = anjuta_column_text_view_grab_focus;
+}
+
+
+GtkWidget *
+anjuta_column_text_view_new (void)
+{
+	return g_object_new (ANJUTA_TYPE_COLUMN_TEXT_VIEW, NULL);
+}
+
+gchar *
+anjuta_column_text_view_get_text (AnjutaColumnTextView *self)
+{
+	GtkTextBuffer *text_buffer;
+	GtkTextIter start_iter;
+	GtkTextIter end_iter;
+	gchar *text;
+
+	text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->text_view));
+	
+	gtk_text_buffer_get_start_iter (text_buffer, &start_iter);
+	gtk_text_buffer_get_end_iter (text_buffer, &end_iter) ;
+
+	text = gtk_text_buffer_get_text (text_buffer, &start_iter, &end_iter, FALSE);
+	
+	return text;
+}
\ No newline at end of file
diff --git a/libanjuta/anjuta-column-text-view.h b/libanjuta/anjuta-column-text-view.h
new file mode 100644
index 0000000..210d236
--- /dev/null
+++ b/libanjuta/anjuta-column-text-view.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) James Liggett 2010 <jrliggett cox net>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _ANJUTA_COLUMN_TEXT_VIEW_H_
+#define _ANJUTA_COLUMN_TEXT_VIEW_H_
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define ANJUTA_TYPE_COLUMN_TEXT_VIEW             (anjuta_column_text_view_get_type ())
+#define ANJUTA_COLUMN_TEXT_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_COLUMN_TEXT_VIEW, AnjutaColumnTextView))
+#define ANJUTA_COLUMN_TEXT_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_COLUMN_TEXT_VIEW, AnjutaColumnTextViewClass))
+#define ANJUTA_IS_COLUMN_TEXT_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_COLUMN_TEXT_VIEW))
+#define ANJUTA_IS_COLUMN_TEXT_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_COLUMN_TEXT_VIEW))
+#define ANJUTA_COLUMN_TEXT_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_COLUMN_TEXT_VIEW, AnjutaColumnTextViewClass))
+
+typedef struct _AnjutaColumnTextViewClass AnjutaColumnTextViewClass;
+typedef struct _AnjutaColumnTextView AnjutaColumnTextView;
+typedef struct _AnjutaColumnTextViewPriv AnjutaColumnTextViewPriv;
+
+struct _AnjutaColumnTextViewClass
+{
+	GtkVBoxClass parent_class;
+};
+
+struct _AnjutaColumnTextView
+{
+	GtkVBox parent_instance;
+
+	AnjutaColumnTextViewPriv *priv;
+};
+
+GType anjuta_column_text_view_get_type (void) G_GNUC_CONST;
+GtkWidget *anjuta_column_text_view_new (void);
+gchar *anjuta_column_text_view_get_text (AnjutaColumnTextView *self);
+
+G_END_DECLS
+
+#endif /* _ANJUTA_COLUMN_TEXT_VIEW_H_ */
diff --git a/libanjuta/anjuta-glade-catalog.c b/libanjuta/anjuta-glade-catalog.c
index 37a4845..446856a 100644
--- a/libanjuta/anjuta-glade-catalog.c
+++ b/libanjuta/anjuta-glade-catalog.c
@@ -3,4 +3,5 @@
 #include <libanjuta/anjuta-drop-entry.h>
 #include <libanjuta/anjuta-file-list.h>
 #include <libanjuta/anjuta-pkg-config-chooser.h>
+#include <libanjuta/anjuta-column-text-view.h>
 
diff --git a/libanjuta/anjuta-glade.xml b/libanjuta/anjuta-glade.xml
index 8ebaa21..4269973 100644
--- a/libanjuta/anjuta-glade.xml
+++ b/libanjuta/anjuta-glade.xml
@@ -36,6 +36,9 @@
 		 generic-name="pkg_config_chooser">
 		</glade-widget-class>
 
+		<glade-widget-class name="AnjutaColumnTextView" title="Column Text View"
+		 generic-name="columntextview" />
+
 	</glade-widget-classes>
 
 	<glade-widget-group name="Anjuta" title="Anjuta">
@@ -43,5 +46,6 @@
 		<glade-widget-class-ref name="AnjutaDropEntry" />
 		<glade-widget-class-ref name="AnjutaFileList" />
 		<glade-widget-class-ref name="AnjutaPkgConfigChooser" />
+		<glade-widget-class-ref name="AnjutaColumnTextView" />
 	</glade-widget-group>
 </glade-catalog>



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