From: Olaf Wintermann Date: Sat, 1 Feb 2025 14:23:18 +0000 (+0100) Subject: add double click handler to MzFilesView and implement browsing X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=c3eeb6e543190aa46a03a7ba8f357e7564a60c7c;p=mizunara.git add double click handler to MzFilesView and implement browsing --- diff --git a/mizunara/gtk-filesview.c b/mizunara/gtk-filesview.c index 361a857..dfac4ea 100644 --- a/mizunara/gtk-filesview.c +++ b/mizunara/gtk-filesview.c @@ -70,6 +70,13 @@ static void motion_cb( gdouble y, gpointer user_data); +static void button_pressed( + GtkGestureClick* self, + gint n_press, + gdouble x, + gdouble y, + gpointer user_data); + static void mz_files_view_class_init(MzFilesViewClass *klass) { printf("mz_files_view_class_init\n"); klass->parent_class.snapshot = mz_files_view_snapshot; @@ -106,6 +113,10 @@ static void mz_files_view_init(MzFilesView *self) { GtkEventController *motion = gtk_event_controller_motion_new(); g_signal_connect(motion, "motion", G_CALLBACK(motion_cb), self); gtk_widget_add_controller(GTK_WIDGET(self), motion); + + GtkGesture *click = gtk_gesture_click_new (); + g_signal_connect(click, "pressed", G_CALLBACK(button_pressed), self); + gtk_widget_add_controller(GTK_WIDGET(self), GTK_EVENT_CONTROLLER(click)); } void mz_files_view_dispose(GObject *object) { @@ -483,16 +494,20 @@ static void drag_begin_cb( int item_width = 180; int item_height = 170; - int col; - int row; + int update_selection = 0; + int col = -1; + int row = -1; size_t item_index; if(point2item(view, start_x, start_y, &col, &row, &item_index)) { if(view->numsections > 0 && item_index < cxListSize(view->sections[0].section.files)) { FileInfo *file = cxListAt(view->sections[0].section.files, item_index); - printf("drag file: %s\n", file->name); + printf("drag file[%d]: %s\n", view->items[item_index].isselected, file->name); view->drag_file = file; view->drag_item = TRUE; - return; + if(view->items[item_index].isselected) { + return; + } + update_selection = 1; } } @@ -512,7 +527,7 @@ static void drag_begin_cb( view->drag_start_row = row; view->drag_col = col; view->drag_row = row; - view->update_selection = 0; + view->update_selection = update_selection; gtk_widget_queue_draw(GTK_WIDGET(view)); } @@ -607,6 +622,32 @@ static void motion_cb( } } +static void button_pressed( + GtkGestureClick* self, + gint n_press, + gdouble x, + gdouble y, + gpointer user_data) +{ + // double click + if(n_press == 2) { + MzFilesView *view = user_data; + int col = -1; + int row = -1; + size_t item_index; + if(point2item(view, x, y, &col, &row, &item_index)) { + if(item_index < view->numitems) { + FileInfo *file = cxListAt(view->sections[0].section.files, item_index); + printf("open file: %s/%s\n", file->parent, file->name); + if(view->open) { + view->open(&file, 1, view->open_userdata); + } + } + } + + } +} + /* -------------------------- public -------------------------- */ diff --git a/mizunara/gtk-filesview.h b/mizunara/gtk-filesview.h index fd2f5ba..c8c55da 100644 --- a/mizunara/gtk-filesview.h +++ b/mizunara/gtk-filesview.h @@ -56,6 +56,10 @@ typedef struct MzViewSection { typedef struct MzFilesView { GtkWidget widget; + + void (*open)(FileInfo **files, size_t numfiles, void *userdata); + void *open_userdata; + MzIconGadget *items; size_t numitems; diff --git a/mizunara/window.c b/mizunara/window.c index 67f7fdc..2c31eda 100644 --- a/mizunara/window.c +++ b/mizunara/window.c @@ -31,6 +31,10 @@ #include "filebrowser.h" #include "bookmarks.h" +#include + +#include + #ifdef GTK_MAJOR_VERSION #include "gtk-filesview.h" #include "bookmarks.h" @@ -96,10 +100,26 @@ UiObject* window_create(const char *url) { return obj; } +static void open_files(FileInfo **files, size_t numfiles, void *userdata) { + MainWindow *win = userdata; + FileInfo *file = files[0]; + if(S_ISDIR(file->mode)) { + char *newpath = util_concat_path(file->parent, file->name); + FileBrowser *browser = win->obj->ctx->document; // TODO: this is more or less deprecated or undefined + ui_set(browser->path, newpath); + filebrowser_load(browser, newpath); + free(newpath); + } else { + printf("TODO: open file: %s/%s\n", file->parent, file->name); + } +} + #ifdef GTK_MAJOR_VERSION static UIWIDGET create_filesview(UiObject *obj, UiWidgetArgs args, void *userdata) { MainWindow *win = userdata; MzFilesView *view = mz_files_view_new(); + view->open = open_files; + view->open_userdata = win; win->files_gridview = GTK_WIDGET(view); GtkWidget *sw = gtk_scrolled_window_new();