forked from qt-creator/qt-creator
ClangFormat: Inline *.ui files
Change-Id: Ie6bcb486c70896894121434b1030861b029a46a2 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -5,8 +5,8 @@ add_qtc_plugin(ClangFormat
|
||||
SOURCES
|
||||
clangformatbaseindenter.cpp clangformatbaseindenter.h
|
||||
clangformatchecks.ui
|
||||
clangformatconfigwidget.cpp clangformatconfigwidget.h clangformatconfigwidget.ui
|
||||
clangformatglobalconfigwidget.cpp clangformatglobalconfigwidget.h clangformatglobalconfigwidget.ui
|
||||
clangformatconfigwidget.cpp clangformatconfigwidget.h
|
||||
clangformatglobalconfigwidget.cpp clangformatglobalconfigwidget.h
|
||||
clangformatconstants.h
|
||||
clangformatfile.cpp clangformatfile.h
|
||||
clangformatindenter.cpp clangformatindenter.h
|
||||
|
@@ -37,11 +37,9 @@ QtcPlugin {
|
||||
"clangformatchecks.ui",
|
||||
"clangformatconfigwidget.cpp",
|
||||
"clangformatconfigwidget.h",
|
||||
"clangformatconfigwidget.ui",
|
||||
"clangformatconstants.h",
|
||||
"clangformatglobalconfigwidget.cpp",
|
||||
"clangformatglobalconfigwidget.h",
|
||||
"clangformatglobalconfigwidget.ui",
|
||||
"clangformatfile.cpp",
|
||||
"clangformatfile.h",
|
||||
"clangformatindenter.cpp",
|
||||
|
@@ -34,30 +34,36 @@
|
||||
// the file was generated by scripts/generateClangFormatChecksUI.py
|
||||
#include "ui_clangformatchecks.h"
|
||||
|
||||
#include "ui_clangformatconfigwidget.h"
|
||||
|
||||
#include <clang/Format/Format.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <cppeditor/cpphighlighter.h>
|
||||
#include <cppeditor/cppcodestylesettings.h>
|
||||
#include <cppeditor/cppcodestylesnippets.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <texteditor/displaysettings.h>
|
||||
#include <texteditor/icodestylepreferences.h>
|
||||
#include <texteditor/snippets/snippeteditor.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
@@ -76,13 +82,47 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
||||
: CppCodeStyleWidget(parent)
|
||||
, m_project(project)
|
||||
, m_checks(std::make_unique<Ui::ClangFormatChecksWidget>())
|
||||
, m_ui(std::make_unique<Ui::ClangFormatConfigWidget>())
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
resize(489, 305);
|
||||
|
||||
m_projectHasClangFormat = new QLabel(this);
|
||||
m_overrideDefault = new QCheckBox(tr("Override Clang Format configuration file"));
|
||||
m_fallbackConfig = new QLabel(tr("Clang-Format Style"));
|
||||
m_config = std::make_unique<ClangFormatFile>(filePathToCurrentSettings(codeStyle),
|
||||
codeStyle->isReadOnly());
|
||||
m_checksScrollArea = new QScrollArea();
|
||||
m_checksWidget = new QWidget;
|
||||
|
||||
m_checks->setupUi(m_checksWidget);
|
||||
m_checksScrollArea->setWidget(m_checksWidget);
|
||||
m_checksScrollArea->setMaximumWidth(500);
|
||||
m_checksWidget->setEnabled(!codeStyle->isReadOnly());
|
||||
|
||||
FilePath fileName;
|
||||
if (m_project)
|
||||
fileName = m_project->projectFilePath().pathAppended("snippet.cpp");
|
||||
else
|
||||
fileName = Core::ICore::userResourcePath("snippet.cpp");
|
||||
|
||||
m_preview = new TextEditor::SnippetEditorWidget(this);
|
||||
TextEditor::DisplaySettings displaySettings = m_preview->displaySettings();
|
||||
displaySettings.m_visualizeWhitespace = true;
|
||||
m_preview->setDisplaySettings(displaySettings);
|
||||
m_preview->setPlainText(QLatin1String(CppEditor::Constants::DEFAULT_CODE_STYLE_SNIPPETS[0]));
|
||||
m_preview->textDocument()->setIndenter(new ClangFormatIndenter(m_preview->document()));
|
||||
m_preview->textDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
|
||||
m_preview->textDocument()->setSyntaxHighlighter(new CppEditor::CppHighlighter);
|
||||
m_preview->textDocument()->indenter()->setFileName(fileName);
|
||||
|
||||
using namespace Layouting;
|
||||
|
||||
Column {
|
||||
m_projectHasClangFormat,
|
||||
m_overrideDefault,
|
||||
m_fallbackConfig,
|
||||
Row { m_checksScrollArea, m_preview }
|
||||
}.attachTo(this);
|
||||
|
||||
initChecksAndPreview(!codeStyle->isReadOnly());
|
||||
initOverrideCheckBox();
|
||||
|
||||
showOrHideWidgets();
|
||||
@@ -94,52 +134,20 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
||||
|
||||
ClangFormatConfigWidget::~ClangFormatConfigWidget() = default;
|
||||
|
||||
void ClangFormatConfigWidget::initChecksAndPreview(bool enabled)
|
||||
{
|
||||
m_checksScrollArea = new QScrollArea();
|
||||
m_checksWidget = new QWidget;
|
||||
m_checks->setupUi(m_checksWidget);
|
||||
m_checksScrollArea->setWidget(m_checksWidget);
|
||||
m_checksScrollArea->setMaximumWidth(500);
|
||||
m_checksWidget->setEnabled(enabled);
|
||||
|
||||
m_ui->horizontalLayout_2->addWidget(m_checksScrollArea);
|
||||
|
||||
m_preview = new TextEditor::SnippetEditorWidget(this);
|
||||
m_ui->horizontalLayout_2->addWidget(m_preview);
|
||||
|
||||
TextEditor::DisplaySettings displaySettings = m_preview->displaySettings();
|
||||
displaySettings.m_visualizeWhitespace = true;
|
||||
m_preview->setDisplaySettings(displaySettings);
|
||||
m_preview->setPlainText(QLatin1String(CppEditor::Constants::DEFAULT_CODE_STYLE_SNIPPETS[0]));
|
||||
m_preview->textDocument()->setIndenter(new ClangFormatIndenter(m_preview->document()));
|
||||
m_preview->textDocument()->setFontSettings(TextEditor::TextEditorSettings::fontSettings());
|
||||
m_preview->textDocument()->setSyntaxHighlighter(new CppEditor::CppHighlighter);
|
||||
|
||||
Utils::FilePath fileName;
|
||||
if (m_project) {
|
||||
fileName = m_project->projectFilePath().pathAppended("snippet.cpp");
|
||||
} else {
|
||||
fileName = Core::ICore::userResourcePath("snippet.cpp");
|
||||
}
|
||||
|
||||
m_preview->textDocument()->indenter()->setFileName(fileName);
|
||||
}
|
||||
|
||||
void ClangFormatConfigWidget::initOverrideCheckBox()
|
||||
{
|
||||
if (m_project) {
|
||||
m_ui->overrideDefault->setChecked(
|
||||
m_overrideDefault->setChecked(
|
||||
m_project->namedSettings(Constants::OVERRIDE_FILE_ID).toBool());
|
||||
} else {
|
||||
m_ui->overrideDefault->setChecked(ClangFormatSettings::instance().overrideDefaultFile());
|
||||
m_ui->overrideDefault->setToolTip(
|
||||
m_overrideDefault->setChecked(ClangFormatSettings::instance().overrideDefaultFile());
|
||||
m_overrideDefault->setToolTip(
|
||||
tr("Override Clang Format configuration file with the fallback configuration."));
|
||||
}
|
||||
|
||||
connect(m_ui->overrideDefault, &QCheckBox::toggled,
|
||||
connect(m_overrideDefault, &QCheckBox::toggled,
|
||||
this, &ClangFormatConfigWidget::showOrHideWidgets);
|
||||
connect(m_ui->overrideDefault, &QCheckBox::toggled, this, [this](bool checked) {
|
||||
connect(m_overrideDefault, &QCheckBox::toggled, this, [this](bool checked) {
|
||||
if (m_project)
|
||||
m_project->setNamedSettings(Constants::OVERRIDE_FILE_ID, checked);
|
||||
else {
|
||||
@@ -185,33 +193,36 @@ static bool projectConfigExists()
|
||||
|
||||
void ClangFormatConfigWidget::showOrHideWidgets()
|
||||
{
|
||||
m_ui->projectHasClangFormat->hide();
|
||||
m_projectHasClangFormat->hide();
|
||||
|
||||
QLayoutItem *lastItem = m_ui->verticalLayout->itemAt(m_ui->verticalLayout->count() - 1);
|
||||
auto verticalLayout = qobject_cast<QVBoxLayout *>(layout());
|
||||
QTC_ASSERT(verticalLayout, return);
|
||||
|
||||
QLayoutItem *lastItem = verticalLayout->itemAt(verticalLayout->count() - 1);
|
||||
if (lastItem->spacerItem())
|
||||
m_ui->verticalLayout->removeItem(lastItem);
|
||||
verticalLayout->removeItem(lastItem);
|
||||
|
||||
if (!m_ui->overrideDefault->isChecked() && m_project) {
|
||||
if (!m_overrideDefault->isChecked() && m_project) {
|
||||
// Show the fallback configuration only globally.
|
||||
m_ui->fallbackConfig->hide();
|
||||
m_fallbackConfig->hide();
|
||||
m_checksScrollArea->hide();
|
||||
m_preview->hide();
|
||||
m_ui->verticalLayout->addStretch(1);
|
||||
verticalLayout->addStretch(1);
|
||||
return;
|
||||
}
|
||||
|
||||
createStyleFileIfNeeded(!m_project);
|
||||
m_ui->fallbackConfig->show();
|
||||
m_fallbackConfig->show();
|
||||
m_checksScrollArea->show();
|
||||
m_preview->show();
|
||||
|
||||
if (!m_project) {
|
||||
const Project *currentProject = SessionManager::startupProject();
|
||||
if (!currentProject || !projectConfigExists()) {
|
||||
m_ui->projectHasClangFormat->hide();
|
||||
m_projectHasClangFormat->hide();
|
||||
} else {
|
||||
m_ui->projectHasClangFormat->show();
|
||||
m_ui->projectHasClangFormat->setText(
|
||||
m_projectHasClangFormat->show();
|
||||
m_projectHasClangFormat->setText(
|
||||
tr("Current project has its own overridden .clang-format file "
|
||||
"and can be configured in Projects > Code Style > C++."));
|
||||
}
|
||||
|
@@ -31,16 +31,20 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace TextEditor { class SnippetEditorWidget; }
|
||||
namespace CppEditor { class CppCodeStyleSettings; }
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
namespace Ui {
|
||||
class ClangFormatConfigWidget;
|
||||
class ClangFormatChecksWidget;
|
||||
}
|
||||
namespace Ui { class ClangFormatChecksWidget; }
|
||||
|
||||
class ClangFormatFile;
|
||||
|
||||
class ClangFormatConfigWidget : public CppEditor::CppCodeStyleWidget
|
||||
@@ -69,6 +73,7 @@ private:
|
||||
|
||||
void fillTable();
|
||||
void saveChanges(QObject *sender);
|
||||
|
||||
void updatePreview();
|
||||
|
||||
ProjectExplorer::Project *m_project;
|
||||
@@ -77,8 +82,12 @@ private:
|
||||
TextEditor::SnippetEditorWidget *m_preview;
|
||||
std::unique_ptr<ClangFormatFile> m_config;
|
||||
std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks;
|
||||
std::unique_ptr<Ui::ClangFormatConfigWidget> m_ui;
|
||||
|
||||
bool m_disableTableUpdate = false;
|
||||
|
||||
QLabel *m_projectHasClangFormat;
|
||||
QCheckBox *m_overrideDefault;
|
||||
QLabel *m_fallbackConfig;
|
||||
};
|
||||
|
||||
} // namespace ClangFormat
|
||||
} // ClangFormat
|
||||
|
@@ -1,57 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ClangFormat::ClangFormatConfigWidget</class>
|
||||
<widget class="QWidget" name="ClangFormat::ClangFormatConfigWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>489</width>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="projectHasClangFormat">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="overrideDefault">
|
||||
<property name="text">
|
||||
<string>Override Clang Format configuration file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="fallbackConfig">
|
||||
<property name="text">
|
||||
<string>Clang-Format Style</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@@ -28,31 +28,56 @@
|
||||
#include "clangformatconstants.h"
|
||||
#include "clangformatsettings.h"
|
||||
|
||||
#include "ui_clangformatglobalconfigwidget.h"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
ClangFormatGlobalConfigWidget::ClangFormatGlobalConfigWidget(ProjectExplorer::Project *project,
|
||||
QWidget *parent)
|
||||
: CppCodeStyleWidget(parent)
|
||||
, m_ui(std::make_unique<Ui::ClangFormatGlobalConfigWidget>())
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
resize(489, 305);
|
||||
|
||||
m_formattingModeLabel = new QLabel(tr("Formatting mode:"));
|
||||
m_indentingOrFormatting = new QComboBox(this);
|
||||
m_formatWhileTyping = new QCheckBox(tr("Format while typing"));
|
||||
m_formatOnSave = new QCheckBox(tr("Format edited code on file save"));
|
||||
|
||||
using namespace Layouting;
|
||||
|
||||
Group globalSettingsGroupBox {
|
||||
title(tr("ClangFormat global setting:")),
|
||||
Column {
|
||||
Row { m_formattingModeLabel, m_indentingOrFormatting, st },
|
||||
m_formatWhileTyping,
|
||||
m_formatOnSave
|
||||
}
|
||||
};
|
||||
|
||||
Column {
|
||||
globalSettingsGroupBox
|
||||
}.attachTo(this);
|
||||
|
||||
initCheckBoxes();
|
||||
initIndentationOrFormattingCombobox();
|
||||
|
||||
if (project) {
|
||||
m_ui->settingsGroupBox->hide();
|
||||
globalSettingsGroupBox.widget->hide();
|
||||
return;
|
||||
}
|
||||
m_ui->settingsGroupBox->show();
|
||||
globalSettingsGroupBox.widget->show();
|
||||
}
|
||||
|
||||
ClangFormatGlobalConfigWidget::~ClangFormatGlobalConfigWidget() = default;
|
||||
@@ -62,27 +87,27 @@ void ClangFormatGlobalConfigWidget::initCheckBoxes()
|
||||
auto setEnableCheckBoxes = [this](int index) {
|
||||
bool isFormatting = index == static_cast<int>(ClangFormatSettings::Mode::Formatting);
|
||||
|
||||
m_ui->formatOnSave->setEnabled(isFormatting);
|
||||
m_ui->formatWhileTyping->setEnabled(isFormatting);
|
||||
m_formatOnSave->setEnabled(isFormatting);
|
||||
m_formatWhileTyping->setEnabled(isFormatting);
|
||||
};
|
||||
setEnableCheckBoxes(m_ui->indentingOrFormatting->currentIndex());
|
||||
connect(m_ui->indentingOrFormatting, &QComboBox::currentIndexChanged,
|
||||
setEnableCheckBoxes(m_indentingOrFormatting->currentIndex());
|
||||
connect(m_indentingOrFormatting, &QComboBox::currentIndexChanged,
|
||||
this, setEnableCheckBoxes);
|
||||
|
||||
m_ui->formatOnSave->setChecked(ClangFormatSettings::instance().formatOnSave());
|
||||
m_ui->formatWhileTyping->setChecked(ClangFormatSettings::instance().formatWhileTyping());
|
||||
m_formatOnSave->setChecked(ClangFormatSettings::instance().formatOnSave());
|
||||
m_formatWhileTyping->setChecked(ClangFormatSettings::instance().formatWhileTyping());
|
||||
}
|
||||
|
||||
void ClangFormatGlobalConfigWidget::initIndentationOrFormattingCombobox()
|
||||
{
|
||||
m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Indenting),
|
||||
tr("Indenting only"));
|
||||
m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Formatting),
|
||||
tr("Full formatting"));
|
||||
m_ui->indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Disable),
|
||||
tr("Disable"));
|
||||
m_indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Indenting),
|
||||
tr("Indenting only"));
|
||||
m_indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Formatting),
|
||||
tr("Full formatting"));
|
||||
m_indentingOrFormatting->insertItem(static_cast<int>(ClangFormatSettings::Mode::Disable),
|
||||
tr("Disable"));
|
||||
|
||||
m_ui->indentingOrFormatting->setCurrentIndex(
|
||||
m_indentingOrFormatting->setCurrentIndex(
|
||||
static_cast<int>(ClangFormatSettings::instance().mode()));
|
||||
}
|
||||
|
||||
@@ -90,9 +115,9 @@ void ClangFormatGlobalConfigWidget::initIndentationOrFormattingCombobox()
|
||||
void ClangFormatGlobalConfigWidget::apply()
|
||||
{
|
||||
ClangFormatSettings &settings = ClangFormatSettings::instance();
|
||||
settings.setFormatOnSave(m_ui->formatOnSave->isChecked());
|
||||
settings.setFormatWhileTyping(m_ui->formatWhileTyping->isChecked());
|
||||
settings.setMode(static_cast<ClangFormatSettings::Mode>(m_ui->indentingOrFormatting->currentIndex()));
|
||||
settings.setFormatOnSave(m_formatOnSave->isChecked());
|
||||
settings.setFormatWhileTyping(m_formatWhileTyping->isChecked());
|
||||
settings.setMode(static_cast<ClangFormatSettings::Mode>(m_indentingOrFormatting->currentIndex()));
|
||||
settings.write();
|
||||
}
|
||||
|
||||
|
@@ -29,12 +29,16 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
|
||||
namespace ClangFormat {
|
||||
|
||||
namespace Ui { class ClangFormatGlobalConfigWidget; }
|
||||
|
||||
class ClangFormatGlobalConfigWidget : public CppEditor::CppCodeStyleWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -49,7 +53,10 @@ private:
|
||||
void initCheckBoxes();
|
||||
void initIndentationOrFormattingCombobox();
|
||||
|
||||
std::unique_ptr<Ui::ClangFormatGlobalConfigWidget> m_ui;
|
||||
QLabel *m_formattingModeLabel;
|
||||
QComboBox *m_indentingOrFormatting;
|
||||
QCheckBox *m_formatWhileTyping;
|
||||
QCheckBox *m_formatOnSave;
|
||||
};
|
||||
|
||||
} // namespace ClangFormat
|
||||
|
Reference in New Issue
Block a user