From 9d58ea3e7cf570566f048b4afae804e9ad2c9a9c Mon Sep 17 00:00:00 2001
From: dt <qtc-committer@nokia.com>
Date: Tue, 21 Jul 2009 13:17:58 +0200
Subject: [PATCH] Sort the session list alphabetically.

Task-Nr: 257986
---
 src/plugins/projectexplorer/session.cpp       |  8 ++++++++
 src/plugins/projectexplorer/sessiondialog.cpp | 14 ++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index 3f1c22357f5..90c66491c5b 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -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;
diff --git a/src/plugins/projectexplorer/sessiondialog.cpp b/src/plugins/projectexplorer/sessiondialog.cpp
index 7ef8d63fd4e..89b0a489bb3 100644
--- a/src/plugins/projectexplorer/sessiondialog.cpp
+++ b/src/plugins/projectexplorer/sessiondialog.cpp
@@ -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));
+        }
     }
 }
 
-- 
GitLab