aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python/pythonlanguageclient.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2025-04-29 11:39:00 +0200
committerEike Ziller <eike.ziller@qt.io>2025-04-29 13:14:46 +0000
commit7a70f962953ca21651415b05ae0a03e668db7a8c (patch)
treedb94c95a08c4c0ca3a72d5b2dcfe646ce53d1ff5 /src/plugins/python/pythonlanguageclient.cpp
parentb28bcbf8c8f7db5f6f99ec07d936d30b348c022e (diff)
InfoBar: Unify code for hiding / suppressing info on button click
Many buttons that are added to info bar entries should also hide the info bar when clicked, and many should even suppress the info bar from showing again (persistently or for the session). The code for that is duplicate in all the button callbacks, which is error prone and also globally retrieves the info bar again on button click, which makes assumptions that we want to break in the future (ICore::infoBar() can return a different info bar, depending on settings, which can change during runtime). Add an additional enum parameter to InfoBarEntry::addCustomButton() that unifies that behavior at a central place, and also unify the button click handling for the InfoBarDisplay implementations. This actually fixes a bug with hiding the "Update" info bar which used an outdated and wrong ID for the duplicated hiding code. Change-Id: I20cd5b5b566e817a873daa6fb77db25eefcb32f0 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/plugins/python/pythonlanguageclient.cpp')
-rw-r--r--src/plugins/python/pythonlanguageclient.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp
index a43227a1500..eab9cb9dbe8 100644
--- a/src/plugins/python/pythonlanguageclient.cpp
+++ b/src/plugins/python/pythonlanguageclient.cpp
@@ -411,22 +411,29 @@ void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,
auto message = Tr::tr("Update Python language server (PyLS) for %1 (%2).")
.arg(pythonName(python), python.toUserOutput());
InfoBarEntry info(updatePylsInfoBarId, message);
- info.addCustomButton(Tr::tr("Always Update"), [this, python, document, state] {
- document->infoBar()->removeInfo(updatePylsInfoBarId);
- Core::ICore::settings()->setValue(alwaysUpdateKey, true);
- InfoBar::globallySuppressInfo(updatePylsInfoBarId);
- installPythonLanguageServer(python, document, state.pylsModulePath, false, true);
- });
- info.addCustomButton(Tr::tr("Update"), [this, python, document, state] {
- document->infoBar()->removeInfo(updatePylsInfoBarId);
- installPythonLanguageServer(python, document, state.pylsModulePath, false, true);
- });
- info.addCustomButton(Tr::tr("Never"), [document, python] {
- document->infoBar()->removeInfo(updatePylsInfoBarId);
- InfoBar::globallySuppressInfo(updatePylsInfoBarId);
- if (auto client = clientForPython(python))
- LanguageClientManager::openDocumentWithClient(document, client);
- });
+ info.addCustomButton(
+ Tr::tr("Always Update"),
+ [this, python, document, state] {
+ Core::ICore::settings()->setValue(alwaysUpdateKey, true);
+ installPythonLanguageServer(python, document, state.pylsModulePath, false, true);
+ },
+ {},
+ InfoBarEntry::ButtonAction::SuppressPersistently);
+ info.addCustomButton(
+ Tr::tr("Update"),
+ [this, python, document, state] {
+ installPythonLanguageServer(python, document, state.pylsModulePath, false, true);
+ },
+ {},
+ InfoBarEntry::ButtonAction::Hide);
+ info.addCustomButton(
+ Tr::tr("Never"),
+ [document, python] {
+ if (auto client = clientForPython(python))
+ LanguageClientManager::openDocumentWithClient(document, client);
+ },
+ {},
+ InfoBarEntry::ButtonAction::SuppressPersistently);
info.setCancelButtonInfo([python, document]{
if (auto client = clientForPython(python))
LanguageClientManager::openDocumentWithClient(document, client);