recent_files.h
The "Open Recent" list: most recent first, a fixed length, and the OS told.
#include <sonore/recent_files.h>- 1type
- Guides: Testing your plugin
On this page
Design notes
What it is for
An application that opens documents keeps the last few, puts them in a menu, and remembers them across runs. The rules are small and easy to get subtly wrong, which is the reason for a class: re-opening a file moves it to the TOP rather than adding it twice; the list never grows past its limit; a file deleted since is offered for removal rather than failing when chosen; and the menu ids map back to the list by index, so a menu built with some files skipped still answers with the right one.
Paths compared as the filesystem compares them
"C:\Music\Kit.wav" and "c:/music/kit.wav" are one file on Windows, and on a default (case-insensitive) macOS volume "Kit.wav" and "kit.wav" are too. A list that compared bytes would show the same document twice. Linux compares exactly, as its filesystems do.
The OS's own list
registerRecentFileNatively() puts a file where the OS shows recent documents: SHAddToRecentDocs on Windows (the Recent folder, jump lists), NSDocumentController on macOS (the Dock menu, "Open Recent"). Linux's desktop list belongs to GTK's recent manager, which needs a running GTK main loop to write anything; the reference does nothing there, and nor does this. Windows is RUN here; the macOS path is compiled only.
Not thread-safe: an application's menu lives on the message thread.
Types 1
An application's "Open Recent" list: UTF-8 paths, most recent first, eight at most unless setMaxNumberOfItems() says otherwise. Mirrors the reference's class of the same name, and the file comment has its rules.
Holds paths only, and saves as text (toString / restoreFromString) for the application's settings file. The two static calls also tell the OS's own list. MESSAGE THREAD: nothing is locked.