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;
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) {
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;
}
}
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));
}
}
}
+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 -------------------------- */
#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"
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();