mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
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.
This commit is contained in:
parent
3dd49a8539
commit
11ada1515d
1 changed files with 10 additions and 7 deletions
|
@ -1433,6 +1433,10 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
|
||||||
// except the requestItemInfo so that on hover the information panel can still be updated
|
// except the requestItemInfo so that on hover the information panel can still be updated
|
||||||
connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
|
connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
|
||||||
this, &DolphinMainWindow::requestItemInfo);
|
this, &DolphinMainWindow::requestItemInfo);
|
||||||
|
|
||||||
|
// Disconnect other slots.
|
||||||
|
disconnect(nullptr, &DolphinViewContainer::selectionModeChanged,
|
||||||
|
actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectViewSignals(viewContainer);
|
connectViewSignals(viewContainer);
|
||||||
|
@ -2286,13 +2290,6 @@ void DolphinMainWindow::updateViewActions()
|
||||||
{
|
{
|
||||||
m_actionHandler->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"));
|
QAction* toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
|
||||||
toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
|
toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
|
||||||
|
|
||||||
|
@ -2350,6 +2347,12 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
|
||||||
const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
|
const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
|
||||||
connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
|
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();
|
const DolphinView* view = container->view();
|
||||||
connect(view, &DolphinView::selectionChanged,
|
connect(view, &DolphinView::selectionChanged,
|
||||||
this, &DolphinMainWindow::slotSelectionChanged);
|
this, &DolphinMainWindow::slotSelectionChanged);
|
||||||
|
|
Loading…
Reference in a new issue