forked from qt-creator/qt-creator
Beautifier: Modernize, code style, and clean up
Use nullptr and range based for loops, unify initializer list code style, remove superfluous includes, make private slots private methods, get rid of QLatin1(Char|String), use initializer lists and some minor code style issues. Change-Id: I94ba10fc96bb628239364a8201bde98a66b2c4c1 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -39,13 +38,11 @@
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
|
||||
AbstractSettings::AbstractSettings(const QString &name, const QString &ending)
|
||||
: m_version(0)
|
||||
, m_ending(ending)
|
||||
, m_styleDir(Core::ICore::userResourcePath() + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
|
||||
+ name)
|
||||
, m_name(name)
|
||||
AbstractSettings::AbstractSettings(const QString &name, const QString &ending) :
|
||||
m_ending(ending),
|
||||
m_styleDir(Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME
|
||||
+ '/' + name),
|
||||
m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,14 +160,14 @@ void AbstractSettings::save()
|
||||
{
|
||||
// Save settings, except styles
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
|
||||
s->beginGroup(Constants::SETTINGS_GROUP);
|
||||
s->beginGroup(m_name);
|
||||
QMap<QString, QVariant>::const_iterator iSettings = m_settings.constBegin();
|
||||
while (iSettings != m_settings.constEnd()) {
|
||||
s->setValue(iSettings.key(), iSettings.value());
|
||||
++iSettings;
|
||||
}
|
||||
s->setValue(QLatin1String("command"), m_command);
|
||||
s->setValue("command", m_command);
|
||||
s->endGroup();
|
||||
s->endGroup();
|
||||
|
||||
@@ -230,11 +227,11 @@ void AbstractSettings::read()
|
||||
{
|
||||
// Read settings, except styles
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
|
||||
s->beginGroup(Constants::SETTINGS_GROUP);
|
||||
s->beginGroup(m_name);
|
||||
const QStringList keys = s->allKeys();
|
||||
foreach (const QString &key, keys) {
|
||||
if (key == QLatin1String("command"))
|
||||
for (const QString &key : keys) {
|
||||
if (key == "command")
|
||||
setCommand(s->value(key).toString());
|
||||
else if (m_settings.contains(key))
|
||||
m_settings[key] = s->value(key);
|
||||
@@ -270,7 +267,7 @@ void AbstractSettings::readDocumentation()
|
||||
QXmlStreamReader xml(&file);
|
||||
if (!xml.readNextStartElement())
|
||||
return;
|
||||
if (xml.name() != QLatin1String(Constants::DOCUMENTATION_XMLROOT)) {
|
||||
if (xml.name() != Constants::DOCUMENTATION_XMLROOT) {
|
||||
BeautifierPlugin::showError(tr("The file \"%1\" is not a valid documentation file.")
|
||||
.arg(filename));
|
||||
return;
|
||||
@@ -285,16 +282,16 @@ void AbstractSettings::readDocumentation()
|
||||
while (!(xml.atEnd() || xml.hasError())) {
|
||||
if (xml.readNext() == QXmlStreamReader::StartElement) {
|
||||
const QStringRef &name = xml.name();
|
||||
if (name == QLatin1String(Constants::DOCUMENTATION_XMLENTRY)) {
|
||||
if (name == Constants::DOCUMENTATION_XMLENTRY) {
|
||||
keys.clear();
|
||||
} else if (name == QLatin1String(Constants::DOCUMENTATION_XMLKEY)) {
|
||||
} else if (name == Constants::DOCUMENTATION_XMLKEY) {
|
||||
if (xml.readNext() == QXmlStreamReader::Characters)
|
||||
keys << xml.text().toString();
|
||||
} else if (name == QLatin1String(Constants::DOCUMENTATION_XMLDOC)) {
|
||||
} else if (name == Constants::DOCUMENTATION_XMLDOC) {
|
||||
if (xml.readNext() == QXmlStreamReader::Characters) {
|
||||
m_docu << xml.text().toString();
|
||||
const int index = m_docu.size() - 1;
|
||||
foreach (const QString &key, keys)
|
||||
for (const QString &key : keys)
|
||||
m_options.insert(key, index);
|
||||
}
|
||||
}
|
||||
@@ -313,9 +310,9 @@ void AbstractSettings::readStyles()
|
||||
return;
|
||||
|
||||
const QStringList files
|
||||
= m_styleDir.entryList(QStringList() << QLatin1Char('*') + m_ending,
|
||||
= m_styleDir.entryList({'*' + m_ending},
|
||||
QDir::Files | QDir::Readable | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &filename, files) {
|
||||
for (const QString &filename : files) {
|
||||
// do not allow empty file names
|
||||
if (filename == m_ending)
|
||||
continue;
|
||||
|
@@ -71,7 +71,7 @@ public:
|
||||
protected:
|
||||
QMap<QString, QString> m_styles;
|
||||
QMap<QString, QVariant> m_settings;
|
||||
int m_version;
|
||||
int m_version = 0;
|
||||
QString m_ending;
|
||||
QDir m_styleDir;
|
||||
|
||||
|
@@ -40,8 +40,6 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
@@ -71,7 +69,7 @@ ArtisticStyle::~ArtisticStyle()
|
||||
bool ArtisticStyle::initialize()
|
||||
{
|
||||
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ArtisticStyle::MENU_ID);
|
||||
menu->menu()->setTitle(QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME));
|
||||
menu->menu()->setTitle(Constants::ArtisticStyle::DISPLAY_NAME);
|
||||
|
||||
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
|
||||
menu->addAction(Core::ActionManager::registerAction(m_formatFile,
|
||||
@@ -90,8 +88,7 @@ void ArtisticStyle::updateActions(Core::IEditor *editor)
|
||||
|
||||
QList<QObject *> ArtisticStyle::autoReleaseObjects()
|
||||
{
|
||||
ArtisticStyleOptionsPage *optionsPage = new ArtisticStyleOptionsPage(m_settings, this);
|
||||
return QList<QObject *>() << optionsPage;
|
||||
return {new ArtisticStyleOptionsPage(m_settings, this)};
|
||||
}
|
||||
|
||||
void ArtisticStyle::formatFile()
|
||||
@@ -99,7 +96,7 @@ void ArtisticStyle::formatFile()
|
||||
const QString cfgFileName = configurationFile();
|
||||
if (cfgFileName.isEmpty()) {
|
||||
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
||||
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
|
||||
Constants::ArtisticStyle::DISPLAY_NAME));
|
||||
} else {
|
||||
m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
|
||||
}
|
||||
@@ -114,8 +111,8 @@ QString ArtisticStyle::configurationFile() const
|
||||
if (const ProjectExplorer::Project *project
|
||||
= ProjectExplorer::ProjectTree::currentProject()) {
|
||||
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
|
||||
foreach (const QString &file, files) {
|
||||
if (!file.endsWith(QLatin1String(".astylerc")))
|
||||
for (const QString &file : files) {
|
||||
if (!file.endsWith(".astylerc"))
|
||||
continue;
|
||||
const QFileInfo fi(file);
|
||||
if (fi.isReadable())
|
||||
@@ -126,10 +123,10 @@ QString ArtisticStyle::configurationFile() const
|
||||
|
||||
if (m_settings->useHomeFile()) {
|
||||
const QDir homeDirectory = QDir::home();
|
||||
QString file = homeDirectory.filePath(QLatin1String(".astylerc"));
|
||||
QString file = homeDirectory.filePath(".astylerc");
|
||||
if (QFile::exists(file))
|
||||
return file;
|
||||
file = homeDirectory.filePath(QLatin1String("astylerc"));
|
||||
file = homeDirectory.filePath("astylerc");
|
||||
if (QFile::exists(file))
|
||||
return file;
|
||||
}
|
||||
@@ -141,15 +138,15 @@ Command ArtisticStyle::command(const QString &cfgFile) const
|
||||
{
|
||||
Command command;
|
||||
command.setExecutable(m_settings->command());
|
||||
command.addOption(QLatin1String("-q"));
|
||||
command.addOption(QLatin1String("--options=") + cfgFile);
|
||||
command.addOption("-q");
|
||||
command.addOption("--options=" + cfgFile);
|
||||
|
||||
if (m_settings->version() > ArtisticStyleSettings::Version_2_03) {
|
||||
command.setProcessing(Command::PipeProcessing);
|
||||
command.setPipeAddsNewline(true);
|
||||
command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
|
||||
} else {
|
||||
command.addOption(QLatin1String("%file"));
|
||||
command.addOption("%file");
|
||||
}
|
||||
|
||||
return command;
|
||||
|
@@ -44,18 +44,16 @@ class ArtisticStyle : public BeautifierAbstractTool
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtisticStyle(BeautifierPlugin *parent = 0);
|
||||
explicit ArtisticStyle(BeautifierPlugin *parent = nullptr);
|
||||
virtual ~ArtisticStyle();
|
||||
bool initialize() override;
|
||||
void updateActions(Core::IEditor *editor) override;
|
||||
QList<QObject *> autoReleaseObjects() override;
|
||||
|
||||
private slots:
|
||||
void formatFile();
|
||||
|
||||
private:
|
||||
void formatFile();
|
||||
BeautifierPlugin *m_beautifierPlugin;
|
||||
QAction *m_formatFile;
|
||||
QAction *m_formatFile = nullptr;
|
||||
ArtisticStyleSettings *m_settings;
|
||||
QString configurationFile() const;
|
||||
Command command(const QString &cfgFile) const;
|
||||
|
@@ -29,11 +29,11 @@ namespace Beautifier {
|
||||
namespace Constants {
|
||||
namespace ArtisticStyle {
|
||||
|
||||
const char DISPLAY_NAME[] = "Artistic Style";
|
||||
const char ACTION_FORMATFILE[] = "ArtisticStyle.FormatFile";
|
||||
const char MENU_ID[] = "ArtisticStyle.Menu";
|
||||
const char OPTION_ID[] = "ArtisticStyle";
|
||||
const char SETTINGS_NAME[] = "artisticstyle";
|
||||
const char DISPLAY_NAME[] = "Artistic Style";
|
||||
const char ACTION_FORMATFILE[] = "ArtisticStyle.FormatFile";
|
||||
const char MENU_ID[] = "ArtisticStyle.Menu";
|
||||
const char OPTION_ID[] = "ArtisticStyle";
|
||||
const char SETTINGS_NAME[] = "artisticstyle";
|
||||
|
||||
} // namespace ArtisticStyle
|
||||
} // namespace Constants
|
||||
|
@@ -34,25 +34,22 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
namespace ArtisticStyle {
|
||||
|
||||
ArtisticStyleOptionsPageWidget::ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::ArtisticStyleOptionsPage)
|
||||
, m_settings(settings)
|
||||
QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ArtisticStyleOptionsPage),
|
||||
m_settings(settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->useHomeFile->setText(ui->useHomeFile->text().replace(
|
||||
QLatin1String("HOME"),
|
||||
QDir::toNativeSeparators(QDir::home().absolutePath())));
|
||||
"HOME", QDir::toNativeSeparators(QDir::home().absolutePath())));
|
||||
ui->command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
ui->command->setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle(
|
||||
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
|
||||
Constants::ArtisticStyle::DISPLAY_NAME));
|
||||
connect(ui->command, &Utils::PathChooser::validChanged, ui->options, &QWidget::setEnabled);
|
||||
ui->configurations->setSettings(m_settings);
|
||||
}
|
||||
@@ -81,18 +78,15 @@ void ArtisticStyleOptionsPageWidget::apply()
|
||||
m_settings->save();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
|
||||
ArtisticStyleOptionsPage::ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_widget(0),
|
||||
m_settings(settings)
|
||||
{
|
||||
setId(Constants::ArtisticStyle::OPTION_ID);
|
||||
setDisplayName(tr("Artistic Style"));
|
||||
setCategory(Constants::OPTION_CATEGORY);
|
||||
setDisplayCategory(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
|
||||
setCategoryIcon(QLatin1String(Constants::OPTION_CATEGORY_ICON));
|
||||
setCategoryIcon(Constants::OPTION_CATEGORY_ICON);
|
||||
}
|
||||
|
||||
QWidget *ArtisticStyleOptionsPage::widget()
|
||||
|
@@ -43,7 +43,8 @@ class ArtisticStyleOptionsPageWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings, QWidget *parent = 0);
|
||||
explicit ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings,
|
||||
QWidget *parent = nullptr);
|
||||
virtual ~ArtisticStyleOptionsPageWidget();
|
||||
void restore();
|
||||
void apply();
|
||||
@@ -58,7 +59,7 @@ class ArtisticStyleOptionsPage : public Core::IOptionsPage
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent = 0);
|
||||
explicit ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent = nullptr);
|
||||
QWidget *widget() override;
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
|
@@ -44,31 +44,30 @@ namespace Internal {
|
||||
namespace ArtisticStyle {
|
||||
|
||||
namespace {
|
||||
const char kUseOtherFiles[] = "useOtherFiles";
|
||||
const char kUseHomeFile[] = "useHomeFile";
|
||||
const char kUseCustomStyle[] = "useCustomStyle";
|
||||
const char kCustomStyle[] = "customStyle";
|
||||
const char USE_OTHER_FILES[] = "useOtherFiles";
|
||||
const char USE_HOME_FILE[] = "useHomeFile";
|
||||
const char USE_CUSTOM_STYLE[] = "useCustomStyle";
|
||||
const char CUSTOM_STYLE[] = "customStyle";
|
||||
}
|
||||
|
||||
ArtisticStyleSettings::ArtisticStyleSettings() :
|
||||
AbstractSettings(QLatin1String(Constants::ArtisticStyle::SETTINGS_NAME),
|
||||
QLatin1String(".astyle"))
|
||||
AbstractSettings(Constants::ArtisticStyle::SETTINGS_NAME, ".astyle")
|
||||
{
|
||||
connect(&m_versionWatcher, &QFutureWatcherBase::finished,
|
||||
this, &ArtisticStyleSettings::helperSetVersion);
|
||||
|
||||
setCommand(QLatin1String("astyle"));
|
||||
m_settings.insert(QLatin1String(kUseOtherFiles), QVariant(true));
|
||||
m_settings.insert(QLatin1String(kUseHomeFile), QVariant(false));
|
||||
m_settings.insert(QLatin1String(kUseCustomStyle), QVariant(false));
|
||||
m_settings.insert(QLatin1String(kCustomStyle), QVariant());
|
||||
setCommand("astyle");
|
||||
m_settings.insert(USE_OTHER_FILES, QVariant(true));
|
||||
m_settings.insert(USE_HOME_FILE, QVariant(false));
|
||||
m_settings.insert(USE_CUSTOM_STYLE, QVariant(false));
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant());
|
||||
read();
|
||||
}
|
||||
|
||||
static int parseVersion(const QString &text)
|
||||
{
|
||||
// The version in Artistic Style is printed like "Artistic Style Version 2.04"
|
||||
const QRegExp rx(QLatin1String("([2-9]{1})\\.([0-9]{2})(\\.[1-9]{1})?$"));
|
||||
const QRegExp rx("([2-9]{1})\\.([0-9]{2})(\\.[1-9]{1})?$");
|
||||
if (rx.indexIn(text) != -1) {
|
||||
const int major = rx.cap(1).toInt() * 100;
|
||||
const int minor = rx.cap(2).toInt();
|
||||
@@ -80,7 +79,7 @@ static int parseVersion(const QString &text)
|
||||
static int updateVersionHelper(const QString &command)
|
||||
{
|
||||
QProcess process;
|
||||
process.start(command, QStringList() << QLatin1String("--version"));
|
||||
process.start(command, {"--version"});
|
||||
if (!process.waitForFinished()) {
|
||||
process.kill();
|
||||
return 0;
|
||||
@@ -109,56 +108,55 @@ void ArtisticStyleSettings::helperSetVersion()
|
||||
|
||||
bool ArtisticStyleSettings::useOtherFiles() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kUseOtherFiles)).toBool();
|
||||
return m_settings.value(USE_OTHER_FILES).toBool();
|
||||
}
|
||||
|
||||
void ArtisticStyleSettings::setUseOtherFiles(bool useOtherFiles)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kUseOtherFiles), QVariant(useOtherFiles));
|
||||
m_settings.insert(USE_OTHER_FILES, QVariant(useOtherFiles));
|
||||
}
|
||||
|
||||
bool ArtisticStyleSettings::useHomeFile() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kUseHomeFile)).toBool();
|
||||
return m_settings.value(USE_HOME_FILE).toBool();
|
||||
}
|
||||
|
||||
void ArtisticStyleSettings::setUseHomeFile(bool useHomeFile)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kUseHomeFile), QVariant(useHomeFile));
|
||||
m_settings.insert(USE_HOME_FILE, QVariant(useHomeFile));
|
||||
}
|
||||
|
||||
bool ArtisticStyleSettings::useCustomStyle() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kUseCustomStyle)).toBool();
|
||||
return m_settings.value(USE_CUSTOM_STYLE).toBool();
|
||||
}
|
||||
|
||||
void ArtisticStyleSettings::setUseCustomStyle(bool useCustomStyle)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kUseCustomStyle), QVariant(useCustomStyle));
|
||||
m_settings.insert(USE_CUSTOM_STYLE, QVariant(useCustomStyle));
|
||||
}
|
||||
|
||||
QString ArtisticStyleSettings::customStyle() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kCustomStyle)).toString();
|
||||
return m_settings.value(CUSTOM_STYLE).toString();
|
||||
}
|
||||
|
||||
void ArtisticStyleSettings::setCustomStyle(const QString &customStyle)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kCustomStyle), QVariant(customStyle));
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant(customStyle));
|
||||
}
|
||||
|
||||
QString ArtisticStyleSettings::documentationFilePath() const
|
||||
{
|
||||
return Core::ICore::userResourcePath() + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::DOCUMENTATION_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Constants::ArtisticStyle::SETTINGS_NAME) + QLatin1String(".xml");
|
||||
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
|
||||
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
|
||||
+ Constants::ArtisticStyle::SETTINGS_NAME + ".xml";
|
||||
}
|
||||
|
||||
void ArtisticStyleSettings::createDocumentationFile() const
|
||||
{
|
||||
QProcess process;
|
||||
process.start(command(), QStringList() << QLatin1String("-h"));
|
||||
process.start(command(), {"-h"});
|
||||
process.waitForFinished(2000); // show help should be really fast.
|
||||
if (process.error() != QProcess::UnknownError)
|
||||
return;
|
||||
@@ -173,43 +171,39 @@ void ArtisticStyleSettings::createDocumentationFile() const
|
||||
bool contextWritten = false;
|
||||
QXmlStreamWriter stream(&file);
|
||||
stream.setAutoFormatting(true);
|
||||
stream.writeStartDocument(QLatin1String("1.0"), true);
|
||||
stream.writeComment(QLatin1String("Created ")
|
||||
+ QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLROOT));
|
||||
stream.writeStartDocument("1.0", true);
|
||||
stream.writeComment("Created " + QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLROOT);
|
||||
|
||||
// astyle writes its output to 'error'...
|
||||
const QStringList lines = QString::fromUtf8(process.readAllStandardError())
|
||||
.split(QLatin1Char('\n'));
|
||||
.split('\n');
|
||||
QStringList keys;
|
||||
QStringList docu;
|
||||
foreach (QString line, lines) {
|
||||
for (QString line : lines) {
|
||||
line = line.trimmed();
|
||||
if ((line.startsWith(QLatin1String("--")) && !line.startsWith(QLatin1String("---")))
|
||||
|| line.startsWith(QLatin1String("OR "))) {
|
||||
QStringList rawKeys = line.split(QLatin1String(" OR "), QString::SkipEmptyParts);
|
||||
foreach (QString k, rawKeys) {
|
||||
if ((line.startsWith("--") && !line.startsWith("---")) || line.startsWith("OR ")) {
|
||||
const QStringList rawKeys = line.split(" OR ", QString::SkipEmptyParts);
|
||||
for (QString k : rawKeys) {
|
||||
k = k.trimmed();
|
||||
k.remove(QLatin1Char('#'));
|
||||
k.remove('#');
|
||||
keys << k;
|
||||
if (k.startsWith(QLatin1String("--")))
|
||||
if (k.startsWith("--"))
|
||||
keys << k.right(k.size() - 2);
|
||||
}
|
||||
} else {
|
||||
if (line.isEmpty()) {
|
||||
if (!keys.isEmpty()) {
|
||||
// Write entry
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLENTRY));
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLKEYS));
|
||||
foreach (const QString &key, keys)
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLKEY), key);
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLENTRY);
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLKEYS);
|
||||
for (const QString &key : keys)
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLKEY, key);
|
||||
stream.writeEndElement();
|
||||
const QString text = QLatin1String("<p><span class=\"option\">")
|
||||
+ keys.filter(QRegExp(QLatin1String("^\\-"))).join(QLatin1String(", "))
|
||||
+ QLatin1String("</span></p><p>")
|
||||
+ (docu.join(QLatin1Char(' ')).toHtmlEscaped())
|
||||
+ QLatin1String("</p>");
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
|
||||
const QString text = "<p><span class=\"option\">"
|
||||
+ keys.filter(QRegExp("^\\-")).join(", ") + "</span></p><p>"
|
||||
+ (docu.join(' ').toHtmlEscaped()) + "</p>";
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLDOC, text);
|
||||
stream.writeEndElement();
|
||||
contextWritten = true;
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "../abstractsettings.h"
|
||||
|
||||
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
|
||||
@@ -63,10 +62,8 @@ public:
|
||||
QString documentationFilePath() const override;
|
||||
void createDocumentationFile() const override;
|
||||
|
||||
private slots:
|
||||
void helperSetVersion();
|
||||
|
||||
private:
|
||||
void helperSetVersion();
|
||||
QFuture<int> m_versionFuture;
|
||||
QFutureWatcher<int> m_versionWatcher;
|
||||
};
|
||||
|
@@ -38,7 +38,7 @@ class BeautifierAbstractTool : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BeautifierAbstractTool(QObject *parent = 0) : QObject(parent) {}
|
||||
explicit BeautifierAbstractTool(QObject *parent = nullptr) : QObject(parent) {}
|
||||
virtual ~BeautifierAbstractTool() {}
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
|
@@ -37,20 +37,15 @@
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <diffeditor/differ.h>
|
||||
#include <texteditor/convenience.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFutureWatcher>
|
||||
@@ -59,7 +54,6 @@
|
||||
#include <QProcess>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBlock>
|
||||
#include <QtPlugin>
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
@@ -79,7 +73,7 @@ FormatTask format(FormatTask task)
|
||||
case Command::FileProcessing: {
|
||||
// Save text to temporary file
|
||||
const QFileInfo fi(task.filePath);
|
||||
Utils::TempFileSaver sourceFile(QDir::tempPath() + QLatin1String("/qtc_beautifier_XXXXXXXX.")
|
||||
Utils::TempFileSaver sourceFile(QDir::tempPath() + "/qtc_beautifier_XXXXXXXX."
|
||||
+ fi.suffix());
|
||||
sourceFile.setAutoRemove(true);
|
||||
sourceFile.write(task.sourceData.toUtf8());
|
||||
@@ -92,7 +86,7 @@ FormatTask format(FormatTask task)
|
||||
// Format temporary file
|
||||
QProcess process;
|
||||
QStringList options = task.command.options();
|
||||
options.replaceInStrings(QLatin1String("%file"), sourceFile.fileName());
|
||||
options.replaceInStrings("%file", sourceFile.fileName());
|
||||
process.start(executable, options);
|
||||
if (!process.waitForFinished(5000)) {
|
||||
process.kill();
|
||||
@@ -103,7 +97,7 @@ FormatTask format(FormatTask task)
|
||||
}
|
||||
const QByteArray output = process.readAllStandardError();
|
||||
if (!output.isEmpty())
|
||||
task.error = executable + QLatin1String(": ") + QString::fromUtf8(output);
|
||||
task.error = executable + ": " + QString::fromUtf8(output);
|
||||
|
||||
// Read text back
|
||||
Utils::FileReader reader;
|
||||
@@ -114,13 +108,13 @@ FormatTask format(FormatTask task)
|
||||
}
|
||||
task.formattedData = QString::fromUtf8(reader.data());
|
||||
return task;
|
||||
} break;
|
||||
}
|
||||
|
||||
case Command::PipeProcessing: {
|
||||
QProcess process;
|
||||
QStringList options = task.command.options();
|
||||
options.replaceInStrings(QLatin1String("%filename"), QFileInfo(task.filePath).fileName());
|
||||
options.replaceInStrings(QLatin1String("%file"), task.filePath);
|
||||
options.replaceInStrings("%filename", QFileInfo(task.filePath).fileName());
|
||||
options.replaceInStrings("%file", task.filePath);
|
||||
process.start(executable, options);
|
||||
if (!process.waitForStarted(3000)) {
|
||||
task.error = QObject::tr("Cannot call %1 or some other error occurred.")
|
||||
@@ -148,9 +142,9 @@ FormatTask format(FormatTask task)
|
||||
if (addsNewline || returnsCRLF) {
|
||||
task.formattedData = QString::fromUtf8(process.readAllStandardOutput());
|
||||
if (addsNewline)
|
||||
task.formattedData.remove(QRegExp(QLatin1String("(\\r\\n|\\n)$")));
|
||||
task.formattedData.remove(QRegExp("(\\r\\n|\\n)$"));
|
||||
if (returnsCRLF)
|
||||
task.formattedData.replace(QLatin1String("\r\n"), QLatin1String("\n"));
|
||||
task.formattedData.replace("\r\n", "\n");
|
||||
return task;
|
||||
}
|
||||
task.formattedData = QString::fromUtf8(process.readAllStandardOutput());
|
||||
@@ -182,10 +176,10 @@ bool BeautifierPlugin::initialize(const QStringList &arguments, QString *errorSt
|
||||
menu->setOnAllDisabledBehavior(Core::ActionContainer::Show);
|
||||
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
|
||||
|
||||
foreach (BeautifierAbstractTool *tool, m_tools) {
|
||||
for (BeautifierAbstractTool *tool : m_tools) {
|
||||
tool->initialize();
|
||||
const QList<QObject *> autoReleasedObjects = tool->autoReleaseObjects();
|
||||
foreach (QObject *object, autoReleasedObjects)
|
||||
for (QObject *object : autoReleasedObjects)
|
||||
addAutoReleasedObject(object);
|
||||
}
|
||||
|
||||
@@ -208,7 +202,7 @@ ExtensionSystem::IPlugin::ShutdownFlag BeautifierPlugin::aboutToShutdown()
|
||||
|
||||
void BeautifierPlugin::updateActions(Core::IEditor *editor)
|
||||
{
|
||||
foreach (BeautifierAbstractTool *tool, m_tools)
|
||||
for (BeautifierAbstractTool *tool : m_tools)
|
||||
tool->updateActions(editor);
|
||||
}
|
||||
|
||||
@@ -333,7 +327,7 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
int newCursorPos = charactersInfrontOfCursor;
|
||||
cursor.beginEditBlock();
|
||||
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
||||
foreach (const DiffEditor::Diff &d, diff) {
|
||||
for (const DiffEditor::Diff &d : diff) {
|
||||
switch (d.command) {
|
||||
case DiffEditor::Diff::Insert:
|
||||
{
|
||||
@@ -344,8 +338,8 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
newCursorPos += size;
|
||||
}
|
||||
// Adjust folded blocks, if a new block is added.
|
||||
if (d.text.contains(QLatin1Char('\n'))) {
|
||||
const int newLineCount = d.text.count(QLatin1Char('\n'));
|
||||
if (d.text.contains('\n')) {
|
||||
const int newLineCount = d.text.count('\n');
|
||||
const int number = cursor.blockNumber();
|
||||
const int total = foldedBlocks.size();
|
||||
for (int i = 0; i < total; ++i) {
|
||||
@@ -354,8 +348,9 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
}
|
||||
}
|
||||
cursor.insertText(d.text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DiffEditor::Diff::Delete:
|
||||
{
|
||||
// Adjust cursor position if we do work in front of the cursor.
|
||||
@@ -368,8 +363,8 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
newCursorPos -= charactersInfrontOfCursor;
|
||||
}
|
||||
// Adjust folded blocks, if at least one block is being deleted.
|
||||
if (d.text.contains(QLatin1Char('\n'))) {
|
||||
const int newLineCount = d.text.count(QLatin1Char('\n'));
|
||||
if (d.text.contains('\n')) {
|
||||
const int newLineCount = d.text.count('\n');
|
||||
const int number = cursor.blockNumber();
|
||||
for (int i = 0, total = foldedBlocks.size(); i < total; ++i) {
|
||||
if (foldedBlocks.at(i) > number) {
|
||||
@@ -384,8 +379,9 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
}
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, d.text.size());
|
||||
cursor.removeSelectedText();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DiffEditor::Diff::Equal:
|
||||
// Adjust cursor position
|
||||
charactersInfrontOfCursor -= d.text.size();
|
||||
@@ -404,7 +400,7 @@ void BeautifierPlugin::updateEditorText(QPlainTextEdit *editor, const QString &t
|
||||
+ absoluteVerticalCursorOffset / fontHeight);
|
||||
// Restore folded blocks
|
||||
const QTextDocument *doc = editor->document();
|
||||
foreach (const int blockId, foldedBlocks) {
|
||||
for (int blockId : foldedBlocks) {
|
||||
const QTextBlock block = doc->findBlockByNumber(qMax(0, blockId));
|
||||
if (block.isValid())
|
||||
TextDocumentLayout::doFoldOrUnfold(block, false);
|
||||
|
@@ -29,10 +29,8 @@
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QFutureInterface>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPointer>
|
||||
#include <QSignalMapper>
|
||||
|
||||
namespace Core { class IEditor; }
|
||||
namespace TextEditor { class TextEditorWidget; }
|
||||
@@ -44,10 +42,6 @@ class BeautifierAbstractTool;
|
||||
|
||||
struct FormatTask
|
||||
{
|
||||
FormatTask() :
|
||||
startPos(-1),
|
||||
endPos(0) {}
|
||||
|
||||
FormatTask(QPlainTextEdit *_editor, const QString &_filePath, const QString &_sourceData,
|
||||
const Command &_command, int _startPos = -1, int _endPos = 0) :
|
||||
editor(_editor),
|
||||
@@ -61,8 +55,8 @@ struct FormatTask
|
||||
QString filePath;
|
||||
QString sourceData;
|
||||
Command command;
|
||||
int startPos;
|
||||
int endPos;
|
||||
int startPos = -1;
|
||||
int endPos = 0;
|
||||
QString formattedData;
|
||||
QString error;
|
||||
};
|
||||
@@ -85,12 +79,9 @@ public:
|
||||
static QString msgCommandPromptDialogTitle(const QString &command);
|
||||
static void showError(const QString &error);
|
||||
|
||||
private slots:
|
||||
void updateActions(Core::IEditor *editor = 0);
|
||||
|
||||
private:
|
||||
void updateActions(Core::IEditor *editor = nullptr);
|
||||
QList<BeautifierAbstractTool *> m_tools;
|
||||
|
||||
void formatEditor(TextEditor::TextEditorWidget *editor, const Command &command,
|
||||
int startPos = -1, int endPos = 0);
|
||||
void formatEditorAsync(TextEditor::TextEditorWidget *editor, const Command &command,
|
||||
|
@@ -39,8 +39,6 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
@@ -48,7 +46,6 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QStringList>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
@@ -69,7 +66,7 @@ ClangFormat::~ClangFormat()
|
||||
bool ClangFormat::initialize()
|
||||
{
|
||||
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ClangFormat::MENU_ID);
|
||||
menu->menu()->setTitle(QLatin1String(Constants::ClangFormat::DISPLAY_NAME));
|
||||
menu->menu()->setTitle(Constants::ClangFormat::DISPLAY_NAME);
|
||||
|
||||
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
|
||||
Core::Command *cmd
|
||||
@@ -98,8 +95,7 @@ void ClangFormat::updateActions(Core::IEditor *editor)
|
||||
|
||||
QList<QObject *> ClangFormat::autoReleaseObjects()
|
||||
{
|
||||
ClangFormatOptionsPage *optionsPage = new ClangFormatOptionsPage(m_settings, this);
|
||||
return QList<QObject *>() << optionsPage;
|
||||
return {new ClangFormatOptionsPage(m_settings, this)};
|
||||
}
|
||||
|
||||
void ClangFormat::formatFile()
|
||||
@@ -131,19 +127,18 @@ Command ClangFormat::command(int offset, int length) const
|
||||
command.setProcessing(Command::PipeProcessing);
|
||||
|
||||
if (m_settings->usePredefinedStyle()) {
|
||||
command.addOption(QLatin1String("-style=") + m_settings->predefinedStyle());
|
||||
command.addOption(QLatin1String("-assume-filename=%filename"));
|
||||
command.addOption("-style=" + m_settings->predefinedStyle());
|
||||
command.addOption("-assume-filename=%filename");
|
||||
} else {
|
||||
command.addOption(QLatin1String("-style=file"));
|
||||
command.addOption("-style=file");
|
||||
const QString path =
|
||||
QFileInfo(m_settings->styleFileName(m_settings->customStyle())).absolutePath();
|
||||
command.addOption(QLatin1String("-assume-filename=") + path + QDir::separator()
|
||||
+ QLatin1String("%filename"));
|
||||
command.addOption("-assume-filename=" + path + QDir::separator() + "%filename");
|
||||
}
|
||||
|
||||
if (offset != -1) {
|
||||
command.addOption(QLatin1String("-offset=") + QString::number(offset));
|
||||
command.addOption(QLatin1String("-length=") + QString::number(length));
|
||||
command.addOption("-offset=" + QString::number(offset));
|
||||
command.addOption("-length=" + QString::number(length));
|
||||
}
|
||||
|
||||
return command;
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "../beautifierabstracttool.h"
|
||||
#include "../command.h"
|
||||
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
|
||||
namespace Beautifier {
|
||||
@@ -45,20 +44,18 @@ class ClangFormat : public BeautifierAbstractTool
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClangFormat(BeautifierPlugin *parent = 0);
|
||||
explicit ClangFormat(BeautifierPlugin *parent = nullptr);
|
||||
virtual ~ClangFormat();
|
||||
bool initialize() override;
|
||||
void updateActions(Core::IEditor *editor) override;
|
||||
QList<QObject *> autoReleaseObjects() override;
|
||||
|
||||
private slots:
|
||||
private:
|
||||
void formatFile();
|
||||
void formatSelectedText();
|
||||
|
||||
private:
|
||||
BeautifierPlugin *m_beautifierPlugin;
|
||||
QAction *m_formatFile;
|
||||
QAction *m_formatRange;
|
||||
QAction *m_formatFile = nullptr;
|
||||
QAction *m_formatRange = nullptr;
|
||||
ClangFormatSettings *m_settings;
|
||||
Command command(int offset = -1, int length = -1) const;
|
||||
};
|
||||
|
@@ -34,24 +34,22 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
namespace ClangFormat {
|
||||
|
||||
ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::ClangFormatOptionsPage)
|
||||
, m_settings(settings)
|
||||
QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ClangFormatOptionsPage),
|
||||
m_settings(settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->options->setEnabled(false);
|
||||
ui->predefinedStyle->addItems(m_settings->predefinedStyles());
|
||||
ui->command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
ui->command->setPromptDialogTitle(
|
||||
BeautifierPlugin::msgCommandPromptDialogTitle(QLatin1String("Clang Format")));
|
||||
BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
|
||||
connect(ui->command, &Utils::PathChooser::validChanged, ui->options, &QWidget::setEnabled);
|
||||
ui->configurations->setSettings(m_settings);
|
||||
}
|
||||
@@ -87,18 +85,15 @@ void ClangFormatOptionsPageWidget::apply()
|
||||
m_settings->save();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
|
||||
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_widget(0),
|
||||
m_settings(settings)
|
||||
{
|
||||
setId(Constants::ClangFormat::OPTION_ID);
|
||||
setDisplayName(tr("Clang Format"));
|
||||
setCategory(Constants::OPTION_CATEGORY);
|
||||
setDisplayCategory(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
|
||||
setCategoryIcon(QLatin1String(Constants::OPTION_CATEGORY_ICON));
|
||||
setCategoryIcon(Constants::OPTION_CATEGORY_ICON);
|
||||
}
|
||||
|
||||
QWidget *ClangFormatOptionsPage::widget()
|
||||
|
@@ -43,7 +43,7 @@ class ClangFormatOptionsPageWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClangFormatOptionsPageWidget(ClangFormatSettings *settings, QWidget *parent = 0);
|
||||
explicit ClangFormatOptionsPageWidget(ClangFormatSettings *settings, QWidget *parent = nullptr);
|
||||
virtual ~ClangFormatOptionsPageWidget();
|
||||
void restore();
|
||||
void apply();
|
||||
@@ -58,7 +58,7 @@ class ClangFormatOptionsPage : public Core::IOptionsPage
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClangFormatOptionsPage(ClangFormatSettings *settings, QObject *parent = 0);
|
||||
explicit ClangFormatOptionsPage(ClangFormatSettings *settings, QObject *parent = nullptr);
|
||||
QWidget *widget() override;
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
|
@@ -39,30 +39,28 @@ namespace Internal {
|
||||
namespace ClangFormat {
|
||||
|
||||
namespace {
|
||||
const char kUsePredefinedStyle[] = "usePredefinedStyle";
|
||||
const char kPredefinedStyle[] = "predefinedStyle";
|
||||
const char kCustomStyle[] = "customStyle";
|
||||
const char kFormatEntireFileFallback[] = "formatEntireFileFallback";
|
||||
const char USE_PREDEFINED_STYLE[] = "usePredefinedStyle";
|
||||
const char PREDEFINED_STYLE[] = "predefinedStyle";
|
||||
const char CUSTOM_STYLE[] = "customStyle";
|
||||
const char FORMAT_ENTIRE_FILE_FALLBACK[] = "formatEntireFileFallback";
|
||||
}
|
||||
|
||||
ClangFormatSettings::ClangFormatSettings() :
|
||||
AbstractSettings(QLatin1String(Constants::ClangFormat::SETTINGS_NAME),
|
||||
QLatin1String(".clang-format"))
|
||||
AbstractSettings(Constants::ClangFormat::SETTINGS_NAME, ".clang-format")
|
||||
{
|
||||
setCommand(QLatin1String("clang-format"));
|
||||
m_settings.insert(QLatin1String(kUsePredefinedStyle), QVariant(true));
|
||||
m_settings.insert(QLatin1String(kPredefinedStyle), QLatin1String("LLVM"));
|
||||
m_settings.insert(QLatin1String(kCustomStyle), QVariant());
|
||||
m_settings.insert(QLatin1String(kFormatEntireFileFallback), QVariant(true));
|
||||
setCommand("clang-format");
|
||||
m_settings.insert(USE_PREDEFINED_STYLE, QVariant(true));
|
||||
m_settings.insert(PREDEFINED_STYLE, "LLVM");
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant());
|
||||
m_settings.insert(FORMAT_ENTIRE_FILE_FALLBACK, QVariant(true));
|
||||
read();
|
||||
}
|
||||
|
||||
QString ClangFormatSettings::documentationFilePath() const
|
||||
{
|
||||
return Core::ICore::userResourcePath() + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::DOCUMENTATION_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Constants::ClangFormat::SETTINGS_NAME) + QLatin1String(".xml");
|
||||
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
|
||||
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
|
||||
+ Constants::ClangFormat::SETTINGS_NAME + ".xml";
|
||||
}
|
||||
|
||||
void ClangFormatSettings::createDocumentationFile() const
|
||||
@@ -76,71 +74,70 @@ void ClangFormatSettings::createDocumentationFile() const
|
||||
|
||||
QXmlStreamWriter stream(&file);
|
||||
stream.setAutoFormatting(true);
|
||||
stream.writeStartDocument(QLatin1String("1.0"), true);
|
||||
stream.writeComment(QLatin1String("Created ")
|
||||
+ QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLROOT));
|
||||
stream.writeStartDocument("1.0", true);
|
||||
stream.writeComment("Created " + QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLROOT);
|
||||
|
||||
const QStringList lines = QStringList()
|
||||
<< QLatin1String("BasedOnStyle {string: LLVM, Google, Chromium, Mozilla, WebKit}")
|
||||
<< QLatin1String("AccessModifierOffset {int}")
|
||||
<< QLatin1String("AlignEscapedNewlinesLeft {bool}")
|
||||
<< QLatin1String("AlignTrailingComments {bool}")
|
||||
<< QLatin1String("AllowAllParametersOfDeclarationOnNextLine {bool}")
|
||||
<< QLatin1String("AllowShortFunctionsOnASingleLine {bool}")
|
||||
<< QLatin1String("AllowShortIfStatementsOnASingleLine {bool}")
|
||||
<< QLatin1String("AllowShortLoopsOnASingleLine {bool}")
|
||||
<< QLatin1String("AlwaysBreakBeforeMultilineStrings {bool}")
|
||||
<< QLatin1String("AlwaysBreakTemplateDeclarations {bool}")
|
||||
<< QLatin1String("BinPackParameters {bool}")
|
||||
<< QLatin1String("BreakBeforeBinaryOperators {bool}")
|
||||
<< QLatin1String("BreakBeforeBraces {BraceBreakingStyle: BS_Attach, BS_Linux, BS_Stroustrup, BS_Allman, BS_GNU}")
|
||||
<< QLatin1String("BreakBeforeTernaryOperators {bool}")
|
||||
<< QLatin1String("BreakConstructorInitializersBeforeComma {bool}")
|
||||
<< QLatin1String("ColumnLimit {unsigned}")
|
||||
<< QLatin1String("CommentPragmas {string}")
|
||||
<< QLatin1String("ConstructorInitializerAllOnOneLineOrOnePerLine {bool}")
|
||||
<< QLatin1String("ConstructorInitializerIndentWidth {unsigned}")
|
||||
<< QLatin1String("ContinuationIndentWidth {unsigned}")
|
||||
<< QLatin1String("Cpp11BracedListStyle {bool}")
|
||||
<< QLatin1String("IndentCaseLabels {bool}")
|
||||
<< QLatin1String("IndentFunctionDeclarationAfterType {bool}")
|
||||
<< QLatin1String("IndentWidth {unsigned}")
|
||||
<< QLatin1String("Language {LanguageKind: LK_None, LK_Cpp, LK_JavaScript, LK_Proto}")
|
||||
<< QLatin1String("MaxEmptyLinesToKeep {unsigned}")
|
||||
<< QLatin1String("NamespaceIndentation {NamespaceIndentationKind: NI_None, NI_Inner, NI_All}")
|
||||
<< QLatin1String("ObjCSpaceAfterProperty {bool}")
|
||||
<< QLatin1String("ObjCSpaceBeforeProtocolList {bool}")
|
||||
<< QLatin1String("PenaltyBreakBeforeFirstCallParameter {unsigned}")
|
||||
<< QLatin1String("PenaltyBreakComment {unsigned}")
|
||||
<< QLatin1String("PenaltyBreakFirstLessLess {unsigned}")
|
||||
<< QLatin1String("PenaltyBreakString {unsigned}")
|
||||
<< QLatin1String("PenaltyExcessCharacter {unsigned}")
|
||||
<< QLatin1String("PenaltyReturnTypeOnItsOwnLine {unsigned}")
|
||||
<< QLatin1String("PointerBindsToType {bool}")
|
||||
<< QLatin1String("SpaceBeforeAssignmentOperators {bool}")
|
||||
<< QLatin1String("SpaceBeforeParens {SpaceBeforeParensOptions: SBPO_Never, SBPO_ControlStatements, SBPO_Always}")
|
||||
<< QLatin1String("SpaceInEmptyParentheses {bool}")
|
||||
<< QLatin1String("SpacesBeforeTrailingComments {unsigned}")
|
||||
<< QLatin1String("SpacesInAngles {bool}")
|
||||
<< QLatin1String("SpacesInCStyleCastParentheses {bool}")
|
||||
<< QLatin1String("SpacesInContainerLiterals {bool}")
|
||||
<< QLatin1String("SpacesInParentheses {bool}")
|
||||
<< QLatin1String("Standard {LanguageStandard: LS_Cpp03, LS_Cpp11, LS_Auto}")
|
||||
<< QLatin1String("TabWidth {unsigned}")
|
||||
<< QLatin1String("UseTab {UseTabStyle: UT_Never, UT_ForIndentation, UT_Always}");
|
||||
const QStringList lines = {
|
||||
"BasedOnStyle {string: LLVM, Google, Chromium, Mozilla, WebKit}",
|
||||
"AccessModifierOffset {int}",
|
||||
"AlignEscapedNewlinesLeft {bool}",
|
||||
"AlignTrailingComments {bool}",
|
||||
"AllowAllParametersOfDeclarationOnNextLine {bool}",
|
||||
"AllowShortFunctionsOnASingleLine {bool}",
|
||||
"AllowShortIfStatementsOnASingleLine {bool}",
|
||||
"AllowShortLoopsOnASingleLine {bool}",
|
||||
"AlwaysBreakBeforeMultilineStrings {bool}",
|
||||
"AlwaysBreakTemplateDeclarations {bool}",
|
||||
"BinPackParameters {bool}",
|
||||
"BreakBeforeBinaryOperators {bool}",
|
||||
"BreakBeforeBraces {BraceBreakingStyle: BS_Attach, BS_Linux, BS_Stroustrup, BS_Allman, BS_GNU}",
|
||||
"BreakBeforeTernaryOperators {bool}",
|
||||
"BreakConstructorInitializersBeforeComma {bool}",
|
||||
"ColumnLimit {unsigned}",
|
||||
"CommentPragmas {string}",
|
||||
"ConstructorInitializerAllOnOneLineOrOnePerLine {bool}",
|
||||
"ConstructorInitializerIndentWidth {unsigned}",
|
||||
"ContinuationIndentWidth {unsigned}",
|
||||
"Cpp11BracedListStyle {bool}",
|
||||
"IndentCaseLabels {bool}",
|
||||
"IndentFunctionDeclarationAfterType {bool}",
|
||||
"IndentWidth {unsigned}",
|
||||
"Language {LanguageKind: LK_None, LK_Cpp, LK_JavaScript, LK_Proto}",
|
||||
"MaxEmptyLinesToKeep {unsigned}",
|
||||
"NamespaceIndentation {NamespaceIndentationKind: NI_None, NI_Inner, NI_All}",
|
||||
"ObjCSpaceAfterProperty {bool}",
|
||||
"ObjCSpaceBeforeProtocolList {bool}",
|
||||
"PenaltyBreakBeforeFirstCallParameter {unsigned}",
|
||||
"PenaltyBreakComment {unsigned}",
|
||||
"PenaltyBreakFirstLessLess {unsigned}",
|
||||
"PenaltyBreakString {unsigned}",
|
||||
"PenaltyExcessCharacter {unsigned}",
|
||||
"PenaltyReturnTypeOnItsOwnLine {unsigned}",
|
||||
"PointerBindsToType {bool}",
|
||||
"SpaceBeforeAssignmentOperators {bool}",
|
||||
"SpaceBeforeParens {SpaceBeforeParensOptions: SBPO_Never, SBPO_ControlStatements, SBPO_Always}",
|
||||
"SpaceInEmptyParentheses {bool}",
|
||||
"SpacesBeforeTrailingComments {unsigned}",
|
||||
"SpacesInAngles {bool}",
|
||||
"SpacesInCStyleCastParentheses {bool}",
|
||||
"SpacesInContainerLiterals {bool}",
|
||||
"SpacesInParentheses {bool}",
|
||||
"Standard {LanguageStandard: LS_Cpp03, LS_Cpp11, LS_Auto}",
|
||||
"TabWidth {unsigned}",
|
||||
"UseTab {UseTabStyle: UT_Never, UT_ForIndentation, UT_Always}"
|
||||
};
|
||||
|
||||
foreach (const QString& line, lines) {
|
||||
const int firstSpace = line.indexOf(QLatin1Char(' '));
|
||||
for (const QString& line : lines) {
|
||||
const int firstSpace = line.indexOf(' ');
|
||||
const QString keyword = line.left(firstSpace);
|
||||
const QString options = line.right(line.size() - firstSpace).trimmed();
|
||||
const QString text = QLatin1String("<p><span class=\"option\">") + keyword
|
||||
+ QLatin1String("</span> <span class=\"param\">") + options
|
||||
+ QLatin1String("</span></p><p>") + tr("No description available.")
|
||||
+ QLatin1String("</p>");
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLENTRY));
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLKEY), keyword);
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
|
||||
const QString text = "<p><span class=\"option\">" + keyword
|
||||
+ "</span> <span class=\"param\">" + options
|
||||
+ "</span></p><p>" + tr("No description available.") + "</p>";
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLENTRY);
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLKEY, keyword);
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLDOC, text);
|
||||
stream.writeEndElement();
|
||||
}
|
||||
|
||||
@@ -150,90 +147,85 @@ void ClangFormatSettings::createDocumentationFile() const
|
||||
|
||||
QStringList ClangFormatSettings::completerWords()
|
||||
{
|
||||
QStringList words;
|
||||
words << QLatin1String("LLVM")
|
||||
<< QLatin1String("Google")
|
||||
<< QLatin1String("Chromium")
|
||||
<< QLatin1String("Mozilla")
|
||||
<< QLatin1String("WebKit")
|
||||
<< QLatin1String("BS_Attach")
|
||||
<< QLatin1String("BS_Linux")
|
||||
<< QLatin1String("BS_Stroustrup")
|
||||
<< QLatin1String("BS_Allman")
|
||||
<< QLatin1String("NI_None")
|
||||
<< QLatin1String("NI_Inner")
|
||||
<< QLatin1String("NI_All")
|
||||
<< QLatin1String("LS_Cpp03")
|
||||
<< QLatin1String("LS_Cpp11")
|
||||
<< QLatin1String("LS_Auto")
|
||||
<< QLatin1String("UT_Never")
|
||||
<< QLatin1String("UT_ForIndentation")
|
||||
<< QLatin1String("UT_Always");
|
||||
return words;
|
||||
return {
|
||||
"LLVM",
|
||||
"Google",
|
||||
"Chromium",
|
||||
"Mozilla",
|
||||
"WebKit",
|
||||
"BS_Attach",
|
||||
"BS_Linux",
|
||||
"BS_Stroustrup",
|
||||
"BS_Allman",
|
||||
"NI_None",
|
||||
"NI_Inner",
|
||||
"NI_All",
|
||||
"LS_Cpp03",
|
||||
"LS_Cpp11",
|
||||
"LS_Auto",
|
||||
"UT_Never",
|
||||
"UT_ForIndentation",
|
||||
"UT_Always"
|
||||
};
|
||||
}
|
||||
|
||||
bool ClangFormatSettings::usePredefinedStyle() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kUsePredefinedStyle)).toBool();
|
||||
return m_settings.value(USE_PREDEFINED_STYLE).toBool();
|
||||
}
|
||||
|
||||
void ClangFormatSettings::setUsePredefinedStyle(bool usePredefinedStyle)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kUsePredefinedStyle), QVariant(usePredefinedStyle));
|
||||
m_settings.insert(USE_PREDEFINED_STYLE, QVariant(usePredefinedStyle));
|
||||
}
|
||||
|
||||
QString ClangFormatSettings::predefinedStyle() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kPredefinedStyle)).toString();
|
||||
return m_settings.value(PREDEFINED_STYLE).toString();
|
||||
}
|
||||
|
||||
void ClangFormatSettings::setPredefinedStyle(const QString &predefinedStyle)
|
||||
{
|
||||
const QStringList test = predefinedStyles();
|
||||
if (test.contains(predefinedStyle))
|
||||
m_settings.insert(QLatin1String(kPredefinedStyle), QVariant(predefinedStyle));
|
||||
m_settings.insert(PREDEFINED_STYLE, QVariant(predefinedStyle));
|
||||
}
|
||||
|
||||
QString ClangFormatSettings::customStyle() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kCustomStyle)).toString();
|
||||
return m_settings.value(CUSTOM_STYLE).toString();
|
||||
}
|
||||
|
||||
void ClangFormatSettings::setCustomStyle(const QString &customStyle)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kCustomStyle), QVariant(customStyle));
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant(customStyle));
|
||||
}
|
||||
|
||||
bool ClangFormatSettings::formatEntireFileFallback() const
|
||||
{
|
||||
return m_settings.value(QLatin1String(kFormatEntireFileFallback)).toBool();
|
||||
return m_settings.value(FORMAT_ENTIRE_FILE_FALLBACK).toBool();
|
||||
}
|
||||
|
||||
void ClangFormatSettings::setFormatEntireFileFallback(bool formatEntireFileFallback)
|
||||
{
|
||||
m_settings.insert(QLatin1String(kFormatEntireFileFallback), QVariant(formatEntireFileFallback));
|
||||
m_settings.insert(FORMAT_ENTIRE_FILE_FALLBACK, QVariant(formatEntireFileFallback));
|
||||
}
|
||||
|
||||
QStringList ClangFormatSettings::predefinedStyles() const
|
||||
{
|
||||
return QStringList() << QLatin1String("LLVM")
|
||||
<< QLatin1String("Google")
|
||||
<< QLatin1String("Chromium")
|
||||
<< QLatin1String("Mozilla")
|
||||
<< QLatin1String("WebKit")
|
||||
<< QLatin1String("File");
|
||||
return {"LLVM", "Google", "Chromium", "Mozilla", "WebKit", "File"};
|
||||
}
|
||||
|
||||
QString ClangFormatSettings::styleFileName(const QString &key) const
|
||||
{
|
||||
return m_styleDir.absolutePath() + QLatin1Char('/') + key + QLatin1Char('/') + m_ending;
|
||||
return m_styleDir.absolutePath() + '/' + key + '/' + m_ending;
|
||||
}
|
||||
|
||||
void ClangFormatSettings::readStyles()
|
||||
{
|
||||
const QStringList dirs = m_styleDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
||||
for (const QString &dir : dirs) {
|
||||
QFile file(m_styleDir.absoluteFilePath(dir + QLatin1Char('/') + m_ending));
|
||||
QFile file(m_styleDir.absoluteFilePath(dir + '/' + m_ending));
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
m_styles.insert(dir, QString::fromLocal8Bit(file.readAll()));
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@
|
||||
|
||||
#include "../abstractsettings.h"
|
||||
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
namespace ClangFormat {
|
||||
|
@@ -28,13 +28,6 @@
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
|
||||
Command::Command()
|
||||
: m_processing(FileProcessing)
|
||||
, m_pipeAddsNewline(false)
|
||||
, m_returnsCRLF(false)
|
||||
{
|
||||
}
|
||||
|
||||
QString Command::executable() const
|
||||
{
|
||||
return m_executable;
|
||||
@@ -85,6 +78,5 @@ void Command::setReturnsCRLF(bool returnsCRLF)
|
||||
m_returnsCRLF = returnsCRLF;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Beautifier
|
||||
|
@@ -39,8 +39,6 @@ public:
|
||||
PipeProcessing
|
||||
};
|
||||
|
||||
Command();
|
||||
|
||||
QString executable() const;
|
||||
void setExecutable(const QString &executable);
|
||||
|
||||
@@ -59,9 +57,9 @@ public:
|
||||
private:
|
||||
QString m_executable;
|
||||
QStringList m_options;
|
||||
Processing m_processing;
|
||||
bool m_pipeAddsNewline;
|
||||
bool m_returnsCRLF;
|
||||
Processing m_processing = FileProcessing;
|
||||
bool m_pipeAddsNewline = false;
|
||||
bool m_returnsCRLF = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -39,14 +39,13 @@ namespace Internal {
|
||||
|
||||
ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ConfigurationDialog),
|
||||
m_settings(0)
|
||||
ui(new Ui::ConfigurationDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Filter out characters which are not allowed in a file name
|
||||
QRegExpValidator *fileNameValidator = new QRegExpValidator(ui->name);
|
||||
fileNameValidator->setRegExp(QRegExp(QLatin1String("^[^\\/\\\\\\?\\>\\<\\*\\%\\:\\\"\\']*$")));
|
||||
fileNameValidator->setRegExp(QRegExp("^[^\\/\\\\\\?\\>\\<\\*\\%\\:\\\"\\']*$"));
|
||||
ui->name->setValidator(fileNameValidator);
|
||||
|
||||
updateDocumentation();
|
||||
@@ -77,16 +76,15 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
|
||||
const QTextCharFormat tfOption = fs.toTextCharFormat(TextEditor::C_FIELD);
|
||||
const QTextCharFormat tfParam = fs.toTextCharFormat(TextEditor::C_STRING);
|
||||
|
||||
const QString css = QString::fromLatin1("span.param {color: %1; background-color: %2;} "
|
||||
"span.option {color: %3; background-color: %4;} "
|
||||
"p { text-align: justify; } ")
|
||||
const QString css = QString::fromLatin1("span.param {color: %1; background-color: %2;} "
|
||||
"span.option {color: %3; background-color: %4;} "
|
||||
"p {text-align: justify;}")
|
||||
.arg(tfParam.foreground().color().name())
|
||||
.arg(tfParam.background().style() == Qt::NoBrush
|
||||
? QString() : tfParam.background().color().name())
|
||||
.arg(tfOption.foreground().color().name())
|
||||
.arg(tfOption.background().style() == Qt::NoBrush
|
||||
? QString() : tfOption.background().color().name())
|
||||
;
|
||||
? QString() : tfOption.background().color().name());
|
||||
ui->documentation->document()->setDefaultStyleSheet(css);
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,6 @@ namespace Beautifier {
|
||||
namespace Internal {
|
||||
|
||||
class AbstractSettings;
|
||||
|
||||
namespace Ui { class ConfigurationDialog; }
|
||||
|
||||
class ConfigurationDialog : public QDialog
|
||||
@@ -40,7 +39,7 @@ class ConfigurationDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigurationDialog(QWidget *parent = 0);
|
||||
explicit ConfigurationDialog(QWidget *parent = nullptr);
|
||||
~ConfigurationDialog();
|
||||
void setSettings(AbstractSettings *settings);
|
||||
|
||||
@@ -49,13 +48,11 @@ public:
|
||||
void setKey(const QString &key);
|
||||
QString value() const;
|
||||
|
||||
private slots:
|
||||
private:
|
||||
void updateOkButton();
|
||||
void updateDocumentation(const QString &word = QString(), const QString &docu = QString());
|
||||
|
||||
private:
|
||||
Ui::ConfigurationDialog *ui;
|
||||
AbstractSettings *m_settings;
|
||||
AbstractSettings *m_settings = nullptr;
|
||||
QString m_currentKey;
|
||||
};
|
||||
|
||||
|
@@ -46,7 +46,7 @@ ConfigurationSyntaxHighlighter::ConfigurationSyntaxHighlighter(QTextDocument *pa
|
||||
m_formatKeyword = fs.toTextCharFormat(TextEditor::C_FIELD);
|
||||
m_formatComment = fs.toTextCharFormat(TextEditor::C_COMMENT);
|
||||
|
||||
m_expressionComment.setPattern(QLatin1String("#[^\\n]*"));
|
||||
m_expressionComment.setPattern("#[^\\n]*");
|
||||
m_expressionComment.setMinimal(false);
|
||||
}
|
||||
|
||||
@@ -57,13 +57,12 @@ void ConfigurationSyntaxHighlighter::setKeywords(const QStringList &keywords)
|
||||
|
||||
// Check for empty keywords since they can cause an endless loop in highlightBlock().
|
||||
QStringList pattern;
|
||||
foreach (const QString &word, keywords) {
|
||||
for (const QString &word : keywords) {
|
||||
if (!word.isEmpty())
|
||||
pattern << QRegExp::escape(word);
|
||||
}
|
||||
|
||||
m_expressionKeyword.setPattern(QLatin1String("(?:\\s|^)(") + pattern.join(QLatin1Char('|'))
|
||||
+ QLatin1String(")(?=\\s|\\:|\\=|\\,|$)"));
|
||||
m_expressionKeyword.setPattern("(?:\\s|^)(" + pattern.join('|') + ")(?=\\s|\\:|\\=|\\,|$)");
|
||||
}
|
||||
|
||||
void ConfigurationSyntaxHighlighter::setCommentExpression(const QRegExp &rx)
|
||||
@@ -92,12 +91,11 @@ void ConfigurationSyntaxHighlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationEditor::ConfigurationEditor(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
, m_settings(0)
|
||||
, m_completer(new QCompleter(this))
|
||||
, m_model(new QStringListModel(QStringList(), m_completer))
|
||||
, m_highlighter(new ConfigurationSyntaxHighlighter(document()))
|
||||
ConfigurationEditor::ConfigurationEditor(QWidget *parent) :
|
||||
QPlainTextEdit(parent),
|
||||
m_completer(new QCompleter(this)),
|
||||
m_model(new QStringListModel(QStringList(), m_completer)),
|
||||
m_highlighter(new ConfigurationSyntaxHighlighter(document()))
|
||||
{
|
||||
m_completer->setModel(m_model);
|
||||
m_completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
|
||||
@@ -203,13 +201,13 @@ QTextCursor ConfigurationEditor::cursorForTextUnderCursor(QTextCursor tc) const
|
||||
|
||||
tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor);
|
||||
QChar ch = document()->characterAt(tc.position() - 1);
|
||||
while (!(ch.isNull() || ch.isSpace() || ch == QLatin1Char(':') || ch == QLatin1Char(','))) {
|
||||
while (!(ch.isNull() || ch.isSpace() || ch == ':' || ch == ',')) {
|
||||
tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
|
||||
ch = document()->characterAt(tc.position() - 1);
|
||||
}
|
||||
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
ch = document()->characterAt(tc.position());
|
||||
while (!(ch.isNull() || ch.isSpace() || ch == QLatin1Char(':') || ch == QLatin1Char(','))) {
|
||||
while (!(ch.isNull() || ch.isSpace() || ch == ':' || ch == ',')) {
|
||||
tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
|
||||
ch = document()->characterAt(tc.position());
|
||||
}
|
||||
@@ -246,7 +244,7 @@ void ConfigurationEditor::updateDocumentation()
|
||||
// in front of a colon for providing a documentation.
|
||||
cursor.movePosition(QTextCursor::PreviousWord);
|
||||
cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
||||
const int pos = cursor.selectedText().lastIndexOf(QLatin1Char(','));
|
||||
const int pos = cursor.selectedText().lastIndexOf(',');
|
||||
if (-1 != pos) {
|
||||
cursor.setPosition(cursor.position() + pos);
|
||||
cursor.movePosition(QTextCursor::NextWord);
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
@@ -35,7 +34,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QCompleter;
|
||||
class QRegExp;
|
||||
class QStringListModel;
|
||||
class QTextDocument;
|
||||
QT_END_NAMESPACE
|
||||
@@ -69,7 +67,7 @@ class ConfigurationEditor : public QPlainTextEdit
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigurationEditor(QWidget *parent = 0);
|
||||
explicit ConfigurationEditor(QWidget *parent = nullptr);
|
||||
void setSettings(AbstractSettings *settings);
|
||||
void setCommentExpression(const QRegExp &rx);
|
||||
|
||||
@@ -77,17 +75,15 @@ protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void insertCompleterText(const QString &text);
|
||||
void updateDocumentation();
|
||||
|
||||
signals:
|
||||
void documentationChanged(const QString &word, const QString &documentation);
|
||||
|
||||
private:
|
||||
void insertCompleterText(const QString &text);
|
||||
void updateDocumentation();
|
||||
QTextCursor cursorForTextUnderCursor(QTextCursor tc = QTextCursor()) const;
|
||||
|
||||
AbstractSettings *m_settings;
|
||||
AbstractSettings *m_settings = nullptr;
|
||||
QCompleter *m_completer;
|
||||
QStringListModel *m_model;
|
||||
ConfigurationSyntaxHighlighter *m_highlighter;
|
||||
|
@@ -29,15 +29,12 @@
|
||||
#include "abstractsettings.h"
|
||||
#include "configurationdialog.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
namespace Beautifier {
|
||||
namespace Internal {
|
||||
|
||||
ConfigurationPanel::ConfigurationPanel(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ConfigurationPanel),
|
||||
m_settings(0)
|
||||
ui(new Ui::ConfigurationPanel)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->add, &QPushButton::clicked, this, &ConfigurationPanel::add);
|
||||
@@ -81,7 +78,7 @@ void ConfigurationPanel::add()
|
||||
ConfigurationDialog dialog;
|
||||
dialog.setWindowTitle(tr("Add Configuration"));
|
||||
dialog.setSettings(m_settings);
|
||||
if (QDialog::Accepted == dialog.exec()) {
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
const QString key = dialog.key();
|
||||
m_settings->setStyle(key, dialog.value());
|
||||
populateConfigurations(key);
|
||||
@@ -95,7 +92,7 @@ void ConfigurationPanel::edit()
|
||||
dialog.setWindowTitle(tr("Edit Configuration"));
|
||||
dialog.setSettings(m_settings);
|
||||
dialog.setKey(key);
|
||||
if (QDialog::Accepted == dialog.exec()) {
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
const QString newKey = dialog.key();
|
||||
if (newKey == key) {
|
||||
m_settings->setStyle(key, dialog.value());
|
||||
@@ -108,7 +105,7 @@ void ConfigurationPanel::edit()
|
||||
|
||||
void ConfigurationPanel::populateConfigurations(const QString &key)
|
||||
{
|
||||
ui->configurations->blockSignals(true);
|
||||
const bool block = ui->configurations->blockSignals(true);
|
||||
const QString currentText = (!key.isEmpty()) ? key : ui->configurations->currentText();
|
||||
ui->configurations->clear();
|
||||
ui->configurations->addItems(m_settings->styles());
|
||||
@@ -116,14 +113,13 @@ void ConfigurationPanel::populateConfigurations(const QString &key)
|
||||
if (textIndex != -1)
|
||||
ui->configurations->setCurrentIndex(textIndex);
|
||||
updateButtons();
|
||||
ui->configurations->blockSignals(false);
|
||||
ui->configurations->blockSignals(block);
|
||||
}
|
||||
|
||||
void ConfigurationPanel::updateButtons()
|
||||
{
|
||||
const bool enabled
|
||||
= ((ui->configurations->count() > 0)
|
||||
&& !m_settings->styleIsReadOnly(ui->configurations->currentText()));
|
||||
const bool enabled = ((ui->configurations->count() > 0)
|
||||
&& !m_settings->styleIsReadOnly(ui->configurations->currentText()));
|
||||
ui->remove->setEnabled(enabled);
|
||||
ui->edit->setEnabled(enabled);
|
||||
}
|
||||
|
@@ -31,8 +31,6 @@ namespace Beautifier {
|
||||
namespace Internal {
|
||||
|
||||
class AbstractSettings;
|
||||
class ConfigurationDialog;
|
||||
|
||||
namespace Ui { class ConfigurationPanel; }
|
||||
|
||||
class ConfigurationPanel : public QWidget
|
||||
@@ -40,22 +38,20 @@ class ConfigurationPanel : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigurationPanel(QWidget *parent = 0);
|
||||
explicit ConfigurationPanel(QWidget *parent = nullptr);
|
||||
~ConfigurationPanel();
|
||||
|
||||
void setSettings(AbstractSettings *settings);
|
||||
void setCurrentConfiguration(const QString &text);
|
||||
QString currentConfiguration() const;
|
||||
|
||||
private slots:
|
||||
private:
|
||||
void remove();
|
||||
void add();
|
||||
void edit();
|
||||
void updateButtons();
|
||||
|
||||
private:
|
||||
Ui::ConfigurationPanel *ui;
|
||||
AbstractSettings *m_settings;
|
||||
AbstractSettings *m_settings = nullptr;
|
||||
void populateConfigurations(const QString &key = QString());
|
||||
};
|
||||
|
||||
|
@@ -39,8 +39,6 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
@@ -58,8 +56,6 @@ namespace Uncrustify {
|
||||
Uncrustify::Uncrustify(BeautifierPlugin *parent) :
|
||||
BeautifierAbstractTool(parent),
|
||||
m_beautifierPlugin(parent),
|
||||
m_formatFile(nullptr),
|
||||
m_formatRange(nullptr),
|
||||
m_settings(new UncrustifySettings)
|
||||
{
|
||||
}
|
||||
@@ -72,7 +68,7 @@ Uncrustify::~Uncrustify()
|
||||
bool Uncrustify::initialize()
|
||||
{
|
||||
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::Uncrustify::MENU_ID);
|
||||
menu->menu()->setTitle(QLatin1String(Constants::Uncrustify::DISPLAY_NAME));
|
||||
menu->menu()->setTitle(Constants::Uncrustify::DISPLAY_NAME);
|
||||
|
||||
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
|
||||
Core::Command *cmd
|
||||
@@ -101,8 +97,7 @@ void Uncrustify::updateActions(Core::IEditor *editor)
|
||||
|
||||
QList<QObject *> Uncrustify::autoReleaseObjects()
|
||||
{
|
||||
UncrustifyOptionsPage *optionsPage = new UncrustifyOptionsPage(m_settings, this);
|
||||
return QList<QObject *>() << optionsPage;
|
||||
return {new UncrustifyOptionsPage(m_settings, this)};
|
||||
}
|
||||
|
||||
void Uncrustify::formatFile()
|
||||
@@ -110,7 +105,7 @@ void Uncrustify::formatFile()
|
||||
const QString cfgFileName = configurationFile();
|
||||
if (cfgFileName.isEmpty()) {
|
||||
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
||||
QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
|
||||
Constants::Uncrustify::DISPLAY_NAME));
|
||||
} else {
|
||||
m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
|
||||
}
|
||||
@@ -121,7 +116,7 @@ void Uncrustify::formatSelectedText()
|
||||
const QString cfgFileName = configurationFile();
|
||||
if (cfgFileName.isEmpty()) {
|
||||
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
|
||||
QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
|
||||
Constants::Uncrustify::DISPLAY_NAME));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,18 +149,18 @@ QString Uncrustify::configurationFile() const
|
||||
if (const ProjectExplorer::Project *project
|
||||
= ProjectExplorer::ProjectTree::currentProject()) {
|
||||
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
|
||||
foreach (const QString &file, files) {
|
||||
if (!file.endsWith(QLatin1String("cfg")))
|
||||
for (const QString &file : files) {
|
||||
if (!file.endsWith("cfg"))
|
||||
continue;
|
||||
const QFileInfo fi(file);
|
||||
if (fi.isReadable() && fi.fileName() == QLatin1String("uncrustify.cfg"))
|
||||
if (fi.isReadable() && fi.fileName() == "uncrustify.cfg")
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_settings->useHomeFile()) {
|
||||
const QString file = QDir::home().filePath(QLatin1String("uncrustify.cfg"));
|
||||
const QString file = QDir::home().filePath("uncrustify.cfg");
|
||||
if (QFile::exists(file))
|
||||
return file;
|
||||
}
|
||||
@@ -179,17 +174,17 @@ Command Uncrustify::command(const QString &cfgFile, bool fragment) const
|
||||
command.setExecutable(m_settings->command());
|
||||
command.setProcessing(Command::PipeProcessing);
|
||||
if (m_settings->version() >= 62) {
|
||||
command.addOption(QLatin1String("--assume"));
|
||||
command.addOption(QLatin1String("%file"));
|
||||
command.addOption("--assume");
|
||||
command.addOption("%file");
|
||||
} else {
|
||||
command.addOption(QLatin1String("-l"));
|
||||
command.addOption(QLatin1String("cpp"));
|
||||
command.addOption("-l");
|
||||
command.addOption("cpp");
|
||||
}
|
||||
command.addOption(QLatin1String("-L"));
|
||||
command.addOption(QLatin1String("1-2"));
|
||||
command.addOption("-L");
|
||||
command.addOption("1-2");
|
||||
if (fragment)
|
||||
command.addOption(QLatin1String("--frag"));
|
||||
command.addOption(QLatin1String("-c"));
|
||||
command.addOption("--frag");
|
||||
command.addOption("-c");
|
||||
command.addOption(cfgFile);
|
||||
return command;
|
||||
}
|
||||
|
@@ -44,20 +44,18 @@ class Uncrustify : public BeautifierAbstractTool
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Uncrustify(BeautifierPlugin *parent = 0);
|
||||
explicit Uncrustify(BeautifierPlugin *parent = nullptr);
|
||||
virtual ~Uncrustify();
|
||||
bool initialize() override;
|
||||
void updateActions(Core::IEditor *editor) override;
|
||||
QList<QObject *> autoReleaseObjects() override;
|
||||
|
||||
private slots:
|
||||
private:
|
||||
void formatFile();
|
||||
void formatSelectedText();
|
||||
|
||||
private:
|
||||
BeautifierPlugin *m_beautifierPlugin;
|
||||
QAction *m_formatFile;
|
||||
QAction *m_formatRange;
|
||||
QAction *m_formatFile = nullptr;
|
||||
QAction *m_formatRange = nullptr;
|
||||
UncrustifySettings *m_settings;
|
||||
QString configurationFile() const;
|
||||
Command command(const QString &cfgFile, bool fragment = false) const;
|
||||
|
@@ -41,18 +41,17 @@ namespace Internal {
|
||||
namespace Uncrustify {
|
||||
|
||||
UncrustifyOptionsPageWidget::UncrustifyOptionsPageWidget(UncrustifySettings *settings,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::UncrustifyOptionsPage)
|
||||
, m_settings(settings)
|
||||
QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::UncrustifyOptionsPage),
|
||||
m_settings(settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->useHomeFile->setText(ui->useHomeFile->text().replace(
|
||||
QLatin1String("HOME"),
|
||||
QDir::toNativeSeparators(QDir::home().absolutePath())));
|
||||
"HOME", QDir::toNativeSeparators(QDir::home().absolutePath())));
|
||||
ui->command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
ui->command->setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle(
|
||||
QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
|
||||
Constants::Uncrustify::DISPLAY_NAME));
|
||||
connect(ui->command, &Utils::PathChooser::validChanged, ui->options, &QWidget::setEnabled);
|
||||
ui->configurations->setSettings(m_settings);
|
||||
}
|
||||
@@ -83,18 +82,15 @@ void UncrustifyOptionsPageWidget::apply()
|
||||
m_settings->save();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
|
||||
UncrustifyOptionsPage::UncrustifyOptionsPage(UncrustifySettings *settings, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_widget(0),
|
||||
m_settings(settings)
|
||||
{
|
||||
setId(Constants::Uncrustify::OPTION_ID);
|
||||
setDisplayName(tr("Uncrustify"));
|
||||
setCategory(Constants::OPTION_CATEGORY);
|
||||
setDisplayCategory(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
|
||||
setCategoryIcon(QLatin1String(Constants::OPTION_CATEGORY_ICON));
|
||||
setCategoryIcon(Constants::OPTION_CATEGORY_ICON);
|
||||
}
|
||||
|
||||
QWidget *UncrustifyOptionsPage::widget()
|
||||
|
@@ -43,7 +43,7 @@ class UncrustifyOptionsPageWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UncrustifyOptionsPageWidget(UncrustifySettings *settings, QWidget *parent = 0);
|
||||
explicit UncrustifyOptionsPageWidget(UncrustifySettings *settings, QWidget *parent = nullptr);
|
||||
virtual ~UncrustifyOptionsPageWidget();
|
||||
void restore();
|
||||
void apply();
|
||||
@@ -58,7 +58,7 @@ class UncrustifyOptionsPage : public Core::IOptionsPage
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UncrustifyOptionsPage(UncrustifySettings *settings, QObject *parent = 0);
|
||||
explicit UncrustifyOptionsPage(UncrustifySettings *settings, QObject *parent = nullptr);
|
||||
QWidget *widget() override;
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
|
@@ -34,7 +34,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
@@ -43,91 +42,90 @@ namespace Internal {
|
||||
namespace Uncrustify {
|
||||
|
||||
namespace {
|
||||
const QString kUseOtherFiles = QLatin1String("useOtherFiles");
|
||||
const QString kUseHomeFile = QLatin1String("useHomeFile");
|
||||
const QString kUseCustomStyle = QLatin1String("useCustomStyle");
|
||||
const QString kCustomStyle = QLatin1String("customStyle");
|
||||
const QString kFormatEntireFileFallback = QLatin1String("formatEntireFileFallback");
|
||||
const char USE_OTHER_FILES[] = "useOtherFiles";
|
||||
const char USE_HOME_FILE[] = "useHomeFile";
|
||||
const char USE_CUSTOM_STYLE[] = "useCustomStyle";
|
||||
const char CUSTOM_STYLE[] = "customStyle";
|
||||
const char FORMAT_ENTIRE_FILE_FALLBACK[] = "formatEntireFileFallback";
|
||||
}
|
||||
|
||||
UncrustifySettings::UncrustifySettings() :
|
||||
AbstractSettings(QLatin1String(Constants::Uncrustify::SETTINGS_NAME), QLatin1String(".cfg"))
|
||||
AbstractSettings(Constants::Uncrustify::SETTINGS_NAME, ".cfg")
|
||||
{
|
||||
connect(&m_versionProcess,
|
||||
static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||
this, &UncrustifySettings::parseVersionProcessResult);
|
||||
|
||||
setCommand(QLatin1String("uncrustify"));
|
||||
m_settings.insert(kUseOtherFiles, QVariant(true));
|
||||
m_settings.insert(kUseHomeFile, QVariant(false));
|
||||
m_settings.insert(kUseCustomStyle, QVariant(false));
|
||||
m_settings.insert(kCustomStyle, QVariant());
|
||||
m_settings.insert(kFormatEntireFileFallback, QVariant(true));
|
||||
setCommand("uncrustify");
|
||||
m_settings.insert(USE_OTHER_FILES, QVariant(true));
|
||||
m_settings.insert(USE_HOME_FILE, QVariant(false));
|
||||
m_settings.insert(USE_CUSTOM_STYLE, QVariant(false));
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant());
|
||||
m_settings.insert(FORMAT_ENTIRE_FILE_FALLBACK, QVariant(true));
|
||||
read();
|
||||
}
|
||||
|
||||
bool UncrustifySettings::useOtherFiles() const
|
||||
{
|
||||
return m_settings.value(kUseOtherFiles).toBool();
|
||||
return m_settings.value(USE_OTHER_FILES).toBool();
|
||||
}
|
||||
|
||||
void UncrustifySettings::setUseOtherFiles(bool useOtherFiles)
|
||||
{
|
||||
m_settings.insert(kUseOtherFiles, QVariant(useOtherFiles));
|
||||
m_settings.insert(USE_OTHER_FILES, QVariant(useOtherFiles));
|
||||
}
|
||||
|
||||
bool UncrustifySettings::useHomeFile() const
|
||||
{
|
||||
return m_settings.value(kUseHomeFile).toBool();
|
||||
return m_settings.value(USE_HOME_FILE).toBool();
|
||||
}
|
||||
|
||||
void UncrustifySettings::setUseHomeFile(bool useHomeFile)
|
||||
{
|
||||
m_settings.insert(kUseHomeFile, QVariant(useHomeFile));
|
||||
m_settings.insert(USE_HOME_FILE, QVariant(useHomeFile));
|
||||
}
|
||||
|
||||
bool UncrustifySettings::useCustomStyle() const
|
||||
{
|
||||
return m_settings.value(kUseCustomStyle).toBool();
|
||||
return m_settings.value(USE_CUSTOM_STYLE).toBool();
|
||||
}
|
||||
|
||||
void UncrustifySettings::setUseCustomStyle(bool useCustomStyle)
|
||||
{
|
||||
m_settings.insert(kUseCustomStyle, QVariant(useCustomStyle));
|
||||
m_settings.insert(USE_CUSTOM_STYLE, QVariant(useCustomStyle));
|
||||
}
|
||||
|
||||
QString UncrustifySettings::customStyle() const
|
||||
{
|
||||
return m_settings.value(kCustomStyle).toString();
|
||||
return m_settings.value(CUSTOM_STYLE).toString();
|
||||
}
|
||||
|
||||
void UncrustifySettings::setCustomStyle(const QString &customStyle)
|
||||
{
|
||||
m_settings.insert(kCustomStyle, QVariant(customStyle));
|
||||
m_settings.insert(CUSTOM_STYLE, QVariant(customStyle));
|
||||
}
|
||||
|
||||
bool UncrustifySettings::formatEntireFileFallback() const
|
||||
{
|
||||
return m_settings.value(kFormatEntireFileFallback).toBool();
|
||||
return m_settings.value(FORMAT_ENTIRE_FILE_FALLBACK).toBool();
|
||||
}
|
||||
|
||||
void UncrustifySettings::setFormatEntireFileFallback(bool formatEntireFileFallback)
|
||||
{
|
||||
m_settings.insert(kFormatEntireFileFallback, QVariant(formatEntireFileFallback));
|
||||
m_settings.insert(FORMAT_ENTIRE_FILE_FALLBACK, QVariant(formatEntireFileFallback));
|
||||
}
|
||||
|
||||
QString UncrustifySettings::documentationFilePath() const
|
||||
{
|
||||
return Core::ICore::userResourcePath() + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Beautifier::Constants::DOCUMENTATION_DIRNAME) + QLatin1Char('/')
|
||||
+ QLatin1String(Constants::Uncrustify::SETTINGS_NAME) + QLatin1String(".xml");
|
||||
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
|
||||
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
|
||||
+ Constants::Uncrustify::SETTINGS_NAME + ".xml";
|
||||
}
|
||||
|
||||
void UncrustifySettings::createDocumentationFile() const
|
||||
{
|
||||
QProcess process;
|
||||
process.start(command(), QStringList() << QLatin1String("--show-config"));
|
||||
process.start(command(), {"--show-config"});
|
||||
process.waitForFinished(2000); // show config should be really fast.
|
||||
if (process.error() != QProcess::UnknownError)
|
||||
return;
|
||||
@@ -142,33 +140,30 @@ void UncrustifySettings::createDocumentationFile() const
|
||||
bool contextWritten = false;
|
||||
QXmlStreamWriter stream(&file);
|
||||
stream.setAutoFormatting(true);
|
||||
stream.writeStartDocument(QLatin1String("1.0"), true);
|
||||
stream.writeComment(QLatin1String("Created ")
|
||||
+ QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLROOT));
|
||||
stream.writeStartDocument("1.0", true);
|
||||
stream.writeComment("Created " + QDateTime::currentDateTime().toString(Qt::ISODate));
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLROOT);
|
||||
|
||||
const QStringList lines = QString::fromUtf8(process.readAll()).split(QLatin1Char('\n'));
|
||||
const QStringList lines = QString::fromUtf8(process.readAll()).split('\n');
|
||||
const int totalLines = lines.count();
|
||||
for (int i = 0; i < totalLines; ++i) {
|
||||
const QString &line = lines.at(i);
|
||||
if (line.startsWith(QLatin1Char('#')) || line.trimmed().isEmpty())
|
||||
if (line.startsWith('#') || line.trimmed().isEmpty())
|
||||
continue;
|
||||
|
||||
const int firstSpace = line.indexOf(QLatin1Char(' '));
|
||||
const int firstSpace = line.indexOf(' ');
|
||||
const QString keyword = line.left(firstSpace);
|
||||
const QString options = line.right(line.size() - firstSpace).trimmed();
|
||||
QStringList docu;
|
||||
while (++i < totalLines) {
|
||||
const QString &subline = lines.at(i);
|
||||
if (line.startsWith(QLatin1Char('#')) || subline.trimmed().isEmpty()) {
|
||||
const QString text = QLatin1String("<p><span class=\"option\">") + keyword
|
||||
+ QLatin1String("</span> <span class=\"param\">") + options
|
||||
+ QLatin1String("</span></p><p>")
|
||||
+ (docu.join(QLatin1Char(' ')).toHtmlEscaped())
|
||||
+ QLatin1String("</p>");
|
||||
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLENTRY));
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLKEY), keyword);
|
||||
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
|
||||
if (line.startsWith('#') || subline.trimmed().isEmpty()) {
|
||||
const QString text = "<p><span class=\"option\">" + keyword
|
||||
+ "</span> <span class=\"param\">" + options
|
||||
+ "</span></p><p>" + docu.join(' ').toHtmlEscaped() + "</p>";
|
||||
stream.writeStartElement(Constants::DOCUMENTATION_XMLENTRY);
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLKEY, keyword);
|
||||
stream.writeTextElement(Constants::DOCUMENTATION_XMLDOC, text);
|
||||
stream.writeEndElement();
|
||||
contextWritten = true;
|
||||
break;
|
||||
@@ -192,7 +187,7 @@ void UncrustifySettings::createDocumentationFile() const
|
||||
static bool parseVersion(const QString &text, int &version)
|
||||
{
|
||||
// The version in Uncrustify is printed like "uncrustify 0.62"
|
||||
const QRegularExpression rx(QLatin1String("([0-9]{1})\\.([0-9]{2})"));
|
||||
const QRegularExpression rx("([0-9]{1})\\.([0-9]{2})");
|
||||
const QRegularExpressionMatch match = rx.match(text);
|
||||
if (!match.hasMatch())
|
||||
return false;
|
||||
@@ -209,7 +204,7 @@ void UncrustifySettings::updateVersion()
|
||||
m_versionProcess.kill();
|
||||
m_versionProcess.waitForFinished();
|
||||
}
|
||||
m_versionProcess.start(command(), QStringList() << QLatin1String("--version"));
|
||||
m_versionProcess.start(command(), {"--version"});
|
||||
}
|
||||
|
||||
void UncrustifySettings::parseVersionProcessResult(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
|
Reference in New Issue
Block a user