radioviz.services.recent_files
Recent files management for the RadiViz application.
This module provides functionality for tracking recently opened files and managing a menu that allows users to quickly access these files.
The RecentFilesManager class handles the core logic for managing
recently opened files, including persistence across application sessions,
automatic cleanup of non-existent files, and integration with Qt menus.
Classes
|
Manages a list of recently opened files and provides a menu for them. |
- class radioviz.services.recent_files.RecentFilesManager(max_files: int | None = 5)[source]
Bases:
QObjectManages a list of recently opened files and provides a menu for them.
This class tracks a configurable number of recently opened files, persists them between application sessions, and provides functionality to update a menu with the recent files list.
- Parameters:
max_files (int) – Maximum number of recent files to track
Initialize the RecentFilesManager.
Creates a new instance of the RecentFilesManager with the specified maximum number of files to track.
- Parameters:
max_files (int, optional) – Maximum number of recent files to track, defaults to 5
- add_file(file_path: str | Path) None[source]
Add a file to the recent files list.
The file is added to the top of the list. If the file is already in the list, it is first removed and then added to the top. If adding the file would exceed the maximum number of files, the oldest file is removed.
- Parameters:
file_path (str | Path) – Path to the file to add
- clear_files() None[source]
Clear the recent files list.
Removes all files from the recent files list and updates the saved settings.
- get_files() list[Path][source]
Get the list of recent files.
This method filters out any files that no longer exist on the filesystem before returning the list.
- Returns:
List of recent file paths
- Return type:
list[pathlib.Path]
- load_recent_files() None[source]
Load the recent files list from settings.
Retrieves the recent files list from the application settings. If no list exists or an error occurs during loading, an empty list is used.
- Raises:
json.JSONDecodeError – if the stored data is not valid JSON
TypeError – if the stored data is not a string