diff --git a/src/plugins/projectexplorer/sessiondialog.cpp b/src/plugins/projectexplorer/sessiondialog.cpp
index 2f6f6b15dcc..4368d9b61d5 100644
--- a/src/plugins/projectexplorer/sessiondialog.cpp
+++ b/src/plugins/projectexplorer/sessiondialog.cpp
@@ -117,30 +117,29 @@ bool SessionNameInputDialog::isSwitchToRequested() const
return m_usedSwitchTo;
}
-
SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent)
{
m_ui.setupUi(this);
connect(m_ui.btCreateNew, &QAbstractButton::clicked,
- this, &SessionDialog::createNew);
+ m_ui.sessionView, &SessionView::createNewSession);
connect(m_ui.btClone, &QAbstractButton::clicked,
- this, &SessionDialog::clone);
+ m_ui.sessionView, &SessionView::cloneCurrentSession);
connect(m_ui.btDelete, &QAbstractButton::clicked,
- this, &SessionDialog::remove);
+ m_ui.sessionView, &SessionView::deleteCurrentSession);
+ connect(m_ui.btSwitch, &QAbstractButton::clicked,
+ m_ui.sessionView, &SessionView::switchToCurrentSession);
+ connect(m_ui.btRename, &QAbstractButton::clicked,
+ m_ui.sessionView, &SessionView::renameCurrentSession);
+ connect(m_ui.sessionView, &SessionView::activated,
+ m_ui.sessionView, &SessionView::switchToCurrentSession);
- connect(m_ui.btSwitch, &QAbstractButton::clicked, this, &SessionDialog::switchToSession);
- connect(m_ui.btRename, &QAbstractButton::clicked, this, &SessionDialog::rename);
-
- connect(m_ui.sessionList, &QListWidget::itemDoubleClicked,
- this, &SessionDialog::switchToSession);
-
- connect(m_ui.sessionList, &QListWidget::currentItemChanged,
- this, &SessionDialog::updateActions);
+ connect(m_ui.sessionView, &SessionView::selected,
+ this, &SessionDialog::updateActions);
+ connect(m_ui.sessionView, &SessionView::sessionSwitched,
+ this, &QDialog::reject);
m_ui.whatsASessionLabel->setOpenExternalLinks(true);
- addItems(true);
- markItems();
}
void SessionDialog::setAutoLoadSession(bool check)
@@ -153,124 +152,22 @@ bool SessionDialog::autoLoadSession() const
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
}
-
-void SessionDialog::addItems(bool setDefaultSession)
+void SessionDialog::updateActions(const QString &session)
{
- QStringList sessions = SessionManager::sessions();
- foreach (const QString &session, sessions) {
- m_ui.sessionList->addItem(session);
- if (setDefaultSession && session == 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 (SessionManager::isDefaultSession(session))
- f.setItalic(true);
- else
- f.setItalic(false);
- if (SessionManager::activeSession() == session && !SessionManager::isDefaultVirgin())
- f.setBold(true);
- else
- f.setBold(false);
- item->setFont(f);
- }
-}
-
-void SessionDialog::addSessionToUi(const QString &name, bool switchTo)
-{
- m_ui.sessionList->clear();
- QStringList sessions = SessionManager::sessions();
- m_ui.sessionList->addItems(sessions);
- m_ui.sessionList->setCurrentRow(sessions.indexOf(name));
- markItems();
- if (switchTo)
- switchToSession();
-}
-
-void SessionDialog::updateActions()
-{
- if (m_ui.sessionList->currentItem()) {
- bool isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default"));
- bool isActive = (m_ui.sessionList->currentItem()->text() == SessionManager::activeSession());
- m_ui.btDelete->setEnabled(!isActive && !isDefault);
- m_ui.btRename->setEnabled(!isDefault);
- m_ui.btClone->setEnabled(true);
- m_ui.btSwitch->setEnabled(true);
- } else {
+ if (session.isEmpty()) {
m_ui.btDelete->setEnabled(false);
m_ui.btRename->setEnabled(false);
m_ui.btClone->setEnabled(false);
m_ui.btSwitch->setEnabled(false);
+ } else {
+ bool isDefault = (session == QLatin1String("default"));
+ bool isActive = (session == SessionManager::activeSession());
+ m_ui.btDelete->setEnabled(!isActive && !isDefault);
+ m_ui.btRename->setEnabled(!isDefault);
+ m_ui.btClone->setEnabled(true);
+ m_ui.btSwitch->setEnabled(true);
}
}
-void SessionDialog::createNew()
-{
- SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
- newSessionInputDialog.setWindowTitle(tr("New Session Name"));
-
- if (newSessionInputDialog.exec() == QDialog::Accepted) {
- QString sessionName = newSessionInputDialog.value();
- if (sessionName.isEmpty() || SessionManager::sessions().contains(sessionName))
- return;
-
- SessionManager::createSession(sessionName);
- addSessionToUi(sessionName, newSessionInputDialog.isSwitchToRequested());
- }
-}
-
-void SessionDialog::clone()
-{
- SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
- newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
- newSessionInputDialog.setWindowTitle(tr("New Session Name"));
-
- if (newSessionInputDialog.exec() == QDialog::Accepted) {
- QString newSession = newSessionInputDialog.value();
- if (SessionManager::cloneSession(m_ui.sessionList->currentItem()->text(), newSession))
- addSessionToUi(newSession, newSessionInputDialog.isSwitchToRequested());
- }
-}
-
-void SessionDialog::remove()
-{
- const QString name = m_ui.sessionList->currentItem()->text();
-
- if (!SessionManager::confirmSessionDelete(name))
- return;
- SessionManager::deleteSession(name);
- m_ui.sessionList->clear();
- addItems(false);
- markItems();
-}
-
-void SessionDialog::rename()
-{
- SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
- newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
- newSessionInputDialog.setWindowTitle(tr("Rename Session"));
-
- if (newSessionInputDialog.exec() == QDialog::Accepted) {
- SessionManager::renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
- m_ui.sessionList->clear();
- addItems(false);
- markItems();
- }
-}
-
-void SessionDialog::switchToSession()
-{
- QString session = m_ui.sessionList->currentItem()->text();
- SessionManager::loadSession(session);
- markItems();
- updateActions();
- reject();
-}
-
} // namespace Internal
} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/sessiondialog.h b/src/plugins/projectexplorer/sessiondialog.h
index bb1ae10dd4f..c9ee6e15f6f 100644
--- a/src/plugins/projectexplorer/sessiondialog.h
+++ b/src/plugins/projectexplorer/sessiondialog.h
@@ -49,17 +49,8 @@ public:
bool autoLoadSession() const;
private:
- void createNew();
- void clone();
- void remove();
- void rename();
- void switchToSession();
+ void updateActions(const QString &session);
- void updateActions();
-
- void addItems(bool setDefaultSession);
- void markItems();
- void addSessionToUi(const QString &name, bool switchTo);
Ui::SessionDialog m_ui;
};
diff --git a/src/plugins/projectexplorer/sessiondialog.ui b/src/plugins/projectexplorer/sessiondialog.ui
index e677951d98a..fd41eeacec1 100644
--- a/src/plugins/projectexplorer/sessiondialog.ui
+++ b/src/plugins/projectexplorer/sessiondialog.ui
@@ -15,7 +15,7 @@
-
-
+
1
@@ -130,6 +130,13 @@
+
+
+ SessionView
+ QTreeView
+ projectexplorer/sessionview.h
+
+
diff --git a/src/plugins/projectexplorer/sessionmodel.cpp b/src/plugins/projectexplorer/sessionmodel.cpp
index 31f984a0835..590393054af 100644
--- a/src/plugins/projectexplorer/sessionmodel.cpp
+++ b/src/plugins/projectexplorer/sessionmodel.cpp
@@ -119,6 +119,18 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const
break;
} // switch (section)
break;
+ case Qt::FontRole: {
+ QFont font;
+ if (SessionManager::isDefaultSession(sessionName))
+ font.setItalic(true);
+ else
+ font.setItalic(false);
+ if (SessionManager::activeSession() == sessionName && !SessionManager::isDefaultVirgin())
+ font.setBold(true);
+ else
+ font.setBold(false);
+ result = font;
+ } break;
case DefaultSessionRole:
result = SessionManager::isDefaultSession(sessionName);
break;