TextArea Contextual Menu

by default Textareas have a contextual menu, that has a whole bunch of stuff that does not apply to the application I am writing
such as FONT, Spelling etc…
but does NOT seem to have SELECT ALL

I know I can override the menu completely with CONSTRUCTCONTEXTUALMENU

but (brain fade I guess)… How to I insert menuitems that relate to the built in edit functions???

  • UNDO
  • REDO
  • CUT
  • COPY
  • PASTE
  • SELECT ALL
  • DELETE

I would like them to automagically inherit the enabled property based on the status of the TextArea
(and for one TA that is ReadOnly… I will leave out UNDO,REDO, PASTE and DELETE)

basically duplicate the main menu EDIT column (except for Dictation and such)

On Windows there is no default contextual menu however I can create one by appending items from the edit menu e.g.base.Append(EditPaste) base.Append(EditSelectAll)

This can cause issues as you really don’t want to have the same item in 2 menus at the same time
I’d clone it and append the clone

[quote=326065:@Norman Palardy]This can cause issues as you really don’t want to have the same item in 2 menus at the same time
I’d clone it and append the clone[/quote]
Not sure I understand what you mean?

or are you saying create a new menu item that has the same properties as say “EditUndo”

  • Text = &Undo
  • Key = Z
    etc

Literally “clone”
The reason is in the notes on the page
http://documentation.xojo.com/index.php/MenuItem.Clone

ok… here is what I did

Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) Handles ConstructContextualMenu as Boolean
  base.Append(EditUndo.clone)
  base.append(EditCut.clone)
  base.Append(EditCopy.clone)
  base.append(EditPaste.clone)
  base.Append(EditClear.clone)
  base.Append(EditSelectAll.clone)
End Function

and it is close but no cigar

  • First time you right click on the TextArea … ALL menu items are active (including cut and copy when there is no text, let alone any selection)
  • all the items work, EXCEPT “UNDO”… it enables/disables properly, and the title changes (“Undo Typing” or “Undo Paste”) but it doesn’t actually undo them

Is there a REDO menuitem???

[quote=326050:@Dave S]How to I insert menuitems that relate to the built in edit functions???
basically duplicate the main menu EDIT column (except for Dictation and such)[/quote]

Popup the edit menu.

http://documentation.xojo.com/index.php/MenuItem.Popup

Thanks Michel… as you notice above (1 post above yours)… I have it working… .but with two issues…

note the “normal” editmenu has things I do not want such as Dictation and Emojis

I don’t think you can suppress them if you want the automatic native behavior. The subject pops up regularly.

You may try renaming the menu from Edit to something else, which will get rid of these items, but not sure if the automatic behavior will remain.

That said, If I never use Dictation, I do use Emojis all the time.

[quote=326075:@Michel Bujardet]Popup the edit menu.

http://documentation.xojo.com/index.php/MenuItem.Popup[/quote]

Same difference… :frowning:
I tried this based on what Michel said

Function MouseDown(X As Integer, Y As Integer) Handles MouseDown as Boolean
  Dim popMenu As MenuItem
  Dim selectedMenu As MenuItem
  If IsContextualClick Then 
    If Me.ReadOnly=False Then 
      popMenu = EditMenu.Clone
    Else
      popMenu = EditCopy.clone
    End If
    selectedMenu = popMenu.Popup
    Return True
  Else
    Return MouseDown(x,y)
  End If
End Function

vs. this

Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) Handles ConstructContextualMenu as Boolean
  if me.ReadOnly=false then 
    base.append(EditMenu.clone)
  else
    base.Append(EditCopy.clone)
  end if
  return true
End Function

or this

Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) Handles ConstructContextualMenu as Boolean
  if me.ReadOnly=false then 
    base.Append(EditUndo.clone)
    base.append(New MenuItem(MenuItem.TextSeparator))
    base.Append(EditCut.clone)
    base.Append(EditCopy.clone)
    base.Append(EditPaste.clone)
    base.Append(EditClear.clone)
    base.Append(New MenuItem(MenuItem.TextSeparator))
    base.Append(EditSelectAll.clone)
  else
    base.Append(EditCopy.clone)
  end if
  return true
End Function

All 3 versions operate EXACTLY the same

  • First time you right click on the TextArea … ALL menu items are active (including cut and copy when there is no text, let alone any selection)
  • all the items work, EXCEPT “UNDO”… it enables/disables properly, and the title changes (“Undo Typing” or “Undo Paste”) but it doesn’t actually undo them

If I do not do ANY of those… and leave the Textarea to its default…
All I get is CUT/COPY/PASTE (and a ton of useless items)
and DO NOT get UNDO/REDO/CLEAR/SELECT ALL

Here is what I came up with… but I lost the Undo/Redo except from the main menu :frowning:

Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) Handles ConstructContextualMenu as Boolean
  Dim mm As MenuItem
  Dim hasTxt As Boolean=(Len(Me.Text)>0)
  Dim hasSel As Boolean =(Me.SelLength>0)
  Dim RO As Boolean =  Me.ReadOnly
  //
  If RO=False Then 
    mm=EditCut.clone
    mm.Enabled=hasSel
    base.append mm
  End If
  //
  mm=EditCopy.clone
  mm.Enabled=hasSel
  base.append mm
  //
  If RO=False Then 
    Dim cb As New Clipboard
    mm=EditPaste.clone
    mm.Enabled=(cb.TextAvailable)
    base.append mm
    //
    mm=EditClear.clone
    mm.Enabled=hasSel
    base.append mm
  End If
  //
  mm=EditSelectAll.clone
  mm.Enabled=hasTxt
  base.append mm
  
  // Note : cannot rely on ENABLE state of parent menu items, as they are not set until THEIR parent is selected
End Function