2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-07-06 10:38:53 +02:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "codestylesettingspropertiespage.h"
|
2022-07-12 17:43:55 +02:00
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
#include "editorconfiguration.h"
|
|
|
|
|
#include "project.h"
|
2023-01-13 12:38:22 +01:00
|
|
|
#include "projectexplorertr.h"
|
2023-11-15 10:24:56 +01:00
|
|
|
#include "projectpanelfactory.h"
|
|
|
|
|
#include "projectsettingswidget.h"
|
2022-07-12 17:43:55 +02:00
|
|
|
|
2022-08-01 17:28:42 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
#include <texteditor/icodestylepreferencesfactory.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/codestyleeditor.h>
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2022-07-12 17:43:55 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QLabel>
|
2024-05-14 10:33:01 +02:00
|
|
|
#include <QLayout>
|
2022-07-12 17:43:55 +02:00
|
|
|
#include <QStackedWidget>
|
|
|
|
|
|
2011-02-03 15:48:14 +01:00
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2022-07-12 17:43:55 +02:00
|
|
|
namespace ProjectExplorer::Internal {
|
|
|
|
|
|
2023-11-15 10:24:56 +01:00
|
|
|
class CodeStyleSettingsWidget final : public ProjectSettingsWidget
|
2011-02-03 15:48:14 +01:00
|
|
|
{
|
2023-11-15 10:24:56 +01:00
|
|
|
public:
|
|
|
|
|
explicit CodeStyleSettingsWidget(Project *project)
|
|
|
|
|
{
|
|
|
|
|
auto languageComboBox = new QComboBox(this);
|
|
|
|
|
auto stackedWidget = new QStackedWidget(this);
|
|
|
|
|
|
|
|
|
|
setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID);
|
|
|
|
|
setUseGlobalSettingsCheckBoxVisible(false);
|
2023-11-16 16:51:58 +01:00
|
|
|
setExpanding(true);
|
2023-11-15 10:24:56 +01:00
|
|
|
|
|
|
|
|
const EditorConfiguration *config = project->editorConfiguration();
|
|
|
|
|
|
|
|
|
|
for (ICodeStylePreferencesFactory *factory : TextEditorSettings::codeStyleFactories()) {
|
|
|
|
|
Utils::Id languageId = factory->languageId();
|
|
|
|
|
ICodeStylePreferences *codeStylePreferences = config->codeStyle(languageId);
|
|
|
|
|
|
|
|
|
|
auto preview = factory->createCodeStyleEditor(codeStylePreferences, project, stackedWidget);
|
|
|
|
|
if (preview && preview->layout())
|
|
|
|
|
preview->layout()->setContentsMargins(QMargins());
|
|
|
|
|
stackedWidget->addWidget(preview);
|
|
|
|
|
languageComboBox->addItem(factory->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(languageComboBox, &QComboBox::currentIndexChanged,
|
|
|
|
|
stackedWidget, &QStackedWidget::setCurrentIndex);
|
|
|
|
|
|
|
|
|
|
using namespace Layouting;
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Row { new QLabel(Tr::tr("Language:")), languageComboBox, st },
|
|
|
|
|
stackedWidget,
|
|
|
|
|
noMargin
|
|
|
|
|
}.attachTo(this);
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
2023-11-15 10:24:56 +01:00
|
|
|
};
|
2011-02-03 15:48:14 +01:00
|
|
|
|
2023-11-15 10:24:56 +01:00
|
|
|
class CodeStyleProjectPanelFactory final : public ProjectPanelFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CodeStyleProjectPanelFactory()
|
|
|
|
|
{
|
|
|
|
|
setPriority(40);
|
|
|
|
|
setDisplayName(Tr::tr("Code Style"));
|
|
|
|
|
setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-07-12 17:43:55 +02:00
|
|
|
|
2023-11-15 10:24:56 +01:00
|
|
|
void setupCodeStyleProjectPanel()
|
|
|
|
|
{
|
|
|
|
|
static CodeStyleProjectPanelFactory theCodeStyleProjectPanelFactory;
|
2011-02-03 15:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 17:43:55 +02:00
|
|
|
} // ProjectExplorer::Internal
|