#pragma once #include "src/settings_interface.h" #include #include #include class RecentFiles { public: // QAction extension to signal file path class Action; // size: length of the list before removing older files // force_empty: work from an empty list RecentFiles(unsigned int size = 10, bool force_empty = false); // Note: recent files list is committed on destruction ~RecentFiles(); // Submit a file to the recent files list // It will not be added if it's already in the list void add_file(const QString& path); // Get the list of recent files const QStringList& get_files(); // Clear the list of recent files void clear(); // Create a QMenu with the list of recent files // The caller is responsable of managing the pointer's lifetime. It works like any other QMnenu, but is already populated. // title: the text shown // parent: the QMenu's parent typedef std::shared_ptr QMenuPtr; QMenuPtr create_menu(const QString& title, QWidget* parent = nullptr); private: SettingsInterface settings_interface; QStringList list; unsigned int size; bool has_list_changed = false; QMenuPtr menu; void generate_menu_actions(); }; class RecentFiles::Action : public QAction { Q_OBJECT public: Action(const QString &text, QObject *parent = nullptr); QString file_path; signals: void chosen_file(const QString& file_path); };