Contextual Additions?

Does anyone know why if a user right-clicks ON TEXT in my text area, underneath my contextual menu there are extra entries such as:

Search With Google
Add to iTunes as a Spoken Track

Is there no way to prevent these from appearing?

Thank you.

I don’t think so. But instead of displaying TextArea’s native menu, you can create your own.

I have already created my own contextual menu, but the google and iTunes options are added to the bottom :frowning:

You have to return True in ConstructContextualMenu.

I already have returned true:

base.append(New MenuItem("Create New File")) Return True

Quickly tested it in a new project on OS X and only “Create New File” is shown. When returning False, spell-checking etc. is added after “Create New File” by the Cocoa framework.

I only see the additional entries if the mouse is OVER SOME TEXT.

Yes, I see. Actually I am wrong about returning True - it doesn’t matter for these entries.

I guess it cannot be prevented?

I assume this needs some declares into the Objective C Runtime.

Thanks anyway Eli :slight_smile:

Here is what you do : place the code in Mousedown. Additions gone. Note hitItem = base.popup which makes the menu appear.

[code]Function MouseDown(X As Integer, Y As Integer) As Boolean
if IsContextualClick = true then
// Make the base item, this is what will be doing the popping up
dim base as new MenuItem

// Add some items
base.Append( new MenuItem( "Picture" ) )
base.Append( new MenuItem( "Movie" ) )
base.Append( new MenuItem( "Sound" ) )
base.Append( new MenuItem( "Recording" ) )

// Now display the menu
dim hitItem as MenuItem
hitItem = base.PopUp

if hitItem <> nil then
  msgbox hitItem.text
  'RaiseEvent itemSelected(hitItem.text)
end if

return true

end if
End Function

Thank you very much Michel.
I will try that later when I get back to my iMac :slight_smile:

Thanks !

Michel - thank you for that solution! If you also want it to select the word (like the “regular” contextual click does), you can add the following code before making the menu. Note: this could probably use some testing, and if this functionality already exists and I didn’t know it, I’m going to feel silly. LOL

    //Select the word
    dim startPos as Integer = me.CharPosAtXY(x,y)
    dim endPos as Integer = me.CharPosAtXY(x,y)
    while startPos > 1 and mid(me.text, startPos - 1,1) <> " "
      startPos = startPos - 1
    while endPos < me.Text.Len + 1 and mid(me.Text, endPos, 1) <> " "
      endPos = endPos + 1
    me.SelStart = startPos - 1
    me.SelLength = (endPos - startPos) 

Excellent idea, especially if the menu contains copy/cut options.

Taking this a step further - is there any way to prevent a contextual click COMPLETELY, so that if a user right-clicks on a text area - absolutely nothing appears - not even the usual OS choices?


Sure, put this in your mousedown event.

  if IsContextualClick = true then
    me.SelStart = me.CharPosAtXY(x,y) 'puts the cursor where you right clicked
    return true 'don't do anything else with the right click
  end if

Ahhh - I tried to simply put return true and got an error :slight_smile:
I will try your code now - thank you.

You shouldn’t get an error if you put a return true in MouseDown. You may have tried it in MouseUp? My code should be in MouseDown.

I put it in MouseUp :slight_smile:
All working now !

Thank you.