Modify behaviour of sessions on the welcomescreen and tweak the session manager

- List sessions by recent use instead of alphabetically
- Tweak the session manager. It is now a persistent dialog with only a close button
- Implement session renaming in the session manager
- Cleanups

Task-Number: QTCREATORBUG-1168
This commit is contained in:
Daniel Molkentin
2010-04-21 16:08:13 +02:00
parent 861981a39d
commit ee8caa5b7c
7 changed files with 148 additions and 72 deletions

View File

@@ -935,7 +935,7 @@ void ProjectExplorerPlugin::showSessionManager()
} else { } else {
d->m_session->save(); d->m_session->save();
} }
SessionDialog sessionDialog(d->m_session, d->m_session->activeSession(), false); SessionDialog sessionDialog(d->m_session);
sessionDialog.exec(); sessionDialog.exec();
updateActions(); updateActions();

View File

@@ -45,7 +45,12 @@
#include <QtCore/QDebug> #include <QtCore/QDebug>
#define MAX_RECENT_PROJECT_ITEMS 6 #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; using namespace ProjectExplorer::Internal;

View File

@@ -1029,24 +1029,17 @@ QString SessionManager::activeSession() const
return m_sessionName; return m_sessionName;
} }
static bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.compare(s2, Qt::CaseInsensitive) < 0;
}
QStringList SessionManager::sessions() const QStringList SessionManager::sessions() const
{ {
if (m_sessions.isEmpty()) { if (m_sessions.isEmpty()) {
// We are not initialized yet, so do that now // We are not initialized yet, so do that now
QDirIterator dirIter(QFileInfo(m_core->settings()->fileName()).path() + "/qtcreator/"); QDir sessionDir(QFileInfo(m_core->settings()->fileName()).path()+ "/qtcreator/");
while (dirIter.hasNext()) { QList<QFileInfo> sessionFiles = sessionDir.entryInfoList(QStringList() << QLatin1String("*.qws"), QDir::NoFilter, QDir::Time);
dirIter.next(); Q_FOREACH(const QFileInfo& fileInfo, sessionFiles) {
const QFileInfo &fileInfo = dirIter.fileInfo(); if (fileInfo.completeBaseName() != "default")
if (fileInfo.suffix() == "qws" && fileInfo.completeBaseName() != "default")
m_sessions << fileInfo.completeBaseName(); m_sessions << fileInfo.completeBaseName();
} }
m_sessions.prepend("default"); m_sessions.prepend("default");
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan);
} }
return m_sessions; return m_sessions;
} }
@@ -1066,11 +1059,20 @@ bool SessionManager::createSession(const QString &session)
{ {
if (sessions().contains(session)) if (sessions().contains(session))
return false; return false;
m_sessions.append(session); Q_ASSERT(m_sessions.size() > 0);
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan); m_sessions.insert(1, session);
return true; 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) bool SessionManager::deleteSession(const QString &session)
{ {
if (!m_sessions.contains(session)) if (!m_sessions.contains(session))
@@ -1090,8 +1092,8 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone)
QFile fi(sessionNameToFileName(original)); QFile fi(sessionNameToFileName(original));
// If the file does not exist, we can still clone // If the file does not exist, we can still clone
if (!fi.exists() || fi.copy(sessionNameToFileName(clone))) { if (!fi.exists() || fi.copy(sessionNameToFileName(clone))) {
m_sessions.append(clone); Q_ASSERT(m_sessions.size() > 0);
qSort(m_sessions.begin(), m_sessions.end(), caseInsensitiveLessThan); m_sessions.insert(1, clone);
return true; return true;
} }
return false; return false;

View File

@@ -107,6 +107,7 @@ public:
bool deleteSession(const QString &session); bool deleteSession(const QString &session);
bool cloneSession(const QString &original, const QString &clone); 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) // loads a session, takes a session name (not filename)
bool loadSession(const QString &session); bool loadSession(const QString &session);

View File

@@ -74,21 +74,20 @@ void SessionValidator::fixup(QString &input) const
input = copy; input = copy;
} }
class NewSessionInputDialog : public QDialog class SessionNameInputDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
NewSessionInputDialog(QStringList sessions); SessionNameInputDialog(const QStringList& sessions);
QString value(); QString value() const;
private: private:
QLineEdit *m_newSessionLineEdit; QLineEdit *m_newSessionLineEdit;
}; };
NewSessionInputDialog::NewSessionInputDialog(QStringList sessions) SessionNameInputDialog::SessionNameInputDialog(const QStringList& sessions)
{ {
setWindowTitle(tr("New session name"));
QVBoxLayout *hlayout = new QVBoxLayout(this); 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); hlayout->addWidget(label);
m_newSessionLineEdit = new QLineEdit(this); m_newSessionLineEdit = new QLineEdit(this);
m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions)); m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions));
@@ -100,57 +99,83 @@ NewSessionInputDialog::NewSessionInputDialog(QStringList sessions)
setLayout(hlayout); setLayout(hlayout);
} }
QString NewSessionInputDialog::value() QString SessionNameInputDialog::value() const
{ {
return m_newSessionLineEdit->text(); return m_newSessionLineEdit->text();
} }
SessionDialog::SessionDialog(SessionManager *sessionManager, const QString &lastSession, bool startup) SessionDialog::SessionDialog(SessionManager *sessionManager)
: m_sessionManager(sessionManager), m_startup(startup) : m_sessionManager(sessionManager)
{ {
m_ui.setupUi(this); 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()), connect(m_ui.btCreateNew, SIGNAL(clicked()),
this, SLOT(createNew())); this, SLOT(createNew()));
connect(m_ui.btClone, SIGNAL(clicked()), connect(m_ui.btClone, SIGNAL(clicked()),
this, SLOT(clone())); this, SLOT(clone()));
connect(m_ui.btDelete, SIGNAL(clicked()), connect(m_ui.btDelete, SIGNAL(clicked()),
this, SLOT(remove())); this, SLOT(remove()));
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 *)), connect(m_ui.sessionList, SIGNAL(itemDoubleClicked (QListWidgetItem *)),
this, SLOT(accept())); this, SLOT(switchToSession()));
connect(m_ui.sessionList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), connect(m_ui.sessionList, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this, SLOT(updateActions())); this, SLOT(updateActions()));
m_ui.whatsASessionLabel->setOpenExternalLinks(true); 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) { foreach (const QString &session, sessions) {
m_ui.sessionList->addItem(session); m_ui.sessionList->addItem(session);
if (session == lastSession) if (setDefaultSession && session == m_sessionManager->activeSession())
m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1); 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() void SessionDialog::updateActions()
{ {
bool enableDelete = false; bool isDefault = false;
bool isActive = false;
if (m_ui.sessionList->currentItem()) if (m_ui.sessionList->currentItem()) {
enableDelete = (m_ui.sessionList->currentItem()->text() != m_sessionManager->activeSession() isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default"));
&& (m_ui.sessionList->currentItem()->text() != QLatin1String("default"))); isActive = (m_ui.sessionList->currentItem()->text() == m_sessionManager->activeSession());
m_ui.btDelete->setEnabled(enableDelete); }
m_ui.btDelete->setDisabled(isActive || isDefault);
m_ui.btRename->setDisabled(isDefault);
} }
void SessionDialog::createNew() void SessionDialog::createNew()
{ {
NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions()); SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions());
newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) { if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value(); QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession)) if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession))
@@ -166,7 +191,8 @@ void SessionDialog::createNew()
void SessionDialog::clone() void SessionDialog::clone()
{ {
NewSessionInputDialog newSessionInputDialog(m_sessionManager->sessions()); SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions());
newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) { if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value(); QString newSession = newSessionInputDialog.value();
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) { 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_sessionManager->deleteSession(m_ui.sessionList->currentItem()->text());
m_ui.sessionList->clear(); 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() void SessionDialog::switchToSession()
{ {
if (m_ui.sessionList->currentItem()) { if (m_ui.sessionList->currentItem()) {
QString session = m_ui.sessionList->currentItem()->text(); QString session = m_ui.sessionList->currentItem()->text();
m_sessionManager->loadSession(session); m_sessionManager->loadSession(session);
markItems();
} }
accept(); updateActions();
} }
} // namespace Internal } // namespace Internal

View File

@@ -45,20 +45,22 @@ class SessionDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
SessionDialog(SessionManager *sessionManager, const QString &lastSession, bool startup); SessionDialog(SessionManager *sessionManager);
private slots: private slots:
void createNew(); void createNew();
void clone(); void clone();
void remove(); void remove();
void rename();
void switchToSession(); void switchToSession();
void updateActions(); void updateActions();
private: private:
void addItems(bool setDefaultSession);
void markItems();
Ui::SessionDialog m_ui; Ui::SessionDialog m_ui;
SessionManager *m_sessionManager; SessionManager *m_sessionManager;
bool m_startup;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -14,29 +14,46 @@
<string>Session Manager</string> <string>Session Manager</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0">
<widget class="QListWidget" name="sessionList"/> <widget class="QListWidget" name="sessionList"/>
</item> </item>
<item row="0" column="2"> <item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QPushButton" name="btCreateNew"> <widget class="QPushButton" name="btCreateNew">
<property name="text"> <property name="text">
<string>Create New Session</string> <string>&amp;New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btRename">
<property name="text">
<string>&amp;Rename</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="btClone"> <widget class="QPushButton" name="btClone">
<property name="text"> <property name="text">
<string>Clone Session</string> <string>C&amp;lone</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="btDelete"> <widget class="QPushButton" name="btDelete">
<property name="text"> <property name="text">
<string>Delete Session</string> <string>&amp;Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btSwitch">
<property name="text">
<string>&amp;Switch to</string>
</property>
<property name="default">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -47,22 +64,29 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>85</width>
<height>40</height> <height>13</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
</item> </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"> <widget class="QLabel" name="whatsASessionLabel">
<property name="text"> <property name="text">
<string>&lt;a href=&quot;qthelp://com.nokia.qtcreator/doc/creator-quick-tour.html#session-management-in-qt-creator&quot;&gt;What is a Session?&lt;/a&gt;</string> <string>&lt;a href=&quot;qthelp://com.nokia.qtcreator/doc/creator-quick-tour.html#session-management-in-qt-creator&quot;&gt;What is a Session?&lt;/a&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="2"> <item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Close</set> <set>QDialogButtonBox::Close</set>
@@ -73,22 +97,6 @@
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ProjectExplorer::Internal::SessionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>246</x>
<y>237</y>
</hint>
<hint type="destinationlabel">
<x>78</x>
<y>216</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>
@@ -105,5 +113,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ProjectExplorer::Internal::SessionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>246</x>
<y>237</y>
</hint>
<hint type="destinationlabel">
<x>78</x>
<y>216</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>