forked from qt-creator/qt-creator
		
	C++: Custom directory list for Switch Header/Source
Some projects use separate directories for sources and headers.
An example tree:
*
|-- src
     |-- foo.cpp
|-- include
     |-- foo.h
Allow the user to specify directories for finding out-of-project related
header/source files, in addition to current directory
Task-number: QTCREATORBUG-8883
Change-Id: I57215c8f2feffcc246d0d161798290861bcfcdd4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
			
			
This commit is contained in:
		
				
					committed by
					
						
						Orgad Shaneh
					
				
			
			
				
	
			
			
			
						parent
						
							d0385537b2
						
					
				
				
					commit
					adee8336bb
				
			@@ -30,6 +30,7 @@
 | 
			
		||||
#include "cppfilesettingspage.h"
 | 
			
		||||
 | 
			
		||||
#include "cpptoolsconstants.h"
 | 
			
		||||
#include "cpptoolsplugin.h"
 | 
			
		||||
#include <ui_cppfilesettingspage.h>
 | 
			
		||||
 | 
			
		||||
#include <coreplugin/icore.h>
 | 
			
		||||
@@ -52,6 +53,8 @@
 | 
			
		||||
 | 
			
		||||
static const char headerSuffixKeyC[] = "HeaderSuffix";
 | 
			
		||||
static const char sourceSuffixKeyC[] = "SourceSuffix";
 | 
			
		||||
static const char headerSearchPathsKeyC[] = "HeaderSearchPaths";
 | 
			
		||||
static const char sourceSearchPathsKeyC[] = "SourceSearchPaths";
 | 
			
		||||
static const char licenseTemplatePathKeyC[] = "LicenseTemplate";
 | 
			
		||||
 | 
			
		||||
const char *licenseTemplateTemplate = QT_TRANSLATE_NOOP("CppTools::Internal::CppFileSettingsWidget",
 | 
			
		||||
@@ -75,6 +78,8 @@ void CppFileSettings::toSettings(QSettings *s) const
 | 
			
		||||
    s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
 | 
			
		||||
    s->setValue(QLatin1String(headerSuffixKeyC), headerSuffix);
 | 
			
		||||
    s->setValue(QLatin1String(sourceSuffixKeyC), sourceSuffix);
 | 
			
		||||
    s->setValue(QLatin1String(headerSearchPathsKeyC), headerSearchPaths);
 | 
			
		||||
    s->setValue(QLatin1String(sourceSearchPathsKeyC), sourceSearchPaths);
 | 
			
		||||
    s->setValue(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), lowerCaseFiles);
 | 
			
		||||
    s->setValue(QLatin1String(licenseTemplatePathKeyC), licenseTemplatePath);
 | 
			
		||||
    s->endGroup();
 | 
			
		||||
@@ -82,9 +87,22 @@ void CppFileSettings::toSettings(QSettings *s) const
 | 
			
		||||
 | 
			
		||||
void CppFileSettings::fromSettings(QSettings *s)
 | 
			
		||||
{
 | 
			
		||||
    const QStringList defaultHeaderSearchPaths = QStringList()
 | 
			
		||||
            << QLatin1String("include")
 | 
			
		||||
            << QLatin1String("Include")
 | 
			
		||||
            << QDir::toNativeSeparators(QLatin1String("../include"))
 | 
			
		||||
            << QDir::toNativeSeparators(QLatin1String("../Include"));
 | 
			
		||||
    const QStringList defaultSourceSearchPaths = QStringList()
 | 
			
		||||
            << QDir::toNativeSeparators(QLatin1String("../src"))
 | 
			
		||||
            << QDir::toNativeSeparators(QLatin1String("../Src"))
 | 
			
		||||
            << QLatin1String("..");
 | 
			
		||||
    s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
 | 
			
		||||
    headerSuffix= s->value(QLatin1String(headerSuffixKeyC), QLatin1String("h")).toString();
 | 
			
		||||
    sourceSuffix = s->value(QLatin1String(sourceSuffixKeyC), QLatin1String("cpp")).toString();
 | 
			
		||||
    headerSearchPaths = s->value(QLatin1String(headerSearchPathsKeyC), defaultHeaderSearchPaths)
 | 
			
		||||
            .toStringList();
 | 
			
		||||
    sourceSearchPaths = s->value(QLatin1String(sourceSearchPathsKeyC), defaultSourceSearchPaths)
 | 
			
		||||
            .toStringList();
 | 
			
		||||
    const bool lowerCaseDefault = Constants::lowerCaseFilesDefault;
 | 
			
		||||
    lowerCaseFiles = s->value(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), QVariant(lowerCaseDefault)).toBool();
 | 
			
		||||
    licenseTemplatePath = s->value(QLatin1String(licenseTemplatePathKeyC), QString()).toString();
 | 
			
		||||
@@ -102,6 +120,8 @@ bool CppFileSettings::equals(const CppFileSettings &rhs) const
 | 
			
		||||
    return lowerCaseFiles == rhs.lowerCaseFiles
 | 
			
		||||
           && headerSuffix == rhs.headerSuffix
 | 
			
		||||
           && sourceSuffix == rhs.sourceSuffix
 | 
			
		||||
           && headerSearchPaths == rhs.headerSearchPaths
 | 
			
		||||
           && sourceSearchPaths == rhs.sourceSearchPaths
 | 
			
		||||
           && licenseTemplatePath == rhs.licenseTemplatePath;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -252,12 +272,22 @@ void CppFileSettingsWidget::setLicenseTemplatePath(const QString &lp)
 | 
			
		||||
    m_ui->licenseTemplatePathChooser->setPath(lp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static QStringList trimmedPaths(const QString &paths)
 | 
			
		||||
{
 | 
			
		||||
    QStringList res;
 | 
			
		||||
    foreach (const QString &path, paths.split(QLatin1Char(','), QString::SkipEmptyParts))
 | 
			
		||||
        res << path.trimmed();
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CppFileSettings CppFileSettingsWidget::settings() const
 | 
			
		||||
{
 | 
			
		||||
    CppFileSettings rc;
 | 
			
		||||
    rc.lowerCaseFiles = m_ui->lowerCaseFileNamesCheckBox->isChecked();
 | 
			
		||||
    rc.headerSuffix = m_ui->headerSuffixComboBox->currentText();
 | 
			
		||||
    rc.sourceSuffix = m_ui->sourceSuffixComboBox->currentText();
 | 
			
		||||
    rc.headerSearchPaths = trimmedPaths(m_ui->headerSearchPathsEdit->text());
 | 
			
		||||
    rc.sourceSearchPaths = trimmedPaths(m_ui->sourceSearchPathsEdit->text());
 | 
			
		||||
    rc.licenseTemplatePath = licenseTemplatePath();
 | 
			
		||||
    return rc;
 | 
			
		||||
}
 | 
			
		||||
@@ -265,8 +295,12 @@ CppFileSettings CppFileSettingsWidget::settings() const
 | 
			
		||||
QString CppFileSettingsWidget::searchKeywords() const
 | 
			
		||||
{
 | 
			
		||||
    QString rc;
 | 
			
		||||
    QTextStream(&rc) << m_ui->headerSuffixLabel->text()
 | 
			
		||||
    QTextStream(&rc) << m_ui->headersGroupBox->title()
 | 
			
		||||
            << ' ' << m_ui->headerSuffixLabel->text()
 | 
			
		||||
            << ' ' << m_ui->headerSearchPathsLabel->text()
 | 
			
		||||
            << ' ' << m_ui->sourcesGroupBox->title()
 | 
			
		||||
            << ' ' << m_ui->sourceSuffixLabel->text()
 | 
			
		||||
            << ' ' << m_ui->sourceSearchPathsLabel->text()
 | 
			
		||||
            << ' ' << m_ui->lowerCaseFileNamesCheckBox->text()
 | 
			
		||||
            << ' ' << m_ui->licenseTemplateLabel->text();
 | 
			
		||||
    rc.remove(QLatin1Char('&'));
 | 
			
		||||
@@ -284,6 +318,8 @@ void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
 | 
			
		||||
    m_ui->lowerCaseFileNamesCheckBox->setChecked(s.lowerCaseFiles);
 | 
			
		||||
    setComboText(m_ui->headerSuffixComboBox, s.headerSuffix);
 | 
			
		||||
    setComboText(m_ui->sourceSuffixComboBox, s.sourceSuffix);
 | 
			
		||||
    m_ui->headerSearchPathsEdit->setText(s.headerSearchPaths.join(QLatin1String(",")));
 | 
			
		||||
    m_ui->sourceSearchPathsEdit->setText(s.sourceSearchPaths.join(QLatin1String(",")));
 | 
			
		||||
    setLicenseTemplatePath(s.licenseTemplatePath);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -336,6 +372,7 @@ void CppFileSettingsPage::apply()
 | 
			
		||||
            *m_settings = newSettings;
 | 
			
		||||
            m_settings->toSettings(Core::ICore::settings());
 | 
			
		||||
            m_settings->applySuffixesToMimeDB();
 | 
			
		||||
            CppToolsPlugin::clearHeaderSourceCache();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user