forked from qt-creator/qt-creator
Beautifier: Inline clangformatoptionspage.ui
Change-Id: I74709de4da72dc39e0667ba267ab841349125570 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -13,7 +13,7 @@ add_qtc_plugin(Beautifier
|
|||||||
beautifierplugin.cpp beautifierplugin.h
|
beautifierplugin.cpp beautifierplugin.h
|
||||||
clangformat/clangformat.cpp clangformat/clangformat.h
|
clangformat/clangformat.cpp clangformat/clangformat.h
|
||||||
clangformat/clangformatconstants.h
|
clangformat/clangformatconstants.h
|
||||||
clangformat/clangformatoptionspage.cpp clangformat/clangformatoptionspage.h clangformat/clangformatoptionspage.ui
|
clangformat/clangformatoptionspage.cpp clangformat/clangformatoptionspage.h
|
||||||
clangformat/clangformatsettings.cpp clangformat/clangformatsettings.h
|
clangformat/clangformatsettings.cpp clangformat/clangformatsettings.h
|
||||||
configurationdialog.cpp configurationdialog.h configurationdialog.ui
|
configurationdialog.cpp configurationdialog.h configurationdialog.ui
|
||||||
configurationeditor.cpp configurationeditor.h
|
configurationeditor.cpp configurationeditor.h
|
||||||
|
@@ -55,7 +55,6 @@ QtcPlugin {
|
|||||||
"clangformatconstants.h",
|
"clangformatconstants.h",
|
||||||
"clangformatoptionspage.cpp",
|
"clangformatoptionspage.cpp",
|
||||||
"clangformatoptionspage.h",
|
"clangformatoptionspage.h",
|
||||||
"clangformatoptionspage.ui",
|
|
||||||
"clangformatsettings.cpp",
|
"clangformatsettings.cpp",
|
||||||
"clangformatsettings.h"
|
"clangformatsettings.h"
|
||||||
]
|
]
|
||||||
|
@@ -24,16 +24,25 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "clangformatoptionspage.h"
|
#include "clangformatoptionspage.h"
|
||||||
#include "ui_clangformatoptionspage.h"
|
|
||||||
|
|
||||||
#include "clangformatconstants.h"
|
#include "clangformatconstants.h"
|
||||||
#include "clangformatsettings.h"
|
#include "clangformatsettings.h"
|
||||||
|
|
||||||
#include "../beautifierconstants.h"
|
#include "../beautifierconstants.h"
|
||||||
#include "../beautifierplugin.h"
|
#include "../beautifierplugin.h"
|
||||||
|
#include "../configurationpanel.h"
|
||||||
|
|
||||||
namespace Beautifier {
|
#include <utils/layoutbuilder.h>
|
||||||
namespace Internal {
|
#include <utils/pathchooser.h>
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QRadioButton>
|
||||||
|
#include <QSpacerItem>
|
||||||
|
|
||||||
|
namespace Beautifier::Internal {
|
||||||
|
|
||||||
class ClangFormatOptionsPageWidget : public Core::IOptionsPageWidget
|
class ClangFormatOptionsPageWidget : public Core::IOptionsPageWidget
|
||||||
{
|
{
|
||||||
@@ -45,60 +54,104 @@ public:
|
|||||||
void apply() final;
|
void apply() final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ClangFormatOptionsPage ui;
|
|
||||||
ClangFormatSettings *m_settings;
|
ClangFormatSettings *m_settings;
|
||||||
|
ConfigurationPanel *m_configurations;
|
||||||
|
QRadioButton *m_usePredefinedStyle;
|
||||||
|
QComboBox *m_predefinedStyle;
|
||||||
|
QComboBox *m_fallbackStyle;
|
||||||
|
Utils::PathChooser *m_command;
|
||||||
|
QLineEdit *m_mime;
|
||||||
};
|
};
|
||||||
|
|
||||||
ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings)
|
ClangFormatOptionsPageWidget::ClangFormatOptionsPageWidget(ClangFormatSettings *settings)
|
||||||
: m_settings(settings)
|
: m_settings(settings)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
auto options = new QGroupBox(tr("Options"));
|
||||||
ui.options->setEnabled(false);
|
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(
|
|
||||||
BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
|
|
||||||
connect(ui.command, &Utils::PathChooser::validChanged, ui.options, &QWidget::setEnabled);
|
|
||||||
connect(ui.predefinedStyle, &QComboBox::currentTextChanged, [this](const QString &item) {
|
|
||||||
ui.fallbackStyle->setEnabled(item == "File");
|
|
||||||
});
|
|
||||||
connect(ui.usePredefinedStyle, &QRadioButton::toggled, [this](bool checked) {
|
|
||||||
ui.fallbackStyle->setEnabled(checked && ui.predefinedStyle->currentText() == "File");
|
|
||||||
ui.predefinedStyle->setEnabled(checked);
|
|
||||||
});
|
|
||||||
ui.configurations->setSettings(m_settings);
|
|
||||||
|
|
||||||
ui.command->setFilePath(m_settings->command());
|
auto useCustomizedStyle = new QRadioButton(tr("Use customized style:"));
|
||||||
ui.mime->setText(m_settings->supportedMimeTypesAsString());
|
useCustomizedStyle->setAutoExclusive(true);
|
||||||
const int predefinedStyleIndex = ui.predefinedStyle->findText(m_settings->predefinedStyle());
|
|
||||||
|
m_configurations = new ConfigurationPanel;
|
||||||
|
m_configurations->setSettings(m_settings);
|
||||||
|
m_configurations->setCurrentConfiguration(m_settings->customStyle());
|
||||||
|
|
||||||
|
m_usePredefinedStyle = new QRadioButton(tr("Use predefined style:"));
|
||||||
|
|
||||||
|
m_usePredefinedStyle->setChecked(true);
|
||||||
|
m_usePredefinedStyle->setAutoExclusive(true);
|
||||||
|
|
||||||
|
m_predefinedStyle = new QComboBox;
|
||||||
|
m_predefinedStyle->addItems(m_settings->predefinedStyles());
|
||||||
|
const int predefinedStyleIndex = m_predefinedStyle->findText(m_settings->predefinedStyle());
|
||||||
if (predefinedStyleIndex != -1)
|
if (predefinedStyleIndex != -1)
|
||||||
ui.predefinedStyle->setCurrentIndex(predefinedStyleIndex);
|
m_predefinedStyle->setCurrentIndex(predefinedStyleIndex);
|
||||||
const int fallbackStyleIndex = ui.fallbackStyle->findText(m_settings->fallbackStyle());
|
|
||||||
|
m_fallbackStyle = new QComboBox;
|
||||||
|
m_fallbackStyle->addItems(m_settings->fallbackStyles());
|
||||||
|
m_fallbackStyle->setEnabled(false);
|
||||||
|
const int fallbackStyleIndex = m_fallbackStyle->findText(m_settings->fallbackStyle());
|
||||||
if (fallbackStyleIndex != -1)
|
if (fallbackStyleIndex != -1)
|
||||||
ui.fallbackStyle->setCurrentIndex(fallbackStyleIndex);
|
m_fallbackStyle->setCurrentIndex(fallbackStyleIndex);
|
||||||
ui.configurations->setSettings(m_settings);
|
|
||||||
ui.configurations->setCurrentConfiguration(m_settings->customStyle());
|
m_mime = new QLineEdit(m_settings->supportedMimeTypesAsString());
|
||||||
|
|
||||||
|
m_command = new Utils::PathChooser;
|
||||||
|
m_command->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||||
|
m_command->setCommandVersionArguments({"--version"});
|
||||||
|
m_command->setPromptDialogTitle(
|
||||||
|
BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
|
||||||
|
m_command->setFilePath(m_settings->command());
|
||||||
|
|
||||||
if (m_settings->usePredefinedStyle())
|
if (m_settings->usePredefinedStyle())
|
||||||
ui.usePredefinedStyle->setChecked(true);
|
m_usePredefinedStyle->setChecked(true);
|
||||||
else
|
else
|
||||||
ui.useCustomizedStyle->setChecked(true);
|
useCustomizedStyle->setChecked(true);
|
||||||
|
|
||||||
|
using namespace Utils::Layouting;
|
||||||
|
const Break br;
|
||||||
|
const Space empty;
|
||||||
|
|
||||||
|
Form {
|
||||||
|
m_usePredefinedStyle, m_predefinedStyle, br,
|
||||||
|
empty, Row { tr("Fallback style:"), m_fallbackStyle }, br,
|
||||||
|
useCustomizedStyle, m_configurations, br,
|
||||||
|
}.attachTo(options);
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Group {
|
||||||
|
Title(tr("Configuration")),
|
||||||
|
Form {
|
||||||
|
tr("Clang Format command:"), m_command, br,
|
||||||
|
tr("Restrict to MIME types:"), m_mime
|
||||||
|
}
|
||||||
|
},
|
||||||
|
options,
|
||||||
|
Stretch()
|
||||||
|
}.attachTo(this);
|
||||||
|
|
||||||
|
connect(m_command, &Utils::PathChooser::validChanged, options, &QWidget::setEnabled);
|
||||||
|
connect(m_predefinedStyle, &QComboBox::currentTextChanged, [this](const QString &item) {
|
||||||
|
m_fallbackStyle->setEnabled(item == "File");
|
||||||
|
});
|
||||||
|
connect(m_usePredefinedStyle, &QRadioButton::toggled, [this](bool checked) {
|
||||||
|
m_fallbackStyle->setEnabled(checked && m_predefinedStyle->currentText() == "File");
|
||||||
|
m_predefinedStyle->setEnabled(checked);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangFormatOptionsPageWidget::apply()
|
void ClangFormatOptionsPageWidget::apply()
|
||||||
{
|
{
|
||||||
m_settings->setCommand(ui.command->filePath().toString());
|
m_settings->setCommand(m_command->filePath().toString());
|
||||||
m_settings->setSupportedMimeTypes(ui.mime->text());
|
m_settings->setSupportedMimeTypes(m_mime->text());
|
||||||
m_settings->setUsePredefinedStyle(ui.usePredefinedStyle->isChecked());
|
m_settings->setUsePredefinedStyle(m_usePredefinedStyle->isChecked());
|
||||||
m_settings->setPredefinedStyle(ui.predefinedStyle->currentText());
|
m_settings->setPredefinedStyle(m_predefinedStyle->currentText());
|
||||||
m_settings->setFallbackStyle(ui.fallbackStyle->currentText());
|
m_settings->setFallbackStyle(m_fallbackStyle->currentText());
|
||||||
m_settings->setCustomStyle(ui.configurations->currentConfiguration());
|
m_settings->setCustomStyle(m_configurations->currentConfiguration());
|
||||||
m_settings->save();
|
m_settings->save();
|
||||||
|
|
||||||
// update since not all MIME types are accepted (invalids or duplicates)
|
// update since not all MIME types are accepted (invalids or duplicates)
|
||||||
ui.mime->setText(m_settings->supportedMimeTypesAsString());
|
m_mime->setText(m_settings->supportedMimeTypesAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings)
|
ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings)
|
||||||
@@ -109,5 +162,4 @@ ClangFormatOptionsPage::ClangFormatOptionsPage(ClangFormatSettings *settings)
|
|||||||
setWidgetCreator([settings] { return new ClangFormatOptionsPageWidget(settings); });
|
setWidgetCreator([settings] { return new ClangFormatOptionsPageWidget(settings); });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // Beautifier::Internal
|
||||||
} // namespace Beautifier
|
|
||||||
|
@@ -27,8 +27,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
|
|
||||||
namespace Beautifier {
|
namespace Beautifier::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class ClangFormatSettings;
|
class ClangFormatSettings;
|
||||||
|
|
||||||
@@ -38,5 +37,4 @@ public:
|
|||||||
explicit ClangFormatOptionsPage(ClangFormatSettings *settings);
|
explicit ClangFormatOptionsPage(ClangFormatSettings *settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // Beautifier::Internal
|
||||||
} // namespace Beautifier
|
|
||||||
|
@@ -1,141 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Beautifier::Internal::ClangFormatOptionsPage</class>
|
|
||||||
<widget class="QWidget" name="Beautifier::Internal::ClangFormatOptionsPage">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>727</width>
|
|
||||||
<height>631</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<widget class="QGroupBox" name="options">
|
|
||||||
<property name="title">
|
|
||||||
<string>Options</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QRadioButton" name="useCustomizedStyle">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use customized style:</string>
|
|
||||||
</property>
|
|
||||||
<property name="autoExclusive">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1" colspan="2">
|
|
||||||
<widget class="Beautifier::Internal::ConfigurationPanel" name="configurations" native="true"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QRadioButton" name="usePredefinedStyle">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Use predefined style:</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="autoExclusive">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" colspan="2">
|
|
||||||
<widget class="QComboBox" name="predefinedStyle"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLabel" name="fallbackStyleLabel">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Fallback style:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QComboBox" name="fallbackStyle">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QGroupBox" name="configuration">
|
|
||||||
<property name="title">
|
|
||||||
<string>Configuration</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="commandLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Clang Format command:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="Utils::PathChooser" name="command" native="true"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="mimeLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Restrict to MIME types:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="mime"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::PathChooser</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header location="global">utils/pathchooser.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>Beautifier::Internal::ConfigurationPanel</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header location="global">beautifier/configurationpanel.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Reference in New Issue
Block a user