forked from qt-creator/qt-creator
CodeStyle: Remove edit pop-up
Removed the Edit pop-up on the CodeStyle page. Now editing is available immediately after opening CodeStyle tab. I left a preview on the project CodeStyle page and added a link to global settings. ToDo: In project CodeStyle page replace preview with CodeStyleEditor. I'm not 100% sure that it is needed. If you have some thoughts please write a comment. Change-Id: I31032a97b9668b4f6b06fc6c5c704700fb44ee4f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -41,8 +41,11 @@
|
||||
#include <cppeditor/cpphighlighter.h>
|
||||
#include <cppeditor/cppcodestylesettings.h>
|
||||
#include <cppeditor/cppcodestylesnippets.h>
|
||||
#include <cppeditor/cpptoolssettings.h>
|
||||
#include <cppeditor/cppcodestylepreferences.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/editorconfiguration.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <texteditor/displaysettings.h>
|
||||
@@ -83,19 +86,18 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
||||
, m_project(project)
|
||||
, m_checks(std::make_unique<Ui::ClangFormatChecksWidget>())
|
||||
{
|
||||
resize(489, 305);
|
||||
m_config = std::make_unique<ClangFormatFile>(filePathToCurrentSettings(codeStyle->currentPreferences()));
|
||||
|
||||
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_checksScrollArea->setMaximumWidth(600);
|
||||
m_checksWidget->setEnabled(!codeStyle->isReadOnly());
|
||||
|
||||
FilePath fileName;
|
||||
@@ -120,11 +122,16 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
||||
m_projectHasClangFormat,
|
||||
m_overrideDefault,
|
||||
m_fallbackConfig,
|
||||
Row { m_checksScrollArea, m_preview }
|
||||
Row { m_checksScrollArea, m_preview }
|
||||
}.attachTo(this);
|
||||
|
||||
initOverrideCheckBox();
|
||||
|
||||
connect(codeStyle, &TextEditor::ICodeStylePreferences::currentPreferencesChanged,
|
||||
this, &ClangFormatConfigWidget::slotCodeStyleChanged);
|
||||
|
||||
slotCodeStyleChanged(codeStyle->currentPreferences());
|
||||
|
||||
showOrHideWidgets();
|
||||
fillTable();
|
||||
updatePreview();
|
||||
@@ -134,6 +141,21 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
|
||||
|
||||
ClangFormatConfigWidget::~ClangFormatConfigWidget() = default;
|
||||
|
||||
void ClangFormatConfigWidget::slotCodeStyleChanged(
|
||||
TextEditor::ICodeStylePreferences *codeStyle)
|
||||
{
|
||||
if (!codeStyle)
|
||||
return;
|
||||
m_config.reset(new ClangFormatFile(filePathToCurrentSettings(codeStyle)));
|
||||
m_config->setIsReadOnly(codeStyle->isReadOnly());
|
||||
m_style = m_config->style();
|
||||
|
||||
m_checksWidget->setEnabled(!codeStyle->isReadOnly());
|
||||
|
||||
fillTable();
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void ClangFormatConfigWidget::initOverrideCheckBox()
|
||||
{
|
||||
if (m_project) {
|
||||
@@ -296,10 +318,16 @@ static void fillComboBoxOrLineEdit(QObject *object, const std::string &text, siz
|
||||
std::string value = text.substr(valueStart + 1, valueEnd - valueStart - 1);
|
||||
trim(value);
|
||||
|
||||
if (comboBox)
|
||||
if (comboBox) {
|
||||
if (comboBox->findText(QString::fromStdString(value)) == -1) {
|
||||
comboBox->setCurrentIndex(0);
|
||||
return;
|
||||
}
|
||||
comboBox->setCurrentText(QString::fromStdString(value));
|
||||
else
|
||||
lineEdit->setText(QString::fromStdString(value));
|
||||
return;
|
||||
}
|
||||
|
||||
lineEdit->setText(QString::fromStdString(value));
|
||||
}
|
||||
|
||||
void ClangFormatConfigWidget::fillTable()
|
||||
@@ -414,7 +442,15 @@ void ClangFormatConfigWidget::apply()
|
||||
if (!m_checksWidget->isVisible() && !m_checksWidget->isEnabled())
|
||||
return;
|
||||
|
||||
saveChanges(this);
|
||||
m_style = m_config->style();
|
||||
}
|
||||
|
||||
void ClangFormatConfigWidget::finish()
|
||||
{
|
||||
if (!m_checksWidget->isVisible() && !m_checksWidget->isEnabled())
|
||||
return;
|
||||
|
||||
m_config->setStyle(m_style);
|
||||
}
|
||||
|
||||
} // namespace ClangFormat
|
||||
|
||||
Reference in New Issue
Block a user