Example for attaching Mac Edit menu bar items when TextEditor has focus?


#1

Hi. Can anyone point me to an example of how to wire-up my Mac JUCE app’s Edit menu items to appear and be properly active when a TextEditor field has the focus? I would expect to have seen this capability in Projucer itself, when editing IDE settings and the like, but such is not the case. There’s only the right-click popup menu edit items. Basically, I’d like those actions tied into the main menu’s Edit menu pull down.

Thank you!

/Jay


#2

https://docs.juce.com/develop/classApplicationCommandManager.html

you gotta do some stuff in the guts of your implementation of how it populates the menu to check flags as to whether or not a menu item should be enabled or not.

when you add your menu bar, the menubar model, and associate it with the ApplicationCommandManager, the function that returns the popup menu for the menu bar is where you’ll check whether your menu item should be enabled/checked/etc.

at least, that’s what my experience was when I had to do it.


#3

Thank you, …but, TextEditor does this already with it’s pop-up Edit menu. I would have expected it to be a couple of lines of code to route the pop-up’s logic to the Mac Menu bar’s Edit menu. Thus why I was asking for an example.


#4

Maybe there is a way to capture the popup menu that’s passed to

void TextEditor::addPopupMenuItems	(	PopupMenu & 	menuToAddTo,
const MouseEvent * 	mouseClickEvent 

and give that to your MenuBarModel…


#5

Thank you, I’ll give that a try.

I find it rather interesting that such a fundamental Mac thing as operating the Mac’s Edit menu while doing TextEditor operations isn’t a readily known JUCE pattern. Maybe I’ll open a GitHub example for how to do it once I get it sorted out. :slight_smile: