Many thanks for putting-in those pop-up menu changes.
Two requests please that have come from experimenting with your changes:
Can you please a method so that we can query if the pop-up is visible (e.g. const bool getPopupVislble() )? The reason for this is that one of my apps needs (in two separate sub-classes of TextEditor, that do different things) to check this when handling loss-of-focus events. I’d handled this in previous Juce builds by modifying the class to look at an exposed menuVisible member variable, but that has now disappeared.
Could you please add a new method to PopupMenu to allow a menu to be added/merged-in at a specific index location at the “top level” of the menu, rather than only in a sub-menu? That will enable me to reposition the default copy/cut etc. menu items provided by addPopupMenuItems, at whatever location I want (e.g. by adding some menu items above them in the list). I want my menu items to appear earlier, but at the same level. I know that I could alternatively copy the supplied PopupMenu to a local PopUpMenu, then clear the supplied PopUpMenu, then add-back the local copy of the original menu as a sub menu, but that isn’t quite the effect I want.
Thanks for saying you’ll add that method - many thanks!
On to your question, sorry Jules, I was confused there … for some reason, I though that I’d be passed a pre-populated menu list. Doh!
So, for the avoidance of doubt, if I want to add the text editor pop-up menu to a sub-menu, I’d do something like this:
void addPopupMenuItems (PopupMenu& m)
{
m.addItem (some of my items before the default ones)
PopupMenu lTextEditorSubMenu;
TextEditor::addPopupMenuItems (lTextEditorSubMenu);
m.addSubMenu(T("Edit..."), lTextEditorSubMenu);
m.addItem (some more items after the default ones)
}
And I just wanted to add the text editor pop-up menu items “in-line”, I’d do something like this (your example):
void addPopupMenuItems (PopupMenu& m)
{
m.addItem (some of my items before the default ones)
TextEditor::addPopupMenuItems (m);
m.addItem (some more items after the default ones)
}
That all looks very easy and hunky-dory. Might be worth adding to the docs.
I’ve just spotted one thing that I really need in the pop-up handler… … which is easy to do.
That is, I need to know exactly where in the text editor the user clicked when they invoked the pop-up menu (this is because the menu is context-sensitive, depending on the position in the underlying text).
Could you please pass-in a reference to the pop-up MouseEvent, in the call to addPopupMenuItems (…); like this…
void TextEditor::mouseDown (const MouseEvent& e)
{
beginDragAutoRepeat (100);
newTransaction();
if (wasFocused || ! selectAllTextWhenFocused)
{
if (! (popupMenuEnabled && e.mods.isPopupMenu()))
{
moveCursorTo (getTextIndexAt (e.x, e.y),
e.mods.isShiftDown());
}
else
{
PopupMenu m;
addPopupMenuItems (m, e);
menuActive = true;
const int result = m.show();
menuActive = false;
if (result != 0)
performPopupMenuAction (result);
}
}
Just requires changes to one or two lines of code.