+void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator)
+{
+ Q_CHECK_PTR(urlNavigator);
+ Q_ASSERT(!m_urlNavigatorConnected);
+ Q_ASSERT(m_urlNavigator.get() != urlNavigator);
+ Q_CHECK_PTR(m_view);
+
+ urlNavigator->setLocationUrl(m_view->url());
+ urlNavigator->setShowHiddenFolders(m_view->hiddenFilesShown());
+ urlNavigator->setSortHiddenFoldersLast(m_view->sortHiddenLast());
+ if (m_urlNavigatorVisualState) {
+ urlNavigator->setVisualState(*m_urlNavigatorVisualState.get());
+ m_urlNavigatorVisualState.reset();
+ }
+ urlNavigator->setActive(isActive());
+
+ // Url changes are still done via m_urlNavigator.
+ connect(urlNavigator, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
+ connect(urlNavigator, &DolphinUrlNavigator::urlsDropped, this, [=](const QUrl &destination, QDropEvent *event) {
+ m_view->dropUrls(destination, event, urlNavigator->dropWidget());
+ });
+ // Aside from these, only visual things need to be connected.
+ connect(m_view, &DolphinView::urlChanged, urlNavigator, &DolphinUrlNavigator::setLocationUrl);
+ connect(urlNavigator, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
+
+ m_urlNavigatorConnected = urlNavigator;
+}
+
+void DolphinViewContainer::disconnectUrlNavigator()
+{
+ if (!m_urlNavigatorConnected) {
+ return;
+ }
+
+ disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlChanged, m_urlNavigator.get(), &DolphinUrlNavigator::setLocationUrl);
+ disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlsDropped, this, nullptr);
+ disconnect(m_view, &DolphinView::urlChanged, m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl);
+ disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
+
+ m_urlNavigatorVisualState = m_urlNavigatorConnected->visualState();
+ m_urlNavigatorConnected = nullptr;
+}
+
+void DolphinViewContainer::setSelectionModeEnabled(bool enabled, KActionCollection *actionCollection, SelectionMode::BottomBar::Contents bottomBarContents)
+{
+ const bool wasEnabled = m_view->selectionMode();
+ m_view->setSelectionModeEnabled(enabled);
+
+ if (!enabled) {
+ if (!wasEnabled) {
+ return; // nothing to do here
+ }
+ Q_CHECK_PTR(m_selectionModeTopBar); // there is no point in disabling selectionMode when it wasn't even enabled once.
+ Q_CHECK_PTR(m_selectionModeBottomBar);
+ if (m_selectionModeTopBar->isAncestorOf(QApplication::focusWidget()) || m_selectionModeBottomBar->isAncestorOf(QApplication::focusWidget())) {
+ m_view->setFocus();
+ }
+ m_selectionModeTopBar->setVisible(false, WithAnimation);
+ m_selectionModeBottomBar->setVisible(false, WithAnimation);
+ Q_EMIT selectionModeChanged(false);
+ return;
+ }
+
+ if (!m_selectionModeTopBar) {
+ // Changing the location will disable selection mode.
+ connect(m_urlNavigator.get(), &DolphinUrlNavigator::urlChanged, this, [this]() {
+ setSelectionModeEnabled(false);
+ });
+
+ m_selectionModeTopBar = new SelectionMode::TopBar(this); // will be created hidden
+ connect(m_selectionModeTopBar, &SelectionMode::TopBar::selectionModeLeavingRequested, this, [this]() {
+ setSelectionModeEnabled(false);
+ });
+ m_topLayout->addWidget(m_selectionModeTopBar, positionFor.selectionModeTopBar, 0);
+ }
+
+ if (!m_selectionModeBottomBar) {
+ m_selectionModeBottomBar = new SelectionMode::BottomBar(actionCollection, this);
+ connect(m_view, &DolphinView::selectionChanged, this, [this](const KFileItemList &selection) {
+ m_selectionModeBottomBar->slotSelectionChanged(selection, m_view->url());
+ });
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::error, this, [this](const QString &errorMessage) {
+ showErrorMessage(errorMessage);
+ });
+ connect(m_selectionModeBottomBar, &SelectionMode::BottomBar::selectionModeLeavingRequested, this, [this]() {
+ setSelectionModeEnabled(false);
+ });
+ m_topLayout->addWidget(m_selectionModeBottomBar, positionFor.selectionModeBottomBar, 0);
+ }
+ m_selectionModeBottomBar->resetContents(bottomBarContents);
+ if (bottomBarContents == SelectionMode::BottomBar::GeneralContents) {
+ m_selectionModeBottomBar->slotSelectionChanged(m_view->selectedItems(), m_view->url());
+ }
+
+ if (!wasEnabled) {
+ m_selectionModeTopBar->setVisible(true, WithAnimation);
+ m_selectionModeBottomBar->setVisible(true, WithAnimation);
+ Q_EMIT selectionModeChanged(true);
+ }
+}
+
+bool DolphinViewContainer::isSelectionModeEnabled() const
+{
+ const bool isEnabled = m_view->selectionMode();
+ Q_ASSERT((!isEnabled
+ // We can't assert that the bars are invisible only because the selection mode is disabled because the hide animation might still be playing.
+ && (!m_selectionModeBottomBar || !m_selectionModeBottomBar->isEnabled() || !m_selectionModeBottomBar->isVisible()
+ || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::PasteContents))
+ || (isEnabled && m_selectionModeTopBar
+ && m_selectionModeTopBar->isVisible()
+ // The bottom bar is either visible or was hidden because it has nothing to show in GeneralContents mode e.g. because no items are selected.
+ && m_selectionModeBottomBar
+ && (m_selectionModeBottomBar->isVisible() || m_selectionModeBottomBar->contents() == SelectionMode::BottomBar::GeneralContents)));
+ return isEnabled;
+}
+
+void DolphinViewContainer::slotSplitTabDisabled()
+{
+ if (m_selectionModeBottomBar) {
+ m_selectionModeBottomBar->slotSplitTabDisabled();
+ }
+}
+
+void DolphinViewContainer::showMessage(const QString &msg, MessageType type)