From 11ada1515d7a2b5f09d25d2df1ce0f6d37887794 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Thu, 15 Sep 2022 13:36:05 +0000 Subject: [PATCH] Improve selection action toggle code @broulik noticed an issue in the code. This commit fixes it. ------------------- Before this commit there was a `QObject::disconnect` call that did nothing (because it had `nullptr` as the first parameter) and there was a `QObject::connect` call that created the same connections multiple times because of this. This had no effect on end users. However such code can lead to issues in the future e.g. if we ever had a situation in which the selection mode could be toggled for an inactive view container. This commit solves this by replacing the `QObject::disconnect` call with one that works. The `QObject::connect` call is moved so there won't be multiple connections of the same type. --- src/dolphinmainwindow.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index d383d04d6d..bcae015d06 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1433,6 +1433,10 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) // except the requestItemInfo so that on hover the information panel can still be updated connect(oldViewContainer->view(), &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo); + + // Disconnect other slots. + disconnect(nullptr, &DolphinViewContainer::selectionModeChanged, + actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked); } connectViewSignals(viewContainer); @@ -2286,13 +2290,6 @@ void DolphinMainWindow::updateViewActions() { m_actionHandler->updateViewActions(); - QAction *toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode")); - disconnect(nullptr, &DolphinViewContainer::selectionModeChanged, - toggleSelectionModeAction, &QAction::setChecked); - toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled()); - connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, - toggleSelectionModeAction, &QAction::setChecked); - QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); @@ -2350,6 +2347,12 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled); + // Make the toggled state of the selection mode actions visually follow the selection mode state of the view. + auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode")); + toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled()); + connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, + toggleSelectionModeAction, &QAction::setChecked); + const DolphinView* view = container->view(); connect(view, &DolphinView::selectionChanged, this, &DolphinMainWindow::slotSelectionChanged);