Access MenuItem.Action and index for a submenu

I would like to create a RecentItems SubMenu.
I have created a class OpenRecentMenuItem whose super is MenuItem.
I also followed desktop-menus

  1. Index Questions:
    This “OpenRecentMenuItem” would be appended or inserted to FileOpenRecent, which has the property “submenu” as Yes.
    Apparently, From what I gather on our forums, since this is true, It can now be classified as an array.
    Since this is true that is an array, the index can have a unique value.
    How does this value get set?

  2. Access MenuItem.Action from certain windows

    A. First item is adding a MenuHandler to a Window. I don’t have the ability to add “OpenRecentMenuItem”, but I do have “FileOpenRecent”
    How do I add the handler for this item to A Window?

    B. Apparently since “OpenRecentMenuItem” is subclassed, it needs to have an eventHandler Action.
    I am first off am not sure what this can contain. What can it contain?
    Also somehow the “OpenRecentMenuItem” action must get to the MenuHandler.
    I don’t think I set a property somewhere.
    How do I do this?

In the MenuItem Subclass, Action, I added:

Dim foo As Integer = Me.Index

to be sure before writing this answer.

The Index value does not appears on screen, but is there. Is this wat you were asking for ?

Edit: I also add a Recent MenuItem, but have a lot of troubles with it. Most of them are my fault: I have to take time to resolve / squash the bugs…

Thanks Emile. That means I set it. Perfect.

Nice !

PS: I recall now. Type Me. then press Tab and read what is available from MenuItem (!). Years ellapsed since I wrote that.

  1. If you append OpenRecentMenuItems to a Menu you don’t need to worry about the index.

  2. If you implement the “Action” event in the OpenRecentMenuItem that is the MenuHandler for that specific instance.

The example in Example Projects > Desktop > Menus > OpenRecentMenu is this.

Thanks Jason.

I have specific ways per window of handling that opening of the file.
How does it know which window it its being called by?

It doesn’t know.

To create an array - won’t work by just appending items & setting indexes. It won’t call the menu handler with the index available to you.

Clarification on my confusion. This is from RealSoftware forum Menu Handler Question
And this is a solution

Function MyMenuHandler(Sender As MenuItem) As Boolean MsgBox("You clicked it!") Return True End Function
Is this like how it works?

That will work but it relies on add handler - it takes more than just this method to make it work. It looks like the old forum thread has everything that you need - if you want to go this route.

That’s what I thought.
Found another way of looking at it (which I don’t understand).
Tim wrote

[quote]No, you cannot call the menu handler. You have to put your code in a method and call it from both the menu handler and from your code.
[/quote]

Fire Menu Items within Code

Here’s an option:

https://blog.xojo.com/wp-content/uploads/2018/05/menu-item-array.xojo_binary_project.zip

Thank you. That’s about what I need.

Now to figure out add handler.