Dialog Window Shortcuts

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

Keeps
Posts: 17
Joined: Sat Sep 03, 2011 4:25 pm

Dialog Window Shortcuts

Post by Keeps »

Hello,

I made a couple simple scripts that did a single thing, then I made a script that had a couple versions of how I wanted it to behave, and I was happy making two copies with different hard-coded settings, as clunky as that is.

Then I wanted to add a script that would have eight permutations of options, and that was absurd. It took an unfortunate amount of work, but I managed to crib together a working popup dialog with all the options and settings, and I love it.

But now I'm thinking I would like to add keyboard shortcuts for the buttons in my dialog popup, and I have no idea how to start that. (Like pressing ESC cancels (something does that for me), I want to be able to type Y or N for "yes" or "no," that kind of thing.
Not a global hotkey, that's working already.) Is that something defined in the HTML? In the popup JS? Or still in the action JS? All three? I'm not having luck with the wiki or any scripts I've already tried - is there a script I could reference that does that?

If anyone wants specifics, here's the current plugin I've got:
https://www.dropbox.com/s/w5wuhd1q86zhu ... .mmip?dl=0
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Dialog Window Shortcuts

Post by drakinite »

Hi there, thanks for making addons for MediaMonkey!

If you just want a simple keydown handler, you can do localListen on document.body and execute code depending on the key that was pressed. https://developer.mozilla.org/en-US/doc ... boardEvent

Code: Select all

localListen(document.body, 'keydown', e => {
	console.log(e); // you can remove this obviously, but this can help show what details of the keyboard event that occurred
	switch(e.key) { // you could also do e.key.toLowerCase() if you want to ignore shift, because shift + y registers as 'Y'
		case 'y':
			// handle yes
			break;
		case 'n':
			// handle no
			break;
		case 'f':
			// handle "female"?
			break;
		case 'm':
			// handle "male"?
			break;
		default:
			// if you want to do something as a default action
	}
});
If you want to do more complex stuff like listening to already-registered hotkeys, Undock Panels (in dialogs/dlgUndockedControl.js) is a working example.

Notes:
  • I noticed the data-defaultSize in dlgSetGender.html is very small. I'd recommend increasing it to something like 500,200 https://i.imgur.com/K5EWtAv.png
  • I would recommend giving some indication in the dialog of what tracks are going to be updated. As a minimum, I would note the number of tracks that are selected, just in case they accidentally decided to mass edit 1000 tracks. Alternatively, you could use the same technique as dlgTrackProperties.js, where it gives a warning before a mass edit. (see the lines of code around 'Are you sure that you want to modify %d files ?')
  • This is minor, but it would be a good idea to make a habit of including "minAppVersion" in info.json for any new addons that are created. That way, future versions of MediaMonkey will be able to know for certain what versions it's compatible with. (In this case, it'd be "minAppVersion": "5.0.0".)
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Keeps
Posts: 17
Joined: Sat Sep 03, 2011 4:25 pm

Re: Dialog Window Shortcuts

Post by Keeps »

That's perfect, thank you!

drakinite wrote: Sat Apr 09, 2022 4:30 pm [*] I noticed the data-defaultSize in dlgSetGender.html is very small. I'd recommend increasing it to something like 500,200 https://i.imgur.com/K5EWtAv.png
Oh, that's why that keeps happening! It kept defaulting really big and never seemed to change sizes, so I just started cutting the dimensions in half until it worked, and I never actually counted. But now it pops up tiny any time I change the size of the main window, which must be when it would have refreshed the initial values that I couldn't get to go away.

drakinite wrote: Sat Apr 09, 2022 4:30 pm [*] I would recommend giving some indication in the dialog of what tracks are going to be updated. As a minimum, I would note the number of tracks that are selected, just in case they accidentally decided to mass edit 1000 tracks. Alternatively, you could use the same technique as dlgTrackProperties.js, where it gives a warning before a mass edit. (see the lines of code around 'Are you sure that you want to modify %d files ?')
I can do that.

drakinite wrote: Sat Apr 09, 2022 4:30 pm [*] This is minor, but it would be a good idea to make a habit of including "minAppVersion" in info.json for any new addons that are created. That way, future versions of MediaMonkey will be able to know for certain what versions it's compatible with. (In this case, it'd be "minAppVersion": "5.0.0".)
I thought I already did, but it isn't in any of my infos. Maybe I just remember putting it in the addon submission form? I'll fix that too, thanks for the help!
Post Reply