# TextEditor pop-up menu handling

**URL:** <https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922>\
**Category:** General JUCE discussion\
**Created:** [July 19, 2007, 8:33am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922 "2007-07-19T08:33:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 8:33am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/1 "2007-07-19T08:33:33Z")

</div>

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

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

Many thanks,

Pete

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 19, 2007, 8:52am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/2 "2007-07-19T08:52:17Z")

</div>

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)

```

}

?

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 9:12am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/3 "2007-07-19T09:12:08Z")

</div>

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:

```auto
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):

```auto
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’ll get there in the end. :roll:

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 19, 2007, 9:14am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/4 "2007-07-19T09:14:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 9:22am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/5 "2007-07-19T09:22:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 19, 2007, 9:36am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/6 "2007-07-19T09:36:11Z")

</div>

It’s quite a long way down the list…

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 9:46am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/7 "2007-07-19T09:46:22Z")

</div>

Hi Jules,

No worries!

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…

```auto
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. 🙂

TIA!!

Pete

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 19, 2007, 9:49am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/8 "2007-07-19T09:49:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 9:55am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/9 "2007-07-19T09:55:13Z")

</div>

Brilliant. 🙂

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [July 19, 2007, 10:54am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/10 "2007-07-19T10:54:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:27am UTC](https://forum.juce.com/t/texteditor-pop-up-menu-handling/1922/11 "2017-05-12T10:27:10Z")

</div>

Closed on May 12, 2017, 10:27am UTC


