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"] [html-path "rktplayer.html"]
[title "Racket Music Player"] [title "Racket Music Player"]
[icon (build-path rkt-gui-dir "rktplayer.png")] [icon (build-path rkt-gui-dir "rktplayer.png")]
[quit-on-close #f]
) )
(define initialized (make-semaphore 0)) (define initialized (make-semaphore 0))
@@ -386,12 +387,14 @@
(send this update-playlist) (send this update-playlist)
) )
(define el-dragged #f)
(define/public (update-playlist) (define/public (update-playlist)
(let* ((html (send playlist to-html)) (let* ((html (send playlist to-html))
(result (send el-playlist set-innerHTML! html)) (result (send el-playlist set-innerHTML! html))
) )
(dbg-rktplayer "result: ~a" result) (dbg-rktplayer "result: ~a" result)
(send this set-attr! "table.tracks tr" '(draggable "true"))
(send this bind! "table.tracks tr" 'click (send this bind! "table.tracks tr" 'click
(λ (el evt data) (λ (el evt data)
(let* ((track-id (send el attr/symbol 'id)) (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) (update-track-nr current-track-nr)
) )
(send this update-volume) (send this update-volume)
@@ -594,6 +637,7 @@
(send player quit) (send player quit)
(set! closed #t) (set! closed #t)
(send this close) (send this close)
(dbg-rktplayer "Calling super -> quit")
(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?) (define/override (can-close?)
(show-hide) (show-hide)
#f) #f)
+1 -1
View File
@@ -1,6 +1,6 @@
#lang racket #lang racket
(require racket-sound) (require racket-audio)
(provide music-lib-relevant? (provide music-lib-relevant?
is-music-dir? is-music-dir?
+1 -1
View File
@@ -1,7 +1,7 @@
#lang racket #lang racket
(require racket/class (require racket/class
racket-sound racket-audio
"utils.rkt" "utils.rkt"
) )
+38 -1
View File
@@ -2,10 +2,11 @@
(require racket/class (require racket/class
"music-library.rkt" "music-library.rkt"
racket-sound racket-audio
"utils.rkt" "utils.rkt"
racket-sprintf racket-sprintf
keystore/class keystore/class
racket/list
) )
(provide track% (provide track%
@@ -331,6 +332,42 @@
(send this save-tab!)) (send this save-tab!))
) )
(define/public (move-track from-idx to-idx)
(let ((tr (list-ref tracks from-idx))
(idx 0))
(if (= from-idx to-idx)
#t
(begin
(when (< from-idx to-idx)
(set! to-idx (- to-idx 1)))
(let* ((l1 (if (= from-idx 0)
'()
(take tracks from-idx)))
(l2 (drop tracks (+ from-idx 1)))
(l (append l1 l2))
)
(set! tracks (append
(if (= to-idx 0) '() (take l to-idx))
(list tr)
(drop l to-idx)))
)
(send this save-tab!)
)
)
)
)
(define/public (drop-id track-id)
(let ((idx (send this index track-id)))
(let* ((l1 (if (= idx 0) '() (take tracks idx)))
(l2 (drop tracks (+ idx 1)))
(l (append l1 l2)))
(set! tracks l)
(send this save-tab!)
)
)
)
(define/public (track i) (define/public (track i)
(list-ref tracks i)) (list-ref tracks i))
+2 -1
View File
@@ -4,7 +4,7 @@
"gui.rkt" "gui.rkt"
"tray.rkt" "tray.rkt"
simple-ini/class simple-ini/class
racket-sound racket-audio
racket-webview racket-webview
racket/runtime-path racket/runtime-path
"utils.rkt" "utils.rkt"
@@ -55,6 +55,7 @@
(when (or (null? no-exit) (when (or (null? no-exit)
(not (eq? (car no-exit) #t))) (not (eq? (car no-exit) #t)))
(webview-wait-for-quit) (webview-wait-for-quit)
(send rktplayer-tray close)
(webview-exit) (webview-exit)
(exit)) (exit))
) )
+2
View File
@@ -50,6 +50,8 @@
[tooltip (tr "Racket Music Player")]) [tooltip (tr "Racket Music Player")])
(begin (begin
(send rktplayer-gui set-window-state-change-callback!
(λ () (adjust-menu)))
(adjust-menu) (adjust-menu)
) )