2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-05-06 12:51:08 +02:00
|
|
|
|
|
|
|
|
#include "customparserssettingspage.h"
|
|
|
|
|
|
|
|
|
|
#include "customparser.h"
|
|
|
|
|
#include "customparserconfigdialog.h"
|
|
|
|
|
#include "projectexplorer.h"
|
|
|
|
|
#include "projectexplorerconstants.h"
|
2023-01-13 12:38:22 +01:00
|
|
|
#include "projectexplorertr.h"
|
2020-05-06 12:51:08 +02:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
2020-08-07 15:39:59 +02:00
|
|
|
#include <QLabel>
|
2020-05-06 12:51:08 +02:00
|
|
|
#include <QList>
|
|
|
|
|
#include <QListWidget>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class CustomParsersSettingsWidget final : public Core::IOptionsPageWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CustomParsersSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
m_customParsers = ProjectExplorerPlugin::customParsers();
|
|
|
|
|
resetListView();
|
|
|
|
|
|
|
|
|
|
const auto mainLayout = new QVBoxLayout(this);
|
|
|
|
|
const auto widgetLayout = new QHBoxLayout;
|
|
|
|
|
mainLayout->addLayout(widgetLayout);
|
2023-01-13 12:38:22 +01:00
|
|
|
const auto hintLabel = new QLabel(Tr::tr(
|
2020-08-07 15:39:59 +02:00
|
|
|
"Custom output parsers defined here can be enabled individually "
|
|
|
|
|
"in the project's build or run settings."));
|
|
|
|
|
mainLayout->addWidget(hintLabel);
|
2020-05-06 12:51:08 +02:00
|
|
|
widgetLayout->addWidget(&m_parserListView);
|
|
|
|
|
const auto buttonLayout = new QVBoxLayout;
|
|
|
|
|
widgetLayout->addLayout(buttonLayout);
|
2023-01-13 12:38:22 +01:00
|
|
|
const auto addButton = new QPushButton(Tr::tr("Add..."));
|
|
|
|
|
const auto removeButton = new QPushButton(Tr::tr("Remove"));
|
2020-05-06 12:51:08 +02:00
|
|
|
const auto editButton = new QPushButton("Edit...");
|
|
|
|
|
buttonLayout->addWidget(addButton);
|
|
|
|
|
buttonLayout->addWidget(removeButton);
|
|
|
|
|
buttonLayout->addWidget(editButton);
|
|
|
|
|
buttonLayout->addStretch(1);
|
|
|
|
|
|
2023-08-01 20:31:02 +02:00
|
|
|
connect(addButton, &QPushButton::clicked, this, [this] {
|
2020-05-06 12:51:08 +02:00
|
|
|
CustomParserConfigDialog dlg(this);
|
|
|
|
|
dlg.setSettings(CustomParserSettings());
|
|
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
|
|
|
|
CustomParserSettings newParser = dlg.settings();
|
2024-07-12 11:32:14 +02:00
|
|
|
newParser.id = Utils::Id::generate();
|
2023-01-13 12:38:22 +01:00
|
|
|
newParser.displayName = Tr::tr("New Parser");
|
2020-05-06 12:51:08 +02:00
|
|
|
m_customParsers << newParser;
|
|
|
|
|
resetListView();
|
|
|
|
|
});
|
2023-08-01 20:31:02 +02:00
|
|
|
connect(removeButton, &QPushButton::clicked, this, [this] {
|
2020-05-06 12:51:08 +02:00
|
|
|
const QList<QListWidgetItem *> sel = m_parserListView.selectedItems();
|
|
|
|
|
QTC_ASSERT(sel.size() == 1, return);
|
|
|
|
|
m_customParsers.removeAt(m_parserListView.row(sel.first()));
|
|
|
|
|
delete sel.first();
|
|
|
|
|
});
|
2023-08-01 20:31:02 +02:00
|
|
|
connect(editButton, &QPushButton::clicked, this, [this] {
|
2020-05-06 12:51:08 +02:00
|
|
|
const QList<QListWidgetItem *> sel = m_parserListView.selectedItems();
|
|
|
|
|
QTC_ASSERT(sel.size() == 1, return);
|
|
|
|
|
CustomParserSettings &s = m_customParsers[m_parserListView.row(sel.first())];
|
|
|
|
|
CustomParserConfigDialog dlg(this);
|
|
|
|
|
dlg.setSettings(s);
|
|
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
|
|
|
|
s.error = dlg.settings().error;
|
|
|
|
|
s.warning = dlg.settings().warning;
|
|
|
|
|
});
|
|
|
|
|
|
2023-08-01 20:31:02 +02:00
|
|
|
connect(&m_parserListView, &QListWidget::itemChanged, this, [this](QListWidgetItem *item) {
|
2020-05-06 12:51:08 +02:00
|
|
|
m_customParsers[m_parserListView.row(item)].displayName = item->text();
|
|
|
|
|
resetListView();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const auto updateButtons = [this, removeButton, editButton] {
|
|
|
|
|
const bool enable = !m_parserListView.selectedItems().isEmpty();
|
|
|
|
|
removeButton->setEnabled(enable);
|
|
|
|
|
editButton->setEnabled(enable);
|
|
|
|
|
};
|
|
|
|
|
updateButtons();
|
|
|
|
|
connect(m_parserListView.selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
|
updateButtons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void apply() override { ProjectExplorerPlugin::setCustomParsers(m_customParsers); }
|
|
|
|
|
|
|
|
|
|
void resetListView()
|
|
|
|
|
{
|
|
|
|
|
m_parserListView.clear();
|
|
|
|
|
Utils::sort(m_customParsers,
|
|
|
|
|
[](const CustomParserSettings &s1, const CustomParserSettings &s2) {
|
|
|
|
|
return s1.displayName < s2.displayName;
|
|
|
|
|
});
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const CustomParserSettings &s : std::as_const(m_customParsers)) {
|
2020-05-06 12:51:08 +02:00
|
|
|
const auto item = new QListWidgetItem(s.displayName);
|
|
|
|
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
|
|
|
|
|
m_parserListView.addItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QListWidget m_parserListView;
|
|
|
|
|
QList<CustomParserSettings> m_customParsers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CustomParsersSettingsPage::CustomParsersSettingsPage()
|
|
|
|
|
{
|
|
|
|
|
setId(Constants::CUSTOM_PARSERS_SETTINGS_PAGE_ID);
|
2023-01-13 12:38:22 +01:00
|
|
|
setDisplayName(Tr::tr("Custom Output Parsers"));
|
2020-05-06 12:51:08 +02:00
|
|
|
setCategory(Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
|
|
|
|
|
setWidgetCreator([] { return new CustomParsersSettingsWidget; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ProjectExplorer
|