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
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <cppeditor/cppcodestylesettingspage.h>
|
||||
|
||||
#include <clang/Format/Format.h>
|
||||
|
||||
#include <QScrollArea>
|
||||
|
||||
#include <memory>
|
||||
@@ -57,6 +59,7 @@ public:
|
||||
QWidget *parent = nullptr);
|
||||
~ClangFormatConfigWidget() override;
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
void setCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings) override;
|
||||
void setTabSettings(const TextEditor::TabSettings &settings) override;
|
||||
void synchronize() override;
|
||||
@@ -67,7 +70,7 @@ private:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
void showOrHideWidgets();
|
||||
void initChecksAndPreview(bool enabled);
|
||||
void initChecksAndPreview();
|
||||
void initOverrideCheckBox();
|
||||
void connectChecks();
|
||||
|
||||
@@ -75,6 +78,7 @@ private:
|
||||
void saveChanges(QObject *sender);
|
||||
|
||||
void updatePreview();
|
||||
void slotCodeStyleChanged(TextEditor::ICodeStylePreferences *currentPreferences);
|
||||
|
||||
ProjectExplorer::Project *m_project;
|
||||
QWidget *m_checksWidget;
|
||||
@@ -82,6 +86,7 @@ private:
|
||||
TextEditor::SnippetEditorWidget *m_preview;
|
||||
std::unique_ptr<ClangFormatFile> m_config;
|
||||
std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks;
|
||||
clang::format::FormatStyle m_style;
|
||||
|
||||
bool m_disableTableUpdate = false;
|
||||
|
||||
|
||||
@@ -35,9 +35,8 @@
|
||||
|
||||
using namespace ClangFormat;
|
||||
|
||||
ClangFormatFile::ClangFormatFile(Utils::FilePath filePath, bool isReadOnly)
|
||||
ClangFormatFile::ClangFormatFile(Utils::FilePath filePath)
|
||||
: m_filePath(filePath)
|
||||
, m_isReadOnly(isReadOnly)
|
||||
{
|
||||
if (!m_filePath.exists()) {
|
||||
// create file and folder
|
||||
@@ -58,7 +57,7 @@ ClangFormatFile::ClangFormatFile(Utils::FilePath filePath, bool isReadOnly)
|
||||
}
|
||||
}
|
||||
|
||||
clang::format::FormatStyle ClangFormatFile::format() {
|
||||
clang::format::FormatStyle ClangFormatFile::style() {
|
||||
return m_style;
|
||||
}
|
||||
|
||||
@@ -78,6 +77,11 @@ bool ClangFormatFile::isReadOnly() const
|
||||
return m_isReadOnly;
|
||||
}
|
||||
|
||||
void ClangFormatFile::setIsReadOnly(bool isReadOnly)
|
||||
{
|
||||
m_isReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
void ClangFormatFile::resetStyleToQtC()
|
||||
{
|
||||
m_style = qtcStyle();
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace ClangFormat {
|
||||
class ClangFormatFile
|
||||
{
|
||||
public:
|
||||
explicit ClangFormatFile(Utils::FilePath file, bool isReadOnly);
|
||||
clang::format::FormatStyle format();
|
||||
explicit ClangFormatFile(Utils::FilePath file);
|
||||
clang::format::FormatStyle style();
|
||||
|
||||
Utils::FilePath filePath();
|
||||
void resetStyleToQtC();
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
void fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings);
|
||||
void fromTabSettings(const TextEditor::TabSettings &settings);
|
||||
bool isReadOnly() const;
|
||||
void setIsReadOnly(bool isReadOnly);
|
||||
|
||||
private:
|
||||
void saveNewFormat();
|
||||
@@ -63,7 +64,7 @@ private:
|
||||
private:
|
||||
Utils::FilePath m_filePath;
|
||||
clang::format::FormatStyle m_style;
|
||||
const bool m_isReadOnly;
|
||||
bool m_isReadOnly;
|
||||
};
|
||||
|
||||
} // namespace ClangFormat
|
||||
|
||||
Reference in New Issue
Block a user