ProjectExplorer: Use a constant for "default" session name

Some duplications of a string may perhaps be fine, but eight occurrences
need a constant. Also, understanding code works better by using the code
model instead of full-text search.

Change-Id: I2944cf9216c825b930dedaae1085491fd10feba5
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alessandro Portale
2021-12-21 16:40:59 +01:00
parent e35dedcf32
commit a6147a0683

View File

@@ -67,6 +67,8 @@ using namespace ProjectExplorer::Internal;
namespace ProjectExplorer { namespace ProjectExplorer {
const char DEFAULT_SESSION[] = "default";
/*! /*!
\class ProjectExplorer::SessionManager \class ProjectExplorer::SessionManager
@@ -99,7 +101,7 @@ public:
bool hasProjects() const { return !m_projects.isEmpty(); } bool hasProjects() const { return !m_projects.isEmpty(); }
QString m_sessionName = QLatin1String("default"); QString m_sessionName = QLatin1String(DEFAULT_SESSION);
bool m_virginSession = true; bool m_virginSession = true;
bool m_loadingSession = false; bool m_loadingSession = false;
bool m_casadeSetActive = false; bool m_casadeSetActive = false;
@@ -176,7 +178,7 @@ bool SessionManager::isDefaultVirgin()
bool SessionManager::isDefaultSession(const QString &session) bool SessionManager::isDefaultSession(const QString &session)
{ {
return session == QLatin1String("default"); return session == QLatin1String(DEFAULT_SESSION);
} }
void SessionManager::saveActiveMode(Id mode) void SessionManager::saveActiveMode(Id mode)
@@ -794,10 +796,10 @@ QStringList SessionManager::sessions()
for (const FilePath &file : sessionFiles) { for (const FilePath &file : sessionFiles) {
const QString &name = file.completeBaseName(); const QString &name = file.completeBaseName();
d->m_sessionDateTimes.insert(name, file.lastModified()); d->m_sessionDateTimes.insert(name, file.lastModified());
if (name != QLatin1String("default")) if (name != QLatin1String(DEFAULT_SESSION))
d->m_sessions << name; d->m_sessions << name;
} }
d->m_sessions.prepend(QLatin1String("default")); d->m_sessions.prepend(QLatin1String(DEFAULT_SESSION));
} }
return d->m_sessions; return d->m_sessions;
} }
@@ -1004,8 +1006,8 @@ void SessionManagerPrivate::restoreProjects(const FilePaths &fileList)
bool SessionManager::loadSession(const QString &session, bool initial) bool SessionManager::loadSession(const QString &session, bool initial)
{ {
const bool loadImplicitDefault = session.isEmpty(); const bool loadImplicitDefault = session.isEmpty();
const bool switchFromImplicitToExplicitDefault = session == "default" const bool switchFromImplicitToExplicitDefault = session == DEFAULT_SESSION
&& d->m_sessionName == "default" && !initial; && d->m_sessionName == DEFAULT_SESSION && !initial;
// Do nothing if we have that session already loaded, // Do nothing if we have that session already loaded,
// exception if the session is the default virgin session // exception if the session is the default virgin session
@@ -1018,7 +1020,7 @@ bool SessionManager::loadSession(const QString &session, bool initial)
FilePaths fileList; FilePaths fileList;
// Try loading the file // Try loading the file
FilePath fileName = sessionNameToFileName(loadImplicitDefault ? "default" : session); FilePath fileName = sessionNameToFileName(loadImplicitDefault ? DEFAULT_SESSION : session);
PersistentSettingsReader reader; PersistentSettingsReader reader;
if (fileName.exists()) { if (fileName.exists()) {
if (!reader.load(fileName)) { if (!reader.load(fileName)) {
@@ -1030,7 +1032,7 @@ bool SessionManager::loadSession(const QString &session, bool initial)
if (loadImplicitDefault) { if (loadImplicitDefault) {
d->restoreValues(reader); d->restoreValues(reader);
emit m_instance->sessionLoaded("default"); emit m_instance->sessionLoaded(DEFAULT_SESSION);
return true; return true;
} }