diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index a3eaf7d77d3..08c559105b2 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -3630,6 +3630,62 @@ QByteArray EditorManager::saveState() return bytes; } +class FileStateEntry +{ +public: + QString filePath; + QString displayName; + Id id; + bool pinned = false; +}; + +static void restore( + const QByteArray &state, + const std::function)> &editorStatesHandler, + const std::function &fileHandler, + const std::function &splitterStateHandler, + const std::function)> &windowStateHandler) +{ + QDataStream stream(state); + QByteArray version; + stream >> version; + const bool isVersion5 = version == "EditorManagerV5"; + if (version != "EditorManagerV4" && !isVersion5) + return; + + QMap editorStates; + stream >> editorStates; + if (editorStatesHandler) + editorStatesHandler(editorStates); + + int editorCount = 0; + stream >> editorCount; + while (--editorCount >= 0) { + FileStateEntry file; + stream >> file.filePath; + stream >> file.displayName; + stream >> file.id; + if (isVersion5) + stream >> file.pinned; + + if (fileHandler) + fileHandler(file); + } + + QByteArray splitterstates; + stream >> splitterstates; + if (splitterStateHandler) + splitterStateHandler(splitterstates); + + if (!stream.atEnd()) { // safety for settings from Qt Creator 4.5 and earlier + // restore windows + QVector windowStates; + stream >> windowStates; + if (windowStateHandler) + windowStateHandler(windowStates); + } +} + /*! \internal @@ -3647,62 +3703,38 @@ void EditorManager::restoreState(const QByteArray &state) delete d->m_editorAreas.at(i); // automatically removes it from list if (d->m_editorAreas.first()->isSplitter()) EditorManagerPrivate::removeAllSplits(); - QDataStream stream(state); - - QByteArray version; - stream >> version; - - const bool isVersion5 = version == "EditorManagerV5"; - if (version != "EditorManagerV4" && !isVersion5) - return; QApplication::setOverrideCursor(Qt::WaitCursor); - stream >> d->m_editorStates; - - int editorCount = 0; - stream >> editorCount; - while (--editorCount >= 0) { - QString fileName; - stream >> fileName; - QString displayName; - stream >> displayName; - Id id; - stream >> id; - bool pinned = false; - if (isVersion5) - stream >> pinned; - - if (!fileName.isEmpty() && !displayName.isEmpty()) { - const FilePath filePath = FilePath::fromUserInput(fileName); + const auto setEditorStates = [](const QMap &s) { d->m_editorStates = s; }; + const auto openFile = [](const FileStateEntry &file) { + if (!file.filePath.isEmpty() && !file.displayName.isEmpty()) { + const FilePath filePath = FilePath::fromUserInput(file.filePath); if (!filePath.exists()) - continue; + return; const FilePath rfp = autoSaveName(filePath); if (rfp.exists() && filePath.lastModified() < rfp.lastModified()) { - if (IEditor *editor = openEditor(filePath, id, DoNotMakeVisible)) - DocumentModelPrivate::setPinned(DocumentModel::entryForDocument(editor->document()), pinned); + if (IEditor *editor = openEditor(filePath, file.id, DoNotMakeVisible)) + DocumentModelPrivate::setPinned( + DocumentModel::entryForDocument(editor->document()), file.pinned); } else { - if (DocumentModel::Entry *entry = DocumentModelPrivate::addSuspendedDocument( - filePath, displayName, id)) - DocumentModelPrivate::setPinned(entry, pinned); + if (DocumentModel::Entry *entry + = DocumentModelPrivate::addSuspendedDocument(filePath, file.displayName, file.id)) + DocumentModelPrivate::setPinned(entry, file.pinned); } } - } - - QByteArray splitterstates; - stream >> splitterstates; - d->m_editorAreas.first()->restoreState(splitterstates); // TODO - - if (!stream.atEnd()) { // safety for settings from Qt Creator 4.5 and earlier - // restore windows - QVector windowStates; - stream >> windowStates; - for (const QVariantHash &windowState : std::as_const(windowStates)) { + }; + const auto restoreSplitterState = [](const QByteArray &state) { + d->m_editorAreas.first()->restoreState(state); + }; + const auto restoreWindows = [](const QVector &states) { + for (const QVariantHash &windowState : std::as_const(states)) { EditorWindow *window = d->createEditorWindow(); window->restoreState(windowState); window->show(); } - } + }; + restore(state, setEditorStates, openFile, restoreSplitterState, restoreWindows); // splitting and stuff results in focus trouble, that's why we set the focus again after restoration if (d->m_currentEditor) { diff --git a/src/plugins/projectexplorer/projectwelcomepage.cpp b/src/plugins/projectexplorer/projectwelcomepage.cpp index a0eca157995..c007372cf4a 100644 --- a/src/plugins/projectexplorer/projectwelcomepage.cpp +++ b/src/plugins/projectexplorer/projectwelcomepage.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,18 @@ protected: } }; +static FilePaths pathsForSessionName(const QString &session) +{ + const FilePath fileName = SessionManager::sessionNameToFileName(session); + PersistentSettingsReader reader; + if (fileName.exists()) { + if (!reader.load(fileName)) + return {}; + } + // qDebug() << reader.restoreValue("EditorSettings").toByteArray(); + return {}; +} + class SessionDelegate : public BaseDelegate { protected: @@ -479,6 +492,10 @@ public: } yy += s(VPaddingXxs); } + if (projects.isEmpty()) { + // check if there are files to show instead + const FilePaths paths = pathsForSessionName(sessionName); + } yy += s(VGapXs); const QStringList actions = {