┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorSerg Podtynnyi <[email protected]>2023-01-29 02:49:38 +0700
committerSerg Podtynnyi <[email protected]>2023-02-06 10:47:49 +0700
commit36dfe5795f3e70ad9ac4954544899bf38c919ca7 (patch)
treeea9617040f70e6333ad10247cbf33237f0d79c42 /src/views
parentb6c280c306a8256f3359407af915f9888fff2231 (diff)
Selects next item in list after delete/trash actions
BUG: 419914 BUG: 181214
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinview.cpp30
-rw-r--r--src/views/dolphinview.h6
-rw-r--r--src/views/dolphinviewactionhandler.cpp2
3 files changed, 38 insertions, 0 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 35d69e610..250fe4cc7 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -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()) {
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index 8cf23c298..cadf3e754 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -797,6 +797,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;
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index cbe8b89e5..32bec03df 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -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);