Browse Source

Added a shortcut key description field to PopupMenu::Item

tags/2021-05-28
jules 9 years ago
parent
commit
6f8b9205a5
2 changed files with 16 additions and 9 deletions
  1. +8
    -9
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp
  2. +8
    -0
      modules/juce_gui_basics/menus/juce_PopupMenu.h

+ 8
- 9
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -82,7 +82,7 @@ struct ItemComponent : public Component
parent.addAndMakeVisible (this);
shortcutKeyDescription = getShortcutKeyDescription();
updateShortcutKeyDescription();
int itemW = 80;
int itemH = 16;
@@ -118,7 +118,7 @@ struct ItemComponent : public Component
item.isTicked,
hasSubMenu (item),
item.text,
shortcutKeyDescription,
item.shortcutKeyDescription,
item.image,
getColour (item));
}
@@ -145,14 +145,13 @@ struct ItemComponent : public Component
}
PopupMenu::Item item;
String shortcutKeyDescription;
private:
// NB: we use a copy of the one from the item info in case we're using our own section comp
ReferenceCountedObjectPtr<CustomComponent> customComp;
bool isHighlighted;
String getShortcutKeyDescription() const
void updateShortcutKeyDescription()
{
if (item.commandManager != nullptr && item.itemID != 0)
{
@@ -173,16 +172,14 @@ private:
shortcutKey << key;
}
return shortcutKey.trim();
item.shortcutKeyDescription = shortcutKey.trim();
}
return String();
}
String getTextForMeasurement() const
{
return shortcutKeyDescription.isNotEmpty() ? item.text + " " + shortcutKeyDescription
: item.text;
return item.shortcutKeyDescription.isNotEmpty() ? item.text + " " + item.shortcutKeyDescription
: item.text;
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ItemComponent)
@@ -1245,6 +1242,7 @@ PopupMenu::Item::Item (const Item& other)
image (other.image != nullptr ? other.image->createCopy() : nullptr),
customComponent (other.customComponent),
commandManager (other.commandManager),
shortcutKeyDescription (other.shortcutKeyDescription),
colour (other.colour),
isEnabled (other.isEnabled),
isTicked (other.isTicked),
@@ -1261,6 +1259,7 @@ PopupMenu::Item& PopupMenu::Item::operator= (const Item& other)
image = (other.image != nullptr ? other.image->createCopy() : nullptr);
customComponent = other.customComponent;
commandManager = other.commandManager;
shortcutKeyDescription = other.shortcutKeyDescription;
colour = other.colour;
isEnabled = other.isEnabled;
isTicked = other.isTicked;


+ 8
- 0
modules/juce_gui_basics/menus/juce_PopupMenu.h View File

@@ -137,6 +137,14 @@ public:
/** A command manager to use to automatically invoke the command, or nullptr if none is specified. */
ApplicationCommandManager* commandManager;
/** An optional string describing the shortcut key for this item.
This is only used for displaying at the right-hand edge of a menu item - the
menu won't attempt to actually catch or process the key. If you supply a
commandManager parameter then the menu will attempt to fill-in this field
automatically.
*/
String shortcutKeyDescription;
/** A colour to use to draw the menu text.
By default this is transparent black, which means that the LookAndFeel should choose the colour.
*/


Loading…
Cancel
Save