Limit recent files to 10

This commit is contained in:
NeoTheFox 2015-03-10 23:04:51 +03:00
parent f920d00c0a
commit 2d0bbd3efb

View File

@ -152,7 +152,7 @@ void MainWindow::open()
if(!recentFiles.contains(filename)) if(!recentFiles.contains(filename))
{ {
recentFiles.prepend(filename); recentFiles.prepend(filename);
if(recentFiles.size() == 5) recentFiles.removeAt(5); if(recentFiles.size() >= 10) recentFiles.removeLast();
} }
updateRecent(); updateRecent();
@ -638,17 +638,17 @@ void MainWindow::injectCommand(QString command)
void MainWindow::updateRecent() void MainWindow::updateRecent()
{ {
if(!recentFiles.isEmpty()) if(!recentFiles.isEmpty()) //If array is empty we should not be bothered
{ {
recentMenu->clear(); recentMenu->clear(); //Clear menu from previos actions
foreach (QString str, recentFiles) foreach (QString str, recentFiles)
{ {
if (!str.isEmpty()) if (!str.isEmpty()) //Empty strings are not needed
{ {
QAction *action = new QAction(this); QAction *action = new QAction(this);
action->setText(str); action->setText(str); //Set filepath as a title
action->setObjectName(str); action->setObjectName(str); //Also set name to the path so we can get it later
recentMenu->addAction(action); recentMenu->addAction(action); //Add action to the menu
connect(action, SIGNAL(triggered()), this, SLOT(recentClicked())); connect(action, SIGNAL(triggered()), this, SLOT(recentClicked()));
} }
} }