2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "sessiondialog.h"
|
|
|
|
|
#include "session.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QValidator>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class SessionValidator : public QValidator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SessionValidator(QObject *parent, QStringList sessions);
|
|
|
|
|
void fixup(QString & input) const;
|
|
|
|
|
QValidator::State validate(QString & input, int & pos) const;
|
|
|
|
|
private:
|
|
|
|
|
QStringList m_sessions;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SessionValidator::SessionValidator(QObject *parent, QStringList sessions)
|
|
|
|
|
: QValidator(parent), m_sessions(sessions)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QValidator::State SessionValidator::validate(QString &input, int &pos) const
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(pos)
|
2010-09-07 13:02:47 +02:00
|
|
|
|
2012-01-09 16:30:33 +01:00
|
|
|
if (input.contains(QLatin1Char('/'))
|
|
|
|
|
|| input.contains(QLatin1Char(':'))
|
|
|
|
|
|| input.contains(QLatin1Char('\\'))
|
|
|
|
|
|| input.contains(QLatin1Char('?'))
|
|
|
|
|
|| input.contains(QLatin1Char('*')))
|
2010-09-07 13:02:47 +02:00
|
|
|
return QValidator::Invalid;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_sessions.contains(input))
|
|
|
|
|
return QValidator::Intermediate;
|
|
|
|
|
else
|
|
|
|
|
return QValidator::Acceptable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionValidator::fixup(QString &input) const
|
|
|
|
|
{
|
|
|
|
|
int i = 2;
|
|
|
|
|
QString copy;
|
|
|
|
|
do {
|
2012-01-09 16:30:33 +01:00
|
|
|
copy = input + QLatin1String(" (") + QString::number(i) + QLatin1Char(')');
|
2008-12-02 12:01:29 +01:00
|
|
|
++i;
|
|
|
|
|
} while (m_sessions.contains(copy));
|
|
|
|
|
input = copy;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 17:32:44 +02:00
|
|
|
SessionNameInputDialog::SessionNameInputDialog(const QStringList &sessions, QWidget *parent)
|
2011-07-07 14:14:10 +02:00
|
|
|
: QDialog(parent), m_usedSwitchTo(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QVBoxLayout *hlayout = new QVBoxLayout(this);
|
2010-04-21 16:08:13 +02:00
|
|
|
QLabel *label = new QLabel(tr("Enter the name of the session:"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
hlayout->addWidget(label);
|
|
|
|
|
m_newSessionLineEdit = new QLineEdit(this);
|
|
|
|
|
m_newSessionLineEdit->setValidator(new SessionValidator(this, sessions));
|
|
|
|
|
hlayout->addWidget(m_newSessionLineEdit);
|
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
2014-07-15 12:38:05 +02:00
|
|
|
m_switchToButton = buttons->addButton(tr("Switch To"), QDialogButtonBox::AcceptRole);
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::clicked, this, &SessionNameInputDialog::clicked);
|
2008-12-02 12:01:29 +01:00
|
|
|
hlayout->addWidget(buttons);
|
|
|
|
|
setLayout(hlayout);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 17:32:44 +02:00
|
|
|
void SessionNameInputDialog::setValue(const QString &value)
|
|
|
|
|
{
|
|
|
|
|
m_newSessionLineEdit->setText(value);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 16:08:13 +02:00
|
|
|
QString SessionNameInputDialog::value() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_newSessionLineEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 14:14:10 +02:00
|
|
|
void SessionNameInputDialog::clicked(QAbstractButton *button)
|
|
|
|
|
{
|
|
|
|
|
if (button == m_switchToButton)
|
|
|
|
|
m_usedSwitchTo = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SessionNameInputDialog::isSwitchToRequested() const
|
|
|
|
|
{
|
|
|
|
|
return m_usedSwitchTo;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 17:32:44 +02:00
|
|
|
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionDialog::SessionDialog(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.btCreateNew, &QAbstractButton::clicked,
|
|
|
|
|
this, &SessionDialog::createNew);
|
|
|
|
|
connect(m_ui.btClone, &QAbstractButton::clicked,
|
|
|
|
|
this, &SessionDialog::clone);
|
|
|
|
|
connect(m_ui.btDelete, &QAbstractButton::clicked,
|
|
|
|
|
this, &SessionDialog::remove);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.btSwitch, &QAbstractButton::clicked, this, &SessionDialog::switchToSession);
|
|
|
|
|
connect(m_ui.btRename, &QAbstractButton::clicked, this, &SessionDialog::rename);
|
2010-04-21 16:08:13 +02:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.sessionList, &QListWidget::itemDoubleClicked,
|
|
|
|
|
this, &SessionDialog::switchToSession);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.sessionList, &QListWidget::currentItemChanged,
|
|
|
|
|
this, &SessionDialog::updateActions);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-28 13:47:15 +02:00
|
|
|
m_ui.whatsASessionLabel->setOpenExternalLinks(true);
|
2010-04-21 16:08:13 +02:00
|
|
|
addItems(true);
|
|
|
|
|
markItems();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-14 11:37:54 +02:00
|
|
|
void SessionDialog::setAutoLoadSession(bool check)
|
|
|
|
|
{
|
|
|
|
|
m_ui.autoLoadCheckBox->setChecked(check ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SessionDialog::autoLoadSession() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-21 16:08:13 +02:00
|
|
|
void SessionDialog::addItems(bool setDefaultSession)
|
|
|
|
|
{
|
2013-09-05 12:35:19 +02:00
|
|
|
QStringList sessions = SessionManager::sessions();
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (const QString &session, sessions) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.sessionList->addItem(session);
|
2013-09-05 12:35:19 +02:00
|
|
|
if (setDefaultSession && session == SessionManager::activeSession())
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-21 16:08:13 +02:00
|
|
|
void SessionDialog::markItems()
|
|
|
|
|
{
|
2012-11-28 20:44:03 +02:00
|
|
|
for (int i = 0; i < m_ui.sessionList->count(); ++i) {
|
2010-04-21 16:08:13 +02:00
|
|
|
QListWidgetItem *item = m_ui.sessionList->item(i);
|
|
|
|
|
QFont f = item->font();
|
|
|
|
|
QString session = item->data(Qt::DisplayRole).toString();
|
2013-09-05 12:35:19 +02:00
|
|
|
if (SessionManager::isDefaultSession(session))
|
2010-04-21 16:08:13 +02:00
|
|
|
f.setItalic(true);
|
|
|
|
|
else
|
|
|
|
|
f.setItalic(false);
|
2013-09-05 12:35:19 +02:00
|
|
|
if (SessionManager::activeSession() == session && !SessionManager::isDefaultVirgin())
|
2010-04-21 16:08:13 +02:00
|
|
|
f.setBold(true);
|
|
|
|
|
else
|
|
|
|
|
f.setBold(false);
|
|
|
|
|
item->setFont(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-11-11 16:52:22 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SessionDialog::updateActions()
|
|
|
|
|
{
|
2010-04-21 16:08:13 +02:00
|
|
|
if (m_ui.sessionList->currentItem()) {
|
2010-09-30 17:12:42 +02:00
|
|
|
bool isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default"));
|
2013-09-05 12:35:19 +02:00
|
|
|
bool isActive = (m_ui.sessionList->currentItem()->text() == SessionManager::activeSession());
|
2010-09-30 17:12:42 +02:00
|
|
|
m_ui.btDelete->setEnabled(!isActive && !isDefault);
|
|
|
|
|
m_ui.btRename->setEnabled(!isDefault);
|
2010-10-11 13:55:42 +02:00
|
|
|
m_ui.btClone->setEnabled(true);
|
|
|
|
|
m_ui.btSwitch->setEnabled(true);
|
2010-09-30 17:12:42 +02:00
|
|
|
} else {
|
|
|
|
|
m_ui.btDelete->setEnabled(false);
|
|
|
|
|
m_ui.btRename->setEnabled(false);
|
|
|
|
|
m_ui.btClone->setEnabled(false);
|
|
|
|
|
m_ui.btSwitch->setEnabled(false);
|
2010-04-21 16:08:13 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionDialog::createNew()
|
|
|
|
|
{
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
|
2014-07-15 12:38:05 +02:00
|
|
|
newSessionInputDialog.setWindowTitle(tr("New Session Name"));
|
2010-04-21 16:08:13 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
2013-11-11 16:52:22 +01:00
|
|
|
QString sessionName = newSessionInputDialog.value();
|
|
|
|
|
if (sessionName.isEmpty() || SessionManager::sessions().contains(sessionName))
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2013-11-11 16:52:22 +01:00
|
|
|
SessionManager::createSession(sessionName);
|
|
|
|
|
addSessionToUi(sessionName, newSessionInputDialog.isSwitchToRequested());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionDialog::clone()
|
|
|
|
|
{
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
|
2010-06-16 17:32:44 +02:00
|
|
|
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
|
2014-07-15 12:38:05 +02:00
|
|
|
newSessionInputDialog.setWindowTitle(tr("New Session Name"));
|
2010-06-16 17:32:44 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
|
|
|
|
QString newSession = newSessionInputDialog.value();
|
2013-11-11 16:52:22 +01:00
|
|
|
if (SessionManager::cloneSession(m_ui.sessionList->currentItem()->text(), newSession))
|
|
|
|
|
addSessionToUi(newSession, newSessionInputDialog.isSwitchToRequested());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionDialog::remove()
|
|
|
|
|
{
|
2013-05-23 15:51:50 +02:00
|
|
|
const QString name = m_ui.sessionList->currentItem()->text();
|
|
|
|
|
|
2013-09-05 12:35:19 +02:00
|
|
|
if (!SessionManager::confirmSessionDelete(name))
|
2013-05-23 15:51:50 +02:00
|
|
|
return;
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionManager::deleteSession(name);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.sessionList->clear();
|
2010-04-21 16:08:13 +02:00
|
|
|
addItems(false);
|
|
|
|
|
markItems();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-21 16:08:13 +02:00
|
|
|
void SessionDialog::rename()
|
|
|
|
|
{
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
|
2010-06-16 17:32:44 +02:00
|
|
|
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
|
2014-07-15 12:38:05 +02:00
|
|
|
newSessionInputDialog.setWindowTitle(tr("Rename Session"));
|
2010-06-16 17:32:44 +02:00
|
|
|
|
2010-04-21 16:08:13 +02:00
|
|
|
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionManager::renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
|
2010-04-21 16:08:13 +02:00
|
|
|
m_ui.sessionList->clear();
|
|
|
|
|
addItems(false);
|
|
|
|
|
markItems();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-31 15:18:46 +02:00
|
|
|
void SessionDialog::switchToSession()
|
|
|
|
|
{
|
2010-09-30 17:12:42 +02:00
|
|
|
QString session = m_ui.sessionList->currentItem()->text();
|
2013-09-05 12:35:19 +02:00
|
|
|
SessionManager::loadSession(session);
|
2010-09-30 17:12:42 +02:00
|
|
|
markItems();
|
2010-04-21 16:08:13 +02:00
|
|
|
updateActions();
|
2011-07-07 14:14:10 +02:00
|
|
|
reject();
|
2009-07-31 15:18:46 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|