[anjuta/git-shell] git: Add AnjutaFileDropEntry



commit b044eb9e93e0d8f78b4cd2da963c08c050208410
Author: James Liggett <jrliggett cox net>
Date:   Mon Aug 9 22:58:10 2010 -0700

    git: Add AnjutaFileDropEntry
    
    This AnjutaDropEntry subclass accepts files instead of strings.

 libanjuta/Makefile.am              |    7 +-
 libanjuta/anjuta-file-drop-entry.c |  221 ++++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-file-drop-entry.h |   59 ++++++++++
 libanjuta/anjuta-glade-catalog.c   |    1 +
 libanjuta/anjuta-glade.xml         |    4 +
 5 files changed, 290 insertions(+), 2 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index 47654d2..ec25c09 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -108,7 +108,9 @@ libanjuta_la_SOURCES= \
 	anjuta-pkg-config-chooser.h \
 	anjuta-pkg-config-chooser.c \
 	anjuta-column-text-view.h \
-	anjuta-column-text-view.c
+	anjuta-column-text-view.c \
+	anjuta-file-drop-entry.h \
+	anjuta-file-drop-entry.c
 
 
 
@@ -177,7 +179,8 @@ libanjuta_include = \
 	anjuta-dock-pane.h \
 	anjuta-file-list.h \
 	anjuta-pkg-config-chooser.h \
-	anjuta-column-text-view.h
+	anjuta-column-text-view.h \
+	anjuta-file-drop-entry.h
 
 libanjutainclude_HEADERS = \
 	$(libanjuta_include) \
diff --git a/libanjuta/anjuta-file-drop-entry.c b/libanjuta/anjuta-file-drop-entry.c
new file mode 100644
index 0000000..8625e52
--- /dev/null
+++ b/libanjuta/anjuta-file-drop-entry.c
@@ -0,0 +1,221 @@
+/* -*- 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-file-drop-entry.h"
+
+enum
+{
+	PROP_0,
+
+	PROP_RELATIVE_PATH
+};
+
+/* DND Targets */
+static GtkTargetEntry dnd_target_entries[] =
+{
+	{
+		"text/uri-list",
+		0,
+		0
+	}
+};
+
+struct _AnjutaFileDropEntryPriv
+{
+	gchar *relative_path;
+};
+
+G_DEFINE_TYPE (AnjutaFileDropEntry, anjuta_file_drop_entry, ANJUTA_TYPE_DROP_ENTRY);
+
+static void
+anjuta_file_drop_entry_init (AnjutaFileDropEntry *self)
+{
+	self->priv = g_new0 (AnjutaFileDropEntryPriv, 1);
+
+	gtk_drag_dest_set (GTK_WIDGET (self), 
+	                   GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT, 
+	                   dnd_target_entries,
+	                   G_N_ELEMENTS (dnd_target_entries), 
+	                   GDK_ACTION_COPY | GDK_ACTION_MOVE);
+}
+
+static void
+anjuta_file_drop_entry_finalize (GObject *object)
+{
+	AnjutaFileDropEntry *self;
+
+	self = ANJUTA_FILE_DROP_ENTRY (object);
+
+	g_free (self->priv->relative_path);
+	g_free (self->priv);
+
+	G_OBJECT_CLASS (anjuta_file_drop_entry_parent_class)->finalize (object);
+}
+
+static void
+anjuta_file_drop_entry_set_property (GObject *object, guint prop_id, 
+                                     const GValue *value, GParamSpec *pspec)
+{
+	AnjutaFileDropEntry *self;
+
+	g_return_if_fail (ANJUTA_IS_FILE_DROP_ENTRY (object));
+
+	self = ANJUTA_FILE_DROP_ENTRY (object);
+
+	switch (prop_id)
+	{
+		case PROP_RELATIVE_PATH:
+			g_free (self->priv->relative_path);
+
+			self->priv->relative_path = g_value_dup_string (value);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+anjuta_file_drop_entry_get_property (GObject *object, guint prop_id, 
+                                     GValue *value, GParamSpec *pspec)
+{
+	AnjutaFileDropEntry *self;
+
+	g_return_if_fail (ANJUTA_IS_FILE_DROP_ENTRY (object));
+
+	self = ANJUTA_FILE_DROP_ENTRY (object);
+
+	switch (prop_id)
+	{
+		case PROP_RELATIVE_PATH:
+			g_value_set_string (value, self->priv->relative_path);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+anjuta_file_drop_entry_drag_data_received (GtkWidget *widget, 
+                                           GdkDragContext *context, gint x, gint y,
+                                           GtkSelectionData *data, guint target_type,
+                                           guint time)
+{
+	AnjutaFileDropEntry *self;
+	gboolean success;
+	gchar **uri_list;
+	GFile *parent_file;
+	GFile *file;
+	gchar *path;
+
+	self = ANJUTA_FILE_DROP_ENTRY (widget);
+	success = FALSE;
+
+	if ((data != NULL) && (data->length >= 0))
+	{
+		if (target_type == 0)
+		{
+			uri_list = gtk_selection_data_get_uris (data);
+			parent_file = NULL;
+
+			if (self->priv->relative_path)
+				parent_file = g_file_new_for_path (self->priv->relative_path);
+
+			/* Take only the first file */
+			file = g_file_new_for_uri (uri_list[0]);
+
+			if (parent_file)
+			{
+				path = g_file_get_relative_path (parent_file, file);
+
+				g_object_unref (parent_file);
+			}
+			else
+				path = g_file_get_path (file);
+
+			if (path)
+			{
+				gtk_entry_set_text (GTK_ENTRY (self), path);
+
+				g_free (path);
+			}
+			
+			success = TRUE;
+
+			g_object_unref (file);
+			g_strfreev (uri_list);
+		}
+	}
+
+	/* Do not delete source data */
+	gtk_drag_finish (context, success, FALSE, time);
+}
+
+static gboolean
+anjuta_file_drop_entry_drag_drop (GtkWidget *widget, GdkDragContext *context, 
+                                  gint x, gint y, guint time)
+{
+	GdkAtom target_type;
+
+	target_type = gtk_drag_dest_find_target (widget, context, NULL);
+
+	g_print ("Drag drop target type: %p\n", GDK_ATOM_TO_POINTER (target_type));
+
+	if (target_type != GDK_NONE)
+		gtk_drag_get_data (widget, context, target_type, time);
+	else
+		gtk_drag_finish (context, FALSE, FALSE, time);
+
+	return TRUE;
+}
+
+static void
+anjuta_file_drop_entry_class_init (AnjutaFileDropEntryClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+	object_class->finalize = anjuta_file_drop_entry_finalize;
+	object_class->set_property = anjuta_file_drop_entry_set_property;
+	object_class->get_property = anjuta_file_drop_entry_get_property;
+	widget_class->drag_data_received = anjuta_file_drop_entry_drag_data_received;
+	widget_class->drag_drop = anjuta_file_drop_entry_drag_drop;
+
+	g_object_class_install_property (object_class,
+	                                 PROP_RELATIVE_PATH,
+	                                 g_param_spec_string ("relative-path",
+	                                                      "relative-path",
+	                                                      _("Path that droppedfiles should be relative to"),
+	                                                      "",
+	                                                      0));
+}
+
+GtkWidget *
+anjuta_file_drop_entry_new (void)
+{
+	return g_object_new (ANJUTA_TYPE_FILE_DROP_ENTRY, NULL);
+}
+
+void
+anjuta_file_drop_entry_set_relative_path (AnjutaFileDropEntry *self, 
+                                          const gchar *path)
+{
+	g_object_set (G_OBJECT (self), "relative-path", path, NULL);
+}
\ No newline at end of file
diff --git a/libanjuta/anjuta-file-drop-entry.h b/libanjuta/anjuta-file-drop-entry.h
new file mode 100644
index 0000000..8dbf5c9
--- /dev/null
+++ b/libanjuta/anjuta-file-drop-entry.h
@@ -0,0 +1,59 @@
+/* -*- 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_FILE_DROP_ENTRY_H_
+#define _ANJUTA_FILE_DROP_ENTRY_H_
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <libanjuta/anjuta-drop-entry.h>
+
+G_BEGIN_DECLS
+
+#define ANJUTA_TYPE_FILE_DROP_ENTRY             (anjuta_file_drop_entry_get_type ())
+#define ANJUTA_FILE_DROP_ENTRY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_FILE_DROP_ENTRY, AnjutaFileDropEntry))
+#define ANJUTA_FILE_DROP_ENTRY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_FILE_DROP_ENTRY, AnjutaFileDropEntryClass))
+#define ANJUTA_IS_FILE_DROP_ENTRY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_FILE_DROP_ENTRY))
+#define ANJUTA_IS_FILE_DROP_ENTRY_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_FILE_DROP_ENTRY))
+#define ANJUTA_FILE_DROP_ENTRY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_FILE_DROP_ENTRY, AnjutaFileDropEntryClass))
+
+typedef struct _AnjutaFileDropEntryClass AnjutaFileDropEntryClass;
+typedef struct _AnjutaFileDropEntry AnjutaFileDropEntry;
+typedef struct _AnjutaFileDropEntryPriv AnjutaFileDropEntryPriv;
+
+struct _AnjutaFileDropEntryClass
+{
+	AnjutaDropEntryClass parent_class;
+};
+
+struct _AnjutaFileDropEntry
+{
+	AnjutaDropEntry parent_instance;
+
+	AnjutaFileDropEntryPriv *priv;
+};
+
+GType anjuta_file_drop_entry_get_type (void) G_GNUC_CONST;
+GtkWidget *anjuta_file_drop_entry_new (void);
+void anjuta_file_drop_entry_set_relative_path (AnjutaFileDropEntry *self, 
+                                               const gchar *path);
+
+G_END_DECLS
+
+#endif /* _ANJUTA_FILE_DROP_ENTRY_H_ */
diff --git a/libanjuta/anjuta-glade-catalog.c b/libanjuta/anjuta-glade-catalog.c
index 446856a..94054a3 100644
--- a/libanjuta/anjuta-glade-catalog.c
+++ b/libanjuta/anjuta-glade-catalog.c
@@ -4,4 +4,5 @@
 #include <libanjuta/anjuta-file-list.h>
 #include <libanjuta/anjuta-pkg-config-chooser.h>
 #include <libanjuta/anjuta-column-text-view.h>
+#include <libanjuta/anjuta-file-drop-entry.h>
 
diff --git a/libanjuta/anjuta-glade.xml b/libanjuta/anjuta-glade.xml
index ebc9e2b..eb439f4 100644
--- a/libanjuta/anjuta-glade.xml
+++ b/libanjuta/anjuta-glade.xml
@@ -38,6 +38,9 @@
 		<glade-widget-class name="AnjutaColumnTextView" title="Column Text View"
 		 generic-name="columntextview" />
 
+		 <glade-widget-class name="AnjutaFileDropEntry" title="File Drop Entry"
+		 generic-name="filedropentry" />
+
 	</glade-widget-classes>
 
 	<glade-widget-group name="Anjuta" title="Anjuta">
@@ -46,5 +49,6 @@
 		<glade-widget-class-ref name="AnjutaFileList" />
 		<glade-widget-class-ref name="AnjutaPkgConfigChooser" />
 		<glade-widget-class-ref name="AnjutaColumnTextView" />
+		<glade-widget-class-ref name="AnjutaFileDropEntry" />
 	</glade-widget-group>
 </glade-catalog>



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