20 #include <QStringList>
22 QString ecvRecentFiles::s_settingKey(
"RecentFiles");
26 m_menu =
new QMenu(tr(
"Open Recent..."), parent);
27 m_menu->setIcon(QIcon(
":/Resources/images/svg/pqRecentFile.png"));
28 m_actionClearMenu =
new QAction(tr(
"Clear Menu"),
this);
30 connect(m_actionClearMenu, &QAction::triggered,
this, [
this]() {
46 list.removeAll(filePath);
47 list.prepend(filePath);
50 if (list.count() > 10) {
51 list = list.mid(0, 10);
58 void ecvRecentFiles::updateMenu() {
61 const QStringList recentList = listRecent();
63 for (
const QString &recentFile : recentList) {
64 QAction *recentAction =
new QAction(contractFilePath(recentFile),
this);
66 recentAction->setData(recentFile);
68 connect(recentAction, &QAction::triggered,
this,
69 &ecvRecentFiles::openFileFromAction);
71 m_menu->addAction(recentAction);
74 if (!m_menu->actions().isEmpty()) {
75 m_menu->addSeparator();
76 m_menu->addAction(m_actionClearMenu);
79 m_menu->setEnabled(!m_menu->actions().isEmpty());
82 void ecvRecentFiles::openFileFromAction() {
83 QAction *action = qobject_cast<QAction *>(sender());
87 QString fileName = action->data().toString();
89 if (!QFile::exists(fileName)) {
93 QStringList fileListOfOne{fileName};
98 QStringList ecvRecentFiles::listRecent() {
103 QStringList::iterator iter = list.begin();
105 while (iter != list.end()) {
106 const QString filePath = *iter;
108 if (!QFile::exists(filePath)) {
109 iter = list.erase(iter);
119 QString ecvRecentFiles::contractFilePath(
const QString &filePath) {
120 QString homePath = QDir::toNativeSeparators(QDir::homePath());
121 QString newPath = QDir::toNativeSeparators(filePath);
123 if (newPath.startsWith(homePath)) {
124 return newPath.replace(0, QDir::homePath().
length(),
'~');
130 QString ecvRecentFiles::expandFilePath(
const QString &filePath) {
131 QString newPath = QDir::toNativeSeparators(filePath);
133 if (newPath.startsWith(
'~')) {
134 QString homePath = QDir::toNativeSeparators(QDir::homePath());
136 return newPath.replace(0, 1, homePath);
static MainWindow * TheInstance()
Returns the unique instance of this object.
void addToDB(const QStringList &filenames, QString fileFilter=QString(), bool displayDialog=true)
static const QString LoadFile()
QMenu * menu()
Returns a "most recently used file" menu.
ecvRecentFiles(QWidget *parent)
void addFilePath(const QString &filePath)
Adds a file path to the recently used menu.
static void removeKey(const QString §ion, const QString &key)
static QVariant getValue(const QString §ion, const QString &key, const QVariant &defaultValue=QVariant())
static void setValue(const QString §ion, const QString &key, const QVariant &value)
__host__ __device__ float length(float2 v)