Commit 9d58ea3e authored by dt's avatar dt
Browse files

Sort the session list alphabetically.

Task-Nr: 257986
parent 9e2f12c7
......@@ -989,6 +989,11 @@ QString SessionManager::activeSession() const
return m_sessionName;
}
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.toLower() < s2.toLower();
}
QStringList SessionManager::sessions() const
{
if (m_sessions.isEmpty()) {
......@@ -1001,6 +1006,7 @@ QStringList SessionManager::sessions() const
m_sessions << fileInfo.completeBaseName();
}
m_sessions.prepend("default");
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan);
}
return m_sessions;
}
......@@ -1021,6 +1027,7 @@ bool SessionManager::createSession(const QString &session)
if (sessions().contains(session))
return false;
m_sessions.append(session);
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan);
return true;
}
......@@ -1044,6 +1051,7 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone)
// If the file does not exist, we can still clone
if (!fi.exists() || fi.copy(sessionNameToFileName(clone))) {
m_sessions.append(clone);
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan);
return true;
}
return false;
......
......@@ -164,8 +164,10 @@ void SessionDialog::createNew()
return;
m_sessionManager->createSession(newSession);
m_ui.sessionList->addItem(newSession);
m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1);
m_ui.sessionList->clear();
QStringList sessions = m_sessionManager->sessions();
m_ui.sessionList->addItems(sessions);
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
}
}
......@@ -174,8 +176,12 @@ void SessionDialog::clone()
NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions());
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession))
m_ui.sessionList->addItem(newSession);
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
m_ui.sessionList->clear();
QStringList sessions = m_sessionManager->sessions();
m_ui.sessionList->addItems(sessions);
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment