TextEditor pop-up menu handling


#1

Hi Jules,

Many thanks for putting-in those pop-up menu changes.

Two requests please that have come from experimenting with your changes:

  1. 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. :slight_smile:

  2. 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.

Hoping that makes sense. :slight_smile:

Many thanks,

Pete


#2

Ah, I wondered where menuVisible flag had come from, but couldn’t remember so chopped it! I’ll put in a proper method to return the status.

Don’t understand your second request… Can’t you just call:

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)

}

?


#3

Hi Jules,

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. :slight_smile:

I’ll get there in the end. :roll:


#4

Yeah, that’ll do it. I’ve checked in the texteditor changes now (I was just messing with that class anyway, so that was good timing).


#5

You still have “dragging” of highlighted text block around in the TextEditor somewhere in the depths of the “to do” list, don’t you? :slight_smile:


#6

It’s quite a long way down the list…


#7

Hi Jules,

No worries!

I’ve just spotted one thing that I really need in the pop-up handler… :frowning: … which is easy to do. :slight_smile:

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. :slight_smile:

TIA!!

Pete


#8

Well ok, but it’ll have to be a pointer, so it could be null if the menu ever needs to be triggered by a non-mouse method.


#9

Brilliant. :slight_smile:


#10

Thanks Jules, the head of SVN now works fine for me. :slight_smile:


#11