Contextual menu won't close

I have a contextual menu which opens another document window in front of the main window.
This has worked fine for a very long time but in Xojo 2018R3 the contextual menu remains visible in front of the new Window until you re-select an item or click anywhere on the Window

What code do you use to display the contextual menu?
It should go away when you select an item.
Try getting the result of the popup,
Then setting the menu to nil, then opening the new window

[quote=423279:@Jeff Tullin]What code do you use to display the contextual menu?
It should go away when you select an item.
Try getting the result of the popup,
Then setting the menu to nil, then opening the new window[/quote]
How do I set the menu to nil?

Function ConstructContextualMenu(index as Integer, base as MenuItem, x as Integer, y as Integer) As Boolean base.append(New MenuItem("Edit")) base.append(New MenuItem("Delete"))

[code]Function ContextualMenuAction(index as Integer, hitItem as MenuItem) As Boolean

Select Case HitItem.text
case “Edit”
editmode = true
frmAddRecord.show[/code]

Ah that’s interesting.
I dont use those functions.

When a contextual menu is needed, I create one on the fly:

[code]dim base as new menuitem
Dim mnuOption as menuitem
mnuOption = new menuitem
mnuOption.text = “Walk”
base.append mnuOption

mnuOption = new menuitem
mnuOption.text = “Chew gum”
base.append mnuOption

mnuOption = base.popup

if mnuOption <> nil then

//do something about it
end if

base = nil[/code]

A complete sample project would be helpful.

[quote=423283:@Craig Grech]

Function ConstructContextualMenu(index as Integer, base as MenuItem, x as Integer, y as Integer) As Boolean base.append(New MenuItem("Edit")) base.append(New MenuItem("Delete"))

[code]Function ContextualMenuAction(index as Integer, hitItem as MenuItem) As Boolean

Select Case HitItem.text
case “Edit”
editmode = true
frmAddRecord.show[/code][/quote]

Are you setting the returning a value of True before leaving the function? If not, it will default to False and the system won’t know that processing of the menu is complete.

The relevant documentation is here:

http://documentation.xojo.com/api/deprecated/window.html#window-constructcontextualmenu
http://documentation.xojo.com/api/deprecated/window.html#window-contextualmenuaction

Your (very) old code may use deprecated documentation and need to be updated (as Dale suggest above).

Used the same code as in the example relevant documentation. What has changed that makes my code above “very” old?
I simply forgot to return True at the end of Function ContextualMenuAction so it didn’t close.

I’m having the same issue even though I return true. Keeps the menu onscreen. Any idea how to close the context menu?

[code]Select Case hitItem.value
Case “Copy Text”
Narrative.SelectAll
Var c As New Clipboard
c.Text = Narrative.Text
Case “Reset Font”
Narrative.SelectAll
Narrative.SelectionFontName = Narrative.FontName
Narrative.SelectionFontSize = Narrative.FontSize

Case “Timeline”
Var data As RowSet = App.GetData("Select * From ProfileAhnentafel Where Id = " + Main.AncestorPage.AncestorList.RowTagAt(Main.AncestorPage.AncestorList.SelectedRowIndex))
If data <> Nil And Not data.AfterLastRow Then
Narrative.AddText(“Timeline”+EndOfLine)
BoldAndCenter(True)
Var lines() As String = data.column(“Event_Summary”).StringValue.Split(EndOfLine)
For Each l As String In lines
Narrative.AddText(App.Tab+App.Tab+l+EndOfLine)
AlignIt(“L”, Narrative.StyledText.ParagraphCount)
Next
lines.ResizeTo(-1)
data.Close
data=Nil
End If

Case “Birth”, “Marriage”, “Death”, “Family Story”,“Obituary”,“Research Notes”
Narrative.AddText(hitItem.Value+EndOfLine)
BoldAndCenter(True)

Case “Confident”, “Circumstantial”, “Speculative”
Narrative.AddText("("+hitItem.Value+")"+EndOfLine)
ItalicIt
Case “Signature”
Narrative.AddText(“Becky Mason Walker”+EndOfLine)
AlignIt(“R”, Narrative.StyledText.ParagraphCount)
Var d As DateTime = DateTime.Now
Narrative.AddText(d.ToString+EndOfLine)
AlignIt(“R”, Narrative.StyledText.ParagraphCount)
End Select
Var num As Integer = Narrative.StyledText.ParagraphCount
Narrative.SelectionStart = Narrative.StyledText.Paragraph(num).StartPosition+Narrative.SelectionLength+1
Narrative.SelectionLength = 0
Return True[/code]

No I haven’t had any problems since return True was added.

Does the problem happen on all selections from the menu or only on particular one(s)? Also, does the menu close if you click somewhere outside the control? OS and Xojo versions?

It happens on all menu selections and disappears when I click either inside the textarea or elsewhere. Also, if I then select a 2nd item, it performs then closes the menu. Latest xojo version and Window 10

Hmmmm. The only way I have managed to reproduce this is by not returning True in the ConstructContextualMenu event handler as well as in the ContextualMenuAction event handler.

I hope this helps.

Are you sure one of your functions aren’t using a lot of resources causing the screen not to update until you click elsewhere.
As a test I would try returning True immediately just to see whether it closes.

Dale, that it! Thanks so very much :slight_smile: