diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index ed07b118f304d430ec35e94aad692808946df11a..4aa2dd0b858e4f417d5b64b5cad23eb68011cd6b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -935,7 +935,7 @@ void ProjectExplorerPlugin::showSessionManager() } else { d->m_session->save(); } - SessionDialog sessionDialog(d->m_session, d->m_session->activeSession(), false); + SessionDialog sessionDialog(d->m_session); sessionDialog.exec(); updateActions(); diff --git a/src/plugins/projectexplorer/projectwelcomepagewidget.cpp b/src/plugins/projectexplorer/projectwelcomepagewidget.cpp index a9feb8f2b2d2cb9883c2c695fd06e1198054248a..f8112a868f15952dfdb4e976d09fc68ef9564d44 100644 --- a/src/plugins/projectexplorer/projectwelcomepagewidget.cpp +++ b/src/plugins/projectexplorer/projectwelcomepagewidget.cpp @@ -45,7 +45,12 @@ #include <QtCore/QDebug> #define MAX_RECENT_PROJECT_ITEMS 6 -#define MAX_RECENT_SESSION_ITEMS 10 + +#ifdef Q_OS_MAC +# define MAX_RECENT_SESSION_ITEMS 8 +#else +# define MAX_RECENT_SESSION_ITEMS 9 +#endif using namespace ProjectExplorer::Internal; diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp index dcd120f1a0e2aa57973b190416fc02f30b93f5c1..8992c434bb3f29cfcbd0f2c8aefa65c48ea8e612 100644 --- a/src/plugins/projectexplorer/session.cpp +++ b/src/plugins/projectexplorer/session.cpp @@ -1029,24 +1029,17 @@ QString SessionManager::activeSession() const return m_sessionName; } -static bool caseInsensitiveLessThan(const QString &s1, const QString &s2) -{ - return s1.compare(s2, Qt::CaseInsensitive) < 0; -} - QStringList SessionManager::sessions() const { if (m_sessions.isEmpty()) { // We are not initialized yet, so do that now - QDirIterator dirIter(QFileInfo(m_core->settings()->fileName()).path() + "/qtcreator/"); - while (dirIter.hasNext()) { - dirIter.next(); - const QFileInfo &fileInfo = dirIter.fileInfo(); - if (fileInfo.suffix() == "qws" && fileInfo.completeBaseName() != "default") + QDir sessionDir(QFileInfo(m_core->settings()->fileName()).path()+ "/qtcreator/"); + QList<QFileInfo> sessionFiles = sessionDir.entryInfoList(QStringList() << QLatin1String("*.qws"), QDir::NoFilter, QDir::Time); + Q_FOREACH(const QFileInfo& fileInfo, sessionFiles) { + if (fileInfo.completeBaseName() != "default") m_sessions << fileInfo.completeBaseName(); } m_sessions.prepend("default"); - qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan); } return m_sessions; } @@ -1066,11 +1059,20 @@ bool SessionManager::createSession(const QString &session) { if (sessions().contains(session)) return false; - m_sessions.append(session); - qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan); + Q_ASSERT(m_sessions.size() > 0); + m_sessions.insert(1, session); return true; } +bool SessionManager::renameSession(const QString &original, const QString &newName) +{ + if (!cloneSession(original, newName)) + return false; + if (original == activeSession()) + loadSession(newName); + return deleteSession(original); +} + bool SessionManager::deleteSession(const QString &session) { if (!m_sessions.contains(session)) @@ -1090,8 +1092,8 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone) QFile fi(sessionNameToFileName(original)); // 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); + Q_ASSERT(m_sessions.size() > 0); + m_sessions.insert(1, clone); return true; } return false; diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h index 91dfd5535dfca33bbc5f94829753c72b451444e2..2e3aa0b464b368ddc092dfc60ee2a44fdaa51c9c 100644 --- a/src/plugins/projectexplorer/session.h +++ b/src/plugins/projectexplorer/session.h @@ -107,6 +107,7 @@ public: bool deleteSession(const QString &session); bool cloneSession(const QString &original, const QString &clone); + bool renameSession(const QString &original, const QString &newName); // loads a session, takes a session name (not filename) bool loadSession(const QString &session); diff --git a/src/plugins/projectexplorer/sessiondialog.cpp b/src/plugins/projectexplorer/sessiondialog.cpp index ed8a97618c7ac52a532bbbb4a1128d405078aba9..111a11d9a8093f7f5b8f562841204658d2beb45c 100644 --- a/src/plugins/projectexplorer/sessiondialog.cpp +++ b/src/plugins/projectexplorer/sessiondialog.cpp @@ -74,21 +74,20 @@ void SessionValidator::fixup(QString &input) const input = copy; } -class NewSessionInputDialog : public QDialog +class SessionNameInputDialog : public QDialog { Q_OBJECT public: - NewSessionInputDialog(QStringList sessions); - QString value(); + SessionNameInputDialog(const QStringList& sessions); + QString value() const; private: QLineEdit *m_newSessionLineEdit; }; -NewSessionInputDialog::NewSessionInputDialog(QStringList sessions) +SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions) { - setWindowTitle(tr("New session name")); QVBoxLayout *hlayout = new QVBoxLayout(this); - QLabel *label = new QLabel(tr("Enter the name of the new session:"), this); + QLabel *label = new QLabel(tr("Enter the name of the session:"), this); hlayout->addWidget(label); m_newSessionLineEdit = new QLineEdit(this); m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions)); @@ -100,57 +99,83 @@ NewSessionInputDialog::NewSessionInputDialog(QStringList sessions) setLayout(hlayout); } -QString NewSessionInputDialog::value() +QString SessionNameInputDialog::value() const { return m_newSessionLineEdit->text(); } -SessionDialog::SessionDialog(SessionManager *sessionManager, const QString &lastSession, bool startup) - : m_sessionManager(sessionManager), m_startup(startup) +SessionDialog::SessionDialog(SessionManager *sessionManager) + : m_sessionManager(sessionManager) { m_ui.setupUi(this); - QPushButton *switchButton = m_ui.buttonBox->addButton(tr("Switch to session"), - QDialogButtonBox::AcceptRole); - connect(switchButton, SIGNAL(clicked()), - this, SLOT(switchToSession())); - connect(m_ui.btCreateNew, SIGNAL(clicked()), this, SLOT(createNew())); - connect(m_ui.btClone, SIGNAL(clicked()), this, SLOT(clone())); connect(m_ui.btDelete, SIGNAL(clicked()), this, SLOT(remove())); - connect(m_ui.sessionList, SIGNAL(itemDoubleClicked ( QListWidgetItem *)), - this, SLOT(accept())); + connect(m_ui.btSwitch, SIGNAL(clicked()), this, SLOT(switchToSession())); + connect(m_ui.btRename, SIGNAL(clicked()), this, SLOT(rename())); + + connect(m_ui.sessionList, SIGNAL(itemDoubleClicked (QListWidgetItem *)), + this, SLOT(switchToSession())); connect(m_ui.sessionList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(updateActions())); m_ui.whatsASessionLabel->setOpenExternalLinks(true); - QStringList sessions = sessionManager->sessions(); + addItems(true); + markItems(); +} + +void SessionDialog::addItems(bool setDefaultSession) +{ + QStringList sessions = m_sessionManager->sessions(); foreach (const QString &session, sessions) { m_ui.sessionList->addItem(session); - if (session == lastSession) + if (setDefaultSession && session == m_sessionManager->activeSession()) m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1); } } +void SessionDialog::markItems() +{ + for(int i = 0; i < m_ui.sessionList->count(); ++i) { + QListWidgetItem *item = m_ui.sessionList->item(i); + QFont f = item->font(); + QString session = item->data(Qt::DisplayRole).toString(); + if (m_sessionManager->isDefaultSession(session)) + f.setItalic(true); + else + f.setItalic(false); + if (m_sessionManager->activeSession() == session && !m_sessionManager->isDefaultVirgin()) + f.setBold(true); + else + f.setBold(false); + item->setFont(f); + } +} void SessionDialog::updateActions() { - bool enableDelete = false; + bool isDefault = false; + bool isActive = false; - if (m_ui.sessionList->currentItem()) - enableDelete = (m_ui.sessionList->currentItem()->text() != m_sessionManager->activeSession() - && (m_ui.sessionList->currentItem()->text() != QLatin1String("default"))); - m_ui.btDelete->setEnabled(enableDelete); + if (m_ui.sessionList->currentItem()) { + isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default")); + isActive = (m_ui.sessionList->currentItem()->text() == m_sessionManager->activeSession()); + } + + m_ui.btDelete->setDisabled(isActive || isDefault); + m_ui.btRename->setDisabled(isDefault); } void SessionDialog::createNew() { - NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions()); + SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions()); + newSessionInputDialog.setWindowTitle(tr("New session name")); + if (newSessionInputDialog.exec() == QDialog::Accepted) { QString newSession = newSessionInputDialog.value(); if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession)) @@ -166,7 +191,8 @@ void SessionDialog::createNew() void SessionDialog::clone() { - NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions()); + SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions()); + newSessionInputDialog.setWindowTitle(tr("New session name")); if (newSessionInputDialog.exec() == QDialog::Accepted) { QString newSession = newSessionInputDialog.value(); if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) { @@ -182,16 +208,32 @@ void SessionDialog::remove() { m_sessionManager->deleteSession(m_ui.sessionList->currentItem()->text()); m_ui.sessionList->clear(); - m_ui.sessionList->addItems(m_sessionManager->sessions()); + addItems(false); + markItems(); } + +void SessionDialog::rename() +{ + SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions()); + newSessionInputDialog.setWindowTitle(tr("Rename session")); + if (newSessionInputDialog.exec() == QDialog::Accepted) { + m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value()); + m_ui.sessionList->clear(); + addItems(false); + markItems(); + } +} + + void SessionDialog::switchToSession() { if (m_ui.sessionList->currentItem()) { QString session = m_ui.sessionList->currentItem()->text(); m_sessionManager->loadSession(session); + markItems(); } - accept(); + updateActions(); } } // namespace Internal diff --git a/src/plugins/projectexplorer/sessiondialog.h b/src/plugins/projectexplorer/sessiondialog.h index d5fe5ba275aeae357dc962d12864c286858729d3..06f116d67bbee903c4739e6196a63c5a4bec637c 100644 --- a/src/plugins/projectexplorer/sessiondialog.h +++ b/src/plugins/projectexplorer/sessiondialog.h @@ -45,20 +45,22 @@ class SessionDialog : public QDialog { Q_OBJECT public: - SessionDialog(SessionManager *sessionManager, const QString &lastSession, bool startup); + SessionDialog(SessionManager *sessionManager); private slots: void createNew(); void clone(); void remove(); + void rename(); void switchToSession(); void updateActions(); private: + void addItems(bool setDefaultSession); + void markItems(); Ui::SessionDialog m_ui; SessionManager *m_sessionManager; - bool m_startup; }; } // namespace Internal diff --git a/src/plugins/projectexplorer/sessiondialog.ui b/src/plugins/projectexplorer/sessiondialog.ui index ecc9bbd988bc36dae2a2d18235abbad3369ec389..7418b159947bc86ef03d0716d12732048e218e1e 100644 --- a/src/plugins/projectexplorer/sessiondialog.ui +++ b/src/plugins/projectexplorer/sessiondialog.ui @@ -14,29 +14,46 @@ <string>Session Manager</string> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="2"> + <item row="0" column="0"> <widget class="QListWidget" name="sessionList"/> </item> - <item row="0" column="2"> + <item row="0" column="1"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QPushButton" name="btCreateNew"> <property name="text"> - <string>Create New Session</string> + <string>&New</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btRename"> + <property name="text"> + <string>&Rename</string> </property> </widget> </item> <item> <widget class="QPushButton" name="btClone"> <property name="text"> - <string>Clone Session</string> + <string>C&lone</string> </property> </widget> </item> <item> <widget class="QPushButton" name="btDelete"> <property name="text"> - <string>Delete Session</string> + <string>&Delete</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btSwitch"> + <property name="text"> + <string>&Switch to</string> + </property> + <property name="default"> + <bool>true</bool> </property> </widget> </item> @@ -47,22 +64,29 @@ </property> <property name="sizeHint" stdset="0"> <size> - <width>20</width> - <height>40</height> + <width>85</width> + <height>13</height> </size> </property> </spacer> </item> </layout> </item> - <item row="1" column="0"> + <item row="1" column="0" colspan="2"> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="2" column="0" rowspan="2"> <widget class="QLabel" name="whatsASessionLabel"> <property name="text"> <string><a href="qthelp://com.nokia.qtcreator/doc/creator-quick-tour.html#session-management-in-qt-creator">What is a Session?</a></string> </property> </widget> </item> - <item row="1" column="1" colspan="2"> + <item row="3" column="1"> <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> <set>QDialogButtonBox::Close</set> @@ -75,33 +99,33 @@ <connections> <connection> <sender>buttonBox</sender> - <signal>accepted()</signal> + <signal>rejected()</signal> <receiver>ProjectExplorer::Internal::SessionDialog</receiver> - <slot>accept()</slot> + <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>246</x> - <y>237</y> + <x>191</x> + <y>244</y> </hint> <hint type="destinationlabel"> - <x>78</x> - <y>216</y> + <x>114</x> + <y>237</y> </hint> </hints> </connection> <connection> <sender>buttonBox</sender> - <signal>rejected()</signal> + <signal>accepted()</signal> <receiver>ProjectExplorer::Internal::SessionDialog</receiver> - <slot>reject()</slot> + <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>191</x> - <y>244</y> + <x>246</x> + <y>237</y> </hint> <hint type="destinationlabel"> - <x>114</x> - <y>237</y> + <x>78</x> + <y>216</y> </hint> </hints> </connection>