drag/drop

This commit is contained in:
2026-05-04 15:41:24 +02:00
parent 57be1f327a
commit 167ef6d8ac
6 changed files with 96 additions and 4 deletions
+52
View File
@@ -43,6 +43,7 @@
[html-path "rktplayer.html"]
[title "Racket Music Player"]
[icon (build-path rkt-gui-dir "rktplayer.png")]
[quit-on-close #f]
)
(define initialized (make-semaphore 0))
@@ -386,12 +387,14 @@
(send this update-playlist)
)
(define el-dragged #f)
(define/public (update-playlist)
(let* ((html (send playlist to-html))
(result (send el-playlist set-innerHTML! html))
)
(dbg-rktplayer "result: ~a" result)
(send this set-attr! "table.tracks tr" '(draggable "true"))
(send this bind! "table.tracks tr" 'click
(λ (el evt data)
(let* ((track-id (send el attr/symbol 'id))
@@ -401,6 +404,46 @@
)
)
)
(send this bind! "table.tracks tr" 'contextmenu
(λ (el evt data)
(let ((mnu (wv-menu 'track-menu
(wv-menu-item 'm-drop-track "Drop track"
#:callback (λ ()
(send playlist drop-id (send el id))
(update-playlist))
)
)
)
(clientX (hash-ref data 'clientX 60))
(clientY (hash-ref data 'clientY 60))
)
(send this popup-menu! mnu clientX clientY))))
(let ((from-idx #f)
(to-idx #f))
(send this bind! "table.tracks tr" 'dragstart
(λ (el evt data)
(set! el-dragged el)
(dbg-rktplayer "Dragging element ~a" (send el id))
(set! from-idx (send playlist index (send el id)))
)
#t)
(send this bind! "table.tracks tr" 'dragover
(λ (el evt data)
#t)
)
(send this bind! "table.tracks tr" 'drop
(λ (el evt data)
(dbg-rktplayer "Element dropped on ~a" (send el id))
(set! to-idx (send playlist index (send el id)))
(when (and (integer? from-idx) (integer? to-idx)
(not (= from-idx to-idx)))
(send playlist move-track from-idx to-idx)
(update-playlist)
)
)
)
)
(update-track-nr current-track-nr)
)
(send this update-volume)
@@ -594,6 +637,7 @@
(send player quit)
(set! closed #t)
(send this close)
(dbg-rktplayer "Calling super -> quit")
(super quit)
)
@@ -623,6 +667,14 @@
)
)
(define window-state-change-callback (λ () #t))
(define/public (set-window-state-change-callback! f)
(set! window-state-change-callback f))
(define/override (window-state-changed st)
(window-state-change-callback))
(define/override (can-close?)
(show-hide)
#f)