forked from qt-creator/qt-creator
Install: Use QMessageBox as fallback
Use a QMessageBox if the InfoBar would be hidden. Change-Id: I29f10a3af6123dcf7811db68b967259f990c5a66 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -17,8 +17,10 @@
|
|||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
#include <utils/unarchiver.h>
|
#include <utils/unarchiver.h>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
@@ -301,14 +303,7 @@ void addInstallModule()
|
|||||||
installOptionsList.append({url, name, version});
|
installOptionsList.append({url, name, version});
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::Id infoBarId = Utils::Id::fromString(
|
auto install = [&state, pluginSpec, installOptionsList, callback]() {
|
||||||
"Install" + pluginSpec->name + QString::number(qHash(installOptionsList)));
|
|
||||||
|
|
||||||
InfoBarEntry entry(infoBarId, msg, InfoBarEntry::GlobalSuppression::Enabled);
|
|
||||||
|
|
||||||
entry.addCustomButton(
|
|
||||||
Tr::tr("Install"),
|
|
||||||
[infoBarId, &state, pluginSpec, installOptionsList, callback]() {
|
|
||||||
auto tree = state.createTree();
|
auto tree = state.createTree();
|
||||||
|
|
||||||
auto progress = new TaskProgress(tree);
|
auto progress = new TaskProgress(tree);
|
||||||
@@ -317,14 +312,50 @@ void addInstallModule()
|
|||||||
tree->setRecipe(
|
tree->setRecipe(
|
||||||
installRecipe(pluginSpec->appDataPath, installOptionsList, callback));
|
installRecipe(pluginSpec->appDataPath, installOptionsList, callback));
|
||||||
tree->start();
|
tree->start();
|
||||||
|
};
|
||||||
|
|
||||||
|
auto denied = [callback]() { callback(false, "User denied installation"); };
|
||||||
|
|
||||||
|
if (QApplication::activeModalWidget()) {
|
||||||
|
auto msgBox = new QMessageBox(
|
||||||
|
QMessageBox::Question,
|
||||||
|
Tr::tr("Install package"),
|
||||||
|
msg,
|
||||||
|
QMessageBox::Yes | QMessageBox::No,
|
||||||
|
Core::ICore::dialogParent());
|
||||||
|
|
||||||
|
const QString details
|
||||||
|
= Tr::tr("The plugin \"%1\" would like to install the following "
|
||||||
|
"package(s):\n\n")
|
||||||
|
.arg(pluginSpec->name)
|
||||||
|
+ Utils::transform(installOptionsList, [](const InstallOptions &options) {
|
||||||
|
return QString("* %1 - %2 (from: %3)")
|
||||||
|
.arg(options.name, options.version, options.url.toString());
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
msgBox->setDetailedText(details);
|
||||||
|
|
||||||
|
auto guard = pluginSpec->connectionGuard.get();
|
||||||
|
QObject::connect(msgBox, &QMessageBox::accepted, guard, install);
|
||||||
|
QObject::connect(msgBox, &QMessageBox::rejected, guard, denied);
|
||||||
|
|
||||||
|
msgBox->show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Utils::Id infoBarId = Utils::Id::fromString(
|
||||||
|
"Install" + pluginSpec->name + QString::number(qHash(installOptionsList)));
|
||||||
|
|
||||||
|
InfoBarEntry entry(infoBarId, msg, InfoBarEntry::GlobalSuppression::Enabled);
|
||||||
|
|
||||||
|
entry.addCustomButton(Tr::tr("Install"), [install, infoBarId]() {
|
||||||
|
install();
|
||||||
Core::ICore::infoBar()->removeInfo(infoBarId);
|
Core::ICore::infoBar()->removeInfo(infoBarId);
|
||||||
});
|
});
|
||||||
entry.setCancelButtonInfo(
|
|
||||||
[callback]() { callback(false, "User denied installation"); });
|
|
||||||
|
|
||||||
entry.setDetailsWidgetCreator([pluginSpec, installOptionsList]() -> QWidget * {
|
entry.setCancelButtonInfo(denied);
|
||||||
const QString markdown
|
|
||||||
|
const QString details
|
||||||
= Tr::tr("The plugin \"**%1**\" would like to install the following "
|
= Tr::tr("The plugin \"**%1**\" would like to install the following "
|
||||||
"package(s):\n\n")
|
"package(s):\n\n")
|
||||||
.arg(pluginSpec->name)
|
.arg(pluginSpec->name)
|
||||||
@@ -333,9 +364,10 @@ void addInstallModule()
|
|||||||
.arg(options.name, options.version, options.url.toString());
|
.arg(options.name, options.version, options.url.toString());
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
|
|
||||||
|
entry.setDetailsWidgetCreator([details]() -> QWidget * {
|
||||||
QLabel *list = new QLabel();
|
QLabel *list = new QLabel();
|
||||||
list->setTextFormat(Qt::TextFormat::MarkdownText);
|
list->setTextFormat(Qt::TextFormat::MarkdownText);
|
||||||
list->setText(markdown);
|
list->setText(details);
|
||||||
list->setMargin(StyleHelper::SpacingTokens::ExPaddingGapS);
|
list->setMargin(StyleHelper::SpacingTokens::ExPaddingGapS);
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user