forked from qt-creator/qt-creator
Vcpkg: streamline vcpkgmanifesteditor.cpp a bit
Change-Id: Iabb1056f789b1e30f95d469ea18ccfb04e978b46 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -29,26 +29,49 @@
|
|||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
|
|
||||||
|
using namespace TextEditor;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Vcpkg::Internal {
|
namespace Vcpkg::Internal {
|
||||||
|
|
||||||
class CMakeCodeDialog : public QDialog
|
static QString cmakeCodeForPackage(const QString &package)
|
||||||
|
{
|
||||||
|
QString result;
|
||||||
|
|
||||||
|
const FilePath usageFile = settings().vcpkgRoot() / "ports" / package / "usage";
|
||||||
|
if (usageFile.exists()) {
|
||||||
|
FileReader reader;
|
||||||
|
if (reader.fetch(usageFile))
|
||||||
|
result = QString::fromUtf8(reader.data());
|
||||||
|
} else {
|
||||||
|
result = QString(
|
||||||
|
R"(The package %1 provides CMake targets:
|
||||||
|
|
||||||
|
# this is heuristically generated, and may not be correct
|
||||||
|
find_package(%1 CONFIG REQUIRED)
|
||||||
|
target_link_libraries(main PRIVATE %1::%1))" ).arg(package);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString cmakeCodeForPackages(const QStringList &packages)
|
||||||
|
{
|
||||||
|
QString result;
|
||||||
|
for (const QString &package : packages)
|
||||||
|
result.append(cmakeCodeForPackage(package) + "\n\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CMakeCodeDialog final : public QDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CMakeCodeDialog(const QStringList &packages, QWidget *parent = nullptr);
|
explicit CMakeCodeDialog(const QStringList &packages)
|
||||||
|
|
||||||
private:
|
|
||||||
static QString cmakeCodeForPackage(const QString &package);
|
|
||||||
static QString cmakeCodeForPackages(const QStringList &packages);
|
|
||||||
};
|
|
||||||
|
|
||||||
CMakeCodeDialog::CMakeCodeDialog(const QStringList &packages, QWidget *parent)
|
|
||||||
: QDialog(parent)
|
|
||||||
{
|
{
|
||||||
resize(600, 600);
|
resize(600, 600);
|
||||||
|
|
||||||
auto codeBrowser = new QPlainTextEdit;
|
auto codeBrowser = new QPlainTextEdit;
|
||||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::fontSettings();
|
codeBrowser->setFont(TextEditorSettings::fontSettings().font());
|
||||||
codeBrowser->setFont(fs.font());
|
|
||||||
codeBrowser->setPlainText(cmakeCodeForPackages(packages));
|
codeBrowser->setPlainText(cmakeCodeForPackages(packages));
|
||||||
|
|
||||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
@@ -62,38 +85,9 @@ CMakeCodeDialog::CMakeCodeDialog(const QStringList &packages, QWidget *parent)
|
|||||||
|
|
||||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
QString CMakeCodeDialog::cmakeCodeForPackage(const QString &package)
|
class VcpkgManifestEditorWidget final : public TextEditor::TextEditorWidget
|
||||||
{
|
|
||||||
QString result;
|
|
||||||
|
|
||||||
const Utils::FilePath usageFile = settings().vcpkgRoot() / "ports" / package / "usage";
|
|
||||||
if (usageFile.exists()) {
|
|
||||||
Utils::FileReader reader;
|
|
||||||
if (reader.fetch(usageFile))
|
|
||||||
result = QString::fromUtf8(reader.data());
|
|
||||||
} else {
|
|
||||||
result = QString(
|
|
||||||
R"(The package %1 provides CMake targets:
|
|
||||||
|
|
||||||
# this is heuristically generated, and may not be correct
|
|
||||||
find_package(%1 CONFIG REQUIRED)
|
|
||||||
target_link_libraries(main PRIVATE %1::%1))"
|
|
||||||
).arg(package);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CMakeCodeDialog::cmakeCodeForPackages(const QStringList &packages)
|
|
||||||
{
|
|
||||||
QString result;
|
|
||||||
for (const QString &package : packages)
|
|
||||||
result.append(cmakeCodeForPackage(package) + "\n\n");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class VcpkgManifestEditorWidget : public TextEditor::TextEditorWidget
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VcpkgManifestEditorWidget()
|
VcpkgManifestEditorWidget()
|
||||||
@@ -147,9 +141,9 @@ private:
|
|||||||
QAction *m_cmakeCodeAction;
|
QAction *m_cmakeCodeAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
static TextEditor::TextDocument *createVcpkgManifestDocument()
|
static TextDocument *createVcpkgManifestDocument()
|
||||||
{
|
{
|
||||||
auto doc = new TextEditor::TextDocument;
|
auto doc = new TextDocument;
|
||||||
doc->setId(Constants::VCPKGMANIFEST_EDITOR_ID);
|
doc->setId(Constants::VCPKGMANIFEST_EDITOR_ID);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
@@ -164,7 +158,7 @@ QByteArray addDependencyToManifest(const QByteArray &manifest, const QString &pa
|
|||||||
return QJsonDocument(jsonObject).toJson();
|
return QJsonDocument(jsonObject).toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
class VcpkgManifestEditorFactory final : public TextEditor::TextEditorFactory
|
class VcpkgManifestEditorFactory final : public TextEditorFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VcpkgManifestEditorFactory()
|
VcpkgManifestEditorFactory()
|
||||||
|
Reference in New Issue
Block a user