forked from qt-creator/qt-creator
C++: Add support for prefixes in switch header/source
Task-number: QTCREATORBUG-11031 Change-Id: I93cce0ebf46984eb06094e1f1519717be2bbaa79 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Petar Perisin
parent
4eff289e03
commit
1fd576c1f6
@@ -51,6 +51,8 @@
|
||||
#include <QTextStream>
|
||||
#include <QFileDialog>
|
||||
|
||||
static const char headerPrefixesKeyC[] = "HeaderPrefixes";
|
||||
static const char sourcePrefixesKeyC[] = "SourcePrefixes";
|
||||
static const char headerSuffixKeyC[] = "HeaderSuffix";
|
||||
static const char sourceSuffixKeyC[] = "SourceSuffix";
|
||||
static const char headerSearchPathsKeyC[] = "HeaderSearchPaths";
|
||||
@@ -76,6 +78,8 @@ CppFileSettings::CppFileSettings() :
|
||||
void CppFileSettings::toSettings(QSettings *s) const
|
||||
{
|
||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||
s->setValue(QLatin1String(headerPrefixesKeyC), headerPrefixes);
|
||||
s->setValue(QLatin1String(sourcePrefixesKeyC), sourcePrefixes);
|
||||
s->setValue(QLatin1String(headerSuffixKeyC), headerSuffix);
|
||||
s->setValue(QLatin1String(sourceSuffixKeyC), sourceSuffix);
|
||||
s->setValue(QLatin1String(headerSearchPathsKeyC), headerSearchPaths);
|
||||
@@ -97,7 +101,9 @@ void CppFileSettings::fromSettings(QSettings *s)
|
||||
<< QDir::toNativeSeparators(QLatin1String("../Src"))
|
||||
<< QLatin1String("..");
|
||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||
headerSuffix= s->value(QLatin1String(headerSuffixKeyC), QLatin1String("h")).toString();
|
||||
headerPrefixes = s->value(QLatin1String(headerPrefixesKeyC)).toStringList();
|
||||
sourcePrefixes = s->value(QLatin1String(sourcePrefixesKeyC)).toStringList();
|
||||
headerSuffix = s->value(QLatin1String(headerSuffixKeyC), QLatin1String("h")).toString();
|
||||
sourceSuffix = s->value(QLatin1String(sourceSuffixKeyC), QLatin1String("cpp")).toString();
|
||||
headerSearchPaths = s->value(QLatin1String(headerSearchPathsKeyC), defaultHeaderSearchPaths)
|
||||
.toStringList();
|
||||
@@ -118,6 +124,8 @@ bool CppFileSettings::applySuffixesToMimeDB()
|
||||
bool CppFileSettings::equals(const CppFileSettings &rhs) const
|
||||
{
|
||||
return lowerCaseFiles == rhs.lowerCaseFiles
|
||||
&& headerPrefixes == rhs.headerPrefixes
|
||||
&& sourcePrefixes == rhs.sourcePrefixes
|
||||
&& headerSuffix == rhs.headerSuffix
|
||||
&& sourceSuffix == rhs.sourceSuffix
|
||||
&& headerSearchPaths == rhs.headerSearchPaths
|
||||
@@ -285,6 +293,8 @@ CppFileSettings CppFileSettingsWidget::settings() const
|
||||
{
|
||||
CppFileSettings rc;
|
||||
rc.lowerCaseFiles = m_ui->lowerCaseFileNamesCheckBox->isChecked();
|
||||
rc.headerPrefixes = trimmedPaths(m_ui->headerPrefixesEdit->text());
|
||||
rc.sourcePrefixes = trimmedPaths(m_ui->sourcePrefixesEdit->text());
|
||||
rc.headerSuffix = m_ui->headerSuffixComboBox->currentText();
|
||||
rc.sourceSuffix = m_ui->sourceSuffixComboBox->currentText();
|
||||
rc.headerSearchPaths = trimmedPaths(m_ui->headerSearchPathsEdit->text());
|
||||
@@ -302,6 +312,8 @@ static inline void setComboText(QComboBox *cb, const QString &text, int defaultI
|
||||
void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
|
||||
{
|
||||
m_ui->lowerCaseFileNamesCheckBox->setChecked(s.lowerCaseFiles);
|
||||
m_ui->headerPrefixesEdit->setText(s.headerPrefixes.join(QLatin1String(",")));
|
||||
m_ui->sourcePrefixesEdit->setText(s.sourcePrefixes.join(QLatin1String(",")));
|
||||
setComboText(m_ui->headerSuffixComboBox, s.headerSuffix);
|
||||
setComboText(m_ui->sourceSuffixComboBox, s.sourceSuffix);
|
||||
m_ui->headerSearchPathsEdit->setText(s.headerSearchPaths.join(QLatin1String(",")));
|
||||
|
||||
@@ -49,8 +49,10 @@ struct CppFileSettings
|
||||
{
|
||||
CppFileSettings();
|
||||
|
||||
QStringList headerPrefixes;
|
||||
QString headerSuffix;
|
||||
QStringList headerSearchPaths;
|
||||
QStringList sourcePrefixes;
|
||||
QString sourceSuffix;
|
||||
QStringList sourceSearchPaths;
|
||||
bool lowerCaseFiles;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>547</width>
|
||||
<height>305</height>
|
||||
<height>363</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@@ -23,7 +23,7 @@
|
||||
<string>Headers</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="0" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="headerSuffixLabel">
|
||||
<property name="text">
|
||||
<string>&Suffix:</string>
|
||||
@@ -33,7 +33,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="headerSuffixComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
@@ -43,7 +43,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="headerSearchPathsLabel">
|
||||
<property name="text">
|
||||
<string>S&earch paths:</string>
|
||||
@@ -53,7 +53,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="headerSearchPathsEdit">
|
||||
<property name="toolTip">
|
||||
<string>Comma-separated list of header paths.
|
||||
@@ -64,6 +64,25 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="headerPrefixesLabel">
|
||||
<property name="text">
|
||||
<string>&Prefixes:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>headerSearchPathsEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="headerPrefixesEdit">
|
||||
<property name="toolTip">
|
||||
<string>Comma-separated list of header prefixes.
|
||||
|
||||
These prefixes are used in addition to current file name on Switch Header/Source.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -79,7 +98,7 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
<string>Sources</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_3">
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="sourceSuffixLabel">
|
||||
<property name="text">
|
||||
<string>S&uffix:</string>
|
||||
@@ -89,7 +108,7 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="sourceSuffixComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
@@ -99,7 +118,7 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="sourceSearchPathsLabel">
|
||||
<property name="text">
|
||||
<string>Se&arch paths:</string>
|
||||
@@ -109,7 +128,7 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="sourceSearchPathsEdit">
|
||||
<property name="toolTip">
|
||||
<string>Comma-separated list of source paths.
|
||||
@@ -120,6 +139,25 @@ These paths are used in addition to current directory on Switch Header/Source.</
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="sourcePrefixesLabel">
|
||||
<property name="text">
|
||||
<string>P&refixes:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>sourceSearchPathsEdit</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="sourcePrefixesEdit">
|
||||
<property name="toolTip">
|
||||
<string>Comma-separated list of source prefixes.
|
||||
|
||||
These prefixes are used in addition to current file name on Switch Header/Source.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cppfilesettingspage.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
@@ -81,16 +82,31 @@ void CppToolsPlugin::test_headersource_data()
|
||||
QTest::addColumn<QString>("headerFileName");
|
||||
QTest::newRow("samedir") << _("foo.cpp") << _("foo.h");
|
||||
QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h");
|
||||
QTest::newRow("headerprefix") << _("foo.cpp") << _("testh_foo.h");
|
||||
QTest::newRow("sourceprefixwsub") << _("testc_foo.cpp") << _("include/foo.h");
|
||||
QTest::newRow("sourceAndHeaderPrefixWithBothsub") << _("src/testc_foo.cpp") << _("include/testh_foo.h");
|
||||
}
|
||||
|
||||
void CppToolsPlugin::initTestCase()
|
||||
{
|
||||
QDir(baseTestDir()).mkpath(_("."));
|
||||
m_fileSettings->headerSearchPaths.append(QLatin1String("include"));
|
||||
m_fileSettings->headerSearchPaths.append(QLatin1String("../include"));
|
||||
m_fileSettings->sourceSearchPaths.append(QLatin1String("src"));
|
||||
m_fileSettings->sourceSearchPaths.append(QLatin1String("../src"));
|
||||
m_fileSettings->headerPrefixes.append(QLatin1String("testh_"));
|
||||
m_fileSettings->sourcePrefixes.append(QLatin1String("testc_"));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::cleanupTestCase()
|
||||
{
|
||||
Utils::FileUtils::removeRecursively(Utils::FileName::fromString(baseTestDir()));
|
||||
m_fileSettings->headerSearchPaths.removeLast();
|
||||
m_fileSettings->headerSearchPaths.removeLast();
|
||||
m_fileSettings->sourceSearchPaths.removeLast();
|
||||
m_fileSettings->sourceSearchPaths.removeLast();
|
||||
m_fileSettings->headerPrefixes.removeLast();
|
||||
m_fileSettings->sourcePrefixes.removeLast();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -106,6 +106,17 @@ const QStringList &CppToolsPlugin::sourceSearchPaths()
|
||||
return m_instance->m_fileSettings->sourceSearchPaths;
|
||||
}
|
||||
|
||||
const QStringList &CppToolsPlugin::headerPrefixes()
|
||||
{
|
||||
return m_instance->m_fileSettings->headerPrefixes;
|
||||
}
|
||||
|
||||
const QStringList &CppToolsPlugin::sourcePrefixes()
|
||||
{
|
||||
return m_instance->m_fileSettings->sourcePrefixes;
|
||||
}
|
||||
|
||||
|
||||
bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
@@ -256,6 +267,28 @@ static QStringList baseNameWithAllSuffixes(const QString &baseName, const QStrin
|
||||
return result;
|
||||
}
|
||||
|
||||
static QStringList baseNamesWithAllPrefixes(const QStringList &baseNames, bool isHeader)
|
||||
{
|
||||
QStringList result;
|
||||
const QStringList &sourcePrefixes = m_instance->sourcePrefixes();
|
||||
const QStringList &headerPrefixes = m_instance->headerPrefixes();
|
||||
|
||||
foreach (const QString &name, baseNames) {
|
||||
foreach (const QString &prefix, isHeader ? headerPrefixes : sourcePrefixes) {
|
||||
if (name.startsWith(prefix)) {
|
||||
QString nameWithoutPrefix = name.mid(prefix.size());
|
||||
result += nameWithoutPrefix;
|
||||
foreach (const QString &prefix, isHeader ? sourcePrefixes : headerPrefixes)
|
||||
result += prefix + nameWithoutPrefix;
|
||||
}
|
||||
}
|
||||
foreach (const QString &prefix, isHeader ? sourcePrefixes : headerPrefixes)
|
||||
result += prefix + name;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static QStringList baseDirWithAllDirectories(const QDir &baseDir, const QStringList &directories)
|
||||
{
|
||||
QStringList result;
|
||||
@@ -346,6 +379,8 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
|
||||
: m_instance->headerSearchPaths();
|
||||
candidateDirs += baseDirWithAllDirectories(absoluteDir, searchPaths);
|
||||
|
||||
candidateFileNames += baseNamesWithAllPrefixes(candidateFileNames, isHeader);
|
||||
|
||||
// Try to find a file in the same or sibling directories first
|
||||
foreach (const QString &candidateDir, candidateDirs) {
|
||||
foreach (const QString &candidateFileName, candidateFileNames) {
|
||||
|
||||
@@ -63,6 +63,8 @@ public:
|
||||
static CppToolsPlugin *instance();
|
||||
static const QStringList &headerSearchPaths();
|
||||
static const QStringList &sourceSearchPaths();
|
||||
static const QStringList &headerPrefixes();
|
||||
static const QStringList &sourcePrefixes();
|
||||
static void clearHeaderSourceCache();
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user