forked from qt-creator/qt-creator
Vcpkg: Prevent user from re-inserting a preexisting dependency
If the selected package already exists as dependency in the project, the dialog shows an info label and prevents re-adding of the package bz disabling the OK button. Task-number: QTCREATORBUG-29333 Change-Id: Icd368bb2b0bde72ebe5efaea6a81e3cf96830ce3 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -99,7 +99,8 @@ public:
|
|||||||
Utils::Theme::IconsBaseColor}}).icon();
|
Utils::Theme::IconsBaseColor}}).icon();
|
||||||
m_searchPkgAction = toolBar()->addAction(vcpkgIcon, Tr::tr("Add vcpkg package..."));
|
m_searchPkgAction = toolBar()->addAction(vcpkgIcon, Tr::tr("Add vcpkg package..."));
|
||||||
connect(m_searchPkgAction, &QAction::triggered, this, [this] {
|
connect(m_searchPkgAction, &QAction::triggered, this, [this] {
|
||||||
const Search::VcpkgManifest package = Search::showVcpkgPackageSearchDialog();
|
const Search::VcpkgManifest package =
|
||||||
|
Search::showVcpkgPackageSearchDialog(documentToManifest());
|
||||||
if (!package.name.isEmpty()) {
|
if (!package.name.isEmpty()) {
|
||||||
const QByteArray modifiedDocument =
|
const QByteArray modifiedDocument =
|
||||||
addDependencyToManifest(textDocument()->contents(), package.name);
|
addDependencyToManifest(textDocument()->contents(), package.name);
|
||||||
@@ -111,10 +112,7 @@ public:
|
|||||||
Utils::Theme::IconsBaseColor}}).icon();
|
Utils::Theme::IconsBaseColor}}).icon();
|
||||||
m_cmakeCodeAction = toolBar()->addAction(cmakeIcon, Tr::tr("CMake code..."));
|
m_cmakeCodeAction = toolBar()->addAction(cmakeIcon, Tr::tr("CMake code..."));
|
||||||
connect(m_cmakeCodeAction, &QAction::triggered, this, [this] {
|
connect(m_cmakeCodeAction, &QAction::triggered, this, [this] {
|
||||||
bool ok = false;
|
CMakeCodeDialog dlg(documentToManifest().dependencies);
|
||||||
const Search::VcpkgManifest manifest =
|
|
||||||
Search::parseVcpkgManifest(textDocument()->contents(), &ok);
|
|
||||||
CMakeCodeDialog dlg(manifest.dependencies);
|
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -138,6 +136,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Search::VcpkgManifest documentToManifest() const
|
||||||
|
{
|
||||||
|
return Search::parseVcpkgManifest(textDocument()->contents());
|
||||||
|
}
|
||||||
|
|
||||||
QAction *m_searchPkgAction;
|
QAction *m_searchPkgAction;
|
||||||
QAction *m_cmakeCodeAction;
|
QAction *m_cmakeCodeAction;
|
||||||
};
|
};
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/infolabel.h>
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
@@ -28,17 +29,20 @@ namespace Vcpkg::Internal::Search {
|
|||||||
class VcpkgPackageSearchDialog : public QDialog
|
class VcpkgPackageSearchDialog : public QDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit VcpkgPackageSearchDialog(QWidget *parent);
|
explicit VcpkgPackageSearchDialog(const VcpkgManifest &preexistingPackages, QWidget *parent);
|
||||||
|
|
||||||
VcpkgManifest selectedPackage() const;
|
VcpkgManifest selectedPackage() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void listPackages(const QString &filter);
|
void listPackages(const QString &filter);
|
||||||
void showPackageDetails(const QString &packageName);
|
void showPackageDetails(const QString &packageName);
|
||||||
|
void updateStatus();
|
||||||
|
|
||||||
VcpkgManifests m_allPackages;
|
VcpkgManifests m_allPackages;
|
||||||
VcpkgManifest m_selectedPackage;
|
VcpkgManifest m_selectedPackage;
|
||||||
|
|
||||||
|
const VcpkgManifest m_projectManifest;
|
||||||
|
|
||||||
FancyLineEdit *m_packagesFilter;
|
FancyLineEdit *m_packagesFilter;
|
||||||
ListWidget *m_packagesList;
|
ListWidget *m_packagesList;
|
||||||
QLineEdit *m_vcpkgName;
|
QLineEdit *m_vcpkgName;
|
||||||
@@ -46,11 +50,14 @@ private:
|
|||||||
QLabel *m_vcpkgLicense;
|
QLabel *m_vcpkgLicense;
|
||||||
QTextBrowser *m_vcpkgDescription;
|
QTextBrowser *m_vcpkgDescription;
|
||||||
QLabel *m_vcpkgHomepage;
|
QLabel *m_vcpkgHomepage;
|
||||||
|
InfoLabel *m_infoLabel;
|
||||||
QDialogButtonBox *m_buttonBox;
|
QDialogButtonBox *m_buttonBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
VcpkgPackageSearchDialog::VcpkgPackageSearchDialog(QWidget *parent)
|
VcpkgPackageSearchDialog::VcpkgPackageSearchDialog(const VcpkgManifest &preexistingPackages,
|
||||||
|
QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
, m_projectManifest(preexistingPackages)
|
||||||
{
|
{
|
||||||
resize(920, 400);
|
resize(920, 400);
|
||||||
setWindowTitle(Tr::tr("Add vcpkg package"));
|
setWindowTitle(Tr::tr("Add vcpkg package"));
|
||||||
@@ -75,7 +82,11 @@ VcpkgPackageSearchDialog::VcpkgPackageSearchDialog(QWidget *parent)
|
|||||||
m_vcpkgHomepage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
m_vcpkgHomepage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
||||||
m_vcpkgHomepage->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
m_vcpkgHomepage->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||||
|
|
||||||
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
|
m_infoLabel = new InfoLabel(Tr::tr("This package is already a project dependency."),
|
||||||
|
InfoLabel::Information);
|
||||||
|
m_infoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||||
|
|
||||||
|
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
Column {
|
Column {
|
||||||
@@ -96,12 +107,13 @@ VcpkgPackageSearchDialog::VcpkgPackageSearchDialog(QWidget *parent)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
m_buttonBox,
|
Row { m_infoLabel, m_buttonBox },
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
|
|
||||||
m_allPackages = vcpkgManifests(settings().vcpkgRoot());
|
m_allPackages = vcpkgManifests(settings().vcpkgRoot());
|
||||||
|
|
||||||
listPackages({});
|
listPackages({});
|
||||||
|
updateStatus();
|
||||||
|
|
||||||
connect(m_packagesFilter, &FancyLineEdit::filterChanged,
|
connect(m_packagesFilter, &FancyLineEdit::filterChanged,
|
||||||
this, &VcpkgPackageSearchDialog::listPackages);
|
this, &VcpkgPackageSearchDialog::listPackages);
|
||||||
@@ -151,7 +163,16 @@ void VcpkgPackageSearchDialog::showPackageDetails(const QString &packageName)
|
|||||||
.arg(manifest.homepage.toDisplayString()));
|
.arg(manifest.homepage.toDisplayString()));
|
||||||
|
|
||||||
m_selectedPackage = manifest;
|
m_selectedPackage = manifest;
|
||||||
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!manifest.name.isEmpty());
|
updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VcpkgPackageSearchDialog::updateStatus()
|
||||||
|
{
|
||||||
|
const QString package = selectedPackage().name;
|
||||||
|
const bool isProjectDependency = m_projectManifest.dependencies.contains(package);
|
||||||
|
m_infoLabel->setVisible(isProjectDependency);
|
||||||
|
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!(package.isEmpty()
|
||||||
|
|| isProjectDependency));
|
||||||
}
|
}
|
||||||
|
|
||||||
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok)
|
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok)
|
||||||
@@ -219,10 +240,13 @@ VcpkgManifests vcpkgManifests(const FilePath &vcpkgRoot)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VcpkgManifest showVcpkgPackageSearchDialog(QWidget *parent)
|
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest, QWidget *parent)
|
||||||
{
|
{
|
||||||
VcpkgPackageSearchDialog dlg(parent ? parent : Core::ICore::dialogParent());
|
QWidget *dlgParent = parent ? parent : Core::ICore::dialogParent();
|
||||||
return (dlg.exec() == QDialog::Accepted) ? dlg.selectedPackage() : VcpkgManifest();
|
VcpkgPackageSearchDialog dlg(projectManifest, dlgParent);
|
||||||
|
const VcpkgManifest result = (dlg.exec() == QDialog::Accepted) ? dlg.selectedPackage()
|
||||||
|
: VcpkgManifest();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Vcpkg::Internal::Search
|
} // namespace Vcpkg::Internal::Search
|
||||||
|
@@ -25,6 +25,7 @@ using VcpkgManifests = QList<VcpkgManifest>;
|
|||||||
|
|
||||||
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok = nullptr);
|
VcpkgManifest parseVcpkgManifest(const QByteArray &vcpkgManifestJsonData, bool *ok = nullptr);
|
||||||
VcpkgManifests vcpkgManifests(const Utils::FilePath &vcpkgRoot);
|
VcpkgManifests vcpkgManifests(const Utils::FilePath &vcpkgRoot);
|
||||||
VcpkgManifest showVcpkgPackageSearchDialog(QWidget *parent = nullptr);
|
VcpkgManifest showVcpkgPackageSearchDialog(const VcpkgManifest &projectManifest,
|
||||||
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
} // namespace Vcpkg::Internal::Search
|
} // namespace Vcpkg::Internal::Search
|
||||||
|
Reference in New Issue
Block a user