Flash menu name when command is invoked with custom item


I have a coloured menu item with a keyboard shortcut attached to it.
I implemented a custom component and add it to the PopupMenu via the addCustomItem.

class ColouredCommandItem : public PopupMenu::CustomComponent
	ColouredCommandItem(int commandID_, ApplicationCommandManager* commandManager_,
			const Colour& itemTextColour)
	: CustomComponent(false), commandID(commandID_), commandManager(commandManager_),
	  textColour(itemTextColour), defLookAndFeel(LookAndFeel::getDefaultLookAndFeel())
		jassert (commandManager != nullptr && commandID != 0);

		const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);

		if (registeredInfo != nullptr)
			ApplicationCommandInfo info (*registeredInfo);
			ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);

			displayName = info.shortName;

			Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
					->getKeyPressesAssignedToCommand (commandID));

			for (int i = 0; i < keyPresses.size(); ++i)
				const String key (keyPresses.getReference(i).getTextDescriptionWithIcons());

				if (shortcutKey.isNotEmpty())
					shortcutKey << ", ";

				if (key.length() == 1 && key[0] < 128)
					shortcutKey << "shortcut: '" << key << '\'';
					shortcutKey << key;

			shortcutKey = shortcutKey.trim();


	void getIdealSize(int& idealWidth, int& idealHeight)
		// tells the menu how big we'd like to be..
		idealWidth = 200;
		idealHeight = 22;

	void paint (Graphics& g)
			g.fillAll (findColour (PopupMenu::highlightedBackgroundColourId));

		g.setFont (defLookAndFeel.getPopupMenuFont());
			g.setColour (findColour(PopupMenu::highlightedTextColourId));
			g.setColour (textColour);

		g.drawFittedText (displayName,
				25, 0, getWidth() - 8, getHeight(),
				Justification::left, 3);

		g.setFont (13.0f);
		g.drawFittedText (shortcutKey,
				0, 0, getWidth() - 5, getHeight(),
				Justification::right, 3);

	void mouseUp(const MouseEvent& e)
		commandManager->invokeDirectly(commandID, true);
	int commandID;
	Colour textColour;
	ApplicationCommandManager* commandManager;
	LookAndFeel& defLookAndFeel;
	String displayName;
	String shortcutKey;

How can I have the menubar name flashing when the command is invoked?

Or is there a more simple solution to have a coloured cammand item?



Did you see PopupMenu::addColouredItem?

And the best way to flash it would be to use the command manager to run it - that should take care of flashing the menu bar when it’s invoked.


I saw the PopupMenu::addColouredItem but how can I then connect the command manager to the item?

The PopupMenu::addCommandItem is also quite handy because it displays the Keyboard shortcut automatically in the menu.

Would it be possible that the addCommandItem has an additional Colour parameter? :slight_smile:
Or another function like addColouredCommandItem?

Thanks ,


Hmm, good point. I’ve been meaning to give that class a bit of an overhaul, and make the per-item options more useable.


That would be really nice. Looking forward.