Implementing list of recently used files

I have seen it somewhere but I can’t seem to find it anymore: building a list with recently used files?

in Xojo Example Projects - Desktop - Menus is OpenRecentMenu.xojo_binary_project

Ahh. Thanks.

Look at that for awhile and there is OpenRecentMenuItem that is not connected to a menu but is used to create a menu item and append to the Open Recent… menu.

If I create a menu or submenu etc. it always is attached to an existing menu or the menu bar… I’ve looked at this 10 ways and can’t figure out how to create this in the project. I see it in this sample project but it only has super MenuItem.

Sorry DOh! It’s “Insert Class” and then set the super to MenuItem. My Bad!

…Under a lot of pressure to get a release done…

Worst time in a development ?

BTW: I do not recall if this is implemented in the example, but in my project, I add a keyboard check.

If the shift key is down while releasing a recent entry, the application remove that entry.

What I forgot to add is a “Recent” validity check. Check if I moved the original file.

PS: I think that I do not really understand what / how the example works (and my implementation is to put a Recents Menu (in the main menubar). I had no example (nothing) to inspire me handly when I added this to my project.

Do you know the list of recently open items in the macOS Dock ?
(I do not checked on Windows 10, yet).

The sample most recents project from Xojo is not very good. I have spent some time yesterday looking at it in relation to how real “open recents” menu works. In fact the Xojo IDE itself has an Open Recent menu… why couldn’t Xojo have used that code in the sample project since it DOES implement the proper functions below.

As for the “Sample project”…

It does not put the most recent item at the TOP but blindly appends to the BOTTOM of a running list.

It does not check that the file is already on the list…remove it from that spot, and add to the top.

It does not show you how to store and retrieve the file path of a file… which is the whole reason anyone is putting something on the Open Recents… so that user can select from there to open a recently used file.

Sure all of these things can be fixed and added… but as a “sample project” that one leaves a LOT to be desired.

here is some old code I used to implement an MRU (most recent used)

DIM MRU_Files(-1) as String // global

SUB MRUF_Manage(filename as string, delete_it as boolean=false)
		#If Not DebugBuild
				#pragma DisableBackgroundTasks
				#pragma DisableBoundsChecking
				#pragma DisableAutoWaitCursor
		#EndIf
		Dim i As Integer
		Dim j As Integer
		Dim x As Integer
		If filename="" Then Exit Sub
		j=-1
		'
		' if file is already in the list .. move it to the top
		'
		x=ubound(MRU_Files)
		If x>=0 Then
				For i=0 To x
						If MRU_Files(i)=filename Then
								 j=i
								Exit For
						End If
				Next i
				If j>0 Then
						MRU_Files.Remove(j)
				Else
						If j=0 Then Exit Sub  ' already at the top
				End If
		End If
		If Not delete_it Then 
				MRU_Files.Insert 0,filename
		End If
END SUB

I also had code that when it loaded the list, it removed any filesnames that no longer existed

all you need to do, is each time you open a file, just pass the filename to MRUF_MANAGE

I forgot to mention that. Before adding an entry in the Menu list, I checked to avoid a duplicate.

I also do not say that I simply append the new entry. I do not question myself if it is better to insert the new entry at the top (+1) of the Menu or simply append. I just do it that way.

I just checked and I know why +1 above: the first entry in my Recents Menu is the … Clear this Menu entry (a nice addition to the “Remove this MenuItem” feature).

When memory fails :frowning:

BTW: I store the file data into a preference file as a pair: item name and NativePath. I load and build the Recents Menu at load time, clears the file (I am unsure this is a good idea), then deals with the Recents and re save the whole Recents Menu at quit time.

[quote=312053:@Tim Turner]It does not put the most recent item at the TOP but blindly appends to the BOTTOM of a running list.

It does not check that the file is already on the list…remove it from that spot, and add to the top.

It does not show you how to store and retrieve the file path of a file… which is the whole reason anyone is putting something on the Open Recents… so that user can select from there to open a recently used file.[/quote]
I’m not sure what example project you are using, but the one in Examples/Desktop/Menus/OpenRecentMenu does add new items to the top of the list and does include the file as the MenuItem tag so it is easily retrievable (which is what happens when you click the menu item).