2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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);
|
2011-07-07 14:14:10 +02:00
|
|
|
m_switchToButton = buttons->addButton(tr("Switch to"), QDialogButtonBox::AcceptRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
|
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
2011-07-07 14:14:10 +02:00
|
|
|
connect(buttons, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
|
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
|
|
|
|
2011-11-22 10:34:46 +01:00
|
|
|
SessionDialog::SessionDialog(SessionManager *sessionManager, QWidget *parent)
|
|
|
|
|
: QDialog(parent), m_sessionManager(sessionManager)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
|
2010-04-21 16:08:13 +02:00
|
|
|
connect(m_ui.btSwitch, SIGNAL(clicked()), this, SLOT(switchToSession()));
|
|
|
|
|
connect(m_ui.btRename, SIGNAL(clicked()), this, SLOT(rename()));
|
|
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(m_ui.sessionList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
2010-04-21 16:08:13 +02:00
|
|
|
this, SLOT(switchToSession()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(m_ui.sessionList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SLOT(updateActions()));
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
QStringList sessions = m_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);
|
2010-04-21 16:08:13 +02:00
|
|
|
if (setDefaultSession && session == m_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();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
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"));
|
|
|
|
|
bool isActive = (m_ui.sessionList->currentItem()->text() == m_sessionManager->activeSession());
|
|
|
|
|
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()
|
|
|
|
|
{
|
2010-06-16 17:32:44 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
|
2010-04-21 16:08:13 +02:00
|
|
|
newSessionInputDialog.setWindowTitle(tr("New session name"));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (newSessionInputDialog.exec() == QDialog::Accepted) {
|
|
|
|
|
QString newSession = newSessionInputDialog.value();
|
|
|
|
|
if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_sessionManager->createSession(newSession);
|
2009-07-21 13:17:58 +02:00
|
|
|
m_ui.sessionList->clear();
|
|
|
|
|
QStringList sessions = m_sessionManager->sessions();
|
|
|
|
|
m_ui.sessionList->addItems(sessions);
|
|
|
|
|
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
|
2010-08-30 18:48:17 +02:00
|
|
|
markItems();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (newSessionInputDialog.isSwitchToRequested())
|
2011-07-07 14:14:10 +02:00
|
|
|
switchToSession();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionDialog::clone()
|
|
|
|
|
{
|
2010-06-16 17:32:44 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
|
|
|
|
|
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
|
2010-04-21 16:08:13 +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();
|
2009-07-21 13:17:58 +02:00
|
|
|
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
|
|
|
|
|
m_ui.sessionList->clear();
|
|
|
|
|
QStringList sessions = m_sessionManager->sessions();
|
|
|
|
|
m_ui.sessionList->addItems(sessions);
|
|
|
|
|
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
|
2010-08-30 18:48:17 +02:00
|
|
|
markItems();
|
2009-07-21 13:17:58 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionDialog::remove()
|
|
|
|
|
{
|
|
|
|
|
m_sessionManager->deleteSession(m_ui.sessionList->currentItem()->text());
|
|
|
|
|
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()
|
|
|
|
|
{
|
2010-06-16 17:32:44 +02:00
|
|
|
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
|
|
|
|
|
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
|
2010-04-21 16:08:13 +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) {
|
|
|
|
|
m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
|
|
|
|
|
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();
|
|
|
|
|
m_sessionManager->loadSession(session);
|
|
|
|
|
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
|