Ephoto: Allow images to be drag and dropped in the thumb grid.

master
Stephen okra Houston 6 years ago
parent 8f9522ce25
commit 4f10741f4f
  1. 14
      src/bin/ephoto_directory_browser.c
  2. 129
      src/bin/ephoto_thumb_browser.c

@ -110,11 +110,15 @@ _drop_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it,
while (s)
{
if (evas_object_image_extension_can_load_get(s))
files = eina_list_append(files, s);
files = eina_list_append(files, s);
s = _drag_data_extract(&dd);
}
free(dd);
if (eina_list_count(files) <= 0)
return EINA_TRUE;
if (db->ephoto->config->move_drop)
ephoto_file_move(db->ephoto, files, path);
else
@ -136,12 +140,9 @@ _drop_item_getcb(Evas_Object *obj, Evas_Coord x, Evas_Coord y,
}
static void
_drop_enter(void *data, Evas_Object *obj EINA_UNUSED)
_drop_enter(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
Ephoto_Directory_Browser *db = data;
if (db->dragging)
elm_object_cursor_set(db->main, ELM_CURSOR_TARGET);
return;
}
static void
@ -151,7 +152,6 @@ _drop_leave(void *data, Evas_Object *obj EINA_UNUSED)
if (db->dragging)
{
elm_object_cursor_set(db->main, ELM_CURSOR_HAND2);
if (db->dir_current)
elm_genlist_item_selected_set(db->dir_current, EINA_TRUE);
}
@ -159,7 +159,7 @@ _drop_leave(void *data, Evas_Object *obj EINA_UNUSED)
static void
_drop_pos(void *data EINA_UNUSED, Evas_Object *cont EINA_UNUSED,
Elm_Object_Item *it EINA_UNUSED, Evas_Coord x EINA_UNUSED,
Elm_Object_Item *it, Evas_Coord x EINA_UNUSED,
Evas_Coord y EINA_UNUSED, int xposret EINA_UNUSED,
int yposret EINA_UNUSED, Elm_Xdnd_Action action EINA_UNUSED)
{

@ -79,6 +79,7 @@ static void _ephoto_thumb_search_cancel(void *data, Evas_Object *obj EINA_UNUSED
void *event_info EINA_UNUSED);
static void _ephoto_thumb_search_start(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED);
static char * _drag_data_extract(char **drag_data);
/*Common Callbacks*/
static void
@ -120,6 +121,131 @@ _5s_timeout_gone(void *data)
return ECORE_CALLBACK_CANCEL;
}
static Eina_Bool
_drop_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it EINA_UNUSED,
Elm_Selection_Data *ev, int xposret EINA_UNUSED, int yposret EINA_UNUSED)
{
Eina_List *files = NULL;
Ephoto_Thumb_Browser *tb = evas_object_data_get(obj, "thumb_browser");
const char *path = tb->ephoto->config->directory;
char *dir;
if (!ev->data)
return EINA_FALSE;
if (ev->len <= 0)
return EINA_FALSE;
if (!path)
return EINA_FALSE;
char *dd = strdup(ev->data);
if (!dd)
return EINA_FALSE;
char *s = _drag_data_extract(&dd);
while (s)
{
dir = ecore_file_dir_get(s);
if (!strcmp(path, dir))
{
free(dir);
break;
}
if (evas_object_image_extension_can_load_get(basename(s)))
files = eina_list_append(files, s);
free(dir);
s = _drag_data_extract(&dd);
}
free(dd);
if (eina_list_count(files) <= 0)
return EINA_TRUE;
if (tb->ephoto->config->move_drop)
ephoto_file_move(tb->ephoto, files, path);
else
ephoto_file_copy(tb->ephoto, files, path);
return EINA_TRUE;
}
static Elm_Object_Item *
_drop_item_getcb(Evas_Object *obj EINA_UNUSED, Evas_Coord x EINA_UNUSED,
Evas_Coord y EINA_UNUSED,int *xposret EINA_UNUSED, int *yposret EINA_UNUSED)
{
return NULL;
}
static void
_drop_enter(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
return;
}
static void
_drop_leave(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
return;
}
static void
_drop_pos(void *data EINA_UNUSED, Evas_Object *cont EINA_UNUSED,
Elm_Object_Item *it EINA_UNUSED, Evas_Coord x EINA_UNUSED,
Evas_Coord y EINA_UNUSED, int xposret EINA_UNUSED,
int yposret EINA_UNUSED, Elm_Xdnd_Action action EINA_UNUSED)
{
return;
}
static char *
_drag_data_extract(char **drag_data)
{
char *uri = NULL;
if (!drag_data)
return uri;
char *p = *drag_data;
if (!p)
return uri;
char *s = strstr(p, FILESEP);
if (s)
p += FILESEP_LEN;
s = strchr(p, '\n');
uri = p;
if (s)
{
if (s - p > 0)
{
char *s1 = s - 1;
if (s1[0] == '\r')
s1[0] = '\0';
else
{
char *s2 = s + 1;
if (s2[0] == '\r')
{
s[0] = '\0';
s++;
}
else
s[0] = '\0';
}
}
else
s[0] = '\0';
s++;
}
else
p = NULL;
*drag_data = s;
return uri;
}
static void
_dnd_drag_start(void *data EINA_UNUSED, Evas_Object *obj)
{
@ -1299,6 +1425,9 @@ _ephoto_thumb_view_add(Ephoto_Thumb_Browser *tb)
_grid_mouse_wheel, tb);
elm_drag_item_container_add(tb->grid, ANIM_TIME, DRAG_TIMEOUT,
_dnd_item_get, _dnd_item_data_get);
elm_drop_item_container_add(tb->grid, ELM_SEL_FORMAT_TARGETS,
_drop_item_getcb, _drop_enter, tb, _drop_leave, tb, _drop_pos, tb,
_drop_dropcb, NULL);
evas_object_data_set(tb->grid, "thumb_browser", tb);
elm_box_pack_end(tb->gridbox, tb->grid);
evas_object_smart_callback_add(tb->grid, "changed", _grid_changed, tb);

Loading…
Cancel
Save