Clangformat: Brings back some of checkboxes

Brought back checkboxes: format while typing, format on save.
Brought back format while typing feature.
Global checkboxes will be hidden in project settings,
and visible for global.

Change-Id: I193cf9e13b10de22091edb5fe04aef957dd74586
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-06-28 16:17:02 +02:00
parent 7899fd6fc4
commit 2f18256633
11 changed files with 111 additions and 13 deletions

View File

@@ -85,6 +85,7 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
initChecksAndPreview(!codeStyle->isReadOnly());
initOverrideCheckBox();
initCheckBoxes();
initIndentationOrFormattingCombobox();
showOrHideWidgets();
@@ -128,6 +129,45 @@ void ClangFormatConfigWidget::initChecksAndPreview(bool enabled)
m_preview->textDocument()->indenter()->setFileName(fileName);
}
void ClangFormatConfigWidget::initCheckBoxes()
{
if (m_project) {
m_ui->formatOnSave->hide();
m_ui->formatWhileTyping->hide();
return;
}
m_ui->formatOnSave->show();
m_ui->formatWhileTyping->show();
auto setEnableCheckBoxes = [this](int index) {
bool isFormatting = index == static_cast<int>(ClangFormatSettings::Mode::Formatting);
m_ui->formatOnSave->setEnabled(isFormatting);
m_ui->formatWhileTyping->setEnabled(isFormatting);
};
setEnableCheckBoxes(m_ui->indentingOrFormatting->currentIndex());
connect(m_ui->indentingOrFormatting, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, setEnableCheckBoxes);
m_ui->formatOnSave->setChecked(ClangFormatSettings::instance().formatOnSave());
m_ui->formatWhileTyping->setChecked(ClangFormatSettings::instance().formatWhileTyping());
connect(m_ui->formatOnSave, &QCheckBox::toggled,
this, [](bool checked) {
ClangFormatSettings &settings = ClangFormatSettings::instance();
settings.setFormatOnSave(checked);
settings.write();
});
connect(m_ui->formatWhileTyping, &QCheckBox::toggled,
this, [](bool checked) {
ClangFormatSettings &settings = ClangFormatSettings::instance();
settings.setFormatWhileTyping(checked);
settings.write();
});
}
void ClangFormatConfigWidget::initOverrideCheckBox()
{
if (m_project) {
@@ -190,7 +230,9 @@ void ClangFormatConfigWidget::initIndentationOrFormattingCombobox()
m_ui->indentingOrFormatting->setCurrentIndex(
static_cast<int>(ClangFormatSettings::instance().mode()));
m_ui->indentingOrFormatting->show();
const bool isGlobal = !m_project;
m_ui->indentingOrFormatting->setVisible(isGlobal);
m_ui->formattingModeLabel->setVisible(isGlobal);
connect(m_ui->indentingOrFormatting, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [](int index) {
@@ -219,6 +261,7 @@ void ClangFormatConfigWidget::showOrHideWidgets()
if (!m_ui->overrideDefault->isChecked() && m_project) {
// Show the fallback configuration only globally.
m_ui->fallbackConfig->hide();
m_checksScrollArea->hide();
m_preview->hide();
m_ui->verticalLayout->addStretch(1);
@@ -226,6 +269,7 @@ void ClangFormatConfigWidget::showOrHideWidgets()
}
createStyleFileIfNeeded(!m_project);
m_ui->fallbackConfig->show();
m_checksScrollArea->show();
m_preview->show();