Commit 0f3b3408 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

implement open by drag&drop. add glade_util_uri_list_parse for the above.

004-02-12  Paolo Borelli  <pborelli@katamail.com>

        * src/glade-project-window.c: implement open by drag&drop.
        * src/glade-utils.[ch]: add glade_util_uri_list_parse for the above.
parent 6a1ca9d0
2004-02-12 Paolo Borelli <pborelli@katamail.com>
* src/glade-project-window.c: implement open by drag&drop.
* src/glade-utils.[ch]: add glade_util_uri_list_parse for the above.
2004-02-11 Joaquin Cuenca Abela <e98cuenc@yahoo.com>
* src/glade_plugin.def: update to latest changes to fix the
......
......@@ -1134,6 +1134,50 @@ gpw_construct_statusbar (GladeProjectWindow *gpw)
return statusbar;
}
enum
{
TARGET_URI_LIST
};
static GtkTargetEntry drop_types[] =
{
{"text/uri-list", 0, TARGET_URI_LIST}
};
static void
gpw_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x, gint y,
GtkSelectionData *selection_data,
guint info, guint time, gpointer data)
{
gchar *uri_list;
GList *list = NULL;
if (info != TARGET_URI_LIST)
return;
/*
* Mmh... it looks like on Windows selection_data->data is not
* NULL terminated, so we need to make sure our local copy is.
*/
uri_list = g_new (gchar, selection_data->length + 1);
memcpy (uri_list, selection_data->data, selection_data->length);
uri_list[selection_data->length] = 0;
list = glade_util_uri_list_parse (uri_list);
for (; list; list = list->next)
{
if (list->data)
glade_project_window_open_project (list->data);
/* we can now free each string in the list */
g_free (list->data);
}
g_list_free (list);
}
static gboolean
gpw_delete_event (GtkWindow *w, gpointer not_used)
{
......@@ -1174,11 +1218,20 @@ glade_project_window_create (GladeProjectWindow *gpw)
glade_project_window_refresh_undo_redo ();
/* support for opening a file by dragging onto the project window */
gtk_drag_dest_set (app,
GTK_DEST_DEFAULT_ALL,
drop_types, G_N_ELEMENTS (drop_types),
GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (G_OBJECT (app), "drag-data-received",
G_CALLBACK (gpw_drag_data_received), NULL);
g_signal_connect (G_OBJECT (app), "delete_event",
G_CALLBACK (gpw_delete_event), NULL);
}
GladeProjectWindow * glade_project_window = NULL;
static GladeProjectWindow *glade_project_window = NULL;
GladeProjectWindow *
glade_project_window_get ()
......
......@@ -536,3 +536,73 @@ glade_util_container_get_all_children (GtkContainer *container)
return g_list_reverse (children);
}
/**
* glade_util_uri_list_parse:
* @uri_list: the text/urilist, must be NULL terminated.
*
* Extracts a list of file names from a standard text/uri-list,
* such as one you would get on a drop operation.
* This is mostly stolen from gnome-vfs-uri.c.
*
* Returns a GList of gchars.
**/
GList *
glade_util_uri_list_parse (const gchar *uri_list)
{
const gchar *p, *q;
GList *result = NULL;
g_return_val_if_fail (uri_list != NULL, NULL);
p = uri_list;
/* We don't actually try to validate the URI according to RFC
* 2396, or even check for allowed characters - we just ignore
* comments and trim whitespace off the ends. We also
* allow LF delimination as well as the specified CRLF.
*/
while (p)
{
if (*p != '#')
{
gchar *retval;
gchar *path;
while (g_ascii_isspace (*p))
p++;
q = p;
while ((*q != '\0') && (*q != '\n') && (*q != '\r'))
q++;
if (q > p)
{
q--;
while (q > p && g_ascii_isspace (*q))
q--;
retval = g_new (gchar, q - p + 2);
memcpy (retval, p, q - p + 1);
retval[q - p + 1] = '\0';
path = g_filename_from_uri (retval, NULL, NULL);
if (!path)
{
g_free (retval);
continue;
}
result = g_list_prepend (result, path);
g_free (retval);
}
}
p = strchr (p, '\n');
if (p)
p++;
}
return g_list_reverse (result);
}
......@@ -37,6 +37,9 @@ GladeWidget *glade_util_get_parent (GtkWidget *w);
void glade_util_replace_placeholder (GladePlaceholder *placeholder, GladeWidget *widget);
GList *glade_util_container_get_all_children (GtkContainer *container);
GList *glade_util_uri_list_parse (const gchar* uri_list);
G_END_DECLS
#endif /* __GLADE_UTILS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment