aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/beautifier/generalsettings.cpp
blob: b0da1fc2d4c52a1d68dc4f421ddcdf2a5d55f316 (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
70
71
72
73
74
75
76
// Copyright (C) 2016 Lorenz Haas
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "generalsettings.h"

#include "beautifierconstants.h"
#include "beautifiertr.h"

#include <utils/algorithm.h>
#include <utils/genericconstants.h>
#include <utils/layoutbuilder.h>

using namespace Utils;

namespace Beautifier::Internal {

GeneralSettings::GeneralSettings()
{
    setId(Constants::OPTION_GENERAL_ID);
    setDisplayName(Tr::tr("General"));
    setCategory(Constants::OPTION_CATEGORY);
    setDisplayCategory(Tr::tr("Beautifier"));
    setCategoryIconPath(":/beautifier/images/settingscategory_beautifier.png");
    setSettingsGroups("Beautifier", "General");

    autoFormatOnSave.setSettingsKey(Utils::Constants::BEAUTIFIER_AUTO_FORMAT_ON_SAVE);
    autoFormatOnSave.setDefaultValue(false);
    autoFormatOnSave.setLabelText(Tr::tr("Enable auto format on file save"));

    autoFormatOnlyCurrentProject.setSettingsKey("autoFormatOnlyCurrentProject");
    autoFormatOnlyCurrentProject.setDefaultValue(true);
    autoFormatOnlyCurrentProject.setLabelText(Tr::tr("Restrict to files contained in the current project"));

    autoFormatTools.setSettingsKey("autoFormatTool");
    autoFormatTools.setLabelText(Tr::tr("Tool:"));
    autoFormatTools.setDefaultValue(0);
    autoFormatTools.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);

    autoFormatMime.setSettingsKey("autoFormatMime");
    autoFormatMime.setDefaultValue("text/x-c++src;text/x-c++hdr");
    autoFormatMime.setLabelText(Tr::tr("Restrict to MIME types:"));
    autoFormatMime.setDisplayStyle(StringAspect::LineEditDisplay);

    setLayouter([this] {
        using namespace Layouting;
        return Column {
            Group {
                title(Tr::tr("Automatic Formatting on File Save")),
                autoFormatOnSave.groupChecker(),
                Form {
                    autoFormatTools, br,
                    autoFormatMime, br,
                    Span(2, autoFormatOnlyCurrentProject)
                }
            },
            st
        };
    });
    readSettings();
}

QList<MimeType> GeneralSettings::allowedMimeTypes() const
{
    const QStringList stringTypes = autoFormatMime.value().split(';');

    QList<MimeType> types;
    for (QString t : stringTypes) {
        t = t.trimmed();
        const MimeType mime = Utils::mimeTypeForName(t);
        if (mime.isValid())
            types << mime;
    }
    return types;
}

} // Beautifier::Internal