2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-03-18 16:43:01 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-03-18 16:43:01 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-03-18 16:43:01 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-03-18 16:43:01 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-03-18 16:43:01 +01:00
|
|
|
|
|
|
|
|
#include "cppfilesettingspage.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
#include "cpptoolsconstants.h"
|
2013-08-25 22:42:37 +03:00
|
|
|
#include "cpptoolsplugin.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <ui_cppfilesettingspage.h>
|
2009-03-18 16:43:01 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2009-06-22 16:22:15 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <coreplugin/mimedatabase.h>
|
2009-06-22 16:22:15 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
|
2012-08-31 16:47:53 +02:00
|
|
|
#include <utils/environment.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDate>
|
|
|
|
|
#include <QLocale>
|
|
|
|
|
#include <QTextCodec>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QFileDialog>
|
2009-03-18 16:43:01 +01:00
|
|
|
|
2014-01-20 09:15:50 +02:00
|
|
|
static const char headerPrefixesKeyC[] = "HeaderPrefixes";
|
|
|
|
|
static const char sourcePrefixesKeyC[] = "SourcePrefixes";
|
2011-05-10 15:19:38 +02:00
|
|
|
static const char headerSuffixKeyC[] = "HeaderSuffix";
|
|
|
|
|
static const char sourceSuffixKeyC[] = "SourceSuffix";
|
2013-08-25 22:42:37 +03:00
|
|
|
static const char headerSearchPathsKeyC[] = "HeaderSearchPaths";
|
|
|
|
|
static const char sourceSearchPathsKeyC[] = "SourceSearchPaths";
|
2011-05-10 15:19:38 +02:00
|
|
|
static const char licenseTemplatePathKeyC[] = "LicenseTemplate";
|
2009-06-22 16:22:15 +02:00
|
|
|
|
|
|
|
|
const char *licenseTemplateTemplate = QT_TRANSLATE_NOOP("CppTools::Internal::CppFileSettingsWidget",
|
|
|
|
|
"/**************************************************************************\n"
|
|
|
|
|
"** Qt Creator license header template\n"
|
|
|
|
|
"** Special keywords: %USER% %DATE% %YEAR%\n"
|
|
|
|
|
"** Environment variables: %$VARIABLE%\n"
|
|
|
|
|
"** To protect a percent sign, use '%%'.\n"
|
|
|
|
|
"**************************************************************************/\n");
|
2009-03-18 16:43:01 +01:00
|
|
|
|
|
|
|
|
namespace CppTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
CppFileSettings::CppFileSettings() :
|
|
|
|
|
lowerCaseFiles(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettings::toSettings(QSettings *s) const
|
|
|
|
|
{
|
|
|
|
|
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
2014-01-20 09:15:50 +02:00
|
|
|
s->setValue(QLatin1String(headerPrefixesKeyC), headerPrefixes);
|
|
|
|
|
s->setValue(QLatin1String(sourcePrefixesKeyC), sourcePrefixes);
|
2009-03-18 16:43:01 +01:00
|
|
|
s->setValue(QLatin1String(headerSuffixKeyC), headerSuffix);
|
|
|
|
|
s->setValue(QLatin1String(sourceSuffixKeyC), sourceSuffix);
|
2013-08-25 22:42:37 +03:00
|
|
|
s->setValue(QLatin1String(headerSearchPathsKeyC), headerSearchPaths);
|
|
|
|
|
s->setValue(QLatin1String(sourceSearchPathsKeyC), sourceSearchPaths);
|
2009-03-18 16:43:01 +01:00
|
|
|
s->setValue(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), lowerCaseFiles);
|
2009-06-22 16:22:15 +02:00
|
|
|
s->setValue(QLatin1String(licenseTemplatePathKeyC), licenseTemplatePath);
|
2009-03-18 16:43:01 +01:00
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettings::fromSettings(QSettings *s)
|
|
|
|
|
{
|
2013-08-25 22:42:37 +03:00
|
|
|
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("..");
|
2009-03-18 16:43:01 +01:00
|
|
|
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
2014-01-20 09:15:50 +02:00
|
|
|
headerPrefixes = s->value(QLatin1String(headerPrefixesKeyC)).toStringList();
|
|
|
|
|
sourcePrefixes = s->value(QLatin1String(sourcePrefixesKeyC)).toStringList();
|
|
|
|
|
headerSuffix = s->value(QLatin1String(headerSuffixKeyC), QLatin1String("h")).toString();
|
2009-03-18 16:43:01 +01:00
|
|
|
sourceSuffix = s->value(QLatin1String(sourceSuffixKeyC), QLatin1String("cpp")).toString();
|
2013-08-25 22:42:37 +03:00
|
|
|
headerSearchPaths = s->value(QLatin1String(headerSearchPathsKeyC), defaultHeaderSearchPaths)
|
|
|
|
|
.toStringList();
|
|
|
|
|
sourceSearchPaths = s->value(QLatin1String(sourceSearchPathsKeyC), defaultSourceSearchPaths)
|
|
|
|
|
.toStringList();
|
2009-03-18 17:05:48 +01:00
|
|
|
const bool lowerCaseDefault = Constants::lowerCaseFilesDefault;
|
|
|
|
|
lowerCaseFiles = s->value(QLatin1String(Constants::LOWERCASE_CPPFILES_KEY), QVariant(lowerCaseDefault)).toBool();
|
2009-06-22 16:22:15 +02:00
|
|
|
licenseTemplatePath = s->value(QLatin1String(licenseTemplatePathKeyC), QString()).toString();
|
2009-03-18 16:43:01 +01:00
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-29 09:04:59 +02:00
|
|
|
bool CppFileSettings::applySuffixesToMimeDB()
|
2009-03-18 16:43:01 +01:00
|
|
|
{
|
2013-08-30 16:38:57 +02:00
|
|
|
return Core::MimeDatabase::setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE), sourceSuffix)
|
|
|
|
|
&& Core::MimeDatabase::setPreferredSuffix(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE), headerSuffix);
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppFileSettings::equals(const CppFileSettings &rhs) const
|
|
|
|
|
{
|
|
|
|
|
return lowerCaseFiles == rhs.lowerCaseFiles
|
2014-01-20 09:15:50 +02:00
|
|
|
&& headerPrefixes == rhs.headerPrefixes
|
|
|
|
|
&& sourcePrefixes == rhs.sourcePrefixes
|
2009-03-18 16:43:01 +01:00
|
|
|
&& headerSuffix == rhs.headerSuffix
|
2009-06-22 16:22:15 +02:00
|
|
|
&& sourceSuffix == rhs.sourceSuffix
|
2013-08-25 22:42:37 +03:00
|
|
|
&& headerSearchPaths == rhs.headerSearchPaths
|
|
|
|
|
&& sourceSearchPaths == rhs.sourceSearchPaths
|
2009-06-22 16:22:15 +02:00
|
|
|
&& licenseTemplatePath == rhs.licenseTemplatePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Replacements of special license template keywords.
|
2010-08-09 12:23:21 +02:00
|
|
|
static bool keyWordReplacement(const QString &keyWord,
|
|
|
|
|
const QString &file,
|
|
|
|
|
const QString &className,
|
|
|
|
|
QString *value)
|
2009-06-22 16:22:15 +02:00
|
|
|
{
|
|
|
|
|
if (keyWord == QLatin1String("%YEAR%")) {
|
2010-08-09 12:23:21 +02:00
|
|
|
*value = QString::number(QDate::currentDate().year());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-10-28 12:13:47 +02:00
|
|
|
if (keyWord == QLatin1String("%MONTH%")) {
|
|
|
|
|
*value = QString::number(QDate::currentDate().month());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (keyWord == QLatin1String("%DAY%")) {
|
|
|
|
|
*value = QString::number(QDate::currentDate().day());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-08-09 12:23:21 +02:00
|
|
|
if (keyWord == QLatin1String("%CLASS%")) {
|
|
|
|
|
*value = className;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (keyWord == QLatin1String("%FILENAME%")) {
|
|
|
|
|
*value = QFileInfo(file).fileName();
|
|
|
|
|
return true;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
|
|
|
|
if (keyWord == QLatin1String("%DATE%")) {
|
|
|
|
|
static QString format;
|
|
|
|
|
// ensure a format with 4 year digits. Some have locales have 2.
|
|
|
|
|
if (format.isEmpty()) {
|
|
|
|
|
QLocale loc;
|
|
|
|
|
format = loc.dateFormat(QLocale::ShortFormat);
|
|
|
|
|
const QChar ypsilon = QLatin1Char('y');
|
|
|
|
|
if (format.count(ypsilon) == 2)
|
|
|
|
|
format.insert(format.indexOf(ypsilon), QString(2, ypsilon));
|
|
|
|
|
}
|
2010-08-09 12:23:21 +02:00
|
|
|
*value = QDate::currentDate().toString(format);
|
|
|
|
|
return true;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
|
|
|
|
if (keyWord == QLatin1String("%USER%")) {
|
2012-08-31 16:47:53 +02:00
|
|
|
*value = Utils::Environment::systemEnvironment().userName();
|
2010-08-09 12:23:21 +02:00
|
|
|
return true;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
|
|
|
|
// Environment variables (for example '%$EMAIL%').
|
|
|
|
|
if (keyWord.startsWith(QLatin1String("%$"))) {
|
|
|
|
|
const QString varName = keyWord.mid(2, keyWord.size() - 3);
|
2010-08-09 12:23:21 +02:00
|
|
|
*value = QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit()));
|
|
|
|
|
return true;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
2010-08-09 12:23:21 +02:00
|
|
|
return false;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse a license template, scan for %KEYWORD% and replace if known.
|
|
|
|
|
// Replace '%%' by '%'.
|
2010-08-09 12:23:21 +02:00
|
|
|
static void parseLicenseTemplatePlaceholders(QString *t, const QString &file, const QString &className)
|
2009-06-22 16:22:15 +02:00
|
|
|
{
|
|
|
|
|
int pos = 0;
|
|
|
|
|
const QChar placeHolder = QLatin1Char('%');
|
|
|
|
|
do {
|
|
|
|
|
const int placeHolderPos = t->indexOf(placeHolder, pos);
|
|
|
|
|
if (placeHolderPos == -1)
|
|
|
|
|
break;
|
|
|
|
|
const int endPlaceHolderPos = t->indexOf(placeHolder, placeHolderPos + 1);
|
|
|
|
|
if (endPlaceHolderPos == -1)
|
|
|
|
|
break;
|
|
|
|
|
if (endPlaceHolderPos == placeHolderPos + 1) { // '%%' -> '%'
|
|
|
|
|
t->remove(placeHolderPos, 1);
|
|
|
|
|
pos = placeHolderPos + 1;
|
|
|
|
|
} else {
|
|
|
|
|
const QString keyWord = t->mid(placeHolderPos, endPlaceHolderPos + 1 - placeHolderPos);
|
2010-08-09 12:23:21 +02:00
|
|
|
QString replacement;
|
|
|
|
|
if (keyWordReplacement(keyWord, file, className, &replacement)) {
|
2009-06-22 16:22:15 +02:00
|
|
|
t->replace(placeHolderPos, keyWord.size(), replacement);
|
|
|
|
|
pos = placeHolderPos + replacement.size();
|
2010-08-09 12:23:21 +02:00
|
|
|
} else {
|
|
|
|
|
// Leave invalid keywords as is.
|
|
|
|
|
pos = endPlaceHolderPos + 1;
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (pos < t->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience that returns the formatted license template.
|
2010-08-09 12:23:21 +02:00
|
|
|
QString CppFileSettings::licenseTemplate(const QString &fileName, const QString &className)
|
2009-06-22 16:22:15 +02:00
|
|
|
{
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
const QSettings *s = Core::ICore::settings();
|
2009-06-22 16:22:15 +02:00
|
|
|
QString key = QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP);
|
|
|
|
|
key += QLatin1Char('/');
|
|
|
|
|
key += QLatin1String(licenseTemplatePathKeyC);
|
|
|
|
|
const QString path = s->value(key, QString()).toString();
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
QFile file(path);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
|
|
|
|
qWarning("Unable to open the license template %s: %s", qPrintable(path), qPrintable(file.errorString()));
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
2010-11-11 11:00:40 +01:00
|
|
|
|
|
|
|
|
QTextStream licenseStream(&file);
|
2013-08-29 15:46:04 +02:00
|
|
|
licenseStream.setCodec(Core::EditorManager::defaultTextCodec());
|
2010-11-11 11:00:40 +01:00
|
|
|
licenseStream.setAutoDetectUnicode(true);
|
|
|
|
|
QString license = licenseStream.readAll();
|
|
|
|
|
|
2010-08-09 12:23:21 +02:00
|
|
|
parseLicenseTemplatePlaceholders(&license, fileName, className);
|
2009-06-22 16:22:15 +02:00
|
|
|
// Ensure exactly one additional new line separating stuff
|
|
|
|
|
const QChar newLine = QLatin1Char('\n');
|
|
|
|
|
if (!license.endsWith(newLine))
|
|
|
|
|
license += newLine;
|
|
|
|
|
license += newLine;
|
|
|
|
|
return license;
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------ CppFileSettingsWidget
|
|
|
|
|
|
|
|
|
|
CppFileSettingsWidget::CppFileSettingsWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2011-11-23 15:15:01 +00:00
|
|
|
m_ui(new Internal::Ui::CppFileSettingsPage)
|
2009-03-18 16:43:01 +01:00
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
// populate suffix combos
|
2013-08-30 16:38:57 +02:00
|
|
|
if (const Core::MimeType sourceMt = Core::MimeDatabase::findByType(QLatin1String(CppTools::Constants::CPP_SOURCE_MIMETYPE)))
|
2009-03-18 16:43:01 +01:00
|
|
|
foreach (const QString &suffix, sourceMt.suffixes())
|
|
|
|
|
m_ui->sourceSuffixComboBox->addItem(suffix);
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
if (const Core::MimeType headerMt = Core::MimeDatabase::findByType(QLatin1String(CppTools::Constants::CPP_HEADER_MIMETYPE)))
|
2009-03-18 16:43:01 +01:00
|
|
|
foreach (const QString &suffix, headerMt.suffixes())
|
|
|
|
|
m_ui->headerSuffixComboBox->addItem(suffix);
|
2009-10-05 11:06:05 +02:00
|
|
|
m_ui->licenseTemplatePathChooser->setExpectedKind(Utils::PathChooser::File);
|
2013-11-25 14:33:05 +01:00
|
|
|
m_ui->licenseTemplatePathChooser->setHistoryCompleter(QLatin1String("Cpp.LicenseTemplate.History"));
|
2011-10-05 20:13:49 +02:00
|
|
|
m_ui->licenseTemplatePathChooser->addButton(tr("Edit..."), this, SLOT(slotEdit()));
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppFileSettingsWidget::~CppFileSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-22 16:22:15 +02:00
|
|
|
QString CppFileSettingsWidget::licenseTemplatePath() const
|
|
|
|
|
{
|
|
|
|
|
return m_ui->licenseTemplatePathChooser->path();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettingsWidget::setLicenseTemplatePath(const QString &lp)
|
|
|
|
|
{
|
|
|
|
|
m_ui->licenseTemplatePathChooser->setPath(lp);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 22:42:37 +03:00
|
|
|
static QStringList trimmedPaths(const QString &paths)
|
|
|
|
|
{
|
|
|
|
|
QStringList res;
|
|
|
|
|
foreach (const QString &path, paths.split(QLatin1Char(','), QString::SkipEmptyParts))
|
|
|
|
|
res << path.trimmed();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
CppFileSettings CppFileSettingsWidget::settings() const
|
|
|
|
|
{
|
|
|
|
|
CppFileSettings rc;
|
|
|
|
|
rc.lowerCaseFiles = m_ui->lowerCaseFileNamesCheckBox->isChecked();
|
2014-01-20 09:15:50 +02:00
|
|
|
rc.headerPrefixes = trimmedPaths(m_ui->headerPrefixesEdit->text());
|
|
|
|
|
rc.sourcePrefixes = trimmedPaths(m_ui->sourcePrefixesEdit->text());
|
2009-03-18 16:43:01 +01:00
|
|
|
rc.headerSuffix = m_ui->headerSuffixComboBox->currentText();
|
|
|
|
|
rc.sourceSuffix = m_ui->sourceSuffixComboBox->currentText();
|
2013-08-25 22:42:37 +03:00
|
|
|
rc.headerSearchPaths = trimmedPaths(m_ui->headerSearchPathsEdit->text());
|
|
|
|
|
rc.sourceSearchPaths = trimmedPaths(m_ui->sourceSearchPathsEdit->text());
|
2009-06-22 16:22:15 +02:00
|
|
|
rc.licenseTemplatePath = licenseTemplatePath();
|
2009-03-18 16:43:01 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void setComboText(QComboBox *cb, const QString &text, int defaultIndex = 0)
|
|
|
|
|
{
|
|
|
|
|
const int index = cb->findText(text);
|
|
|
|
|
cb->setCurrentIndex(index == -1 ? defaultIndex: index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettingsWidget::setSettings(const CppFileSettings &s)
|
|
|
|
|
{
|
|
|
|
|
m_ui->lowerCaseFileNamesCheckBox->setChecked(s.lowerCaseFiles);
|
2014-01-20 09:15:50 +02:00
|
|
|
m_ui->headerPrefixesEdit->setText(s.headerPrefixes.join(QLatin1String(",")));
|
|
|
|
|
m_ui->sourcePrefixesEdit->setText(s.sourcePrefixes.join(QLatin1String(",")));
|
2009-03-18 16:43:01 +01:00
|
|
|
setComboText(m_ui->headerSuffixComboBox, s.headerSuffix);
|
|
|
|
|
setComboText(m_ui->sourceSuffixComboBox, s.sourceSuffix);
|
2013-08-25 22:42:37 +03:00
|
|
|
m_ui->headerSearchPathsEdit->setText(s.headerSearchPaths.join(QLatin1String(",")));
|
|
|
|
|
m_ui->sourceSearchPathsEdit->setText(s.sourceSearchPaths.join(QLatin1String(",")));
|
2009-06-22 16:22:15 +02:00
|
|
|
setLicenseTemplatePath(s.licenseTemplatePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettingsWidget::slotEdit()
|
|
|
|
|
{
|
|
|
|
|
QString path = licenseTemplatePath();
|
2011-03-30 15:15:15 +02:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
// Pick a file name and write new template, edit with C++
|
|
|
|
|
path = QFileDialog::getSaveFileName(this, tr("Choose Location for New License Template File"));
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
Utils::FileSaver saver(path, QIODevice::Text);
|
|
|
|
|
saver.write(tr(licenseTemplateTemplate).toUtf8());
|
|
|
|
|
if (!saver.finalize(this))
|
|
|
|
|
return;
|
|
|
|
|
setLicenseTemplatePath(path);
|
2009-06-22 16:22:15 +02:00
|
|
|
}
|
2011-03-30 15:15:15 +02:00
|
|
|
// Edit (now) existing file with C++
|
2013-05-31 12:52:53 +02:00
|
|
|
Core::EditorManager::openEditor(path, CppEditor::Constants::CPPEDITOR_ID);
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------- CppFileSettingsPage
|
2009-04-29 09:04:59 +02:00
|
|
|
CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings,
|
|
|
|
|
QObject *parent) :
|
|
|
|
|
Core::IOptionsPage(parent),
|
|
|
|
|
m_settings(settings)
|
2009-03-18 16:43:01 +01:00
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId(Constants::CPP_FILE_SETTINGS_ID);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("CppTools", Constants::CPP_FILE_SETTINGS_NAME));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayCategory(QCoreApplication::translate("CppTools", Constants::CPP_SETTINGS_TR_CATEGORY));
|
|
|
|
|
setCategoryIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *CppFileSettingsPage::widget()
|
2009-03-18 16:43:01 +01:00
|
|
|
{
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_widget = new CppFileSettingsWidget;
|
|
|
|
|
m_widget->setSettings(*m_settings);
|
|
|
|
|
}
|
2009-03-18 16:43:01 +01:00
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFileSettingsPage::apply()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget) {
|
|
|
|
|
const CppFileSettings newSettings = m_widget->settings();
|
2009-04-29 09:04:59 +02:00
|
|
|
if (newSettings != *m_settings) {
|
|
|
|
|
*m_settings = newSettings;
|
2012-01-24 15:36:40 +01:00
|
|
|
m_settings->toSettings(Core::ICore::settings());
|
2009-04-29 09:04:59 +02:00
|
|
|
m_settings->applySuffixesToMimeDB();
|
2013-08-25 22:42:37 +03:00
|
|
|
CppToolsPlugin::clearHeaderSourceCache();
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
void CppFileSettingsPage::finish()
|
2009-11-20 16:55:23 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2009-11-20 16:55:23 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-13 17:31:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace CppTools
|