blob: 7edfb3d89ff6c983b2fde7a7e5f6fddc240d51c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
};
|