Skip to content
Browse files

Fixed several issues related to restoring previously opened files

Now the list of previously opened files is stored separately from the
recent file list, fixing several issues.

This closes #38

Done-with: Thorbjørn Lindeijer
  • Loading branch information...
1 parent fddf8c0 commit bd2f284f7b75ca8d03aad77c48a115d11479716d @stefanbeller stefanbeller committed with bjorn Jul 18, 2011
Showing with 23 additions and 14 deletions.
  1. +23 −14 src/tiled/mainwindow.cpp
View
37 src/tiled/mainwindow.cpp
@@ -484,24 +484,33 @@ bool MainWindow::openFile(const QString &fileName)
void MainWindow::openLastFiles()
{
- const QStringList files = recentFiles();
-
mSettings.beginGroup(QLatin1String("recentFiles"));
- int openCount = mSettings.value(QLatin1String("recentOpenedFiles"), 1).toInt();
+ QStringList lastOpenFiles = mSettings.value(
+ QLatin1String("lastOpenFiles")).toStringList();
+ QVariant openCountVariant = mSettings.value(
+ QLatin1String("recentOpenedFiles"));
+
+ // Backwards compatibility mode
+ if (openCountVariant.isValid()) {
+ const QStringList recentFiles = mSettings.value(
+ QLatin1String("fileNames")).toStringList();
+ int openCount = qMin(openCountVariant.toInt(), recentFiles.size());
+ for (; openCount; --openCount)
+ lastOpenFiles.append(recentFiles.at(openCount - 1));
+ mSettings.remove(QLatin1String("recentOpenedFiles"));
+ }
QStringList mapScales = mSettings.value(
- QLatin1String("mapScale")).toStringList();
+ QLatin1String("mapScale")).toStringList();
QStringList scrollX = mSettings.value(
- QLatin1String("scrollX")).toStringList();
+ QLatin1String("scrollX")).toStringList();
QStringList scrollY = mSettings.value(
- QLatin1String("scrollY")).toStringList();
+ QLatin1String("scrollY")).toStringList();
QStringList selectedLayer = mSettings.value(
- QLatin1String("selectedLayer")).toStringList();
+ QLatin1String("selectedLayer")).toStringList();
- for (int i = 0; i < openCount; i++) {
- if (!(i < files.size()))
- break;
+ for (int i = 0; i < lastOpenFiles.size(); i++) {
if (!(i < mapScales.size()))
continue;
if (!(i < scrollX.size()))
@@ -511,7 +520,7 @@ void MainWindow::openLastFiles()
if (!(i < selectedLayer.size()))
continue;
- if (openFile(files.at(i))) {
+ if (openFile(lastOpenFiles.at(i))) {
MapView *mapView = mDocumentManager->currentMapView();
// Restore camera to the previous position
@@ -1159,18 +1168,17 @@ void MainWindow::writeSettings()
mSettings.endGroup();
mSettings.beginGroup(QLatin1String("recentFiles"));
- mSettings.setValue(QLatin1String("recentOpenedFiles"),
- mDocumentManager->documentCount());
-
if (MapDocument *document = mDocumentManager->currentDocument())
mSettings.setValue(QLatin1String("lastActive"), document->fileName());
+ QStringList fileList;
QStringList mapScales;
QStringList scrollX;
QStringList scrollY;
QStringList selectedLayer;
for (int i = 0; i < mDocumentManager->documentCount(); i++) {
mDocumentManager->switchToDocument(i);
+ fileList.append(mDocumentManager->currentDocument()->fileName());
MapView *mapView = mDocumentManager->currentMapView();
const int currentLayerIndex = mMapDocument->currentLayerIndex();
@@ -1181,6 +1189,7 @@ void MainWindow::writeSettings()
mapView->verticalScrollBar()->sliderPosition()));
selectedLayer.append(QString::number(currentLayerIndex));
}
+ mSettings.setValue(QLatin1String("lastOpenFiles"), fileList);
mSettings.setValue(QLatin1String("mapScale"), mapScales);
mSettings.setValue(QLatin1String("scrollX"), scrollX);
mSettings.setValue(QLatin1String("scrollY"), scrollY);

0 comments on commit bd2f284

Please sign in to comment.
Something went wrong with that request. Please try again.