1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-17 00:44:19 +00:00

Added some PopupMenu::addItem overloads which let you attach a lambda callback to be invoked for a menu item.

This commit is contained in:
jules 2019-06-17 17:28:46 +01:00
parent acbdec3f71
commit 0367d5c3a9
7 changed files with 215 additions and 139 deletions

View file

@ -30,8 +30,8 @@ namespace juce
class KeyMappingEditorComponent::ChangeKeyButton : public Button
{
public:
ChangeKeyButton (KeyMappingEditorComponent& kec, const CommandID command,
const String& keyName, const int keyIndex)
ChangeKeyButton (KeyMappingEditorComponent& kec, CommandID command,
const String& keyName, int keyIndex)
: Button (keyName),
owner (kec),
commandID (command),
@ -50,31 +50,31 @@ public:
keyNum >= 0 ? getName() : String());
}
static void menuCallback (int result, ChangeKeyButton* button)
{
if (button != nullptr)
{
switch (result)
{
case 1: button->assignNewKey(); break;
case 2: button->owner.getMappings().removeKeyPress (button->commandID, button->keyNum); break;
default: break;
}
}
}
void clicked() override
{
if (keyNum >= 0)
{
// existing key clicked..
Component::SafePointer<ChangeKeyButton> button (this);
PopupMenu m;
m.addItem (1, TRANS("Change this key-mapping"));
m.addSeparator();
m.addItem (2, TRANS("Remove this key-mapping"));
m.showMenuAsync (PopupMenu::Options(),
ModalCallbackFunction::forComponent (menuCallback, this));
m.addItem (TRANS("Change this key-mapping"),
[button]
{
if (button != nullptr)
button.getComponent()->assignNewKey();
});
m.addSeparator();
m.addItem (TRANS("Remove this key-mapping"),
[button]
{
if (button != nullptr)
button->owner.getMappings().removeKeyPress (button->commandID,
button->keyNum);
});
m.showMenuAsync (PopupMenu::Options().withTargetComponent (this));
}
else
{