Property not getting set.

Hi,
All my sheet windows have the following code in their open event:

WindowIsOpen = True

And the following code in their close event:

WindowIsOpen = False

In my main window I have the following code in the ConstructContextualMenu event

[code] If WindowIsOpen = False Then

Dim row As Integer = Me.RowFromXY(X, Y)
If row > -1 Then
  base.append(New MenuItem("Create New Good Entry"))
  base.append(New MenuItem("Create New Bad Entry"))
  base.append(New MenuItem("Edit / Delete Selected Entry"))
  Return True
  
else
  base.append(New MenuItem("Create New Good Entry"))
  base.append(New MenuItem("Create New Bad Entry"))
end if

else
Return True

End if

Return True[/code]

The problem is that the property WindowIsOpen does not seem to be getting set to True, because if I right click and then open a window - I can then right click again and open another window.

Can anyone tell me why the right click continues to work (even though the property is set to true)?

The property WindowIsOpen is in a module.

Thank you all in advance.

Its a bug. There are problems with the contextual menus. I had this same issue and ended up creating my own classContextualMenu because I spent days debugging only to find there were problems. Its easy to use, here we go https://github.com/CharlieXojo/classContextualMenu

Here was my discussion on the issue I had and very similar to what you describe above - Forum Post

I understand it has been fixed for the next release but if you cant wait, try my solution above.

Thanks Mike - I will give that a try.
Much appreciated.

if the window is open make sure you remove all items from base so its empty

Norman,
my code has no base items in the else condition?

I quickly wrote something that I think is close to the code you posted & it doesn’t let me put up the contextual menu more than once

Any chance you could post it here?

create a new desktop project

on window1

[code]
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
If WindowIsOpen = False Then

base.append(New MenuItem("Create New Good Entry"))
base.append(New MenuItem("Create New Bad Entry"))
base.append(New MenuItem("Edit / Delete Selected Entry"))
Return True

else
Return True

End if

End Function[/code]

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

dim w as new Window2

w.showmodalwithin(self)

End Function[/code]

create a new module (module1) with a global property

WindowIsOpen As boolean

create new sheet window (window2)

Sub Open() WindowIsOpen = true End Sub

Sub Close()
  WindowIsOpen = false
  
End Sub[/code]

add a bevel button to window with this as its action event
[code]Sub Action()
  self.close
  
End Sub

I think the only difference is that you apparently had this in a listbox as there was the code for row from xy

Your code does not work on a listbox with 3 choices in the ConstructContextualMenu :frowning:

ah that is case #31366 which you can see is already marked fixed
but I can tell you it’s not in 2.1 :frowning: - sorry

For now you CAN ignore the action by putting a check like

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

if not windowIsOpen then
dim w as new Window2

w.showmodalwithin(self)
end if

End Function[/code]

that will show the menu BUT selecting an item won’t do anything

Are you talking about windows with their Frame property set to “Sheet Window”? Then you have to open them in your code with Window.ShowModalWithin. In addition you then probably also can get rid of the property WindowIsOpen.

[quote=118794:@Richard Summers]The problem is that the property WindowIsOpen does not seem to be getting set to True, because if I right click and then open a window - I can then right click again and open another window.

Can anyone tell me why the right click continues to work (even though the property is set to true)?[/quote]

Could be the same as in https://forum.xojo.com/14611-contextual-popupmenu

Eli - I have tried various combinations of your recommendation above - none of which work:

AddWindow.ShowModal
AddWindow.ShowModalWithin
AddWindow.ShowModalWithin()
AddWindow.ShowModalWithin(self)
AddWindow.ShowModalWithin(Window1)

I either get the error: This method requires more parameters than were passed. or This Item Does Not Exist.

It is obviously the bug which everyone is talking about - so I will have to remove the contextual menu completely, and try Mike’s solution.
thanks for trying to help - much appreciated.