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:
Artem Sokolovskii
2022-08-01 17:28:42 +02:00
parent 4f0ac5678f
commit 74ac09346f
12 changed files with 113 additions and 179 deletions

View File

@@ -41,8 +41,11 @@
#include <cppeditor/cpphighlighter.h> #include <cppeditor/cpphighlighter.h>
#include <cppeditor/cppcodestylesettings.h> #include <cppeditor/cppcodestylesettings.h>
#include <cppeditor/cppcodestylesnippets.h> #include <cppeditor/cppcodestylesnippets.h>
#include <cppeditor/cpptoolssettings.h>
#include <cppeditor/cppcodestylepreferences.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <texteditor/displaysettings.h> #include <texteditor/displaysettings.h>
@@ -83,19 +86,18 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
, m_project(project) , m_project(project)
, m_checks(std::make_unique<Ui::ClangFormatChecksWidget>()) , 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_projectHasClangFormat = new QLabel(this);
m_overrideDefault = new QCheckBox(tr("Override Clang Format configuration file")); m_overrideDefault = new QCheckBox(tr("Override Clang Format configuration file"));
m_fallbackConfig = new QLabel(tr("Clang-Format Style")); m_fallbackConfig = new QLabel(tr("Clang-Format Style"));
m_config = std::make_unique<ClangFormatFile>(filePathToCurrentSettings(codeStyle),
codeStyle->isReadOnly());
m_checksScrollArea = new QScrollArea(); m_checksScrollArea = new QScrollArea();
m_checksWidget = new QWidget; m_checksWidget = new QWidget;
m_checks->setupUi(m_checksWidget); m_checks->setupUi(m_checksWidget);
m_checksScrollArea->setWidget(m_checksWidget); m_checksScrollArea->setWidget(m_checksWidget);
m_checksScrollArea->setMaximumWidth(500); m_checksScrollArea->setMaximumWidth(600);
m_checksWidget->setEnabled(!codeStyle->isReadOnly()); m_checksWidget->setEnabled(!codeStyle->isReadOnly());
FilePath fileName; FilePath fileName;
@@ -125,6 +127,11 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
initOverrideCheckBox(); initOverrideCheckBox();
connect(codeStyle, &TextEditor::ICodeStylePreferences::currentPreferencesChanged,
this, &ClangFormatConfigWidget::slotCodeStyleChanged);
slotCodeStyleChanged(codeStyle->currentPreferences());
showOrHideWidgets(); showOrHideWidgets();
fillTable(); fillTable();
updatePreview(); updatePreview();
@@ -134,6 +141,21 @@ ClangFormatConfigWidget::ClangFormatConfigWidget(TextEditor::ICodeStylePreferenc
ClangFormatConfigWidget::~ClangFormatConfigWidget() = default; 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() void ClangFormatConfigWidget::initOverrideCheckBox()
{ {
if (m_project) { if (m_project) {
@@ -296,9 +318,15 @@ static void fillComboBoxOrLineEdit(QObject *object, const std::string &text, siz
std::string value = text.substr(valueStart + 1, valueEnd - valueStart - 1); std::string value = text.substr(valueStart + 1, valueEnd - valueStart - 1);
trim(value); trim(value);
if (comboBox) if (comboBox) {
if (comboBox->findText(QString::fromStdString(value)) == -1) {
comboBox->setCurrentIndex(0);
return;
}
comboBox->setCurrentText(QString::fromStdString(value)); comboBox->setCurrentText(QString::fromStdString(value));
else return;
}
lineEdit->setText(QString::fromStdString(value)); lineEdit->setText(QString::fromStdString(value));
} }
@@ -414,7 +442,15 @@ void ClangFormatConfigWidget::apply()
if (!m_checksWidget->isVisible() && !m_checksWidget->isEnabled()) if (!m_checksWidget->isVisible() && !m_checksWidget->isEnabled())
return; 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 } // namespace ClangFormat

View File

@@ -27,6 +27,8 @@
#include <cppeditor/cppcodestylesettingspage.h> #include <cppeditor/cppcodestylesettingspage.h>
#include <clang/Format/Format.h>
#include <QScrollArea> #include <QScrollArea>
#include <memory> #include <memory>
@@ -57,6 +59,7 @@ public:
QWidget *parent = nullptr); QWidget *parent = nullptr);
~ClangFormatConfigWidget() override; ~ClangFormatConfigWidget() override;
void apply() override; void apply() override;
void finish() override;
void setCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings) override; void setCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings) override;
void setTabSettings(const TextEditor::TabSettings &settings) override; void setTabSettings(const TextEditor::TabSettings &settings) override;
void synchronize() override; void synchronize() override;
@@ -67,7 +70,7 @@ private:
bool eventFilter(QObject *object, QEvent *event) override; bool eventFilter(QObject *object, QEvent *event) override;
void showOrHideWidgets(); void showOrHideWidgets();
void initChecksAndPreview(bool enabled); void initChecksAndPreview();
void initOverrideCheckBox(); void initOverrideCheckBox();
void connectChecks(); void connectChecks();
@@ -75,6 +78,7 @@ private:
void saveChanges(QObject *sender); void saveChanges(QObject *sender);
void updatePreview(); void updatePreview();
void slotCodeStyleChanged(TextEditor::ICodeStylePreferences *currentPreferences);
ProjectExplorer::Project *m_project; ProjectExplorer::Project *m_project;
QWidget *m_checksWidget; QWidget *m_checksWidget;
@@ -82,6 +86,7 @@ private:
TextEditor::SnippetEditorWidget *m_preview; TextEditor::SnippetEditorWidget *m_preview;
std::unique_ptr<ClangFormatFile> m_config; std::unique_ptr<ClangFormatFile> m_config;
std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks; std::unique_ptr<Ui::ClangFormatChecksWidget> m_checks;
clang::format::FormatStyle m_style;
bool m_disableTableUpdate = false; bool m_disableTableUpdate = false;

View File

@@ -35,9 +35,8 @@
using namespace ClangFormat; using namespace ClangFormat;
ClangFormatFile::ClangFormatFile(Utils::FilePath filePath, bool isReadOnly) ClangFormatFile::ClangFormatFile(Utils::FilePath filePath)
: m_filePath(filePath) : m_filePath(filePath)
, m_isReadOnly(isReadOnly)
{ {
if (!m_filePath.exists()) { if (!m_filePath.exists()) {
// create file and folder // 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; return m_style;
} }
@@ -78,6 +77,11 @@ bool ClangFormatFile::isReadOnly() const
return m_isReadOnly; return m_isReadOnly;
} }
void ClangFormatFile::setIsReadOnly(bool isReadOnly)
{
m_isReadOnly = isReadOnly;
}
void ClangFormatFile::resetStyleToQtC() void ClangFormatFile::resetStyleToQtC()
{ {
m_style = qtcStyle(); m_style = qtcStyle();

View File

@@ -37,8 +37,8 @@ namespace ClangFormat {
class ClangFormatFile class ClangFormatFile
{ {
public: public:
explicit ClangFormatFile(Utils::FilePath file, bool isReadOnly); explicit ClangFormatFile(Utils::FilePath file);
clang::format::FormatStyle format(); clang::format::FormatStyle style();
Utils::FilePath filePath(); Utils::FilePath filePath();
void resetStyleToQtC(); void resetStyleToQtC();
@@ -55,6 +55,7 @@ public:
void fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings); void fromCppCodeStyleSettings(const CppEditor::CppCodeStyleSettings &settings);
void fromTabSettings(const TextEditor::TabSettings &settings); void fromTabSettings(const TextEditor::TabSettings &settings);
bool isReadOnly() const; bool isReadOnly() const;
void setIsReadOnly(bool isReadOnly);
private: private:
void saveNewFormat(); void saveNewFormat();
@@ -63,7 +64,7 @@ private:
private: private:
Utils::FilePath m_filePath; Utils::FilePath m_filePath;
clang::format::FormatStyle m_style; clang::format::FormatStyle m_style;
const bool m_isReadOnly; bool m_isReadOnly;
}; };
} // namespace ClangFormat } // namespace ClangFormat

View File

@@ -259,7 +259,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() && !m_preferences->currentDelegate(); const bool enable = !preferences->isReadOnly();
m_ui->tabSettingsWidget->setEnabled(enable); m_ui->tabSettingsWidget->setEnabled(enable);
m_ui->contentGroupBox->setEnabled(enable); m_ui->contentGroupBox->setEnabled(enable);
m_ui->bracesGroupBox->setEnabled(enable); m_ui->bracesGroupBox->setEnabled(enable);
@@ -369,6 +369,9 @@ void CppCodeStylePreferencesWidget::addTab(CppCodeStyleWidget *page, QString tab
connect(this, &CppCodeStylePreferencesWidget::applyEmitted, connect(this, &CppCodeStylePreferencesWidget::applyEmitted,
page, &CppCodeStyleWidget::apply); page, &CppCodeStyleWidget::apply);
connect(this, &CppCodeStylePreferencesWidget::finishEmitted,
page, &CppCodeStyleWidget::finish);
page->synchronize(); page->synchronize();
} }
@@ -377,6 +380,11 @@ void CppCodeStylePreferencesWidget::apply()
emit applyEmitted(); emit applyEmitted();
} }
void CppCodeStylePreferencesWidget::finish()
{
emit finishEmitted();
}
// ------------------ CppCodeStyleSettingsPage // ------------------ CppCodeStyleSettingsPage
CppCodeStyleSettingsPage::CppCodeStyleSettingsPage() CppCodeStyleSettingsPage::CppCodeStyleSettingsPage()
@@ -431,6 +439,7 @@ void CppCodeStyleSettingsPage::apply()
void CppCodeStyleSettingsPage::finish() void CppCodeStyleSettingsPage::finish()
{ {
m_widget->finish();
delete m_widget; delete m_widget;
} }

View File

@@ -76,6 +76,7 @@ public:
void setCodeStyle(CppCodeStylePreferences *codeStylePreferences); void setCodeStyle(CppCodeStylePreferences *codeStylePreferences);
void addTab(CppCodeStyleWidget *page, QString tabName); void addTab(CppCodeStyleWidget *page, QString tabName);
void apply() override; void apply() override;
void finish() override;
private: private:
void decorateEditors(const TextEditor::FontSettings &fontSettings); void decorateEditors(const TextEditor::FontSettings &fontSettings);
@@ -98,6 +99,7 @@ signals:
void codeStyleSettingsChanged(const CppEditor::CppCodeStyleSettings &); void codeStyleSettingsChanged(const CppEditor::CppCodeStyleSettings &);
void tabSettingsChanged(const TextEditor::TabSettings &); void tabSettingsChanged(const TextEditor::TabSettings &);
void applyEmitted(); void applyEmitted();
void finishEmitted();
}; };

View File

@@ -28,6 +28,8 @@
#include "editorconfiguration.h" #include "editorconfiguration.h"
#include "project.h" #include "project.h"
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <texteditor/icodestylepreferencesfactory.h> #include <texteditor/icodestylepreferencesfactory.h>
#include <texteditor/codestyleeditor.h> #include <texteditor/codestyleeditor.h>
@@ -48,8 +50,8 @@ CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project)
auto languageComboBox = new QComboBox(this); auto languageComboBox = new QComboBox(this);
auto stackedWidget = new QStackedWidget(this); auto stackedWidget = new QStackedWidget(this);
setGlobalSettingsId(CppEditor::Constants::CPP_CODE_STYLE_SETTINGS_ID);
setUseGlobalSettingsCheckBoxVisible(false); setUseGlobalSettingsCheckBoxVisible(false);
setUseGlobalSettingsLabelVisible(false);
const EditorConfiguration *config = project->editorConfiguration(); const EditorConfiguration *config = project->editorConfiguration();

View File

@@ -52,12 +52,20 @@ 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_preview = new SnippetEditorWidget(this); m_additionalGlobalSettingsWidget = factory->createAdditionalGlobalSettings(project, parent);
DisplaySettings displaySettings = m_preview->displaySettings();
displaySettings.m_visualizeWhitespace = true; if (m_additionalGlobalSettingsWidget)
m_preview->setDisplaySettings(displaySettings); m_layout->addWidget(m_additionalGlobalSettingsWidget);
QString groupId = factory->snippetProviderGroupId();
SnippetProvider::decorateEditor(m_preview, groupId); m_layout->addWidget(selector);
if (!project) {
m_widget = factory->createEditor(codeStyle, project, parent);
if (m_widget)
m_layout->addWidget(m_widget);
return;
}
QLabel *label = new QLabel( QLabel *label = new QLabel(
tr("Edit preview contents to see how the current settings " tr("Edit preview contents to see how the current settings "
"are applied to custom code snippets. Changes in the preview " "are applied to custom code snippets. Changes in the preview "
@@ -66,11 +74,14 @@ CodeStyleEditor::CodeStyleEditor(ICodeStylePreferencesFactory *factory,
font.setItalic(true); font.setItalic(true);
label->setFont(font); label->setFont(font);
label->setWordWrap(true); label->setWordWrap(true);
m_additionalGlobalSettingsWidget = factory->createAdditionalGlobalSettings(project, parent);
if (m_additionalGlobalSettingsWidget)
m_layout->addWidget(m_additionalGlobalSettingsWidget);
m_layout->addWidget(selector); m_preview = new SnippetEditorWidget(this);
DisplaySettings displaySettings = m_preview->displaySettings();
displaySettings.m_visualizeWhitespace = true;
m_preview->setDisplaySettings(displaySettings);
QString groupId = factory->snippetProviderGroupId();
SnippetProvider::decorateEditor(m_preview, groupId);
m_layout->addWidget(m_preview); m_layout->addWidget(m_preview);
m_layout->addWidget(label); m_layout->addWidget(label);
connect(codeStyle, &ICodeStylePreferences::currentTabSettingsChanged, connect(codeStyle, &ICodeStylePreferences::currentTabSettingsChanged,
@@ -105,8 +116,15 @@ void CodeStyleEditor::updatePreview()
void CodeStyleEditor::apply() void CodeStyleEditor::apply()
{ {
if (!m_additionalGlobalSettingsWidget) if (m_widget)
return; m_widget->apply();
if (m_additionalGlobalSettingsWidget)
m_additionalGlobalSettingsWidget->apply(); m_additionalGlobalSettingsWidget->apply();
} }
void CodeStyleEditor::finish()
{
if (m_widget)
m_widget->finish();
}

View File

@@ -50,6 +50,7 @@ public:
QWidget *parent = nullptr); QWidget *parent = nullptr);
void apply() override; void apply() override;
void finish() override;
private: private:
void updatePreview(); void updatePreview();
@@ -58,6 +59,7 @@ private:
ICodeStylePreferences *m_codeStyle; ICodeStylePreferences *m_codeStyle;
SnippetEditorWidget *m_preview; SnippetEditorWidget *m_preview;
CodeStyleEditorWidget *m_additionalGlobalSettingsWidget; CodeStyleEditorWidget *m_additionalGlobalSettingsWidget;
CodeStyleEditorWidget *m_widget;
}; };
} // namespace TextEditor } // namespace TextEditor

View File

@@ -49,118 +49,6 @@ using namespace TextEditor;
using namespace Utils; using namespace Utils;
namespace TextEditor { namespace TextEditor {
namespace Internal {
class CodeStyleDialog : public QDialog
{
Q_OBJECT
public:
explicit CodeStyleDialog(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle,
ProjectExplorer::Project *project = nullptr,
QWidget *parent = nullptr);
~CodeStyleDialog() override;
ICodeStylePreferences *codeStyle() const;
private:
void slotCopyClicked();
void slotDisplayNameChanged();
ICodeStylePreferences *m_codeStyle;
QLineEdit *m_lineEdit;
QDialogButtonBox *m_buttons;
QLabel *m_warningLabel = nullptr;
QPushButton *m_copyButton = nullptr;
QString m_originalDisplayName;
};
CodeStyleDialog::CodeStyleDialog(ICodeStylePreferencesFactory *factory,
ICodeStylePreferences *codeStyle,
ProjectExplorer::Project *project,
QWidget *parent)
: QDialog(parent)
{
setWindowTitle(tr("Edit Code Style"));
auto layout = new QVBoxLayout(this);
QLabel *label = new QLabel(tr("Code style name:"));
m_lineEdit = new QLineEdit(codeStyle->displayName(), this);
auto nameLayout = new QHBoxLayout;
nameLayout->addWidget(label);
nameLayout->addWidget(m_lineEdit);
layout->addLayout(nameLayout);
if (codeStyle->isReadOnly()) {
auto warningLayout = new QHBoxLayout;
m_warningLabel = new QLabel(
tr("You cannot save changes to a built-in code style. "
"Copy it first to create your own version."), this);
QFont font = m_warningLabel->font();
font.setItalic(true);
m_warningLabel->setFont(font);
m_warningLabel->setWordWrap(true);
m_copyButton = new QPushButton(tr("Copy Built-in Code Style"), this);
m_copyButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(m_copyButton, &QAbstractButton::clicked, this, &CodeStyleDialog::slotCopyClicked);
warningLayout->addWidget(m_warningLabel);
warningLayout->addWidget(m_copyButton);
layout->addLayout(warningLayout);
}
m_originalDisplayName = codeStyle->displayName();
m_codeStyle = factory->createCodeStyle();
m_codeStyle->setTabSettings(codeStyle->tabSettings());
m_codeStyle->setValue(codeStyle->value());
m_codeStyle->setId(codeStyle->id());
m_codeStyle->setDisplayName(m_originalDisplayName);
m_codeStyle->setReadOnly(codeStyle->isReadOnly());
CodeStyleEditorWidget *editor = factory->createEditor(m_codeStyle, project, this);
m_buttons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
if (codeStyle->isReadOnly()) {
QPushButton *okButton = m_buttons->button(QDialogButtonBox::Ok);
okButton->setEnabled(false);
}
if (editor)
layout->addWidget(editor);
layout->addWidget(m_buttons);
resize(850, 600);
connect(m_lineEdit, &QLineEdit::textChanged, this, &CodeStyleDialog::slotDisplayNameChanged);
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttons, &QDialogButtonBox::accepted, editor, &TextEditor::CodeStyleEditorWidget::apply);
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
ICodeStylePreferences *CodeStyleDialog::codeStyle() const
{
return m_codeStyle;
}
void CodeStyleDialog::slotCopyClicked()
{
if (m_warningLabel)
m_warningLabel->hide();
if (m_copyButton)
m_copyButton->hide();
QPushButton *okButton = m_buttons->button(QDialogButtonBox::Ok);
okButton->setEnabled(true);
if (m_lineEdit->text() == m_originalDisplayName)
m_lineEdit->setText(tr("%1 (Copy)").arg(m_lineEdit->text()));
m_lineEdit->selectAll();
}
void CodeStyleDialog::slotDisplayNameChanged()
{
m_codeStyle->setDisplayName(m_lineEdit->text());
}
CodeStyleDialog::~CodeStyleDialog()
{
delete m_codeStyle;
}
} // Internal
CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory, CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *factory,
ProjectExplorer::Project *project, ProjectExplorer::Project *project,
@@ -175,7 +63,6 @@ CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *f
m_delegateComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_delegateComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
auto copyButton = new QPushButton(tr("Copy...")); auto copyButton = new QPushButton(tr("Copy..."));
auto editButton = new QPushButton(tr("Edit..."));
m_removeButton = new QPushButton(tr("Remove")); m_removeButton = new QPushButton(tr("Remove"));
@@ -192,12 +79,8 @@ CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *f
tr("Current settings:"), tr("Current settings:"),
m_delegateComboBox, m_delegateComboBox,
copyButton, copyButton,
editButton,
m_removeButton, m_removeButton,
m_exportButton, m_exportButton,
br,
Span(5, Space(1)),
m_importButton m_importButton
}, },
@@ -207,8 +90,6 @@ CodeStyleSelectorWidget::CodeStyleSelectorWidget(ICodeStylePreferencesFactory *f
this, &CodeStyleSelectorWidget::slotComboBoxActivated); this, &CodeStyleSelectorWidget::slotComboBoxActivated);
connect(copyButton, &QAbstractButton::clicked, connect(copyButton, &QAbstractButton::clicked,
this, &CodeStyleSelectorWidget::slotCopyClicked); this, &CodeStyleSelectorWidget::slotCopyClicked);
connect(editButton, &QAbstractButton::clicked,
this, &CodeStyleSelectorWidget::slotEditClicked);
connect(m_removeButton, &QAbstractButton::clicked, connect(m_removeButton, &QAbstractButton::clicked,
this, &CodeStyleSelectorWidget::slotRemoveClicked); this, &CodeStyleSelectorWidget::slotRemoveClicked);
connect(m_importButton, &QAbstractButton::clicked, connect(m_importButton, &QAbstractButton::clicked,
@@ -314,30 +195,6 @@ void CodeStyleSelectorWidget::slotCopyClicked()
} }
} }
void CodeStyleSelectorWidget::slotEditClicked()
{
if (!m_codeStyle)
return;
ICodeStylePreferences *codeStyle = m_codeStyle->currentPreferences();
// check if it's read-only
Internal::CodeStyleDialog dialog(m_factory, codeStyle, m_project, this);
if (dialog.exec() == QDialog::Accepted) {
ICodeStylePreferences *dialogCodeStyle = dialog.codeStyle();
if (codeStyle->isReadOnly()) {
CodeStylePool *codeStylePool = m_codeStyle->delegatingPool();
codeStyle = codeStylePool->cloneCodeStyle(dialogCodeStyle);
if (codeStyle)
m_codeStyle->setCurrentDelegate(codeStyle);
return;
}
codeStyle->setTabSettings(dialogCodeStyle->tabSettings());
codeStyle->setValue(dialogCodeStyle->value());
codeStyle->setDisplayName(dialogCodeStyle->displayName());
}
}
void CodeStyleSelectorWidget::slotRemoveClicked() void CodeStyleSelectorWidget::slotRemoveClicked()
{ {
if (!m_codeStyle) if (!m_codeStyle)
@@ -457,5 +314,3 @@ QString CodeStyleSelectorWidget::displayName(ICodeStylePreferences *codeStyle) c
} }
} // TextEditor } // TextEditor
#include "codestyleselectorwidget.moc"

View File

@@ -58,7 +58,6 @@ private:
void slotComboBoxActivated(int index); void slotComboBoxActivated(int index);
void slotCurrentDelegateChanged(ICodeStylePreferences *delegate); void slotCurrentDelegateChanged(ICodeStylePreferences *delegate);
void slotCopyClicked(); void slotCopyClicked();
void slotEditClicked();
void slotRemoveClicked(); void slotRemoveClicked();
void slotImportClicked(); void slotImportClicked();
void slotExportClicked(); void slotExportClicked();

View File

@@ -47,6 +47,7 @@ public:
: QWidget(parent) : QWidget(parent)
{} {}
virtual void apply() {} virtual void apply() {}
virtual void finish() {}
}; };
class TEXTEDITOR_EXPORT ICodeStylePreferencesFactory class TEXTEDITOR_EXPORT ICodeStylePreferencesFactory