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:
|
2017-04-14 10:12:30 +02:00
|
|
|
SessionValidator(QObject *parent, const QStringList &sessions);
|
2018-07-12 22:17:17 +02:00
|
|
|
void fixup(QString & input) const override;
|
|
|
|
|
QValidator::State validate(QString & input, int & pos) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
|
|
|
|
QStringList m_sessions;
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-14 10:12:30 +02:00
|
|
|
SessionValidator::SessionValidator(QObject *parent, const QStringList &sessions)
|
2008-12-02 12:01:29 +01:00
|
|
|
: 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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-29 13:45:19 +02:00
|
|
|
SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-04-13 15:52:14 +02:00
|
|
|
auto hlayout = new QVBoxLayout(this);
|
|
|
|
|
auto 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);
|
2017-05-29 13:45:19 +02:00
|
|
|
m_newSessionLineEdit->setValidator(new SessionValidator(this, SessionManager::sessions()));
|
2008-12-02 12:01:29 +01:00
|
|
|
hlayout->addWidget(m_newSessionLineEdit);
|
2016-04-13 15:52:14 +02:00
|
|
|
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
2017-05-29 17:46:59 +02:00
|
|
|
m_okButton = buttons->button(QDialogButtonBox::Ok);
|
|
|
|
|
m_switchToButton = new QPushButton;
|
|
|
|
|
buttons->addButton(m_switchToButton, QDialogButtonBox::AcceptRole);
|
2017-05-29 13:45:19 +02:00
|
|
|
connect(m_switchToButton, &QPushButton::clicked, [this]() {
|
|
|
|
|
m_usedSwitchTo = true;
|
|
|
|
|
});
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
2008-12-02 12:01:29 +01:00
|
|
|
hlayout->addWidget(buttons);
|
|
|
|
|
setLayout(hlayout);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-29 17:46:59 +02:00
|
|
|
void SessionNameInputDialog::setActionText(const QString &actionText, const QString &openActionText)
|
|
|
|
|
{
|
|
|
|
|
m_okButton->setText(actionText);
|
|
|
|
|
m_switchToButton->setText(openActionText);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
bool SessionNameInputDialog::isSwitchToRequested() const
|
|
|
|
|
{
|
|
|
|
|
return m_usedSwitchTo;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
SessionDialog::SessionDialog(QWidget *parent) : QDialog(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
2017-03-30 20:51:27 +02:00
|
|
|
m_ui.sessionView->setActivationMode(Utils::DoubleClickActivation);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.btCreateNew, &QAbstractButton::clicked,
|
2016-09-23 20:45:03 +02:00
|
|
|
m_ui.sessionView, &SessionView::createNewSession);
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.btClone, &QAbstractButton::clicked,
|
2016-09-23 20:45:03 +02:00
|
|
|
m_ui.sessionView, &SessionView::cloneCurrentSession);
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_ui.btDelete, &QAbstractButton::clicked,
|
2016-09-23 20:45:03 +02:00
|
|
|
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.sessionView, &SessionView::selected,
|
|
|
|
|
this, &SessionDialog::updateActions);
|
|
|
|
|
connect(m_ui.sessionView, &SessionView::sessionSwitched,
|
|
|
|
|
this, &QDialog::reject);
|
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
|
|
|
}
|
|
|
|
|
|
2010-09-14 11:37:54 +02:00
|
|
|
void SessionDialog::setAutoLoadSession(bool check)
|
|
|
|
|
{
|
2017-05-16 11:19:47 +02:00
|
|
|
m_ui.autoLoadCheckBox->setChecked(check);
|
2010-09-14 11:37:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SessionDialog::autoLoadSession() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui.autoLoadCheckBox->checkState() == Qt::Checked;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 20:45:03 +02:00
|
|
|
void SessionDialog::updateActions(const QString &session)
|
2013-11-11 16:52:22 +01:00
|
|
|
{
|
2016-09-23 20:45:03 +02:00
|
|
|
if (session.isEmpty()) {
|
2010-09-30 17:12:42 +02:00
|
|
|
m_ui.btDelete->setEnabled(false);
|
|
|
|
|
m_ui.btRename->setEnabled(false);
|
|
|
|
|
m_ui.btClone->setEnabled(false);
|
|
|
|
|
m_ui.btSwitch->setEnabled(false);
|
2016-09-23 20:45:03 +02:00
|
|
|
} 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);
|
2010-04-21 16:08:13 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|