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
274 stars 21 forks source link

Can't delete files #163

Closed FunctionDJ closed 2 years ago

FunctionDJ commented 2 years ago

I'm trying to run fb.RunContextCommandWithMetadb("Delete file(s)", handle) but it always fails (returns false). Am i doing something wrong? I tried both with a handle list and a single handle.

marc2k3 commented 2 years ago

Well it must be Delete File for a handle or handle list with a count of 1 and Delete Files for a handle list with multiple handles. If you really meant that, don't write Delete file(s) because that's obviously wrong/misleading to anyone reading.

Also, the return value it not based on the success of the command. It's whether the command exists. And if the dialogs/operations are asynchronous, the function will return immediately anyway. Taking it to the extreme, it could be minutes/hours before whatever action is finished.

Anyway, you might find it easier to use FileSystemObject.

FunctionDJ commented 2 years ago

Thanks for the advice! I just used the name that i saw in the Keyboard Shortcuts settings. Using the variations you mentioned makes a lot more sense, but i don't know where they are listed. Also really good to know about the async behaviour. I'll probably end up using FSO like you recommended.

FunctionDJ commented 2 years ago

I appears that fb.RunContextCommandWithMetadb("Delete files", fb.GetSelections()) only works when more than 1 track is selected, even though the result of GetSelections() is always a handle list.

regorxxx commented 2 years ago

If you check marc answer, the menu changes to Delete file whenever the list only has 1 handle. The menu is related to the handle count, not to the object prototype used. So that's not a bug but intended behavior, since the menu is created outside SMP context. Anyway you can bypass that limitation with a bit of code:

const handleList = fb.GetSelections();
fb.RunContextCommandWithMetadb(handleList.Count > 1 ? "Delete files" : "Delete file", handleList)
FunctionDJ commented 2 years ago

@regorxxx that's basically what i wrote already :D i wasn't sure that these command names are literally taken from the available context menu, that's good to know. for some reason i thought it was just something that grew historically or something like that. thanks!

regorxxx commented 2 years ago

Yep it's a bit counterintuitive on first thought. But since the menus are created by the main program.... have that in mind in your other use-cases, it can only use whatever is there for the selection (not sure if that's related in any way to your "play" error).