TheQwertiest / foo_spider_monkey_panel

foobar2000 component that allows to use JavaScript to create CUI/DUI panels
https://theqwertiest.github.io/foo_spider_monkey_panel/
MIT License
271 stars 21 forks source link

on_playlist_item_added/removed doesn't trigger on undo/redo #186

Open Daxtear opened 2 years ago

Daxtear commented 2 years ago

I am executing code when adding/removing files from a certain playlist. This works fine until I decide to undo, which has no way to be caught as far as I'm aware, causing things to desync. So there'd either be the need for new callbacks for undo/redo, or what would at least also work in my usecase is having undo/redo trigger on_playlist_item_added/removed when it should.

marc2k3 commented 2 years ago

It's the responsibility of foobar2000 core or other component adding/removing files to call undo backup. This is not a job to be handled inside the callback. Lots of components will be capturing the same notification. Your history would be ruined if they all did the same thing.

Example one:

Empty playlist, drag files from album list to it. Press Ctrl+Z. Contents cleared. You didn't have to do anything.

Example two:

Empty playlist, you use plman.InsertPlaylistItems to add a handle list. Ctrl+Z... nothing happens. This is because it's your responsibility to call plman.UndoBackup BEFORE InsertPlaylistItems.

In both of these examples, on_playlist_items_removed is triggered after the CTRL+Z.

Daxtear commented 2 years ago

That is not what I'm doing. I'm using a panel in conjunction with the default DUI playlist view. On playlist_item_added for a specific playlist, I then execute code to also add those items to another playlist. Same deal for removed. Basically I want to keep them synced WITHOUT just pasting all contents of one into the other. It's for "items recently added to this playlist". Sometimes I make mistakes though and want to delete them again. If I do that by simply deleting them, no problem. If I do that by using undo, on_playlist_items_removed is not triggered and so the "recently added to this playlist"-playlist doesn't apply the changes made to the main playlist by undoing.