From: Olaf Wintermann Date: Thu, 30 Jan 2025 21:10:10 +0000 (+0100) Subject: prepare dnd support for MzFilesView X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;ds=sidebyside;p=mizunara.git prepare dnd support for MzFilesView --- diff --git a/mizunara/application.h b/mizunara/application.h index af25e8b..d5465f2 100644 --- a/mizunara/application.h +++ b/mizunara/application.h @@ -128,12 +128,14 @@ struct FileBrowser { */ struct FilesSection { CxList *files; + char *parent_url; size_t num_bytes; time_t mtime_from; time_t mtime_to; }; struct FileInfo { + char *parent; char *name; size_t size; time_t mtime; diff --git a/mizunara/filebrowser.c b/mizunara/filebrowser.c index 2787172..3cf3bd3 100644 --- a/mizunara/filebrowser.c +++ b/mizunara/filebrowser.c @@ -112,6 +112,7 @@ int jobthr_filebrowser_op_load(void *data) { } FileInfo f; + f.parent = op->url; f.name = strdup(ent->d_name); if(!fstatat(fd, ent->d_name, &s, 0)) { @@ -143,7 +144,9 @@ void filebrowser_op_finished(UiEvent *event, void *data) { FilesSection *section = malloc(sizeof(FilesSection)); memset(section, 0, sizeof(FilesSection)); section->files = op->result; + section->parent_url = op->url; op->result = NULL; + op->url = NULL; // update_grid takes ownership of section op->browser->update_grid(op->browser, section, 1, op->browser->update_grid_data); @@ -155,7 +158,6 @@ void filebrowser_op_finished(UiEvent *event, void *data) { } cxListFree(op->result); - free(op->url); free(op); } diff --git a/mizunara/gtk-filesview.c b/mizunara/gtk-filesview.c index ff98435..361a857 100644 --- a/mizunara/gtk-filesview.c +++ b/mizunara/gtk-filesview.c @@ -31,6 +31,8 @@ #include #include +#include + G_DEFINE_TYPE(MzFilesView, mz_files_view, GTK_TYPE_WIDGET) @@ -51,6 +53,17 @@ static void drag_update_cb( gdouble y, gpointer user_data); +static GdkContentProvider* dnd_prepare( + GtkDragSource* self, + gdouble x, + gdouble y, + gpointer user_data); + +static void dnd_begin( + GtkDragSource* self, + GdkDrag* drag, + gpointer user_data); + static void motion_cb( GtkEventControllerMotion* self, gdouble x, @@ -79,6 +92,11 @@ static void mz_files_view_init(MzFilesView *self) { self->highlight_row = -1; // event handler + GtkDragSource *dnd_source = gtk_drag_source_new(); + g_signal_connect(dnd_source, "prepare", G_CALLBACK(dnd_prepare), self); + g_signal_connect(dnd_source, "drag-begin", G_CALLBACK(dnd_begin), self); + gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(dnd_source)); + GtkGesture *drag = gtk_gesture_drag_new(); g_signal_connect(drag, "drag-begin", G_CALLBACK(drag_begin_cb), self); g_signal_connect(drag, "drag-end", G_CALLBACK(drag_end_cb), self); @@ -426,6 +444,32 @@ static void mz_files_view_size_allocate( /* -------------------------- event handler -------------------------- */ +static GdkContentProvider* dnd_prepare( + GtkDragSource *self, + gdouble x, + gdouble y, + gpointer user_data) +{ + MzFilesView *view = user_data; + if(view->drag_item) { + char *path = util_concat_path(view->drag_file->parent, view->drag_file->name); + printf("dnd file: %s\n", path); + GFile *file = g_file_new_for_path(path); + free(path); + GdkContentProvider *provider = gdk_content_provider_new_typed(G_TYPE_FILE, file); + return provider; + } + return NULL; +} + +static void dnd_begin( + GtkDragSource* self, + GdkDrag* drag, + gpointer user_data) +{ + printf("dnd_begin\n"); +} + static void drag_begin_cb( GtkGestureDrag* self, gdouble start_x,