2013-10-17 11:19:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-10-17 11:19:26 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
2013-10-17 11:19:26 +02: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.
|
2013-10-17 11:19:26 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cpppreprocessordialog.h"
|
|
|
|
|
#include "ui_cpppreprocessordialog.h"
|
|
|
|
|
|
2013-10-17 07:59:57 +02:00
|
|
|
#include "cppeditorconstants.h"
|
2013-10-17 11:19:26 +02:00
|
|
|
#include "cppsnippetprovider.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
2016-08-03 23:29:58 +03:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2013-10-17 11:19:26 +02:00
|
|
|
using namespace CppEditor::Internal;
|
|
|
|
|
|
2013-10-17 15:36:48 +02:00
|
|
|
static bool projectPartLessThan(const CppTools::ProjectPart::Ptr &projectPart1,
|
|
|
|
|
const CppTools::ProjectPart::Ptr &projectPart2)
|
|
|
|
|
{
|
|
|
|
|
return projectPart1->displayName < projectPart2->displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 10:21:03 +01:00
|
|
|
CppPreProcessorDialog::CppPreProcessorDialog(QWidget *parent, const QString &filePath,
|
2013-10-17 11:19:26 +02:00
|
|
|
const QList<CppTools::ProjectPart::Ptr> &projectParts)
|
2013-12-19 10:21:03 +01:00
|
|
|
: QDialog(parent)
|
2013-10-17 11:19:26 +02:00
|
|
|
, m_ui(new Ui::CppPreProcessorDialog())
|
2013-12-19 10:21:03 +01:00
|
|
|
, m_filePath(filePath)
|
2013-10-17 11:19:26 +02:00
|
|
|
{
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
|
|
m_ui->setupUi(this);
|
2015-01-10 23:40:32 +02:00
|
|
|
m_ui->editorLabel->setText(m_ui->editorLabel->text().arg(Utils::FileName::fromString(m_filePath).fileName()));
|
2013-10-18 11:09:46 +02:00
|
|
|
m_ui->editWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2013-10-17 11:19:26 +02:00
|
|
|
|
|
|
|
|
CppSnippetProvider().decorateEditor(m_ui->editWidget);
|
|
|
|
|
|
2014-08-21 15:22:08 +02:00
|
|
|
const QString &projectPartIdToUse = ProjectExplorer::SessionManager::value(
|
2013-10-17 07:59:57 +02:00
|
|
|
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath).toString();
|
|
|
|
|
int currentIndex = 0;
|
|
|
|
|
|
2013-10-17 15:36:48 +02:00
|
|
|
QList<CppTools::ProjectPart::Ptr> sortedProjectParts(projectParts);
|
2016-08-03 23:29:58 +03:00
|
|
|
std::stable_sort(sortedProjectParts.begin(), sortedProjectParts.end(), projectPartLessThan);
|
2013-10-17 15:36:48 +02:00
|
|
|
|
|
|
|
|
foreach (CppTools::ProjectPart::Ptr projectPart, sortedProjectParts) {
|
2013-10-17 11:19:26 +02:00
|
|
|
m_ui->projectComboBox->addItem(projectPart->displayName);
|
|
|
|
|
ProjectPartAddition addition;
|
|
|
|
|
addition.projectPart = projectPart;
|
|
|
|
|
addition.additionalDirectives = ProjectExplorer::SessionManager::value(
|
2015-07-14 17:30:17 +02:00
|
|
|
projectPart->id() + QLatin1Char(',') + m_filePath).toString();
|
2014-08-21 15:22:08 +02:00
|
|
|
if (projectPart->id() == projectPartIdToUse)
|
2013-10-17 07:59:57 +02:00
|
|
|
currentIndex = m_ui->projectComboBox->count() - 1;
|
2013-10-17 11:19:26 +02:00
|
|
|
m_partAdditions << addition;
|
|
|
|
|
}
|
|
|
|
|
if (m_ui->projectComboBox->count() <= 1)
|
|
|
|
|
m_ui->projectComboBox->setEnabled(false);
|
2013-10-17 07:59:57 +02:00
|
|
|
m_ui->projectComboBox->setCurrentIndex(currentIndex);
|
|
|
|
|
m_ui->editWidget->setPlainText(m_partAdditions.value(currentIndex).additionalDirectives);
|
2013-10-17 11:19:26 +02:00
|
|
|
|
2016-05-28 23:47:48 +03:00
|
|
|
connect(m_ui->projectComboBox,
|
|
|
|
|
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &CppPreProcessorDialog::projectChanged);
|
|
|
|
|
connect(m_ui->editWidget, &QPlainTextEdit::textChanged, this, &CppPreProcessorDialog::textChanged);
|
2013-10-17 11:19:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppPreProcessorDialog::~CppPreProcessorDialog()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CppPreProcessorDialog::exec()
|
|
|
|
|
{
|
|
|
|
|
if (QDialog::exec() == Rejected)
|
|
|
|
|
return Rejected;
|
|
|
|
|
|
2013-10-17 07:59:57 +02:00
|
|
|
ProjectExplorer::SessionManager::setValue(
|
|
|
|
|
QLatin1String(Constants::CPP_PREPROCESSOR_PROJECT_PREFIX) + m_filePath,
|
2015-07-14 17:30:17 +02:00
|
|
|
m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart->id());
|
2013-10-17 07:59:57 +02:00
|
|
|
|
2013-10-17 11:19:26 +02:00
|
|
|
foreach (ProjectPartAddition partAddition, m_partAdditions) {
|
|
|
|
|
const QString &previousDirectives = ProjectExplorer::SessionManager::value(
|
2015-07-14 17:30:17 +02:00
|
|
|
partAddition.projectPart->id()
|
2013-10-17 11:19:26 +02:00
|
|
|
+ QLatin1Char(',')
|
|
|
|
|
+ m_filePath).toString();
|
|
|
|
|
if (previousDirectives != partAddition.additionalDirectives) {
|
|
|
|
|
ProjectExplorer::SessionManager::setValue(
|
2015-07-14 17:30:17 +02:00
|
|
|
partAddition.projectPart->id() + QLatin1Char(',') + m_filePath,
|
2013-10-17 11:19:26 +02:00
|
|
|
partAddition.additionalDirectives);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Accepted;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 15:23:13 +01:00
|
|
|
CppTools::ProjectPart::Ptr CppPreProcessorDialog::projectPart() const
|
|
|
|
|
{
|
|
|
|
|
return m_partAdditions[m_ui->projectComboBox->currentIndex()].projectPart;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-17 11:19:26 +02:00
|
|
|
QString CppPreProcessorDialog::additionalPreProcessorDirectives() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->editWidget->toPlainText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPreProcessorDialog::projectChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
m_ui->editWidget->setPlainText(m_partAdditions[index].additionalDirectives);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPreProcessorDialog::textChanged()
|
|
|
|
|
{
|
|
|
|
|
m_partAdditions[m_ui->projectComboBox->currentIndex()].additionalDirectives
|
|
|
|
|
= m_ui->editWidget->toPlainText();
|
|
|
|
|
}
|