]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make "open path" and "open path in new tab" scroll to the selected item
authorAkseli Lahtinen <akselmo@akselmo.dev>
Fri, 29 Nov 2024 09:24:55 +0000 (09:24 +0000)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Fri, 29 Nov 2024 09:24:55 +0000 (09:24 +0000)
**Open Path**

When user clicks on "Open Path" after searching for an item,
user expects the view to show the item immediately.

We wait for the KItemListSmoothScroller to be done with its animation before the
scrollbar sizes are being changed.

**Open Path in New Tab**

When user selects "Open Path in New Tab", we open a new tab to the folder where the file is, then select and set the file current. We need to get the correct tab when opening one, so it has been added as a return value.

BUG:495613

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphintabwidget.cpp
src/dolphintabwidget.h
src/kitemviews/kitemlistcontainer.cpp
src/kitemviews/private/kitemlistsmoothscroller.cpp
src/kitemviews/private/kitemlistsmoothscroller.h

index 77034dadbec6a307b13e3d620949571cc15d7fdd..84023ddbdea05551727b90a97922e17973650644 100644 (file)
@@ -216,7 +216,11 @@ void DolphinContextMenu::addOpenParentFolderActions()
     });
 
     addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "Open Path in New Tab"), [this]() {
-        m_mainWindow->openNewTab(KIO::upUrl(m_fileInfo.targetUrl()));
+        const QUrl url = m_fileInfo.targetUrl();
+        const QUrl parentUrl = KIO::upUrl(url);
+        DolphinTabPage *tabPage = m_mainWindow->openNewTab(parentUrl);
+        tabPage->activeViewContainer()->view()->markUrlsAsSelected({url});
+        tabPage->activeViewContainer()->view()->markUrlAsCurrent(url);
     });
 
     addAction(QIcon::fromTheme(QStringLiteral("window-new")), i18nc("@action:inmenu", "Open Path in New Window"), [this]() {
index 6f23581b4435d876e4aaa93496da97badd787d56..ead46de30a56ee239442fb69a8e8aa4c5cdb1a9c 100644 (file)
@@ -489,9 +489,9 @@ void DolphinMainWindow::addToPlaces()
     }
 }
 
-void DolphinMainWindow::openNewTab(const QUrl &url)
+DolphinTabPage *DolphinMainWindow::openNewTab(const QUrl &url)
 {
-    m_tabWidget->openNewTab(url, QUrl());
+    return m_tabWidget->openNewTab(url, QUrl());
 }
 
 void DolphinMainWindow::openNewTabAndActivate(const QUrl &url)
index 37994b85ae4d6940f951a863e0ae86cfdda2e35a..ceda3cb73f9fb8ed417f935f33536dbe665aca7d 100644 (file)
@@ -209,8 +209,9 @@ public Q_SLOTS:
 
     /**
      * Opens a new tab in the background showing the URL \a url.
+     * @return A pointer to the opened DolphinTabPage.
      */
-    void openNewTab(const QUrl &url);
+    DolphinTabPage *openNewTab(const QUrl &url);
 
     /**
      * Opens a new tab  showing the URL \a url and activate it.
index 825ff3c7f8c76642edf9175fca5e40a0193fa9a1..5ad2a368cad7630b7f17fcbdb3eba23d4714f57d 100644 (file)
@@ -170,7 +170,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl &primaryUrl, const QUrl &s
     }
 }
 
-void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl, DolphinTabWidget::NewTabPosition position)
+DolphinTabPage *DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl, DolphinTabWidget::NewTabPosition position)
 {
     QWidget *focusWidget = QApplication::focusWidget();
 
@@ -202,6 +202,7 @@ void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryU
         // in background, assure that the previous focused widget gets the focus back.
         focusWidget->setFocus();
     }
+    return tabPage;
 }
 
 void DolphinTabWidget::openDirectories(const QList<QUrl> &dirs, bool splitView)
index a28a6bea1ff0941d78e265a28bec044c6febdede..52d3fd626889ad4ab7f14633522b0e24fe5cfc84 100644 (file)
@@ -132,10 +132,11 @@ public Q_SLOTS:
     /**
      * Opens a new tab in the background showing the URL \a primaryUrl and the
      * optional URL \a secondaryUrl.
+     * @return A pointer to the opened DolphinTabPage.
      */
-    void openNewTab(const QUrl &primaryUrl,
-                    const QUrl &secondaryUrl = QUrl(),
-                    DolphinTabWidget::NewTabPosition position = DolphinTabWidget::NewTabPosition::FollowSetting);
+    DolphinTabPage *openNewTab(const QUrl &primaryUrl,
+                               const QUrl &secondaryUrl = QUrl(),
+                               DolphinTabWidget::NewTabPosition position = DolphinTabWidget::NewTabPosition::FollowSetting);
 
     /**
      * Opens each directory in \p dirs in a separate tab unless it is already open.
index 65250832b023efe5e65b258b20dcaf6a0ee89651..ff12aee7ca0492ad7d2ed62f3331ac821b5d9108 100644 (file)
@@ -291,6 +291,9 @@ void KItemListContainer::updateScrollOffsetScrollBar()
     int maximum = 0;
     if (view->scrollOrientation() == Qt::Vertical) {
         smoothScroller = m_verticalSmoothScroller;
+        if (smoothScroller->isAnimating()) {
+            return;
+        }
         scrollOffsetScrollBar = verticalScrollBar();
 
         // Don't scroll super fast when using a wheel mouse:
@@ -311,6 +314,9 @@ void KItemListContainer::updateScrollOffsetScrollBar()
         maximum = qMax(0, int(view->maximumScrollOffset() - view->size().height()));
     } else {
         smoothScroller = m_horizontalSmoothScroller;
+        if (smoothScroller->isAnimating()) {
+            return;
+        }
         scrollOffsetScrollBar = horizontalScrollBar();
         singleStep = view->itemSize().width();
         pageStep = view->size().width();
@@ -347,11 +353,17 @@ void KItemListContainer::updateItemOffsetScrollBar()
     int pageStep = 0;
     if (view->scrollOrientation() == Qt::Vertical) {
         smoothScroller = m_horizontalSmoothScroller;
+        if (smoothScroller->isAnimating()) {
+            return;
+        }
         itemOffsetScrollBar = horizontalScrollBar();
         singleStep = view->size().width() / 10;
         pageStep = view->size().width();
     } else {
         smoothScroller = m_verticalSmoothScroller;
+        if (smoothScroller->isAnimating()) {
+            return;
+        }
         itemOffsetScrollBar = verticalScrollBar();
         singleStep = view->size().height() / 10;
         pageStep = view->size().height();
index fd26d198f23b5c4a8dd22ccf0dec4ad9d71e18ea..517f6d983cc5c9a38e7673c1ad286677b7d31a7f 100644 (file)
@@ -214,4 +214,12 @@ void KItemListSmoothScroller::handleWheelEvent(QWheelEvent *event)
     m_smoothScrolling = previous;
 }
 
+bool KItemListSmoothScroller::isAnimating()
+{
+    if (m_animation) {
+        return (m_animation->state() == QAbstractAnimation::Running);
+    }
+    return false;
+}
+
 #include "moc_kitemlistsmoothscroller.cpp"
index 32effa3d66c2d079b2046c27179ebe715e05e3fd..9cbfbc1b8bc96a6c01786b0bb7371bd2d5b4da08 100644 (file)
@@ -68,6 +68,7 @@ public:
      */
     void handleWheelEvent(QWheelEvent *event);
 
+    bool isAnimating();
 Q_SIGNALS:
     /**
      * Emitted when the scrolling animation has finished