]> uap-core.de Git - mizunara.git/commitdiff
add double click handler to MzFilesView and implement browsing
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Feb 2025 14:23:18 +0000 (15:23 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 1 Feb 2025 14:23:18 +0000 (15:23 +0100)
mizunara/gtk-filesview.c
mizunara/gtk-filesview.h
mizunara/window.c

index 361a8570926970c370e04308d3a552364377dbd6..dfac4ea96e178d614c550d069829a3fe32515135 100644 (file)
@@ -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 -------------------------- */
 
index fd2f5bad0a5010774728ae5d6b91c1b74be9bcd7..c8c55dacc917758eb725dea1283f3885e42d08d5 100644 (file)
@@ -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;
     
index 67f7fdcc2a467ad4b774de811e7f9e172c163625..2c31eda769c32dd4d3c842a8137788c941cd66f1 100644 (file)
 #include "filebrowser.h"
 #include "bookmarks.h"
 
+#include <sys/stat.h>
+
+#include <libidav/utils.h>
+
 #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();