forked from qt-creator/qt-creator
ClangFormat: Grey out Clang-Format Style config when not overridden
Add feature to grey out the Clang-Format Style configuration widget after unchecking the 'Override' checkbox. Change-Id: I94bbb1f4436f3caeaed55d49582211257e480d0d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -89,7 +89,8 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
|||||||
|
|
||||||
d->checksScrollArea->setWidget(d->checksWidget);
|
d->checksScrollArea->setWidget(d->checksWidget);
|
||||||
d->checksScrollArea->setWidgetResizable(true);
|
d->checksScrollArea->setWidgetResizable(true);
|
||||||
d->checksWidget->setEnabled(!codeStyle->isReadOnly());
|
d->checksWidget->setEnabled(!codeStyle->isReadOnly()
|
||||||
|
&& !codeStyle->isTemporarilyReadOnly());
|
||||||
|
|
||||||
FilePath fileName;
|
FilePath fileName;
|
||||||
if (d->project)
|
if (d->project)
|
||||||
@@ -140,7 +141,8 @@ void ClangFormatConfigWidget::slotCodeStyleChanged(
|
|||||||
d->config->setIsReadOnly(codeStyle->isReadOnly());
|
d->config->setIsReadOnly(codeStyle->isReadOnly());
|
||||||
d->style = d->config->style();
|
d->style = d->config->style();
|
||||||
|
|
||||||
d->checksWidget->setEnabled(!codeStyle->isReadOnly());
|
d->checksWidget->setEnabled(!codeStyle->isReadOnly()
|
||||||
|
&& !codeStyle->isTemporarilyReadOnly());
|
||||||
|
|
||||||
fillTable();
|
fillTable();
|
||||||
updatePreview();
|
updatePreview();
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include "clangformatutils.h"
|
#include "clangformatutils.h"
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <texteditor/icodestylepreferences.h>
|
||||||
|
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
@@ -24,10 +25,11 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace ClangFormat {
|
namespace ClangFormat {
|
||||||
|
|
||||||
ClangFormatGlobalConfigWidget::ClangFormatGlobalConfigWidget(ProjectExplorer::Project *project,
|
ClangFormatGlobalConfigWidget::ClangFormatGlobalConfigWidget(
|
||||||
QWidget *parent)
|
TextEditor::ICodeStylePreferences *codeStyle, ProjectExplorer::Project *project, QWidget *parent)
|
||||||
: CppCodeStyleWidget(parent)
|
: CppCodeStyleWidget(parent)
|
||||||
, m_project(project)
|
, m_project(project)
|
||||||
|
, m_codeStyle(codeStyle)
|
||||||
{
|
{
|
||||||
resize(489, 305);
|
resize(489, 305);
|
||||||
|
|
||||||
@@ -164,10 +166,19 @@ void ClangFormatGlobalConfigWidget::initOverrideCheckBox()
|
|||||||
Tr::tr("Override Clang Format configuration file with the chosen configuration."));
|
Tr::tr("Override Clang Format configuration file with the chosen configuration."));
|
||||||
|
|
||||||
m_overrideDefault->setChecked(getProjectOverriddenSettings(m_project));
|
m_overrideDefault->setChecked(getProjectOverriddenSettings(m_project));
|
||||||
|
m_codeStyle->currentPreferences()->setTemporarilyReadOnly(!m_overrideDefault->isChecked());
|
||||||
|
|
||||||
connect(m_overrideDefault, &QCheckBox::toggled, this, [this](bool checked) {
|
connect(m_overrideDefault, &QCheckBox::toggled, this, [this](bool checked) {
|
||||||
if (m_project)
|
if (m_project)
|
||||||
m_project->setNamedSettings(Constants::OVERRIDE_FILE_ID, checked);
|
m_project->setNamedSettings(Constants::OVERRIDE_FILE_ID, checked);
|
||||||
|
else {
|
||||||
|
m_codeStyle->currentPreferences()->setTemporarilyReadOnly(!checked);
|
||||||
|
emit m_codeStyle->currentPreferencesChanged(m_codeStyle->currentPreferences());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_codeStyle, &TextEditor::ICodeStylePreferences::currentPreferencesChanged, this, [this] {
|
||||||
|
m_codeStyle->currentPreferences()->setTemporarilyReadOnly(!m_overrideDefault->isChecked());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ class QLabel;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer { class Project; }
|
||||||
|
namespace TextEditor { class ICodeStylePreferences; }
|
||||||
|
|
||||||
namespace ClangFormat {
|
namespace ClangFormat {
|
||||||
|
|
||||||
@@ -22,7 +23,8 @@ class ClangFormatGlobalConfigWidget : public CppEditor::CppCodeStyleWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClangFormatGlobalConfigWidget(ProjectExplorer::Project *project = nullptr,
|
explicit ClangFormatGlobalConfigWidget(TextEditor::ICodeStylePreferences *codeStyle,
|
||||||
|
ProjectExplorer::Project *project = nullptr,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
~ClangFormatGlobalConfigWidget() override;
|
~ClangFormatGlobalConfigWidget() override;
|
||||||
void apply() override;
|
void apply() override;
|
||||||
@@ -36,6 +38,7 @@ private:
|
|||||||
bool projectClangFormatFileExists();
|
bool projectClangFormatFileExists();
|
||||||
|
|
||||||
ProjectExplorer::Project *m_project;
|
ProjectExplorer::Project *m_project;
|
||||||
|
TextEditor::ICodeStylePreferences *m_codeStyle;
|
||||||
|
|
||||||
QLabel *m_projectHasClangFormat;
|
QLabel *m_projectHasClangFormat;
|
||||||
QLabel *m_formattingModeLabel;
|
QLabel *m_formattingModeLabel;
|
||||||
|
@@ -51,9 +51,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
CodeStyleEditorWidget *createAdditionalGlobalSettings(
|
CodeStyleEditorWidget *createAdditionalGlobalSettings(
|
||||||
Project *project, QWidget *parent) override
|
ICodeStylePreferences *codeStyle, Project *project, QWidget *parent) override
|
||||||
{
|
{
|
||||||
return new ClangFormatGlobalConfigWidget(project, parent);
|
return new ClangFormatGlobalConfigWidget(codeStyle, project, parent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -414,7 +414,7 @@ void CppCodeStylePreferencesWidget::setCodeStyleSettings(const CppCodeStyleSetti
|
|||||||
|
|
||||||
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(ICodeStylePreferences *preferences, bool preview)
|
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(ICodeStylePreferences *preferences, bool preview)
|
||||||
{
|
{
|
||||||
const bool enable = !preferences->isReadOnly();
|
const bool enable = !preferences->isReadOnly() && !preferences->isTemporarilyReadOnly();
|
||||||
for (QWidget *widget : d->m_controllers)
|
for (QWidget *widget : d->m_controllers)
|
||||||
widget->setEnabled(enable);
|
widget->setEnabled(enable);
|
||||||
|
|
||||||
|
@@ -31,7 +31,9 @@ CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
|
|||||||
m_layout = new QVBoxLayout(this);
|
m_layout = new QVBoxLayout(this);
|
||||||
auto selector = new CodeStyleSelectorWidget(factory, project, this);
|
auto selector = new CodeStyleSelectorWidget(factory, project, this);
|
||||||
selector->setCodeStyle(codeStyle);
|
selector->setCodeStyle(codeStyle);
|
||||||
m_additionalGlobalSettingsWidget = factory->createAdditionalGlobalSettings(project, parent);
|
m_additionalGlobalSettingsWidget = factory->createAdditionalGlobalSettings(codeStyle,
|
||||||
|
project,
|
||||||
|
parent);
|
||||||
|
|
||||||
if (m_additionalGlobalSettingsWidget)
|
if (m_additionalGlobalSettingsWidget)
|
||||||
m_layout->addWidget(m_additionalGlobalSettingsWidget);
|
m_layout->addWidget(m_additionalGlobalSettingsWidget);
|
||||||
|
@@ -24,6 +24,7 @@ public:
|
|||||||
QByteArray m_id;
|
QByteArray m_id;
|
||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
bool m_readOnly = false;
|
bool m_readOnly = false;
|
||||||
|
bool m_temporarilyReadOnly = false;
|
||||||
QString m_settingsSuffix;
|
QString m_settingsSuffix;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,6 +72,16 @@ void ICodeStylePreferences::setReadOnly(bool on)
|
|||||||
d->m_readOnly = on;
|
d->m_readOnly = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ICodeStylePreferences::setTemporarilyReadOnly(bool on)
|
||||||
|
{
|
||||||
|
d->m_temporarilyReadOnly = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ICodeStylePreferences::isTemporarilyReadOnly() const
|
||||||
|
{
|
||||||
|
return d->m_temporarilyReadOnly;
|
||||||
|
}
|
||||||
|
|
||||||
void ICodeStylePreferences::setTabSettings(const TabSettings &settings)
|
void ICodeStylePreferences::setTabSettings(const TabSettings &settings)
|
||||||
{
|
{
|
||||||
if (d->m_tabSettings == settings)
|
if (d->m_tabSettings == settings)
|
||||||
|
@@ -37,6 +37,9 @@ public:
|
|||||||
bool isReadOnly() const;
|
bool isReadOnly() const;
|
||||||
void setReadOnly(bool on);
|
void setReadOnly(bool on);
|
||||||
|
|
||||||
|
bool isTemporarilyReadOnly() const;
|
||||||
|
void setTemporarilyReadOnly(bool on);
|
||||||
|
|
||||||
void setTabSettings(const TabSettings &settings);
|
void setTabSettings(const TabSettings &settings);
|
||||||
TabSettings tabSettings() const;
|
TabSettings tabSettings() const;
|
||||||
TabSettings currentTabSettings() const;
|
TabSettings currentTabSettings() const;
|
||||||
|
@@ -18,7 +18,7 @@ CodeStyleEditorWidget *ICodeStylePreferencesFactory::createCodeStyleEditor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CodeStyleEditorWidget *ICodeStylePreferencesFactory::createAdditionalGlobalSettings(
|
CodeStyleEditorWidget *ICodeStylePreferencesFactory::createAdditionalGlobalSettings(
|
||||||
ProjectExplorer::Project *, QWidget *)
|
ICodeStylePreferences *, ProjectExplorer::Project *, QWidget *)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,10 @@ public:
|
|||||||
virtual CodeStyleEditorWidget *createCodeStyleEditor(ICodeStylePreferences *codeStyle,
|
virtual CodeStyleEditorWidget *createCodeStyleEditor(ICodeStylePreferences *codeStyle,
|
||||||
ProjectExplorer::Project *project = nullptr,
|
ProjectExplorer::Project *project = nullptr,
|
||||||
QWidget *parent = nullptr);
|
QWidget *parent = nullptr);
|
||||||
virtual CodeStyleEditorWidget *createAdditionalGlobalSettings(
|
virtual CodeStyleEditorWidget *createAdditionalGlobalSettings(ICodeStylePreferences *codeStyle,
|
||||||
ProjectExplorer::Project *project = nullptr, QWidget *parent = nullptr);
|
ProjectExplorer::Project *project
|
||||||
|
= nullptr,
|
||||||
|
QWidget *parent = nullptr);
|
||||||
virtual Utils::Id languageId() = 0;
|
virtual Utils::Id languageId() = 0;
|
||||||
virtual QString displayName() = 0;
|
virtual QString displayName() = 0;
|
||||||
virtual ICodeStylePreferences *createCodeStyle() const = 0;
|
virtual ICodeStylePreferences *createCodeStyle() const = 0;
|
||||||
|
Reference in New Issue
Block a user