aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/cpppreprocessordialog.cpp
blob: a7a39750e9567cf31d330bda32f230a407d9d9af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "cpppreprocessordialog.h"

#include "cppeditorconstants.h"
#include "cppeditortr.h"
#include "cpptoolsreuse.h"

#include <coreplugin/session.h>

#include <texteditor/snippets/snippeteditor.h>

#include <utils/layoutbuilder.h>

#include <QDialogButtonBox>

using namespace Utils;

namespace CppEditor::Internal {

CppPreProcessorDialog::CppPreProcessorDialog(const FilePath &filePath, QWidget *parent)
    : QDialog(parent)
    , m_filePath(filePath)
{
    resize(400, 300);
    setWindowTitle(Tr::tr("Additional C++ Preprocessor Directives"));

    const Key key = Constants::EXTRA_PREPROCESSOR_DIRECTIVES + keyFromString(m_filePath.toString());
    const QString directives = Core::SessionManager::value(key).toString();

    m_editWidget = new TextEditor::SnippetEditorWidget;
    m_editWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    m_editWidget->setPlainText(directives);
    decorateCppEditor(m_editWidget);

    auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

    using namespace Layouting;

    Column {
        Tr::tr("Additional C++ Preprocessor Directives for %1:").arg(m_filePath.fileName()),
        m_editWidget,
        buttonBox,
    }.attachTo(this);

    connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}

CppPreProcessorDialog::~CppPreProcessorDialog() = default;

int CppPreProcessorDialog::exec()
{
    if (QDialog::exec() == Rejected)
        return Rejected;

    const Key key = Constants::EXTRA_PREPROCESSOR_DIRECTIVES + keyFromString(m_filePath.toString());
    Core::SessionManager::setValue(key, extraPreprocessorDirectives());

    return Accepted;
}

QString CppPreProcessorDialog::extraPreprocessorDirectives() const
{
    return m_editWidget->toPlainText();
}

} // CppEditor::Internal