// 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 #include #include using namespace Utils; namespace Beautifier::Internal { static GeneralSettings *m_instance; GeneralSettings *GeneralSettings::instance() { return m_instance; } GeneralSettings::GeneralSettings() { m_instance = this; 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"); setSettings(this); setAutoApply(false); registerAspect(&autoFormatOnSave); autoFormatOnSave.setSettingsKey(Utils::Constants::BEAUTIFIER_AUTO_FORMAT_ON_SAVE); autoFormatOnSave.setDefaultValue(false); autoFormatOnSave.setLabelText(Tr::tr("Enable auto format on file save")); registerAspect(&autoFormatOnlyCurrentProject); autoFormatOnlyCurrentProject.setSettingsKey("autoFormatOnlyCurrentProject"); autoFormatOnlyCurrentProject.setDefaultValue(true); autoFormatOnlyCurrentProject.setLabelText(Tr::tr("Restrict to files contained in the current project")); registerAspect(&autoFormatTools); autoFormatTools.setSettingsKey("autoFormatTool"); autoFormatTools.setLabelText(Tr::tr("Tool:")); autoFormatTools.setDefaultValue(0); autoFormatTools.setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox); registerAspect(&autoFormatMime); 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](QWidget *widget) { using namespace Layouting; Column { Group { title(Tr::tr("Automatic Formatting on File Save")), autoFormatOnSave.groupChecker(), Form { autoFormatTools, br, autoFormatMime, br, Span(2, autoFormatOnlyCurrentProject) } }, st }.attachTo(widget); }); } QList GeneralSettings::allowedMimeTypes() const { const QStringList stringTypes = autoFormatMime.value().split(';'); QList types; for (QString t : stringTypes) { t = t.trimmed(); const MimeType mime = Utils::mimeTypeForName(t); if (mime.isValid()) types << mime; } return types; } } // Beautifier::Internal