summaryrefslogtreecommitdiff
path: root/src/plugins/beautifier
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/beautifier')
-rw-r--r--src/plugins/beautifier/artisticstyle/artisticstyle.cpp69
-rw-r--r--src/plugins/beautifier/artisticstyle/artisticstyle.h4
-rw-r--r--src/plugins/beautifier/uncrustify/uncrustify.cpp55
-rw-r--r--src/plugins/beautifier/uncrustify/uncrustify.h4
4 files changed, 74 insertions, 58 deletions
diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
index e6ffd8808c..06e48f40a2 100644
--- a/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
+++ b/src/plugins/beautifier/artisticstyle/artisticstyle.cpp
@@ -101,7 +101,19 @@ QList<QObject *> ArtisticStyle::autoReleaseObjects()
void ArtisticStyle::formatFile()
{
- QString cfgFileName;
+ const QString cfgFileName = configurationFile();
+ if (cfgFileName.isEmpty()) {
+ BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
+ QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
+ } else {
+ m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
+ }
+}
+
+QString ArtisticStyle::configurationFile() const
+{
+ if (m_settings->useCustomStyle())
+ return m_settings->styleFileName(m_settings->customStyle());
if (m_settings->useOtherFiles()) {
if (const ProjectExplorer::Project *project
@@ -112,48 +124,41 @@ void ArtisticStyle::formatFile()
if (!file.endsWith(QLatin1String(".astylerc")))
continue;
const QFileInfo fi(file);
- if (fi.isReadable()) {
- cfgFileName = file;
- break;
- }
+ if (fi.isReadable())
+ return file;
}
}
}
- if (cfgFileName.isEmpty() && m_settings->useHomeFile()) {
+ if (m_settings->useHomeFile()) {
const QDir homeDirectory = QDir::home();
QString file = homeDirectory.filePath(QLatin1String(".astylerc"));
- if (QFile::exists(file)) {
- cfgFileName = file;
- } else {
- file = homeDirectory.filePath(QLatin1String("astylerc"));
- if (QFile::exists(file))
- cfgFileName = file;
- }
+ if (QFile::exists(file))
+ return file;
+ file = homeDirectory.filePath(QLatin1String("astylerc"));
+ if (QFile::exists(file))
+ return file;
}
- if (m_settings->useCustomStyle())
- cfgFileName = m_settings->styleFileName(m_settings->customStyle());
+ return QString();
+}
- if (cfgFileName.isEmpty()) {
- BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
- QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
+Command ArtisticStyle::command(const QString &cfgFile) const
+{
+ Command command;
+ command.setExecutable(m_settings->command());
+ command.addOption(QLatin1String("-q"));
+ command.addOption(QLatin1String("--options=") + cfgFile);
+
+ if (m_settings->version() > ArtisticStyleSettings::Version_2_03) {
+ command.setProcessing(Command::PipeProcessing);
+ command.setPipeAddsNewline(true);
+ command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
} else {
- Command command;
- command.setExecutable(m_settings->command());
- command.addOption(QLatin1String("-q"));
- command.addOption(QLatin1String("--options=") + cfgFileName);
-
- 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"));
- }
-
- m_beautifierPlugin->formatCurrentFile(command);
+ command.addOption(QLatin1String("%file"));
}
+
+ return command;
}
} // namespace ArtisticStyle
diff --git a/src/plugins/beautifier/artisticstyle/artisticstyle.h b/src/plugins/beautifier/artisticstyle/artisticstyle.h
index e362fdd5fa..c839f3480b 100644
--- a/src/plugins/beautifier/artisticstyle/artisticstyle.h
+++ b/src/plugins/beautifier/artisticstyle/artisticstyle.h
@@ -32,7 +32,7 @@
#define BEAUTIFIER_ARTISTICSTYLE_H
#include "../beautifierabstracttool.h"
-
+#include "../command.h"
QT_FORWARD_DECLARE_CLASS(QAction)
@@ -63,6 +63,8 @@ private:
BeautifierPlugin *m_beautifierPlugin;
QAction *m_formatFile;
ArtisticStyleSettings *m_settings;
+ QString configurationFile() const;
+ Command command(const QString &cfgFile) const;
};
} // namespace ArtisticStyle
diff --git a/src/plugins/beautifier/uncrustify/uncrustify.cpp b/src/plugins/beautifier/uncrustify/uncrustify.cpp
index 1e8aa673a8..594ee41784 100644
--- a/src/plugins/beautifier/uncrustify/uncrustify.cpp
+++ b/src/plugins/beautifier/uncrustify/uncrustify.cpp
@@ -102,7 +102,19 @@ QList<QObject *> Uncrustify::autoReleaseObjects()
void Uncrustify::formatFile()
{
- QString cfgFileName;
+ const QString cfgFileName = configurationFile();
+ if (cfgFileName.isEmpty()) {
+ BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
+ QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
+ } else {
+ m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
+ }
+}
+
+QString Uncrustify::configurationFile() const
+{
+ if (m_settings->useCustomStyle())
+ return m_settings->styleFileName(m_settings->customStyle());
if (m_settings->useOtherFiles()) {
if (const ProjectExplorer::Project *project
@@ -113,38 +125,33 @@ void Uncrustify::formatFile()
if (!file.endsWith(QLatin1String("cfg")))
continue;
const QFileInfo fi(file);
- if (fi.isReadable() && fi.fileName() == QLatin1String("uncrustify.cfg")) {
- cfgFileName = file;
- break;
- }
+ if (fi.isReadable() && fi.fileName() == QLatin1String("uncrustify.cfg"))
+ return file;
}
}
}
- if (cfgFileName.isEmpty() && m_settings->useHomeFile()) {
+ if (m_settings->useHomeFile()) {
const QString file = QDir::home().filePath(QLatin1String("uncrustify.cfg"));
if (QFile::exists(file))
- cfgFileName = file;
+ return file;
}
- if (m_settings->useCustomStyle())
- cfgFileName = m_settings->styleFileName(m_settings->customStyle());
+ return QString();
+}
- if (cfgFileName.isEmpty()) {
- BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
- QLatin1String(Constants::Uncrustify::DISPLAY_NAME)));
- } else {
- Command command;
- command.setExecutable(m_settings->command());
- command.setProcessing(Command::PipeProcessing);
- command.addOption(QLatin1String("-l"));
- command.addOption(QLatin1String("cpp"));
- command.addOption(QLatin1String("-L"));
- command.addOption(QLatin1String("1-2"));
- command.addOption(QLatin1String("-c"));
- command.addOption(cfgFileName);
- m_beautifierPlugin->formatCurrentFile(command);
- }
+Command Uncrustify::command(const QString &cfgFile) const
+{
+ Command command;
+ command.setExecutable(m_settings->command());
+ command.setProcessing(Command::PipeProcessing);
+ command.addOption(QLatin1String("-l"));
+ command.addOption(QLatin1String("cpp"));
+ command.addOption(QLatin1String("-L"));
+ command.addOption(QLatin1String("1-2"));
+ command.addOption(QLatin1String("-c"));
+ command.addOption(cfgFile);
+ return command;
}
} // namespace Uncrustify
diff --git a/src/plugins/beautifier/uncrustify/uncrustify.h b/src/plugins/beautifier/uncrustify/uncrustify.h
index 5c85aefea5..64f6b08f98 100644
--- a/src/plugins/beautifier/uncrustify/uncrustify.h
+++ b/src/plugins/beautifier/uncrustify/uncrustify.h
@@ -32,7 +32,7 @@
#define BEAUTIFIER_UNCRUSTIFY_H
#include "../beautifierabstracttool.h"
-
+#include "../command.h"
QT_FORWARD_DECLARE_CLASS(QAction)
@@ -63,6 +63,8 @@ private:
BeautifierPlugin *m_beautifierPlugin;
QAction *m_formatFile;
UncrustifySettings *m_settings;
+ QString configurationFile() const;
+ Command command(const QString &cfgFile) const;
};
} // namespace Uncrustify