forked from qt-creator/qt-creator
InfoBar: Make adding more buttons possible
Change-Id: Ic0c946cf3f87fe46cd06391f38e0bc71374ad340 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -85,10 +85,9 @@ InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _
|
||||
{
|
||||
}
|
||||
|
||||
void InfoBarEntry::setCustomButtonInfo(const QString &_buttonText, CallBack callBack)
|
||||
void InfoBarEntry::addCustomButton(const QString &buttonText, CallBack callBack)
|
||||
{
|
||||
m_buttonText = _buttonText;
|
||||
m_buttonCallBack = callBack;
|
||||
m_buttons.append({buttonText, callBack});
|
||||
}
|
||||
|
||||
void InfoBarEntry::setCancelButtonInfo(CallBack callBack)
|
||||
@@ -317,11 +316,10 @@ void InfoBarDisplay::update()
|
||||
hbox->addWidget(cb);
|
||||
}
|
||||
|
||||
if (!info.m_buttonText.isEmpty()) {
|
||||
for (const InfoBarEntry::Button &button : qAsConst(info.m_buttons)) {
|
||||
auto infoWidgetButton = new QToolButton;
|
||||
infoWidgetButton->setText(info.m_buttonText);
|
||||
connect(infoWidgetButton, &QAbstractButton::clicked, [info]() { info.m_buttonCallBack(); });
|
||||
|
||||
infoWidgetButton->setText(button.text);
|
||||
connect(infoWidgetButton, &QAbstractButton::clicked, [button]() { button.callback(); });
|
||||
hbox->addWidget(infoWidgetButton);
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ public:
|
||||
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppression _globalSuppression = GlobalSuppression::Disabled);
|
||||
|
||||
using CallBack = std::function<void()>;
|
||||
void setCustomButtonInfo(const QString &_buttonText, CallBack callBack);
|
||||
void addCustomButton(const QString &_buttonText, CallBack callBack);
|
||||
void setCancelButtonInfo(CallBack callBack);
|
||||
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
|
||||
using ComboCallBack = std::function<void(const QString &)>;
|
||||
@@ -68,10 +68,15 @@ public:
|
||||
void setDetailsWidgetCreator(const DetailsWidgetCreator &creator);
|
||||
|
||||
private:
|
||||
struct Button
|
||||
{
|
||||
QString text;
|
||||
CallBack callback;
|
||||
};
|
||||
|
||||
Id m_id;
|
||||
QString m_infoText;
|
||||
QString m_buttonText;
|
||||
CallBack m_buttonCallBack;
|
||||
QList<Button> m_buttons;
|
||||
QString m_cancelButtonText;
|
||||
CallBack m_cancelButtonCallBack;
|
||||
GlobalSuppression m_globalSuppression;
|
||||
|
@@ -746,7 +746,7 @@ void AndroidManifestEditorWidget::updateInfoBar(const QString &errorMessage, int
|
||||
else
|
||||
text = tr("%2: Could not parse file: \"%1\".").arg(errorMessage).arg(line);
|
||||
Utils::InfoBarEntry infoBarEntry(infoBarId, text);
|
||||
infoBarEntry.setCustomButtonInfo(tr("Goto error"), [this]() {
|
||||
infoBarEntry.addCustomButton(tr("Goto error"), [this]() {
|
||||
m_textEditorWidget->gotoLine(m_errorLine, m_errorColumn);
|
||||
});
|
||||
infoBar->removeInfo(infoBarId);
|
||||
|
@@ -195,7 +195,7 @@ void AndroidPlugin::askUserAboutAndroidSetup()
|
||||
"Android kits can be usable and all essential packages are installed. "
|
||||
"To do it later, select Options > Devices > Android."),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Configure Android"), [this] {
|
||||
info.addCustomButton(tr("Configure Android"), [this] {
|
||||
Core::ICore::infoBar()->removeInfo(kSetupAndroidSetting);
|
||||
Core::ICore::infoBar()->globallySuppressInfo(kSetupAndroidSetting);
|
||||
QTimer::singleShot(0, this, [this]() { d->potentialKit.executeFromMenu(); });
|
||||
|
@@ -415,7 +415,7 @@ void CorePlugin::warnAboutCrashReporing()
|
||||
|
||||
Utils::InfoBarEntry info(kWarnCrashReportingSetting, warnStr,
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Configure..."), [] {
|
||||
info.addCustomButton(tr("Configure..."), [] {
|
||||
ICore::infoBar()->removeInfo(kWarnCrashReportingSetting);
|
||||
ICore::infoBar()->globallySuppressInfo(kWarnCrashReportingSetting);
|
||||
ICore::showOptionsDialog(Core::Constants::SETTINGS_ID_SYSTEM);
|
||||
|
@@ -2034,12 +2034,12 @@ void EditorManagerPrivate::updateMakeWritableWarning()
|
||||
InfoBarEntry info(Id(kMakeWritableWarning),
|
||||
tr("<b>Warning:</b> This file was not opened in %1 yet.")
|
||||
.arg(versionControl->displayName()));
|
||||
info.setCustomButtonInfo(tr("Open"), &vcsOpenCurrentEditor);
|
||||
info.addCustomButton(tr("Open"), &vcsOpenCurrentEditor);
|
||||
document->infoBar()->addInfo(info);
|
||||
} else {
|
||||
InfoBarEntry info(Id(kMakeWritableWarning),
|
||||
tr("<b>Warning:</b> You are changing a read-only file."));
|
||||
info.setCustomButtonInfo(tr("Make Writable"), &makeCurrentEditorWritable);
|
||||
info.addCustomButton(tr("Make Writable"), &makeCurrentEditorWritable);
|
||||
document->infoBar()->addInfo(info);
|
||||
}
|
||||
} else {
|
||||
|
@@ -285,7 +285,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search
|
||||
tr("The search resulted in more than %n items, do you still want to continue?",
|
||||
nullptr, SEARCHRESULT_WARNING_LIMIT));
|
||||
info.setCancelButtonInfo(tr("Cancel"), [this]() { cancelAfterSizeWarning(); });
|
||||
info.setCustomButtonInfo(tr("Continue"), [this]() { continueAfterSizeWarning(); });
|
||||
info.addCustomButton(tr("Continue"), [this]() { continueAfterSizeWarning(); });
|
||||
m_infoBar.addInfo(info);
|
||||
emit requestPopup(false/*no focus*/);
|
||||
}
|
||||
|
@@ -308,7 +308,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inpu
|
||||
.arg(versionControl->displayName()),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
d->m_unconfiguredVcs = versionControl;
|
||||
info.setCustomButtonInfo(ICore::msgShowOptionsDialog(), []() {
|
||||
info.addCustomButton(ICore::msgShowOptionsDialog(), []() {
|
||||
QTC_ASSERT(d->m_unconfiguredVcs, return);
|
||||
ICore::showOptionsDialog(d->m_unconfiguredVcs->id());
|
||||
});
|
||||
|
@@ -139,7 +139,7 @@ static InfoBarEntry createMinimizableInfo(const Id &id,
|
||||
// The minimizer() might delete the "Minimize" button immediately and as
|
||||
// result invalid reads will happen in QToolButton::mouseReleaseEvent().
|
||||
// Avoid this by running the minimizer in the next event loop iteration.
|
||||
info.setCustomButtonInfo(MinimizableInfoBars::tr("Minimize"), [minimizer] {
|
||||
info.addCustomButton(MinimizableInfoBars::tr("Minimize"), [minimizer] {
|
||||
QMetaObject::invokeMethod(settings(), [minimizer] { minimizer(); }, Qt::QueuedConnection);
|
||||
});
|
||||
|
||||
|
@@ -778,7 +778,7 @@ IEditor *FormEditorData::createEditor()
|
||||
if (formWindowEditor) {
|
||||
Utils::InfoBarEntry info(Id(Constants::INFO_READ_ONLY),
|
||||
tr("This file can only be edited in <b>Design</b> mode."));
|
||||
info.setCustomButtonInfo(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
||||
info.addCustomButton(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
||||
formWindowEditor->document()->infoBar()->addInfo(info);
|
||||
}
|
||||
return formWindowEditor;
|
||||
|
@@ -315,7 +315,7 @@ void DiffEditorWidgetController::updateCannotDecodeInfo()
|
||||
tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding.")
|
||||
.arg(m_document->displayName(),
|
||||
QString::fromLatin1(m_document->codec()->name())));
|
||||
info.setCustomButtonInfo(tr("Select Encoding"), [this]() { m_document->selectEncoding(); });
|
||||
info.addCustomButton(tr("Select Encoding"), [this]() { m_document->selectEncoding(); });
|
||||
infoBar->addInfo(info);
|
||||
} else {
|
||||
infoBar->removeInfo(selectEncodingId);
|
||||
|
@@ -114,7 +114,7 @@ void McuSupportPlugin::askUserAboutMcuSupportKitsSetup()
|
||||
tr("Create Kits for Qt for MCUs? "
|
||||
"To do it later, select Options > Devices > MCU."),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Create Kits for Qt for MCUs"), [setupMcuSupportKits] {
|
||||
info.addCustomButton(tr("Create Kits for Qt for MCUs"), [setupMcuSupportKits] {
|
||||
ICore::infoBar()->removeInfo(setupMcuSupportKits);
|
||||
QTimer::singleShot(0, []() { ICore::showOptionsDialog(Constants::SETTINGS_ID); });
|
||||
});
|
||||
@@ -141,7 +141,7 @@ void McuSupportPlugin::askUserAboutMcuSupportKitsUpgrade()
|
||||
McuSupportOptions::UpgradeOption::Replace;
|
||||
});
|
||||
|
||||
info.setCustomButtonInfo(tr("Proceed"), [upgradeMcuSupportKits] {
|
||||
info.addCustomButton(tr("Proceed"), [upgradeMcuSupportKits] {
|
||||
ICore::infoBar()->removeInfo(upgradeMcuSupportKits);
|
||||
QTimer::singleShot(0, []() { McuSupportOptions::upgradeKits(selectedOption); });
|
||||
});
|
||||
|
@@ -382,8 +382,8 @@ void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
|
||||
Utils::InfoBarEntry info(installPylsInfoBarId,
|
||||
message,
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Install"),
|
||||
[=]() { installPythonLanguageServer(python, document); });
|
||||
info.addCustomButton(tr("Install"),
|
||||
[=]() { installPythonLanguageServer(python, document); });
|
||||
infoBar->addInfo(info);
|
||||
m_infoBarEntries[python] << document;
|
||||
} else if (state.state == PythonLanguageServerState::AlreadyInstalled
|
||||
@@ -394,8 +394,7 @@ void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
|
||||
Utils::InfoBarEntry info(startPylsInfoBarId,
|
||||
message,
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Set Up"),
|
||||
[=]() { setupPythonLanguageServer(python, document); });
|
||||
info.addCustomButton(tr("Set Up"), [=]() { setupPythonLanguageServer(python, document); });
|
||||
infoBar->addInfo(info);
|
||||
m_infoBarEntries[python] << document;
|
||||
} else if (state.state == PythonLanguageServerState::ConfiguredButDisabled
|
||||
@@ -405,8 +404,7 @@ void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
|
||||
Utils::InfoBarEntry info(enablePylsInfoBarId,
|
||||
message,
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Enable"),
|
||||
[=]() { enablePythonLanguageServer(python, document); });
|
||||
info.addCustomButton(tr("Enable"), [=]() { enablePythonLanguageServer(python, document); });
|
||||
infoBar->addInfo(info);
|
||||
m_infoBarEntries[python] << document;
|
||||
}
|
||||
|
@@ -700,7 +700,7 @@ void QmlJSEditorDocument::setIsDesignModePreferred(bool value)
|
||||
if (infoBar()->canInfoBeAdded(QML_UI_FILE_WARNING)) {
|
||||
Utils::InfoBarEntry info(QML_UI_FILE_WARNING,
|
||||
tr("This file should only be edited in <b>Design</b> mode."));
|
||||
info.setCustomButtonInfo(tr("Switch Mode"), []() {
|
||||
info.addCustomButton(tr("Switch Mode"), []() {
|
||||
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
|
||||
});
|
||||
infoBar()->addInfo(info);
|
||||
|
@@ -113,7 +113,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
|
||||
info(openInQDSAppSetting,
|
||||
tr("Would you like to open the project in Qt Design Studio?"),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Disabled);
|
||||
info.setCustomButtonInfo(tr("Open in Qt Design Studio"), [&, fileName] {
|
||||
info.addCustomButton(tr("Open in Qt Design Studio"), [&, fileName] {
|
||||
Core::ICore::infoBar()->removeInfo(openInQDSAppSetting);
|
||||
QmlProjectPlugin::openQDS(fileName);
|
||||
});
|
||||
|
@@ -212,7 +212,7 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
|
||||
info(openInQDSAppSetting,
|
||||
description + "\n" + tr("Do you want to open this file in Qt Design Studio?"),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Disabled);
|
||||
info.setCustomButtonInfo(tr("Open in Qt Design Studio"), [filePath] {
|
||||
info.addCustomButton(tr("Open in Qt Design Studio"), [filePath] {
|
||||
Core::ICore::infoBar()->removeInfo(openInQDSAppSetting);
|
||||
|
||||
if (findAndOpenProject(filePath)) {
|
||||
|
@@ -121,7 +121,7 @@ static void askAboutQtInstallation()
|
||||
"Link with a Qt installation to automatically register Qt versions and kits? To do "
|
||||
"this later, select Options > Kits > Qt Versions > Link with Qt."),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(QtSupportPlugin::tr("Link with Qt"), [] {
|
||||
info.addCustomButton(QtSupportPlugin::tr("Link with Qt"), [] {
|
||||
ICore::infoBar()->removeInfo(kLinkWithQtInstallationSetting);
|
||||
QTimer::singleShot(0, ICore::dialogParent(), &QtOptionsPage::linkWithQt);
|
||||
});
|
||||
|
@@ -163,7 +163,7 @@ IEditor *ScxmlEditorData::createEditor()
|
||||
if (xmlEditor) {
|
||||
Utils::InfoBarEntry info(Id(Constants::INFO_READ_ONLY),
|
||||
tr("This file can only be edited in <b>Design</b> mode."));
|
||||
info.setCustomButtonInfo(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
||||
info.addCustomButton(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
|
||||
xmlEditor->document()->infoBar()->addInfo(info);
|
||||
}
|
||||
|
||||
|
@@ -1599,7 +1599,7 @@ void TextEditorWidgetPrivate::updateCannotDecodeInfo()
|
||||
InfoBarEntry info(selectEncodingId,
|
||||
TextEditorWidget::tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
|
||||
.arg(m_document->displayName(), QString::fromLatin1(m_document->codec()->name())));
|
||||
info.setCustomButtonInfo(TextEditorWidget::tr("Select Encoding"), [this]() { q->selectEncoding(); });
|
||||
info.addCustomButton(TextEditorWidget::tr("Select Encoding"), [this]() { q->selectEncoding(); });
|
||||
infoBar->addInfo(info);
|
||||
} else {
|
||||
infoBar->removeInfo(selectEncodingId);
|
||||
@@ -3234,7 +3234,7 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions
|
||||
BaseTextEditor::tr("A highlight definition was not found for this file. "
|
||||
"Would you like to download additional highlight definition files?"),
|
||||
InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(BaseTextEditor::tr("Download Definitions"), [missing, this]() {
|
||||
info.addCustomButton(BaseTextEditor::tr("Download Definitions"), [missing, this]() {
|
||||
m_document->infoBar()->removeInfo(missing);
|
||||
Highlighter::downloadDefinitions();
|
||||
});
|
||||
@@ -3250,7 +3250,7 @@ void TextEditorWidgetPrivate::updateSyntaxInfoBar(const Highlighter::Definitions
|
||||
this->configureGenericHighlighter(Highlighter::definitionForName(definition));
|
||||
});
|
||||
|
||||
info.setCustomButtonInfo(BaseTextEditor::tr("Remember My Choice"), [multiple, this]() {
|
||||
info.addCustomButton(BaseTextEditor::tr("Remember My Choice"), [multiple, this]() {
|
||||
m_document->infoBar()->removeInfo(multiple);
|
||||
rememberCurrentSyntaxDefinition();
|
||||
});
|
||||
|
@@ -206,7 +206,7 @@ void UpdateInfoPlugin::checkForUpdatesFinished()
|
||||
d->m_progress->setKeepOnFinish(FutureProgress::HideOnFinish);
|
||||
emit newUpdatesAvailable(true);
|
||||
Utils::InfoBarEntry info(InstallUpdates, tr("New updates are available. Start the update?"));
|
||||
info.setCustomButtonInfo(tr("Start Update"), [this] {
|
||||
info.addCustomButton(tr("Start Update"), [this] {
|
||||
Core::ICore::infoBar()->removeInfo(InstallUpdates);
|
||||
startUpdater();
|
||||
});
|
||||
|
@@ -108,7 +108,7 @@ void WebAssemblyPlugin::askUserAboutEmSdkSetup()
|
||||
tr("Setup Emscripten SDK for WebAssembly? "
|
||||
"To do it later, select Options > Devices > WebAssembly."),
|
||||
InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Setup Emscripten SDK"), [setupWebAssemblyEmSdk] {
|
||||
info.addCustomButton(tr("Setup Emscripten SDK"), [setupWebAssemblyEmSdk] {
|
||||
ICore::infoBar()->removeInfo(setupWebAssemblyEmSdk);
|
||||
QTimer::singleShot(0, []() { ICore::showOptionsDialog(Constants::SETTINGS_ID); });
|
||||
});
|
||||
|
@@ -60,7 +60,7 @@ void IntroductionWidget::askUserAboutIntroduction(QWidget *parent, QSettings *se
|
||||
"interface elements and shows how they are used. To take the tour later, "
|
||||
"select Help > UI Tour."),
|
||||
Utils::InfoBarEntry::GlobalSuppression::Enabled);
|
||||
info.setCustomButtonInfo(tr("Take UI Tour"), [parent] {
|
||||
info.addCustomButton(tr("Take UI Tour"), [parent] {
|
||||
Core::ICore::infoBar()->removeInfo(kTakeTourSetting);
|
||||
Core::ICore::infoBar()->globallySuppressInfo(kTakeTourSetting);
|
||||
auto intro = new IntroductionWidget(parent);
|
||||
|
Reference in New Issue
Block a user