forked from qt-creator/qt-creator
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:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
@@ -73,22 +97,6 @@
|
||||
</widget>
|
||||
<resources/>
|
||||
<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>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
@@ -105,5 +113,21 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user