forked from qt-creator/qt-creator
LanguageClient: fix show message box
Add a default close button and connect all language server defined buttons to accepted, so the message box gets closed when the user presses a button. Change-Id: I846eadf5953e75441bdc7910c2587a2fa098a388 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -1669,10 +1669,15 @@ LanguageClientValue<MessageActionItem> ClientPrivate::showMessageBox(
|
||||
}
|
||||
QHash<QAbstractButton *, MessageActionItem> itemForButton;
|
||||
if (const std::optional<QList<MessageActionItem>> actions = message.actions()) {
|
||||
for (const MessageActionItem &action : *actions)
|
||||
itemForButton.insert(box->addButton(action.title(), QMessageBox::InvalidRole), action);
|
||||
auto button = box->addButton(QMessageBox::Close);
|
||||
connect(button, &QPushButton::clicked, box, &QMessageBox::reject);
|
||||
for (const MessageActionItem &action : *actions) {
|
||||
connect(button, &QPushButton::clicked, box, &QMessageBox::accept);
|
||||
itemForButton.insert(button, action);
|
||||
}
|
||||
}
|
||||
box->exec();
|
||||
if (box->exec() == QDialog::Rejected)
|
||||
return {};
|
||||
const MessageActionItem &item = itemForButton.value(box->clickedButton());
|
||||
return item.isValid() ? LanguageClientValue<MessageActionItem>(item)
|
||||
: LanguageClientValue<MessageActionItem>();
|
||||
|
||||
Reference in New Issue
Block a user