Sessions: use new SessionsView with modified date

This removes sessionList logic which moved to
SessionView / SessionModel which is already used
in the WelcomePage.

Change-Id: I108b84a038ae49cf75397988b20d6b5123912292
Task-number: QTCREATORBUG-15790
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tim Jenssen
2016-09-23 20:45:03 +02:00
parent 29f6f4f253
commit 4e3dcbd4d8
4 changed files with 43 additions and 136 deletions

View File

@@ -117,30 +117,29 @@ bool SessionNameInputDialog::isSwitchToRequested() const
return m_usedSwitchTo; return m_usedSwitchTo;
} }
SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent) SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
connect(m_ui.btCreateNew, &QAbstractButton::clicked, connect(m_ui.btCreateNew, &QAbstractButton::clicked,
this, &SessionDialog::createNew); m_ui.sessionView, &SessionView::createNewSession);
connect(m_ui.btClone, &QAbstractButton::clicked, connect(m_ui.btClone, &QAbstractButton::clicked,
this, &SessionDialog::clone); m_ui.sessionView, &SessionView::cloneCurrentSession);
connect(m_ui.btDelete, &QAbstractButton::clicked, 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.sessionView, &SessionView::selected,
connect(m_ui.btRename, &QAbstractButton::clicked, this, &SessionDialog::rename); this, &SessionDialog::updateActions);
connect(m_ui.sessionView, &SessionView::sessionSwitched,
connect(m_ui.sessionList, &QListWidget::itemDoubleClicked, this, &QDialog::reject);
this, &SessionDialog::switchToSession);
connect(m_ui.sessionList, &QListWidget::currentItemChanged,
this, &SessionDialog::updateActions);
m_ui.whatsASessionLabel->setOpenExternalLinks(true); m_ui.whatsASessionLabel->setOpenExternalLinks(true);
addItems(true);
markItems();
} }
void SessionDialog::setAutoLoadSession(bool check) void SessionDialog::setAutoLoadSession(bool check)
@@ -153,124 +152,22 @@ bool SessionDialog::autoLoadSession() const
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked; return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
} }
void SessionDialog::updateActions(const QString &session)
void SessionDialog::addItems(bool setDefaultSession)
{ {
QStringList sessions = SessionManager::sessions(); if (session.isEmpty()) {
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 {
m_ui.btDelete->setEnabled(false); m_ui.btDelete->setEnabled(false);
m_ui.btRename->setEnabled(false); m_ui.btRename->setEnabled(false);
m_ui.btClone->setEnabled(false); m_ui.btClone->setEnabled(false);
m_ui.btSwitch->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 Internal
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -49,17 +49,8 @@ public:
bool autoLoadSession() const; bool autoLoadSession() const;
private: private:
void createNew(); void updateActions(const QString &session);
void clone();
void remove();
void rename();
void switchToSession();
void updateActions();
void addItems(bool setDefaultSession);
void markItems();
void addSessionToUi(const QString &name, bool switchTo);
Ui::SessionDialog m_ui; Ui::SessionDialog m_ui;
}; };

View File

@@ -15,7 +15,7 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QListWidget" name="sessionList"> <widget class="SessionView" name="sessionView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch> <horstretch>1</horstretch>
@@ -130,6 +130,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>SessionView</class>
<extends>QTreeView</extends>
<header>projectexplorer/sessionview.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>

View File

@@ -119,6 +119,18 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const
break; break;
} // switch (section) } // switch (section)
break; 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: case DefaultSessionRole:
result = SessionManager::isDefaultSession(sessionName); result = SessionManager::isDefaultSession(sessionName);
break; break;