### Create a Recent Files Menu

Example of creating a recent files menu as part of a Files Menu.
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private MenuBar1 As MenuBar
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
...
AddRecentFilesMenu
...
End Sub`
'Add the recent files menu with some items
`Sub AddRecentFilesMenu
Dim rf As List
rf.Initialize
rf.AddAll(Array As String("/path/filename1", "/path/filename2", "/path/filename3"))
'Add a separator first
AddMenuSeparator(MenuBar1, 0)
'Add the list of files
For Each f As String In rf
AddRecentFilesMenuItem(MenuBar1, 0, f)
Next
End Sub`
'Add a recent files menuitem to a menu
`Sub AddRecentFilesMenuItem(mb As MenuBar, menuidx As Int, filename As String)
Dim filesmenu As Menu = mb.Menus.Get(menuidx)
Dim recentfilemenuitem As MenuItem
recentfilemenuitem.Initialize(filename,"recentfilesmenu")
recentfilemenuitem.Tag = filename
filesmenu.MenuItems.Add(recentfilemenuitem)
End Sub`
'Remove a recent files menu item
`Sub RemoveRecentFilesMenuItem(mb As MenuBar, menuidx As Int, recentfile As String)
Dim filesmenu As Menu = mb.Menus.Get(menuidx)
For i = 0 To filesmenu.MenuItems.Size - 1
Dim mi As MenuItem = filesmenu.MenuItems.Get(i)
'handle null entries, like the separators
If mi.Text <> Null Then
If mi.Text.EqualsIgnoreCase(recentfile) Then
filesmenu.MenuItems.RemoveAt(i)
Exit
End If
End If
Next
End Sub`
'Handle the recent files menu actions
`Sub RecentFilesMenu_Action
Dim recent As MenuItem =Sender
Log("recent clicked: "&recent.Tag)
End Sub`
'Adds a separator menu item
'Example call: AddMenuSeparator(MenuBar1, 0) where 0 is the first menu item
`Sub AddMenuSeparator(mb As MenuBar, menuidx As Int)
Dim joSepMi As JavaObject
joSepMi.InitializeNewInstance("javafx.scene.control.SeparatorMenuItem", Null)
Dim mnu As Menu = mb.Menus.Get(menuidx)
mnu.MenuItems.Add(joSepMi)
End Sub`
'Add a seperator to a menu using standard wa BUT this is not working as showing the minus sign
'Sub AddMenuSeparator2(mb As MenuBar, menuidx As Int)
' Dim mnu As Menu = mb.Menus.Get(menuidx)
' Dim sepmi As MenuItem
' sepmi.Initialize("-",Null)
' mnu.MenuItems.Add(sepmi)
'End Sub

Changed: 2018-05-06 17:16, Category: Menu, File: T6C220M1609.htm, ID: 1609