aboutsummaryrefslogtreecommitdiffstats
path: root/src/recent_files.h
diff options
context:
space:
mode:
authorConfuSomu2024-06-01 18:05:30 -0400
committerConfuSomu2024-06-01 18:07:06 -0400
commit48a338b1321d9e169c73b71c01cd2f9ba00f9c53 (patch)
treea4c991f800a7bd8bf0d33a56fc7998996c793c3b /src/recent_files.h
parente3efc04807f946cc75b06ec84b4af79d66b23cce (diff)
downloadActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.tar
ActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.tar.gz
ActorViewer-48a338b1321d9e169c73b71c01cd2f9ba00f9c53.zip
Implement Recent files list and menu
Diffstat (limited to 'src/recent_files.h')
-rw-r--r--src/recent_files.h54
1 files changed, 54 insertions, 0 deletions
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 <QStringList>
+#include <QMenu>
+#include <memory>
+
+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<QMenu> 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);
+};