]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Selects next item in list after delete/trash actions
authorSerg Podtynnyi <serg@podtynnyi.com>
Sat, 28 Jan 2023 19:49:38 +0000 (02:49 +0700)
committerSerg Podtynnyi <serg@podtynnyi.com>
Mon, 6 Feb 2023 03:47:49 +0000 (10:47 +0700)
BUG: 419914
BUG: 181214

src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/dolphinviewactionhandler.cpp

index 35d69e610e69ad4c247660f6b918149c07ae88ae..250fe4cc7a25b7f301f4e5039feebc489154e0ea 100644 (file)
@@ -87,6 +87,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
     , m_view(nullptr)
     , m_container(nullptr)
     , m_toolTipManager(nullptr)
+    , m_selectNextItem(false)
     , m_selectionChangedTimer(nullptr)
     , m_currentItemUrl()
     , m_scrollToCurrentItem(false)
@@ -749,6 +750,7 @@ void DolphinView::trashSelectedItems()
     using Iface = KIO::AskUserActionInterface;
     auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Trash, Iface::DefaultConfirmation, this);
     connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished);
+    m_selectNextItem = true;
     trashJob->start();
 #else
     KIO::JobUiDelegate uiDelegate;
@@ -770,6 +772,7 @@ void DolphinView::deleteSelectedItems()
     using Iface = KIO::AskUserActionInterface;
     auto *trashJob = new KIO::DeleteOrTrashJob(list, Iface::Delete, Iface::DefaultConfirmation, this);
     connect(trashJob, &KJob::result, this, &DolphinView::slotTrashFileFinished);
+    m_selectNextItem = true;
     trashJob->start();
 #else
     KIO::JobUiDelegate uiDelegate;
@@ -1389,6 +1392,7 @@ void DolphinView::slotJobResult(KJob *job)
 
 void DolphinView::slotSelectionChanged(const KItemSet &current, const KItemSet &previous)
 {
+    m_selectNextItem = false;
     const int currentCount = current.count();
     const int previousCount = previous.count();
     const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) || (currentCount > 0 && previousCount == 0);
@@ -1741,6 +1745,7 @@ void DolphinView::slotTwoClicksRenamingTimerTimeout()
 void DolphinView::slotTrashFileFinished(KJob *job)
 {
     if (job->error() == 0) {
+        selectNextItem(); // Fixes BUG: 419914 via selecting next item
         Q_EMIT operationCompletedMessage(i18nc("@info:status", "Trash operation completed."));
     } else if (job->error() != KIO::ERR_USER_CANCELED) {
         Q_EMIT errorMessage(job->errorString());
@@ -1750,12 +1755,37 @@ void DolphinView::slotTrashFileFinished(KJob *job)
 void DolphinView::slotDeleteFileFinished(KJob *job)
 {
     if (job->error() == 0) {
+        selectNextItem(); // Fixes BUG: 419914 via selecting next item
         Q_EMIT operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
     } else if (job->error() != KIO::ERR_USER_CANCELED) {
         Q_EMIT errorMessage(job->errorString());
     }
 }
 
+void DolphinView::selectNextItem()
+{
+    if (m_active && m_selectNextItem) {
+        KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
+        if (selectedItems().isEmpty()) {
+            Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed.");
+            return;
+        }
+        const auto lastSelectedIndex = m_model->index(selectedItems().last());
+        if (lastSelectedIndex < 0) {
+            Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed.");
+            return;
+        }
+        auto nextItem = lastSelectedIndex + 1;
+        if (nextItem >= itemsCount()) {
+            nextItem = lastSelectedIndex - selectedItemsCount();
+        }
+        if (nextItem >= 0) {
+            selectionManager->setSelected(nextItem, 1);
+        }
+        m_selectNextItem = false;
+    }
+}
+
 void DolphinView::slotRenamingResult(KJob *job)
 {
     if (job->error()) {
index 8cf23c298018cf87a81ec5ae9f1e2f6a28203422..cadf3e754622f293ff20d8010dfe0fb7e6853279 100644 (file)
@@ -796,6 +796,11 @@ private Q_SLOTS:
      */
     void observeCreatedItem(const QUrl &url);
 
+    /**
+     * Selects the next item after prev selection deleted/trashed
+     */
+    void selectNextItem();
+
     /**
      * Called when a redirection happens.
      * Testcase: fish://localhost
@@ -893,6 +898,7 @@ private:
     bool m_isFolderWritable;
     bool m_dragging; // True if a dragging is done. Required to be able to decide whether a
                      // tooltip may be shown when hovering an item.
+    bool m_selectNextItem;
 
     enum class LoadingState { Idle, Loading, Canceled, Completed };
     LoadingState m_loadingState = LoadingState::Idle;
index cbe8b89e5d958d3b9786140c8a3bddb6ffaa761f..32bec03df7de314c9af9274a55ead699e369a489 100644 (file)
@@ -93,6 +93,7 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac
 
     auto trashAction = KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection);
     auto trashShortcuts = trashAction->shortcuts();
+    trashAction->setAutoRepeat(false);
     if (!trashShortcuts.contains(QKeySequence::Delete)) {
         trashShortcuts.append(QKeySequence::Delete);
         m_actionCollection->setDefaultShortcuts(trashAction, trashShortcuts);
@@ -105,6 +106,7 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac
 
     auto deleteAction = KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
     auto deleteShortcuts = deleteAction->shortcuts();
+    deleteAction->setAutoRepeat(false);
     if (!deleteShortcuts.contains(Qt::SHIFT | Qt::Key_Delete)) {
         deleteShortcuts.append(Qt::SHIFT | Qt::Key_Delete);
         m_actionCollection->setDefaultShortcuts(deleteAction, deleteShortcuts);