diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-18 12:02:53 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-04-18 12:02:53 +0200 |
commit | 78bf582fb29151a916d2c93e9f056d9464d1f997 (patch) | |
tree | 3f496d985eb4108dc4e3f8a12b3e3ee0557eb8f9 | |
parent | 9d08630aea8485c5e22efc0745a5cbca1f5bf9e4 (diff) |
dragndrop move/copy action selection
-rw-r--r-- | deadbeef.h | 2 | ||||
-rw-r--r-- | playlist.c | 88 | ||||
-rw-r--r-- | playlist.h | 2 | ||||
-rw-r--r-- | plugins.c | 2 | ||||
-rw-r--r-- | plugins/gtkui/ddblistview.c | 3 | ||||
-rw-r--r-- | plugins/gtkui/ddblistview.h | 2 | ||||
-rw-r--r-- | plugins/gtkui/ddbtabstrip.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/mainplaylist.c | 9 | ||||
-rw-r--r-- | plugins/gtkui/trkproperties.c | 2 |
9 files changed, 55 insertions, 61 deletions
@@ -419,7 +419,7 @@ typedef struct { // void (*pl_set_tail) (DB_playItem_t *it, int iter); // DB_playItem_t* (*pl_get_head) (void); // DB_playItem_t* (*pl_get_tail) (void); - void (*pl_move_items) (int iter, DB_playItem_t *drop_before, uint32_t *indexes, int count); + void (*pl_move_items) (int iter, int plt_from, DB_playItem_t *drop_before, uint32_t *indexes, int count); void (*pl_copy_items) (int iter, int plt_from, DB_playItem_t *before, uint32_t *indices, int cnt); void (*pl_search_reset) (void); void (*pl_search_process) (const char *text); @@ -1236,7 +1236,7 @@ pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *us } int -pl_remove_item (playItem_t *it) { +plt_remove_item (playlist_t *playlist, playItem_t *it) { if (!it) return -1; streamer_song_removed_notify (it); @@ -1275,6 +1275,11 @@ pl_remove_item (playItem_t *it) { } int +pl_remove_item (playItem_t *it) { + return plt_remove_item (playlist, it); +} + +int pl_getcount (int iter) { if (!playlist) { return 0; @@ -1337,7 +1342,7 @@ pl_get_idx_of (playItem_t *it) { } playItem_t * -pl_insert_item (playItem_t *after, playItem_t *it) { +plt_insert_item (playlist_t *playlist, playItem_t *after, playItem_t *it) { GLOBAL_LOCK; pl_item_ref (it); if (!after) { @@ -1379,6 +1384,11 @@ pl_insert_item (playItem_t *after, playItem_t *it) { return it; } +playItem_t * +pl_insert_item (playItem_t *after, playItem_t *it) { + return plt_insert_item (playlist, after, it); +} + void pl_item_copy (playItem_t *out, playItem_t *it) { LOCK; @@ -2626,63 +2636,49 @@ pl_set_cursor (int iter, int cursor) { // list of items is indexes[count] // drop_before is insertion point void -pl_move_items (int iter, playItem_t *drop_before, uint32_t *indexes, int count) { - // unlink items from playlist, and link together +pl_move_items (int iter, int plt_from, playItem_t *drop_before, uint32_t *indexes, int count) { GLOBAL_LOCK; + playlist_t *playlist = playlists_head; + playlist_t *to = plt_get_curr_ptr (); + + int i; + for (i = 0; i < plt_from; i++) { + playlist = playlist->next; + } + + if (!playlist || !to) { + GLOBAL_UNLOCK; + return; + } + + // unlink items from playlist, and link together playItem_t *head = NULL; playItem_t *tail = NULL; int processed = 0; int idx = 0; playItem_t *next = NULL; - for (playItem_t *it = playlist->head[iter]; it && processed < count; it = next, idx++) { - next = it->next[iter]; - if (idx == indexes[processed]) { - if (it->prev[iter]) { - it->prev[iter]->next[iter] = it->next[iter]; - } - else { - playlist->head[iter] = it->next[iter]; - } - if (it->next[iter]) { - it->next[iter]->prev[iter] = it->prev[iter]; - } - else { - playlist->tail[iter] = it->prev[iter]; - } - if (tail) { - tail->next[iter] = it; - it->prev[iter] = tail; - tail = it; - } - else { - head = tail = it; - it->prev[iter] = it->next[iter] = NULL; - } - processed++; - } - } + // find insertion point playItem_t *drop_after = NULL; if (drop_before) { drop_after = drop_before->prev[iter]; } else { - drop_after = playlist->tail[iter]; - } - // insert in between - head->prev[iter] = drop_after; - if (drop_after) { - drop_after->next[iter] = head; + drop_after = to->tail[iter]; } - else { - playlist->head[iter] = head; - } - tail->next[iter] = drop_before; - if (drop_before) { - drop_before->prev[iter] = tail; - } - else { - playlist->tail[iter] = tail; + + for (playItem_t *it = playlist->head[iter]; it && processed < count; it = next, idx++) { + next = it->next[iter]; + if (idx == indexes[processed]) { + pl_item_ref (it); + if (drop_after == it) { + drop_after = it->prev[PL_MAIN]; + } + plt_remove_item (playlist, it); + plt_insert_item (to, drop_after, it); + pl_item_unref (it); + processed++; + } } GLOBAL_UNLOCK; } @@ -276,7 +276,7 @@ void pl_set_cursor (int iter, int cursor); void -pl_move_items (int iter, playItem_t *drop_before, uint32_t *indexes, int count); +pl_move_items (int iter, int plt_from, playItem_t *drop_before, uint32_t *indexes, int count); void pl_copy_items (int iter, int plt_from, playItem_t *before, uint32_t *indices, int cnt); @@ -159,7 +159,7 @@ static DB_functions_t deadbeef_api = { .pl_get_next = (DB_playItem_t *(*) (DB_playItem_t *, int))pl_get_next, .pl_get_prev = (DB_playItem_t *(*) (DB_playItem_t *, int))pl_get_prev, .pl_format_title = (int (*) (DB_playItem_t *it, int idx, char *s, int size, int id, const char *fmt))pl_format_title, - .pl_move_items = (void (*) (int iter, DB_playItem_t *drop_before, uint32_t *indexes, int count))pl_move_items, + .pl_move_items = (void (*) (int iter, int plt_from, DB_playItem_t *drop_before, uint32_t *indexes, int count))pl_move_items, .pl_copy_items = (void (*) (int iter, int plt_from, DB_playItem_t *before, uint32_t *indices, int cnt))pl_copy_items, .pl_search_reset = pl_search_reset, .pl_search_process = pl_search_process, diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c index 57269e8a..035a75a8 100644 --- a/plugins/gtkui/ddblistview.c +++ b/plugins/gtkui/ddblistview.c @@ -932,7 +932,7 @@ ddb_listview_list_drag_data_received (GtkWidget *widget, UNREF (drop_before); drop_before = next; } - ps->binding->drag_n_drop (drop_before, plt, d, length); + ps->binding->drag_n_drop (drop_before, plt, d, length, drag_context->action == GDK_ACTION_COPY ? 1 : 0); if (drop_before) { UNREF (drop_before); } @@ -1965,7 +1965,6 @@ ddb_listview_list_drag_end (GtkWidget *widget, GdkDragContext *drag_context, gpointer user_data) { - printf ("ddb_listview_list_drag_end\n"); DdbListview *ps = DDB_LISTVIEW (gtk_object_get_data (GTK_OBJECT (widget), "owner")); ddb_listview_refresh (ps, DDB_REFRESH_LIST|DDB_EXPOSE_LIST); ps->scroll_direction = 0; diff --git a/plugins/gtkui/ddblistview.h b/plugins/gtkui/ddblistview.h index e75ca059..0060669d 100644 --- a/plugins/gtkui/ddblistview.h +++ b/plugins/gtkui/ddblistview.h @@ -68,7 +68,7 @@ typedef struct { int (*get_group) (DdbListviewIter it, char *str, int size); // drag-n-drop - void (*drag_n_drop) (DdbListviewIter before, int playlist, uint32_t *indices, int length); + void (*drag_n_drop) (DdbListviewIter before, int playlist, uint32_t *indices, int length, int copy); void (*external_drag_n_drop) (DdbListviewIter before, char *mem, int length); // callbacks diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c index aeb5868b..cece5b22 100644 --- a/plugins/gtkui/ddbtabstrip.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -249,11 +249,7 @@ on_tabstrip_drag_data_received (GtkWidget *widget, int plt = *d; d++; int length = (data->length/4)-1; - if (plt == deadbeef->plt_get_curr ()) { - gtk_drag_finish (drag_context, TRUE, FALSE, time); - return; - } - ps->binding->drag_n_drop (NULL, plt, d, length); + ps->binding->drag_n_drop (NULL, plt, d, length, drag_context->action == GDK_ACTION_COPY ? 1 : 0); } gtk_drag_finish (drag_context, TRUE, FALSE, time); } diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c index 4e8ddd93..f360fecf 100644 --- a/plugins/gtkui/mainplaylist.c +++ b/plugins/gtkui/mainplaylist.c @@ -98,14 +98,15 @@ int main_get_idx (DdbListviewIter it) { return idx; } -void main_drag_n_drop (DdbListviewIter before, int playlist, uint32_t *indices, int length) { +void +main_drag_n_drop (DdbListviewIter before, int from_playlist, uint32_t *indices, int length, int copy) { deadbeef->plt_lock (); int curr = deadbeef->plt_get_curr (); - if (playlist == curr) { - deadbeef->pl_move_items (PL_MAIN, (DB_playItem_t *)before, indices, length); + if (copy) { + deadbeef->pl_copy_items (PL_MAIN, from_playlist, (DB_playItem_t *)before, indices, length); } else { - deadbeef->pl_copy_items (PL_MAIN, playlist, (DB_playItem_t *)before, indices, length); + deadbeef->pl_move_items (PL_MAIN, from_playlist, (DB_playItem_t *)before, indices, length); } deadbeef->plt_unlock (); } diff --git a/plugins/gtkui/trkproperties.c b/plugins/gtkui/trkproperties.c index a4a9462e..f4ce782f 100644 --- a/plugins/gtkui/trkproperties.c +++ b/plugins/gtkui/trkproperties.c @@ -25,6 +25,8 @@ #include "support.h" #include "../../deadbeef.h" #include "gtkui.h" +#include "mainplaylist.h" +#include "search.h" static GtkWidget *trackproperties; static DB_playItem_t *track; |