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:
David Schulz
2023-03-20 11:42:41 +01:00
parent 7d4f123842
commit 6dcc1771e3

View File

@@ -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>();