Add Clear Files option to Recent Files
This commit is contained in:
@@ -452,6 +452,8 @@ void MainWindow::createActions()
|
||||
QToolBar *fileToolBar = addToolBar(tr("File"));
|
||||
fileToolBar->setObjectName("fileToolBar");
|
||||
|
||||
connect(fileMenu, &QMenu::aboutToShow, this, &MainWindow::updateRecentFileActions);
|
||||
|
||||
const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/images/new.png"));
|
||||
QAction *newAct = new QAction(newIcon, tr("&New"), this);
|
||||
newAct->setShortcuts(QKeySequence::New);
|
||||
@@ -468,6 +470,18 @@ void MainWindow::createActions()
|
||||
fileMenu->addAction(openAct);
|
||||
fileToolBar->addAction(openAct);
|
||||
|
||||
const QIcon recentIcon = QIcon::fromTheme("document-open-recent");
|
||||
QMenu *recentMenu = fileMenu->addMenu(recentIcon, tr("Open recent"));
|
||||
m_recentFileSubMenuAct = recentMenu->menuAction();
|
||||
|
||||
for (int i = 0; i < m_MaxRecentFiles; ++i) {
|
||||
m_recentFileActs[i] = recentMenu->addAction(QString(), this, &MainWindow::openRecentFile);
|
||||
m_recentFileActs[i]->setVisible(false);
|
||||
}
|
||||
recentMenu->addSeparator();
|
||||
const QIcon clearRecentIcon = QIcon::fromTheme("edit-clear-history");
|
||||
recentMenu->addAction(clearRecentIcon, tr("Clear list"), this, &MainWindow::clearRecentFiles);
|
||||
|
||||
const QIcon saveIcon = QIcon::fromTheme("document-save", QIcon(":/images/save.png"));
|
||||
QAction *saveAct = new QAction(saveIcon, tr("&Save"), this);
|
||||
saveAct->setShortcuts(QKeySequence::Save);
|
||||
@@ -488,19 +502,6 @@ void MainWindow::createActions()
|
||||
|
||||
fileMenu->addSeparator();
|
||||
|
||||
QMenu *recentMenu = fileMenu->addMenu(tr("Recent"));
|
||||
connect(recentMenu, &QMenu::aboutToShow, this, &MainWindow::updateRecentFileActions);
|
||||
m_recentFileSubMenuAct = recentMenu->menuAction();
|
||||
|
||||
for (int i = 0; i < m_MaxRecentFiles; ++i) {
|
||||
m_recentFileActs[i] = recentMenu->addAction(QString(), this, &MainWindow::openRecentFile);
|
||||
m_recentFileActs[i]->setVisible(false);
|
||||
}
|
||||
|
||||
m_recentFileSeparator = fileMenu->addSeparator();
|
||||
|
||||
setRecentFilesVisible(MainWindow::hasRecentFiles());
|
||||
|
||||
m_exportAutoAct = fileMenu->addAction(tr("Export subpage..."));
|
||||
m_exportAutoAct->setEnabled(false);
|
||||
m_exportAutoAct->setShortcut(tr("Ctrl+E"));
|
||||
@@ -1318,12 +1319,6 @@ void MainWindow::loadFile(const QString &fileName)
|
||||
statusBar()->showMessage(tr("File loaded"), 2000);
|
||||
}
|
||||
|
||||
void MainWindow::setRecentFilesVisible(bool visible)
|
||||
{
|
||||
m_recentFileSubMenuAct->setVisible(visible);
|
||||
m_recentFileSeparator->setVisible(visible);
|
||||
}
|
||||
|
||||
static inline QString recentFilesKey() { return QStringLiteral("recentFileList"); }
|
||||
static inline QString fileKey() { return QStringLiteral("file"); }
|
||||
|
||||
@@ -1350,14 +1345,6 @@ static void writeRecentFiles(const QStringList &files, QSettings &settings)
|
||||
settings.endArray();
|
||||
}
|
||||
|
||||
bool MainWindow::hasRecentFiles()
|
||||
{
|
||||
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
const int count = settings.beginReadArray(recentFilesKey());
|
||||
settings.endArray();
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
void MainWindow::prependToRecentFiles(const QString &fileName)
|
||||
{
|
||||
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
@@ -1369,7 +1356,7 @@ void MainWindow::prependToRecentFiles(const QString &fileName)
|
||||
if (oldRecentFiles != recentFiles)
|
||||
writeRecentFiles(recentFiles, settings);
|
||||
|
||||
setRecentFilesVisible(!recentFiles.isEmpty());
|
||||
m_recentFileSubMenuAct->setEnabled(!recentFiles.isEmpty());
|
||||
}
|
||||
|
||||
void MainWindow::updateRecentFileActions()
|
||||
@@ -1387,6 +1374,15 @@ void MainWindow::updateRecentFileActions()
|
||||
}
|
||||
for ( ; i < m_MaxRecentFiles; ++i)
|
||||
m_recentFileActs[i]->setVisible(false);
|
||||
|
||||
m_recentFileSubMenuAct->setEnabled(recentFiles.size() != 0);
|
||||
}
|
||||
|
||||
void MainWindow::clearRecentFiles()
|
||||
{
|
||||
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
|
||||
writeRecentFiles(QStringList(), settings);
|
||||
}
|
||||
|
||||
void MainWindow::updateExportAutoAction()
|
||||
|
||||
@@ -74,6 +74,7 @@ private slots:
|
||||
void exportImage();
|
||||
void exportM29();
|
||||
void updateRecentFileActions();
|
||||
void clearRecentFiles();
|
||||
void updateExportAutoAction();
|
||||
void openRecentFile();
|
||||
void about();
|
||||
@@ -118,9 +119,7 @@ private:
|
||||
void openFile(const QString &fileName);
|
||||
void loadFile(const QString &fileName);
|
||||
void extractImages(QImage sceneImage[], bool smooth = false, bool flashExtract = false);
|
||||
static bool hasRecentFiles();
|
||||
void prependToRecentFiles(const QString &fileName);
|
||||
void setRecentFilesVisible(bool visible);
|
||||
bool saveFile(const QString &fileName);
|
||||
void setCurrentFile(const QString &fileName);
|
||||
static QString strippedName(const QString &fullFileName);
|
||||
@@ -144,7 +143,6 @@ private:
|
||||
DClutDockWidget *m_dClutDockWidget;
|
||||
|
||||
QAction *m_recentFileActs[m_MaxRecentFiles];
|
||||
QAction *m_recentFileSeparator;
|
||||
QAction *m_recentFileSubMenuAct;
|
||||
QAction *m_exportAutoAct;
|
||||
QAction *m_deleteSubPageAction;
|
||||
|
||||
Reference in New Issue
Block a user