Contextual menu won't close

  1. 4 months ago

    Craig G

    Feb 1 Australia

    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

    @Craig G

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

    Function ContextualMenuAction(index as Integer, hitItem as MenuItem) As Boolean Select Case HitItem.text case "Edit" editmode = true frmAddRecord.show

    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.

  2. Jeff T

    Feb 1 Pre-Release Testers Midlands of England, Europe

    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

  3. Craig G

    Feb 1 Australia
    Edited 4 months ago

    @Jeff T 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

    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"))
    Function ContextualMenuAction(index as Integer, hitItem as MenuItem) As Boolean
    
    Select Case HitItem.text
    case "Edit"
    editmode = true
    frmAddRecord.show
  4. Jeff T

    Feb 1 Pre-Release Testers Midlands of England, Europe

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

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

    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
  5. Greg O

    Feb 1 Xojo Inc

    A complete sample project would be helpful.

  6. Dale A

    Feb 1 Answer San Diego, California, USA

    @Craig G

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

    Function ContextualMenuAction(index as Integer, hitItem as MenuItem) As Boolean Select Case HitItem.text case "Edit" editmode = true frmAddRecord.show

    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.

  7. Emile S

    Feb 2 Europe (France, Strasbourg)

    The relevant documentation is here:

    http://docs.xojo.com/Window.ConstructContextualMenu
    http://docs.xojo.com/Window.ContextualMenuAction

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

  8. 3 months ago

    Craig G

    Feb 10 Australia

    @Emile S 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.

or Sign Up to reply!