forked from qt-creator/qt-creator
ExtensionManager: Improve Install step
Change-Id: I1668aa41a78fa9a0b6bd4505566268359746c4c7 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include <utils/wizardpage.h>
|
#include <utils/wizardpage.h>
|
||||||
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
@@ -47,6 +48,7 @@ struct Data
|
|||||||
FilePath extractedPath;
|
FilePath extractedPath;
|
||||||
bool installIntoApplication = false;
|
bool installIntoApplication = false;
|
||||||
std::unique_ptr<PluginSpec> pluginSpec = nullptr;
|
std::unique_ptr<PluginSpec> pluginSpec = nullptr;
|
||||||
|
bool loadImmediately = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool hasLibSuffix(const FilePath &path)
|
static bool hasLibSuffix(const FilePath &path)
|
||||||
@@ -314,20 +316,44 @@ public:
|
|||||||
|
|
||||||
m_summaryLabel = new QLabel(this);
|
m_summaryLabel = new QLabel(this);
|
||||||
m_summaryLabel->setWordWrap(true);
|
m_summaryLabel->setWordWrap(true);
|
||||||
Layouting::Column { m_summaryLabel }.attachTo(this);
|
m_summaryLabel->setTextFormat(Qt::MarkdownText);
|
||||||
|
m_summaryLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
|
||||||
|
m_summaryLabel->setOpenExternalLinks(true);
|
||||||
|
|
||||||
|
m_loadImmediately = new QCheckBox(Tr::tr("Load plugin immediately"));
|
||||||
|
connect(m_loadImmediately, &QCheckBox::toggled, this, [this](bool checked) {
|
||||||
|
m_data->loadImmediately = checked;
|
||||||
|
});
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
using namespace Layouting;
|
||||||
|
Column {
|
||||||
|
m_summaryLabel,
|
||||||
|
m_loadImmediately
|
||||||
|
}.attachTo(this);
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializePage() final
|
void initializePage() final
|
||||||
{
|
{
|
||||||
m_summaryLabel->setText(
|
const FilePath installLocation = m_data->pluginSpec->installLocation(
|
||||||
Tr::tr("\"%1\" will be installed into \"%2\".")
|
!m_data->installIntoApplication);
|
||||||
.arg(m_data->sourcePath.toUserOutput())
|
installLocation.ensureWritableDir();
|
||||||
.arg(m_data->pluginSpec->installLocation(!m_data->installIntoApplication)
|
|
||||||
.toUserOutput()));
|
m_summaryLabel->setText(Tr::tr("%1 will be installed into %2.")
|
||||||
|
.arg(QString("[%1](%2)")
|
||||||
|
.arg(m_data->sourcePath.fileName())
|
||||||
|
.arg(m_data->sourcePath.parentDir().toUrl().toString()))
|
||||||
|
.arg(QString("[%1](%2)")
|
||||||
|
.arg(installLocation.fileName())
|
||||||
|
.arg(installLocation.toUrl().toString())));
|
||||||
|
|
||||||
|
m_loadImmediately->setVisible(m_data->pluginSpec && m_data->pluginSpec->isSoftLoadable());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *m_summaryLabel;
|
QLabel *m_summaryLabel;
|
||||||
|
QCheckBox *m_loadImmediately;
|
||||||
Data *m_data = nullptr;
|
Data *m_data = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -395,27 +421,36 @@ bool executePluginInstallWizard(const FilePath &archive)
|
|||||||
auto summaryPage = new SummaryPage(&data, &wizard);
|
auto summaryPage = new SummaryPage(&data, &wizard);
|
||||||
wizard.addPage(summaryPage);
|
wizard.addPage(summaryPage);
|
||||||
|
|
||||||
if (wizard.exec()) {
|
auto install = [&wizard, &data]() {
|
||||||
const FilePath installPath = data.pluginSpec->installLocation(!data.installIntoApplication);
|
if (wizard.exec()) {
|
||||||
if (hasLibSuffix(data.sourcePath)) {
|
const FilePath installPath = data.pluginSpec->installLocation(
|
||||||
return copyPluginFile(data.sourcePath, installPath);
|
!data.installIntoApplication);
|
||||||
} else {
|
if (hasLibSuffix(data.sourcePath)) {
|
||||||
QString error;
|
return copyPluginFile(data.sourcePath, installPath);
|
||||||
FileUtils::CopyAskingForOverwrite copy(ICore::dialogParent(),
|
} else {
|
||||||
postCopyOperation());
|
QString error;
|
||||||
if (!FileUtils::copyRecursively(data.extractedPath,
|
FileUtils::CopyAskingForOverwrite copy(ICore::dialogParent(), postCopyOperation());
|
||||||
installPath,
|
if (!FileUtils::copyRecursively(data.extractedPath, installPath, &error, copy())) {
|
||||||
&error,
|
QMessageBox::warning(
|
||||||
copy())) {
|
ICore::dialogParent(), Tr::tr("Failed to Copy Plugin Files"), error);
|
||||||
QMessageBox::warning(ICore::dialogParent(),
|
return false;
|
||||||
Tr::tr("Failed to Copy Plugin Files"),
|
}
|
||||||
error);
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!install())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (data.loadImmediately) {
|
||||||
|
auto spec = data.pluginSpec.release();
|
||||||
|
spec->setEnabledBySettings(true);
|
||||||
|
PluginManager::addPlugins({spec});
|
||||||
|
PluginManager::loadPluginsAtRuntime({spec});
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
@@ -729,8 +729,8 @@ void ExtensionManagerWidget::fetchAndInstallPlugin(const QUrl &url)
|
|||||||
if (storage->packageData.isEmpty())
|
if (storage->packageData.isEmpty())
|
||||||
return;
|
return;
|
||||||
const FilePath source = FilePath::fromUrl(storage->url);
|
const FilePath source = FilePath::fromUrl(storage->url);
|
||||||
TempFileSaver saver(TemporaryDirectory::masterDirectoryPath()
|
TempFileSaver saver(
|
||||||
+ "/XXXXXX" + source.fileName());
|
TemporaryDirectory::masterDirectoryPath() + "/XXXXXX-" + source.fileName());
|
||||||
|
|
||||||
saver.write(storage->packageData);
|
saver.write(storage->packageData);
|
||||||
if (saver.finalize(ICore::dialogParent()))
|
if (saver.finalize(ICore::dialogParent()))
|
||||||
|
Reference in New Issue
Block a user