summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtkplaylist.c17
-rw-r--r--playlist.c29
-rw-r--r--playlist.h3
3 files changed, 46 insertions, 3 deletions
diff --git a/gtkplaylist.c b/gtkplaylist.c
index d034b5b2..b31b09df 100644
--- a/gtkplaylist.c
+++ b/gtkplaylist.c
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
+#include <assert.h>
#include "gtkplaylist.h"
#include "callbacks.h"
#include "interface.h"
@@ -175,9 +176,10 @@ draw_playlist (GtkWidget *widget, int x, int y, int w, int h) {
}
}
it = it_copy;
- for (row = row1; row < row2; row++) {
- draw_ps_row (backbuf, cr, row, it);
- it = it->next;
+ int idx = 0;
+ for (row = row1; row < row2; row++, idx++) {
+ draw_ps_row (backbuf, cr, row, it);
+ it = it->next;
}
cairo_destroy (cr);
@@ -706,6 +708,15 @@ gtkps_keypress (int keyval, int state) {
messagepump_push (M_PLAYSONGNUM, 0, playlist_row, 0);
return;
}
+ else if (keyval == GDK_Delete) {
+ ps_delete_selected ();
+ if (playlist_row >= ps_getcount ()) {
+ playlist_row = ps_getcount () - 1;
+ }
+ draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
+ gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
+ return;
+ }
else if (keyval == GDK_Down && playlist_row < ps_getcount () - 1) {
playlist_row++;
if (playlist_row > scrollpos + widget->allocation.height / rowheight - 1) {
diff --git a/playlist.c b/playlist.c
index d2f9e9af..c4808acb 100644
--- a/playlist.c
+++ b/playlist.c
@@ -573,3 +573,32 @@ ps_find_meta (playItem_t *it, const char *key) {
}
return "?";
}
+
+void
+ps_delete_selected (void) {
+ playItem_t *next = NULL;
+ for (playItem_t *it = playlist_head; it; it = next) {
+ next = it->next;
+ if (it->selected) {
+ if (it->prev) {
+ it->prev->next = it->next;
+ }
+ if (it->next) {
+ it->next->prev = it->prev;
+ }
+ if (playlist_head == it) {
+ playlist_head = it->next;
+ }
+ if (playlist_tail == it) {
+ playlist_tail = it->prev;
+ }
+ if (playlist_current_ptr == it) {
+ playlist_current_ptr = NULL;
+ }
+ ps_item_free (it);
+ free (it);
+ ps_count--;
+ }
+ }
+}
+
diff --git a/playlist.h b/playlist.h
index 7a36eaf4..5e511be0 100644
--- a/playlist.h
+++ b/playlist.h
@@ -75,4 +75,7 @@ ps_format_item_display_name (playItem_t *it, char *str, int len);
const char *
ps_find_meta (playItem_t *it, const char *key);
+void
+ps_delete_selected (void);
+
#endif // __PLAYLIST_H