forked from qt-creator/qt-creator
EditorManager: Split reading the settings from actually doing anything
So we can add reading the settings just to retrieve a file list in a second step. Task-number: QTCREATORBUG-7660 Change-Id: I65856ab97bfe2ee69194d484926f83621fa85327 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -3630,6 +3630,62 @@ QByteArray EditorManager::saveState()
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FileStateEntry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString filePath;
|
||||||
|
QString displayName;
|
||||||
|
Id id;
|
||||||
|
bool pinned = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void restore(
|
||||||
|
const QByteArray &state,
|
||||||
|
const std::function<void(QMap<QString, QVariant>)> &editorStatesHandler,
|
||||||
|
const std::function<void(FileStateEntry)> &fileHandler,
|
||||||
|
const std::function<void(QByteArray)> &splitterStateHandler,
|
||||||
|
const std::function<void(QVector<QVariantHash>)> &windowStateHandler)
|
||||||
|
{
|
||||||
|
QDataStream stream(state);
|
||||||
|
QByteArray version;
|
||||||
|
stream >> version;
|
||||||
|
const bool isVersion5 = version == "EditorManagerV5";
|
||||||
|
if (version != "EditorManagerV4" && !isVersion5)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMap<QString, QVariant> 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<QVariantHash> windowStates;
|
||||||
|
stream >> windowStates;
|
||||||
|
if (windowStateHandler)
|
||||||
|
windowStateHandler(windowStates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
|
|
||||||
@@ -3647,62 +3703,38 @@ void EditorManager::restoreState(const QByteArray &state)
|
|||||||
delete d->m_editorAreas.at(i); // automatically removes it from list
|
delete d->m_editorAreas.at(i); // automatically removes it from list
|
||||||
if (d->m_editorAreas.first()->isSplitter())
|
if (d->m_editorAreas.first()->isSplitter())
|
||||||
EditorManagerPrivate::removeAllSplits();
|
EditorManagerPrivate::removeAllSplits();
|
||||||
QDataStream stream(state);
|
|
||||||
|
|
||||||
QByteArray version;
|
|
||||||
stream >> version;
|
|
||||||
|
|
||||||
const bool isVersion5 = version == "EditorManagerV5";
|
|
||||||
if (version != "EditorManagerV4" && !isVersion5)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
|
||||||
stream >> d->m_editorStates;
|
const auto setEditorStates = [](const QMap<QString, QVariant> &s) { d->m_editorStates = s; };
|
||||||
|
const auto openFile = [](const FileStateEntry &file) {
|
||||||
int editorCount = 0;
|
if (!file.filePath.isEmpty() && !file.displayName.isEmpty()) {
|
||||||
stream >> editorCount;
|
const FilePath filePath = FilePath::fromUserInput(file.filePath);
|
||||||
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);
|
|
||||||
if (!filePath.exists())
|
if (!filePath.exists())
|
||||||
continue;
|
return;
|
||||||
const FilePath rfp = autoSaveName(filePath);
|
const FilePath rfp = autoSaveName(filePath);
|
||||||
if (rfp.exists() && filePath.lastModified() < rfp.lastModified()) {
|
if (rfp.exists() && filePath.lastModified() < rfp.lastModified()) {
|
||||||
if (IEditor *editor = openEditor(filePath, id, DoNotMakeVisible))
|
if (IEditor *editor = openEditor(filePath, file.id, DoNotMakeVisible))
|
||||||
DocumentModelPrivate::setPinned(DocumentModel::entryForDocument(editor->document()), pinned);
|
DocumentModelPrivate::setPinned(
|
||||||
|
DocumentModel::entryForDocument(editor->document()), file.pinned);
|
||||||
} else {
|
} else {
|
||||||
if (DocumentModel::Entry *entry = DocumentModelPrivate::addSuspendedDocument(
|
if (DocumentModel::Entry *entry
|
||||||
filePath, displayName, id))
|
= DocumentModelPrivate::addSuspendedDocument(filePath, file.displayName, file.id))
|
||||||
DocumentModelPrivate::setPinned(entry, pinned);
|
DocumentModelPrivate::setPinned(entry, file.pinned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
const auto restoreSplitterState = [](const QByteArray &state) {
|
||||||
QByteArray splitterstates;
|
d->m_editorAreas.first()->restoreState(state);
|
||||||
stream >> splitterstates;
|
};
|
||||||
d->m_editorAreas.first()->restoreState(splitterstates); // TODO
|
const auto restoreWindows = [](const QVector<QVariantHash> &states) {
|
||||||
|
for (const QVariantHash &windowState : std::as_const(states)) {
|
||||||
if (!stream.atEnd()) { // safety for settings from Qt Creator 4.5 and earlier
|
|
||||||
// restore windows
|
|
||||||
QVector<QVariantHash> windowStates;
|
|
||||||
stream >> windowStates;
|
|
||||||
for (const QVariantHash &windowState : std::as_const(windowStates)) {
|
|
||||||
EditorWindow *window = d->createEditorWindow();
|
EditorWindow *window = d->createEditorWindow();
|
||||||
window->restoreState(windowState);
|
window->restoreState(windowState);
|
||||||
window->show();
|
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
|
// splitting and stuff results in focus trouble, that's why we set the focus again after restoration
|
||||||
if (d->m_currentEditor) {
|
if (d->m_currentEditor) {
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/icon.h>
|
#include <utils/icon.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
#include <utils/persistentsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
@@ -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
|
class SessionDelegate : public BaseDelegate
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -479,6 +492,10 @@ public:
|
|||||||
}
|
}
|
||||||
yy += s(VPaddingXxs);
|
yy += s(VPaddingXxs);
|
||||||
}
|
}
|
||||||
|
if (projects.isEmpty()) {
|
||||||
|
// check if there are files to show instead
|
||||||
|
const FilePaths paths = pathsForSessionName(sessionName);
|
||||||
|
}
|
||||||
yy += s(VGapXs);
|
yy += s(VGapXs);
|
||||||
|
|
||||||
const QStringList actions = {
|
const QStringList actions = {
|
||||||
|
Reference in New Issue
Block a user