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
|
|
|
|
|
|
|
|
namespace Beautifier {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
namespace ClangFormat {
|
|
|
|
|
|
2020-01-09 16:19:52 +01:00
|
|
|
class ClangFormatOptionsPageWidget : public Core::IOptionsPageWidget
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(Beautifier::Internal::ClangFormat)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit ClangFormatOptionsPageWidget(ClangFormatSettings *settings);
|
|
|
|
|
|
|
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Ui::ClangFormatOptionsPage ui;
|
|
|
|
|
ClangFormatSettings *m_settings;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings)
|
|
|
|
|
: m_settings(settings)
|
2013-12-11 21:55:45 +01:00
|
|
|
{
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.setupUi(this);
|
|
|
|
|
ui.options->setEnabled(false);
|
|
|
|
|
ui.predefinedStyle->addItems(m_settings->predefinedStyles());
|
|
|
|
|
ui.fallbackStyle->addItems(m_settings->fallbackStyles());
|
|
|
|
|
ui.command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
|
|
|
|
ui.command->setCommandVersionArguments({"--version"});
|
|
|
|
|
ui.command->setPromptDialogTitle(
|
2016-04-21 21:08:57 +02:00
|
|
|
BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
|
2020-01-09 16:19:52 +01:00
|
|
|
connect(ui.command, &Utils::PathChooser::validChanged, ui.options, &QWidget::setEnabled);
|
|
|
|
|
connect(ui.predefinedStyle, &QComboBox::currentTextChanged, [this](const QString &item) {
|
|
|
|
|
ui.fallbackStyle->setEnabled(item == "File");
|
2017-03-01 20:40:27 +01:00
|
|
|
});
|
2020-01-09 16:19:52 +01:00
|
|
|
connect(ui.usePredefinedStyle, &QRadioButton::toggled, [this](bool checked) {
|
|
|
|
|
ui.fallbackStyle->setEnabled(checked && ui.predefinedStyle->currentText() == "File");
|
|
|
|
|
ui.predefinedStyle->setEnabled(checked);
|
2017-03-01 20:40:27 +01:00
|
|
|
});
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.configurations->setSettings(m_settings);
|
2013-12-11 21:55:45 +01:00
|
|
|
|
2020-04-09 11:05:50 +02:00
|
|
|
ui.command->setFilePath(m_settings->command());
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.mime->setText(m_settings->supportedMimeTypesAsString());
|
|
|
|
|
const int predefinedStyleIndex = ui.predefinedStyle->findText(m_settings->predefinedStyle());
|
2017-03-01 20:40:27 +01:00
|
|
|
if (predefinedStyleIndex != -1)
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.predefinedStyle->setCurrentIndex(predefinedStyleIndex);
|
|
|
|
|
const int fallbackStyleIndex = ui.fallbackStyle->findText(m_settings->fallbackStyle());
|
2017-03-01 20:40:27 +01:00
|
|
|
if (fallbackStyleIndex != -1)
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.fallbackStyle->setCurrentIndex(fallbackStyleIndex);
|
|
|
|
|
ui.configurations->setSettings(m_settings);
|
|
|
|
|
ui.configurations->setCurrentConfiguration(m_settings->customStyle());
|
2013-12-11 21:55:45 +01:00
|
|
|
|
|
|
|
|
if (m_settings->usePredefinedStyle())
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.usePredefinedStyle->setChecked(true);
|
2013-12-11 21:55:45 +01:00
|
|
|
else
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.useCustomizedStyle->setChecked(true);
|
2013-12-11 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangFormatOptionsPageWidget::apply()
|
|
|
|
|
{
|
2020-04-09 11:35:12 +02:00
|
|
|
m_settings->setCommand(ui.command->filePath().toString());
|
2020-01-09 16:19:52 +01:00
|
|
|
m_settings->setSupportedMimeTypes(ui.mime->text());
|
|
|
|
|
m_settings->setUsePredefinedStyle(ui.usePredefinedStyle->isChecked());
|
|
|
|
|
m_settings->setPredefinedStyle(ui.predefinedStyle->currentText());
|
|
|
|
|
m_settings->setFallbackStyle(ui.fallbackStyle->currentText());
|
|
|
|
|
m_settings->setCustomStyle(ui.configurations->currentConfiguration());
|
2013-12-11 21:55:45 +01:00
|
|
|
m_settings->save();
|
2016-05-19 21:30:27 +02:00
|
|
|
|
|
|
|
|
// update since not all MIME types are accepted (invalids or duplicates)
|
2020-01-09 16:19:52 +01:00
|
|
|
ui.mime->setText(m_settings->supportedMimeTypesAsString());
|
2013-12-11 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 19:06:02 +01:00
|
|
|
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings)
|
2013-12-11 21:55:45 +01:00
|
|
|
{
|
|
|
|
|
setId(Constants::ClangFormat::OPTION_ID);
|
2020-01-09 16:19:52 +01:00
|
|
|
setDisplayName(ClangFormatOptionsPageWidget::tr("Clang Format"));
|
2013-12-11 21:55:45 +01:00
|
|
|
setCategory(Constants::OPTION_CATEGORY);
|
2020-01-09 16:19:52 +01:00
|
|
|
setWidgetCreator([settings] { return new ClangFormatOptionsPageWidget(settings); });
|
2013-12-11 21:55:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangFormat
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Beautifier
|