2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Lorenz Haas
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-12-11 21:55:45 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "clangformatoptionspage.h"
|
|
|
|
|
#include "ui_clangformatoptionspage.h"
|
|
|
|
|
|
|
|
|
|
#include "clangformatconstants.h"
|
|
|
|
|
#include "clangformatsettings.h"
|
|
|
|
|
|
|
|
|
|
#include "../beautifierconstants.h"
|
2014-03-05 14:02:01 +01:00
|
|
|
#include "../beautifierplugin.h"
|
2013-12-11 21:55:45 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
namespace Beautifier {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
namespace ClangFormat {
|
|
|
|
|
|
|
|
|
|
ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings,
|
2016-04-21 21:08:57 +02:00
|
|
|
QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::ClangFormatOptionsPage),
|
|
|
|
|
m_settings(settings)
|
2013-12-11 21:55:45 +01:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
ui->options->setEnabled(false);
|
|
|
|
|
ui->predefinedStyle->addItems(m_settings->predefinedStyles());
|
|
|
|
|
ui->command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
2014-03-05 14:02:01 +01:00
|
|
|
ui->command->setPromptDialogTitle(
|
2016-04-21 21:08:57 +02:00
|
|
|
BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
|
2015-06-21 19:29:13 +02:00
|
|
|
connect(ui->command, &Utils::PathChooser::validChanged, ui->options, &QWidget::setEnabled);
|
2013-12-11 21:55:45 +01:00
|
|
|
ui->configurations->setSettings(m_settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangFormatOptionsPageWidget::~ClangFormatOptionsPageWidget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangFormatOptionsPageWidget::restore()
|
|
|
|
|
{
|
|
|
|
|
ui->command->setPath(m_settings->command());
|
2016-05-19 21:30:27 +02:00
|
|
|
ui->mime->setText(m_settings->supportedMimeTypesAsString());
|
2015-06-21 19:12:02 +02:00
|
|
|
const int textIndex = ui->predefinedStyle->findText(m_settings->predefinedStyle());
|
2014-02-18 08:32:38 +01:00
|
|
|
if (textIndex != -1)
|
|
|
|
|
ui->predefinedStyle->setCurrentIndex(textIndex);
|
2013-12-11 21:55:45 +01:00
|
|
|
ui->formatEntireFileFallback->setChecked(m_settings->formatEntireFileFallback());
|
|
|
|
|
ui->configurations->setSettings(m_settings);
|
|
|
|
|
ui->configurations->setCurrentConfiguration(m_settings->customStyle());
|
|
|
|
|
|
|
|
|
|
if (m_settings->usePredefinedStyle())
|
|
|
|
|
ui->usePredefinedStyle->setChecked(true);
|
|
|
|
|
else
|
|
|
|
|
ui->useCustomizedStyle->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangFormatOptionsPageWidget::apply()
|
|
|
|
|
{
|
|
|
|
|
m_settings->setCommand(ui->command->path());
|
2016-05-19 21:30:27 +02:00
|
|
|
m_settings->setSupportedMimeTypes(ui->mime->text());
|
2013-12-11 21:55:45 +01:00
|
|
|
m_settings->setUsePredefinedStyle(ui->usePredefinedStyle->isChecked());
|
|
|
|
|
m_settings->setPredefinedStyle(ui->predefinedStyle->currentText());
|
|
|
|
|
m_settings->setCustomStyle(ui->configurations->currentConfiguration());
|
|
|
|
|
m_settings->setFormatEntireFileFallback(ui->formatEntireFileFallback->isChecked());
|
|
|
|
|
m_settings->save();
|
2016-05-19 21:30:27 +02:00
|
|
|
|
|
|
|
|
// update since not all MIME types are accepted (invalids or duplicates)
|
2016-06-01 18:12:51 +02:00
|
|
|
ui->mime->setText(m_settings->supportedMimeTypesAsString());
|
2013-12-11 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings, QObject *parent) :
|
|
|
|
|
IOptionsPage(parent),
|
2014-04-30 12:56:36 +02:00
|
|
|
m_settings(settings)
|
2013-12-11 21:55:45 +01:00
|
|
|
{
|
|
|
|
|
setId(Constants::ClangFormat::OPTION_ID);
|
2014-02-24 10:33:56 +01:00
|
|
|
setDisplayName(tr("Clang Format"));
|
2013-12-11 21:55:45 +01:00
|
|
|
setCategory(Constants::OPTION_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
|
2016-04-21 21:08:57 +02:00
|
|
|
setCategoryIcon(Constants::OPTION_CATEGORY_ICON);
|
2013-12-11 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *ClangFormatOptionsPage::widget()
|
|
|
|
|
{
|
|
|
|
|
m_settings->read();
|
|
|
|
|
|
2014-04-30 12:56:36 +02:00
|
|
|
if (!m_widget)
|
2013-12-11 21:55:45 +01:00
|
|
|
m_widget = new ClangFormatOptionsPageWidget(m_settings);
|
|
|
|
|
m_widget->restore();
|
|
|
|
|
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangFormatOptionsPage::apply()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_widget->apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangFormatOptionsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangFormat
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Beautifier
|