forked from qt-creator/qt-creator
TextEditor: Introduce a per-project variant of the comments settings
These settings can clearly differ per project. Note that the classes have to live in the ProjectExplorer plugin, which has a (questionable) dependency on TextEditor. Change-Id: I7e3816da30cecd1ccb66549a2226b44dc0a26cb4 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/documentmodel.h>
|
||||
#include <texteditor/commentssettings.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@@ -20,6 +21,7 @@ namespace { typedef QByteArray _; }
|
||||
using CppEditor::Tests::TemporaryDir;
|
||||
using CppEditor::Tests::TestCase;
|
||||
using CppEditor::Internal::Tests::VerifyCleanCppModelManager;
|
||||
using namespace TextEditor;
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
@@ -27,6 +29,19 @@ namespace CppEditor {
|
||||
namespace Internal {
|
||||
namespace Tests {
|
||||
|
||||
class SettingsInjector
|
||||
{
|
||||
public:
|
||||
SettingsInjector(const CommentsSettings::Data &tempSettings)
|
||||
{
|
||||
CommentsSettings::setData(tempSettings);
|
||||
}
|
||||
~SettingsInjector() { CommentsSettings::setData(m_oldSettings); }
|
||||
|
||||
private:
|
||||
const CommentsSettings::Data m_oldSettings = CommentsSettings::data();
|
||||
};
|
||||
|
||||
void DoxygenTest::initTestCase()
|
||||
{
|
||||
verifyCleanState();
|
||||
@@ -39,8 +54,6 @@ void DoxygenTest::cleanTestCase()
|
||||
|
||||
void DoxygenTest::cleanup()
|
||||
{
|
||||
if (oldSettings)
|
||||
CppToolsSettings::setCommentsSettings(*oldSettings);
|
||||
QVERIFY(Core::EditorManager::closeAllEditors(false));
|
||||
QVERIFY(TestCase::garbageCollectGlobalSnapshot());
|
||||
}
|
||||
@@ -372,7 +385,7 @@ void DoxygenTest::testWithMacroFromHeaderBeforeFunction()
|
||||
|
||||
const CppTestDocument headerDocumentDefiningMacro("header.h", "#define API\n");
|
||||
|
||||
runTest(given, expected, /*settings=*/ 0, {headerDocumentDefiningMacro});
|
||||
runTest(given, expected, {headerDocumentDefiningMacro});
|
||||
}
|
||||
|
||||
void DoxygenTest::testNoLeadingAsterisks_data()
|
||||
@@ -396,8 +409,9 @@ void DoxygenTest::testNoLeadingAsterisks()
|
||||
TextEditor::CommentsSettings::Data injection;
|
||||
injection.enableDoxygen = true;
|
||||
injection.leadingAsterisks = false;
|
||||
const SettingsInjector injector(injection);
|
||||
|
||||
runTest(given, expected, &injection);
|
||||
runTest(given, expected);
|
||||
}
|
||||
|
||||
void DoxygenTest::verifyCleanState() const
|
||||
@@ -410,7 +424,6 @@ void DoxygenTest::verifyCleanState() const
|
||||
/// The '|' in the input denotes the cursor position.
|
||||
void DoxygenTest::runTest(const QByteArray &original,
|
||||
const QByteArray &expected,
|
||||
TextEditor::CommentsSettings::Data *settings,
|
||||
const TestDocuments &includedHeaderDocuments)
|
||||
{
|
||||
// Write files to disk
|
||||
@@ -433,11 +446,6 @@ void DoxygenTest::runTest(const QByteArray &original,
|
||||
QVERIFY(TestCase::openCppEditor(testDocument.filePath(), &testDocument.m_editor,
|
||||
&testDocument.m_editorWidget));
|
||||
|
||||
if (settings) {
|
||||
oldSettings.reset(new TextEditor::CommentsSettings::Data(CppToolsSettings::commentsSettings()));
|
||||
CppToolsSettings::setCommentsSettings(*settings);
|
||||
}
|
||||
|
||||
// We want to test documents that start with a comment. By default, the
|
||||
// editor will fold the very first comment it encounters, assuming
|
||||
// it is a license header. Currently unfoldAll() does not work as
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#include "cpptoolstestcase.h"
|
||||
|
||||
#include <texteditor/commentssettings.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
|
||||
@@ -36,10 +34,7 @@ private:
|
||||
void verifyCleanState() const;
|
||||
void runTest(const QByteArray &original,
|
||||
const QByteArray &expected,
|
||||
TextEditor::CommentsSettings::Data *settings = 0,
|
||||
const TestDocuments &includedHeaderDocuments = TestDocuments());
|
||||
|
||||
QScopedPointer<TextEditor::CommentsSettings::Data> oldSettings;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
|
||||
@@ -307,7 +307,8 @@ bool handleDoxygenContinuation(QTextCursor &cursor,
|
||||
static bool trySplitComment(TextEditor::TextEditorWidget *editorWidget,
|
||||
const CPlusPlus::Snapshot &snapshot)
|
||||
{
|
||||
const TextEditor::CommentsSettings::Data &settings = CppToolsSettings::instance()->commentsSettings();
|
||||
const TextEditor::CommentsSettings::Data &settings
|
||||
= TextEditorSettings::commentsSettings(editorWidget->textDocument()->filePath());
|
||||
if (!settings.enableDoxygen && !settings.leadingAsterisks)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "cppcodestylepreferencesfactory.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <texteditor/commentssettings.h>
|
||||
#include <texteditor/completionsettingspage.h>
|
||||
#include <texteditor/codestylepool.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
@@ -33,7 +32,6 @@ namespace Internal {
|
||||
class CppToolsSettingsPrivate
|
||||
{
|
||||
public:
|
||||
CommentsSettings::Data m_commentsSettings;
|
||||
CppCodeStylePreferences *m_globalCodeStyle = nullptr;
|
||||
};
|
||||
|
||||
@@ -50,10 +48,6 @@ CppToolsSettings::CppToolsSettings()
|
||||
|
||||
qRegisterMetaType<CppCodeStyleSettings>("CppEditor::CppCodeStyleSettings");
|
||||
|
||||
d->m_commentsSettings = TextEditorSettings::commentsSettings();
|
||||
connect(TextEditorSettings::instance(), &TextEditorSettings::commentsSettingsChanged,
|
||||
this, &CppToolsSettings::setCommentsSettings);
|
||||
|
||||
// code style factory
|
||||
ICodeStylePreferencesFactory *factory = new CppCodeStylePreferencesFactory();
|
||||
TextEditorSettings::registerCodeStyleFactory(factory);
|
||||
@@ -164,16 +158,6 @@ CppCodeStylePreferences *CppToolsSettings::cppCodeStyle()
|
||||
return d->m_globalCodeStyle;
|
||||
}
|
||||
|
||||
const CommentsSettings::Data &CppToolsSettings::commentsSettings()
|
||||
{
|
||||
return d->m_commentsSettings;
|
||||
}
|
||||
|
||||
void CppToolsSettings::setCommentsSettings(const CommentsSettings::Data &commentsSettings)
|
||||
{
|
||||
d->m_commentsSettings = commentsSettings;
|
||||
}
|
||||
|
||||
static QString sortEditorDocumentOutlineKey()
|
||||
{
|
||||
return QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)
|
||||
|
||||
@@ -5,12 +5,8 @@
|
||||
|
||||
#include "cppeditor_global.h"
|
||||
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace TextEditor { class CommentsSettings; }
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
class CppCodeStylePreferences;
|
||||
@@ -27,9 +23,6 @@ public:
|
||||
|
||||
static CppCodeStylePreferences *cppCodeStyle();
|
||||
|
||||
static const TextEditor::CommentsSettings::Data &commentsSettings();
|
||||
static void setCommentsSettings(const TextEditor::CommentsSettings::Data &commentsSettings);
|
||||
|
||||
static bool sortedEditorDocumentOutline();
|
||||
static void setSortedEditorDocumentOutline(bool sorted);
|
||||
};
|
||||
|
||||
@@ -124,6 +124,7 @@ add_qtc_plugin(ProjectExplorer
|
||||
processparameters.cpp processparameters.h
|
||||
processstep.cpp processstep.h
|
||||
project.cpp project.h
|
||||
projectcommentssettings.cpp projectcommentssettings.h
|
||||
projectconfiguration.cpp projectconfiguration.h
|
||||
projectconfigurationmodel.cpp projectconfigurationmodel.h
|
||||
projectexplorer.cpp projectexplorer.h
|
||||
|
||||
128
src/plugins/projectexplorer/projectcommentssettings.cpp
Normal file
128
src/plugins/projectexplorer/projectcommentssettings.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "projectcommentssettings.h"
|
||||
|
||||
#include "project.h"
|
||||
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
const char kUseGlobalKey[] = "UseGlobalKey";
|
||||
|
||||
ProjectCommentsSettings::ProjectCommentsSettings(ProjectExplorer::Project *project)
|
||||
: m_project(project)
|
||||
{
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
CommentsSettings::Data ProjectCommentsSettings::settings() const
|
||||
{
|
||||
return m_useGlobalSettings ? CommentsSettings::data() : m_customSettings;
|
||||
}
|
||||
|
||||
void ProjectCommentsSettings::setSettings(const CommentsSettings::Data &settings)
|
||||
{
|
||||
if (settings == m_customSettings)
|
||||
return;
|
||||
m_customSettings = settings;
|
||||
saveSettings();
|
||||
emit TextEditorSettings::instance()->commentsSettingsChanged();
|
||||
}
|
||||
|
||||
void ProjectCommentsSettings::setUseGlobalSettings(bool useGlobal)
|
||||
{
|
||||
if (useGlobal == m_useGlobalSettings)
|
||||
return;
|
||||
m_useGlobalSettings = useGlobal;
|
||||
saveSettings();
|
||||
emit TextEditorSettings::instance()->commentsSettingsChanged();
|
||||
}
|
||||
|
||||
void ProjectCommentsSettings::loadSettings()
|
||||
{
|
||||
if (!m_project)
|
||||
return;
|
||||
|
||||
const QVariant entry = m_project->namedSettings(CommentsSettings::mainSettingsKey());
|
||||
if (!entry.isValid())
|
||||
return;
|
||||
|
||||
const QVariantMap data = entry.toMap();
|
||||
m_useGlobalSettings = data.value(kUseGlobalKey, true).toBool();
|
||||
m_customSettings.enableDoxygen = data.value(CommentsSettings::enableDoxygenSettingsKey(),
|
||||
m_customSettings.enableDoxygen).toBool();
|
||||
m_customSettings.generateBrief = data.value(CommentsSettings::generateBriefSettingsKey(),
|
||||
m_customSettings.generateBrief).toBool();
|
||||
m_customSettings.leadingAsterisks = data.value(CommentsSettings::leadingAsterisksSettingsKey(),
|
||||
m_customSettings.leadingAsterisks).toBool();
|
||||
}
|
||||
|
||||
void ProjectCommentsSettings::saveSettings()
|
||||
{
|
||||
if (!m_project)
|
||||
return;
|
||||
|
||||
// Optimization: Don't save anything if the user never switched away from the default.
|
||||
if (m_useGlobalSettings && !m_project->namedSettings
|
||||
(CommentsSettings::mainSettingsKey()).isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap data;
|
||||
data.insert(kUseGlobalKey, m_useGlobalSettings);
|
||||
data.insert(CommentsSettings::enableDoxygenSettingsKey(), m_customSettings.enableDoxygen);
|
||||
data.insert(CommentsSettings::generateBriefSettingsKey(), m_customSettings.generateBrief);
|
||||
data.insert(CommentsSettings::leadingAsterisksSettingsKey(), m_customSettings.leadingAsterisks);
|
||||
m_project->setNamedSettings(CommentsSettings::mainSettingsKey(), data);
|
||||
}
|
||||
|
||||
class ProjectCommentsSettingsWidget::Private
|
||||
{
|
||||
public:
|
||||
Private(ProjectExplorer::Project *project) : settings(project) {}
|
||||
|
||||
ProjectCommentsSettings settings;
|
||||
CommentsSettingsWidget widget{settings.settings()};
|
||||
QCheckBox useGlobalSettingsCheckBox;
|
||||
};
|
||||
|
||||
ProjectCommentsSettingsWidget::ProjectCommentsSettingsWidget(ProjectExplorer::Project *project)
|
||||
: d(new Private(project))
|
||||
{
|
||||
setGlobalSettingsId(TextEditor::Constants::TEXT_EDITOR_COMMENTS_SETTINGS);
|
||||
const auto layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(&d->widget);
|
||||
|
||||
const auto updateGlobalSettingsCheckBox = [this] {
|
||||
setUseGlobalSettingsCheckBoxEnabled(true);
|
||||
setUseGlobalSettings(d->settings.useGlobalSettings());
|
||||
d->widget.setEnabled(!useGlobalSettings());
|
||||
};
|
||||
updateGlobalSettingsCheckBox();
|
||||
connect(TextEditorSettings::instance(), &TextEditorSettings::commentsSettingsChanged,
|
||||
this, updateGlobalSettingsCheckBox);
|
||||
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged, this,
|
||||
[this](bool checked) {
|
||||
d->widget.setEnabled(!checked);
|
||||
d->settings.setUseGlobalSettings(checked);
|
||||
if (!checked)
|
||||
d->settings.setSettings(d->widget.settingsData());
|
||||
});
|
||||
connect(&d->widget, &CommentsSettingsWidget::settingsChanged, this, [this] {
|
||||
d->settings.setSettings(d->widget.settingsData());
|
||||
});
|
||||
}
|
||||
|
||||
ProjectCommentsSettingsWidget::~ProjectCommentsSettingsWidget() { delete d; }
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
49
src/plugins/projectexplorer/projectcommentssettings.h
Normal file
49
src/plugins/projectexplorer/projectcommentssettings.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "projectsettingswidget.h"
|
||||
|
||||
#include <texteditor/commentssettings.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class ProjectCommentsSettings
|
||||
{
|
||||
public:
|
||||
// Passing a null ptr is allowed and yields the global settings, so you can use
|
||||
// this class transparently for both cases.
|
||||
ProjectCommentsSettings(Project *project);
|
||||
|
||||
TextEditor::CommentsSettings::Data settings() const;
|
||||
void setSettings(const TextEditor::CommentsSettings::Data &settings);
|
||||
bool useGlobalSettings() const { return m_useGlobalSettings; }
|
||||
void setUseGlobalSettings(bool useGlobal);
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
ProjectExplorer::Project * const m_project;
|
||||
TextEditor::CommentsSettings::Data m_customSettings;
|
||||
bool m_useGlobalSettings = true;
|
||||
};
|
||||
|
||||
class ProjectCommentsSettingsWidget : public ProjectSettingsWidget
|
||||
{
|
||||
public:
|
||||
ProjectCommentsSettingsWidget(ProjectExplorer::Project *project);
|
||||
~ProjectCommentsSettingsWidget();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "parseissuesdialog.h"
|
||||
#include "processstep.h"
|
||||
#include "project.h"
|
||||
#include "projectcommentssettings.h"
|
||||
#include "projectexplorericons.h"
|
||||
#include "projectexplorersettings.h"
|
||||
#include "projectexplorertr.h"
|
||||
@@ -115,6 +116,7 @@
|
||||
#include <texteditor/findinfiles.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fileutils.h>
|
||||
@@ -883,6 +885,17 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
panelFactory->setCreateWidgetFunction([](Project *project) { return new CodeStyleSettingsWidget(project); });
|
||||
ProjectPanelFactory::registerFactory(panelFactory);
|
||||
|
||||
panelFactory = new ProjectExplorer::ProjectPanelFactory;
|
||||
panelFactory->setPriority(45);
|
||||
panelFactory->setDisplayName(Tr::tr("Documentation Comments"));
|
||||
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
|
||||
return new ProjectCommentsSettingsWidget(project);
|
||||
});
|
||||
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
|
||||
TextEditor::TextEditorSettings::setCommentsSettingsRetriever([](const FilePath &filePath) {
|
||||
return ProjectCommentsSettings(ProjectManager::projectForFile(filePath)).settings();
|
||||
});
|
||||
|
||||
panelFactory = new ProjectPanelFactory;
|
||||
panelFactory->setPriority(50);
|
||||
panelFactory->setDisplayName(Tr::tr("Dependencies"));
|
||||
|
||||
@@ -101,6 +101,7 @@ Project {
|
||||
"processparameters.cpp", "processparameters.h",
|
||||
"processstep.cpp", "processstep.h",
|
||||
"project.cpp", "project.h",
|
||||
"projectcommentssettings.cpp", "projectcommentssettings.h",
|
||||
"projectconfiguration.cpp", "projectconfiguration.h",
|
||||
"projectconfigurationmodel.cpp", "projectconfigurationmodel.h",
|
||||
"projectexplorer.cpp", "projectexplorer.h",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "texteditortr.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
@@ -24,22 +25,19 @@ const char kGenerateBrief[] = "GenerateBrief";
|
||||
const char kAddLeadingAsterisks[] = "AddLeadingAsterisks";
|
||||
}
|
||||
|
||||
bool operator==(const CommentsSettings::Data &a, const CommentsSettings::Data &b)
|
||||
{
|
||||
return a.enableDoxygen == b.enableDoxygen
|
||||
&& a.generateBrief == b.generateBrief
|
||||
&& a.leadingAsterisks == b.leadingAsterisks;
|
||||
}
|
||||
|
||||
void CommentsSettings::setData(const Data &data)
|
||||
{
|
||||
if (data == instance().m_data)
|
||||
return;
|
||||
instance().m_data = data;
|
||||
instance().save();
|
||||
emit TextEditorSettings::instance()->commentsSettingsChanged(data);
|
||||
}
|
||||
|
||||
QString CommentsSettings::mainSettingsKey() { return kDocumentationCommentsGroup; }
|
||||
QString CommentsSettings::enableDoxygenSettingsKey() { return kEnableDoxygenBlocks; }
|
||||
QString CommentsSettings::generateBriefSettingsKey() { return kGenerateBrief; }
|
||||
QString CommentsSettings::leadingAsterisksSettingsKey() { return kAddLeadingAsterisks; }
|
||||
|
||||
CommentsSettings::CommentsSettings()
|
||||
{
|
||||
load();
|
||||
@@ -71,79 +69,86 @@ void CommentsSettings::load()
|
||||
s->endGroup();
|
||||
}
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class CommentsSettingsWidget final : public Core::IOptionsPageWidget
|
||||
class CommentsSettingsWidget::Private
|
||||
{
|
||||
public:
|
||||
explicit CommentsSettingsWidget()
|
||||
{
|
||||
initFromSettings();
|
||||
|
||||
m_enableDoxygenCheckBox.setText(Tr::tr("Enable Doxygen blocks"));
|
||||
m_enableDoxygenCheckBox.setToolTip(
|
||||
Tr::tr("Automatically creates a Doxygen comment upon pressing "
|
||||
"enter after a '/**', '/*!', '//!' or '///'."));
|
||||
|
||||
m_generateBriefCheckBox.setText(Tr::tr("Generate brief description"));
|
||||
m_generateBriefCheckBox.setToolTip(
|
||||
Tr::tr("Generates a <i>brief</i> command with an initial "
|
||||
"description for the corresponding declaration."));
|
||||
|
||||
m_leadingAsterisksCheckBox.setText(Tr::tr("Add leading asterisks"));
|
||||
m_leadingAsterisksCheckBox.setToolTip(
|
||||
Tr::tr("Adds leading asterisks when continuing C/C++ \"/*\", Qt \"/*!\" "
|
||||
"and Java \"/**\" style comments on new lines."));
|
||||
|
||||
Column {
|
||||
&m_enableDoxygenCheckBox,
|
||||
Row { Space(30), &m_generateBriefCheckBox },
|
||||
&m_leadingAsterisksCheckBox,
|
||||
st
|
||||
}.attachTo(this);
|
||||
|
||||
connect(&m_enableDoxygenCheckBox, &QCheckBox::toggled,
|
||||
&m_generateBriefCheckBox, &QCheckBox::setEnabled);
|
||||
}
|
||||
|
||||
private:
|
||||
void initFromSettings()
|
||||
{
|
||||
const CommentsSettings::Data &settings = CommentsSettings::data();
|
||||
m_enableDoxygenCheckBox.setChecked(settings.enableDoxygen);
|
||||
m_generateBriefCheckBox.setEnabled(m_enableDoxygenCheckBox.isChecked());
|
||||
m_generateBriefCheckBox.setChecked(settings.generateBrief);
|
||||
m_leadingAsterisksCheckBox.setChecked(settings.leadingAsterisks);
|
||||
}
|
||||
|
||||
CommentsSettings::Data toSettings() const
|
||||
{
|
||||
CommentsSettings::Data settings;
|
||||
settings.enableDoxygen = m_enableDoxygenCheckBox.isChecked();
|
||||
settings.generateBrief = m_generateBriefCheckBox.isChecked();
|
||||
settings.leadingAsterisks = m_leadingAsterisksCheckBox.isChecked();
|
||||
return settings;
|
||||
}
|
||||
|
||||
void apply() override
|
||||
{
|
||||
CommentsSettings::setData(toSettings());
|
||||
}
|
||||
|
||||
QCheckBox m_overwriteClosingChars;
|
||||
QCheckBox m_enableDoxygenCheckBox;
|
||||
QCheckBox m_generateBriefCheckBox;
|
||||
QCheckBox m_leadingAsterisksCheckBox;
|
||||
};
|
||||
|
||||
CommentsSettingsWidget::CommentsSettingsWidget(const CommentsSettings::Data &settings)
|
||||
: d(new Private)
|
||||
{
|
||||
initFromSettings(settings);
|
||||
|
||||
d->m_enableDoxygenCheckBox.setText(Tr::tr("Enable Doxygen blocks"));
|
||||
d->m_enableDoxygenCheckBox.setToolTip(
|
||||
Tr::tr("Automatically creates a Doxygen comment upon pressing "
|
||||
"enter after a '/**', '/*!', '//!' or '///'."));
|
||||
|
||||
d->m_generateBriefCheckBox.setText(Tr::tr("Generate brief description"));
|
||||
d->m_generateBriefCheckBox.setToolTip(
|
||||
Tr::tr("Generates a <i>brief</i> command with an initial "
|
||||
"description for the corresponding declaration."));
|
||||
|
||||
d->m_leadingAsterisksCheckBox.setText(Tr::tr("Add leading asterisks"));
|
||||
d->m_leadingAsterisksCheckBox.setToolTip(
|
||||
Tr::tr("Adds leading asterisks when continuing C/C++ \"/*\", Qt \"/*!\" "
|
||||
"and Java \"/**\" style comments on new lines."));
|
||||
|
||||
Column {
|
||||
&d->m_enableDoxygenCheckBox,
|
||||
Row { Space(30), &d->m_generateBriefCheckBox },
|
||||
&d->m_leadingAsterisksCheckBox,
|
||||
st
|
||||
}.attachTo(this);
|
||||
|
||||
connect(&d->m_enableDoxygenCheckBox, &QCheckBox::toggled,
|
||||
&d->m_generateBriefCheckBox, &QCheckBox::setEnabled);
|
||||
|
||||
for (QCheckBox *checkBox : {&d->m_enableDoxygenCheckBox, &d->m_generateBriefCheckBox,
|
||||
&d->m_leadingAsterisksCheckBox}) {
|
||||
connect(checkBox, &QCheckBox::clicked, this, &CommentsSettingsWidget::settingsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
CommentsSettingsWidget::~CommentsSettingsWidget() { delete d; }
|
||||
|
||||
CommentsSettings::Data CommentsSettingsWidget::settingsData() const
|
||||
{
|
||||
CommentsSettings::Data settings;
|
||||
settings.enableDoxygen = d->m_enableDoxygenCheckBox.isChecked();
|
||||
settings.generateBrief = d->m_generateBriefCheckBox.isChecked();
|
||||
settings.leadingAsterisks = d->m_leadingAsterisksCheckBox.isChecked();
|
||||
return settings;
|
||||
}
|
||||
|
||||
void CommentsSettingsWidget::apply()
|
||||
{
|
||||
// This function is only ever called for the global settings page.
|
||||
CommentsSettings::setData(settingsData());
|
||||
}
|
||||
|
||||
void CommentsSettingsWidget::initFromSettings(const CommentsSettings::Data &settings)
|
||||
{
|
||||
d->m_enableDoxygenCheckBox.setChecked(settings.enableDoxygen);
|
||||
d->m_generateBriefCheckBox.setEnabled(d->m_enableDoxygenCheckBox.isChecked());
|
||||
d->m_generateBriefCheckBox.setChecked(settings.generateBrief);
|
||||
d->m_leadingAsterisksCheckBox.setChecked(settings.leadingAsterisks);
|
||||
}
|
||||
|
||||
namespace Internal {
|
||||
|
||||
CommentsSettingsPage::CommentsSettingsPage()
|
||||
{
|
||||
setId("Q.Comments");
|
||||
setId(Constants::TEXT_EDITOR_COMMENTS_SETTINGS);
|
||||
setDisplayName(Tr::tr("Documentation Comments"));
|
||||
setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
|
||||
setDisplayCategory(Tr::tr("Text Editor"));
|
||||
setCategoryIconPath(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON_PATH);
|
||||
setWidgetCreator([] { return new CommentsSettingsWidget; });
|
||||
setWidgetCreator([] { return new CommentsSettingsWidget(CommentsSettings::data()); });
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
namespace ProjectExplorer { class Project; }
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
@@ -18,9 +16,6 @@ class TEXTEDITOR_EXPORT CommentsSettings
|
||||
public:
|
||||
class Data {
|
||||
public:
|
||||
friend bool operator==(const Data &a, const Data &b);
|
||||
friend bool operator!=(const Data &a, const Data &b) { return !(a == b); }
|
||||
|
||||
bool enableDoxygen = true;
|
||||
bool generateBrief = true;
|
||||
bool leadingAsterisks = true;
|
||||
@@ -29,6 +24,11 @@ public:
|
||||
static Data data() { return instance().m_data; }
|
||||
static void setData(const Data &data);
|
||||
|
||||
static QString mainSettingsKey();
|
||||
static QString enableDoxygenSettingsKey();
|
||||
static QString generateBriefSettingsKey();
|
||||
static QString leadingAsterisksSettingsKey();
|
||||
|
||||
private:
|
||||
CommentsSettings();
|
||||
static CommentsSettings &instance();
|
||||
@@ -37,6 +37,38 @@ private:
|
||||
|
||||
Data m_data;
|
||||
};
|
||||
inline bool operator==(const CommentsSettings::Data &a, const CommentsSettings::Data &b)
|
||||
{
|
||||
return a.enableDoxygen == b.enableDoxygen
|
||||
&& a.generateBrief == b.generateBrief
|
||||
&& a.leadingAsterisks == b.leadingAsterisks;
|
||||
}
|
||||
inline bool operator!=(const CommentsSettings::Data &a, const CommentsSettings::Data &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
|
||||
class TEXTEDITOR_EXPORT CommentsSettingsWidget final : public Core::IOptionsPageWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CommentsSettingsWidget(const CommentsSettings::Data &settings);
|
||||
~CommentsSettingsWidget();
|
||||
|
||||
CommentsSettings::Data settingsData() const;
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
private:
|
||||
void apply() override;
|
||||
|
||||
void initFromSettings(const CommentsSettings::Data &settings);
|
||||
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
namespace Internal {
|
||||
|
||||
@@ -47,5 +79,4 @@ public:
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
@@ -226,6 +226,7 @@ const char TEXT_EDITOR_BEHAVIOR_SETTINGS[] = "B.BehaviourSettings";
|
||||
const char TEXT_EDITOR_DISPLAY_SETTINGS[] = "D.DisplaySettings";
|
||||
const char TEXT_EDITOR_HIGHLIGHTER_SETTINGS[] = "E.HighlighterSettings";
|
||||
const char TEXT_EDITOR_SNIPPETS_SETTINGS[] = "F.SnippetsSettings";
|
||||
const char TEXT_EDITOR_COMMENTS_SETTINGS[] = "Q.CommentsSettings";
|
||||
|
||||
const char HIGHLIGHTER_SETTINGS_CATEGORY[] = "HighlighterSettings";
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "texteditorplugin.h"
|
||||
|
||||
#include "commentssettings.h"
|
||||
#include "findincurrentfile.h"
|
||||
#include "findinfiles.h"
|
||||
#include "findinopenfiles.h"
|
||||
@@ -35,6 +36,8 @@
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <projectexplorer/projectpanelfactory.h>
|
||||
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/macroexpander.h>
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
QMap<Utils::Id, CodeStylePool *> m_languageToCodeStylePool;
|
||||
QMap<QString, Utils::Id> m_mimeTypeToLanguage;
|
||||
|
||||
std::function<CommentsSettings::Data(const Utils::FilePath &)> m_retrieveCommentsSettings;
|
||||
|
||||
private:
|
||||
static std::vector<FormatDescription> initialFormats();
|
||||
};
|
||||
@@ -503,9 +505,16 @@ const ExtraEncodingSettings &TextEditorSettings::extraEncodingSettings()
|
||||
return d->m_behaviorSettingsPage.extraEncodingSettings();
|
||||
}
|
||||
|
||||
CommentsSettings::Data TextEditorSettings::commentsSettings()
|
||||
void TextEditorSettings::setCommentsSettingsRetriever(
|
||||
const std::function<CommentsSettings::Data(const Utils::FilePath &)> &retrieve)
|
||||
{
|
||||
return CommentsSettings::data();
|
||||
d->m_retrieveCommentsSettings = retrieve;
|
||||
}
|
||||
|
||||
CommentsSettings::Data TextEditorSettings::commentsSettings(const Utils::FilePath &filePath)
|
||||
{
|
||||
QTC_ASSERT(d->m_retrieveCommentsSettings, return CommentsSettings::data());
|
||||
return d->m_retrieveCommentsSettings(filePath);
|
||||
}
|
||||
|
||||
void TextEditorSettings::registerCodeStyleFactory(ICodeStylePreferencesFactory *factory)
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
template <typename Key, typename T>
|
||||
class QMap;
|
||||
@@ -55,7 +57,10 @@ public:
|
||||
static const CompletionSettings &completionSettings();
|
||||
static const HighlighterSettings &highlighterSettings();
|
||||
static const ExtraEncodingSettings &extraEncodingSettings();
|
||||
static CommentsSettings::Data commentsSettings();
|
||||
|
||||
static void setCommentsSettingsRetriever(
|
||||
const std::function<CommentsSettings::Data(const Utils::FilePath &)> &);
|
||||
static CommentsSettings::Data commentsSettings(const Utils::FilePath &filePath);
|
||||
|
||||
static ICodeStylePreferencesFactory *codeStyleFactory(Utils::Id languageId);
|
||||
static const QMap<Utils::Id, ICodeStylePreferencesFactory *> &codeStyleFactories();
|
||||
@@ -87,7 +92,7 @@ signals:
|
||||
void displaySettingsChanged(const TextEditor::DisplaySettings &);
|
||||
void completionSettingsChanged(const TextEditor::CompletionSettings &);
|
||||
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
|
||||
void commentsSettingsChanged(const TextEditor::CommentsSettings::Data &);
|
||||
void commentsSettingsChanged();
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
||||
Reference in New Issue
Block a user