From 48a338b1321d9e169c73b71c01cd2f9ba00f9c53 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Sat, 1 Jun 2024 18:05:30 -0400 Subject: Implement Recent files list and menu --- src/recent_files.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/recent_files.h (limited to 'src/recent_files.h') diff --git a/src/recent_files.h b/src/recent_files.h new file mode 100644 index 0000000..7edfb3d --- /dev/null +++ b/src/recent_files.h @@ -0,0 +1,54 @@ +#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); +}; -- cgit v1.2.3-54-g00ecf