B4J Library [class] Recent Files Manager

SS-2019-04-08_12.45.37.png


A simple class that manages the list of recent files.
You can set the maximum number of recent files. The default is 5.

Depends on: B4XCollections and JavaObject.

Usage instructions:

1. Call xui.SetDataFolder to set the default files folder:
B4X:
xui.SetDataFolder("FormsBuilder")
2. Initialize the object:
B4X:
RecentManager.Initialize(Me, "Recent", MenuBar1.Menus.Get(0))
The third parameter is the "files" menu.
The manager will add and remove the recent files menu items as needed.

3. Whenever you want to add a file to the recent files list:
B4X:
RecentManager.AddFile(f)
This will usually happen when the user loads a file or "saves as" a file.

4. Save the list of files when the program ends:
B4X:
Sub MainForm_Closed
   RecentManager.SaveList
End Sub

Updates

v1.01 - Files are checked for existence when the list is loaded.
Top item is the most recently used file.
 

Attachments

  • RecentFilesManager.bas
    2.4 KB · Views: 609
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
1620914725672.png


This is a very useful class. I'm using it in several projects now.

I've created a more complete example where it also checks for unsaved changes. The data is saved using json and the new json string is compared to the original one, to find whether changes were made.
You can use other formats, including B4XSerializator to save the data.
 

Attachments

  • RecentExample.zip
    4.9 KB · Views: 496
Last edited:
Top