Do not display deleted files as recent files (#15)

This commit is contained in:
Tim Siebels 2017-09-29 09:59:03 +02:00 committed by Maijin
parent f3448fa886
commit bbf424a950

View File

@ -73,33 +73,39 @@ NewFileDialog::NewFileDialog(QWidget *parent) :
QStringList files = settings.value("recentFileList").toStringList(); QStringList files = settings.value("recentFileList").toStringList();
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); QMutableListIterator<QString> it(files);
int i = 0;
for (int i = 0; i < numRecentFiles; ++i) while (it.hasNext())
{ {
const QString& file = it.next();
// Get stored files // Get stored files
//QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
// Remove all but the file name // Remove all but the file name
QString sep = QDir::separator(); const QString sep = QDir::separator();
QStringList name_list = files[i].split(sep); const QStringList name_list = file.split(sep);
QString name = name_list.last(); const QString name = name_list.last();
// Get file info // Get file info
QFileInfo info(files[i]); QFileInfo info(file);
if (!info.exists()) {
QListWidgetItem *item = new QListWidgetItem( it.remove();
getIconFor(name, i), } else {
files[i] + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size()) QListWidgetItem *item = new QListWidgetItem(
); getIconFor(name, i++),
//":/img/icons/target.svg"), name ); file + "\nCreated: " + info.created().toString() + "\nSize: " + formatBytecount(info.size())
item->setData(Qt::UserRole, files[i]); );
ui->recentsList->addItem(item); //":/img/icons/target.svg"), name );
item->setData(Qt::UserRole, file);
ui->recentsList->addItem(item);
}
} }
ui->recentsList->setSortingEnabled(true); ui->recentsList->setSortingEnabled(true);
// Hide "create" button until the dialog works // Hide "create" button until the dialog works
ui->createButton->hide(); ui->createButton->hide();
// Removes files were deleted from the stringlist. Save it again.
settings.setValue("recentFileList", files);
} }
NewFileDialog::~NewFileDialog() NewFileDialog::~NewFileDialog()