Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:epopov:branches:openSUSE:Factory
dolphin
2001-selection.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2001-selection.patch of Package dolphin
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 0bc972c08d73d40db6bfdfcc2010f4fcc03b87f9..a7c81d70635f44e41d2b5f62689a0f95411ea826 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -91,6 +91,8 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) , m_selectedUrls() , m_clearSelectionBeforeSelectingNewItems(false) , m_markFirstNewlySelectedItemAsCurrent(false) + , m_selectJobCreatedItems(false) + , m_ignoreSelectionChanges(false) , m_versionControlObserver(nullptr) , m_twoClicksRenamingTimer(nullptr) , m_placeholderLabel(nullptr) @@ -219,6 +221,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) KItemListSelectionManager *selectionManager = controller->selectionManager(); connect(selectionManager, &KItemListSelectionManager::selectionChanged, this, &DolphinView::slotSelectionChanged); + connect(selectionManager, &KItemListSelectionManager::currentChanged, m_view, &DolphinItemListView::scrollToItem); #if HAVE_BALOO m_toolTipManager = new ToolTipManager(this); @@ -742,8 +745,6 @@ void DolphinView::renameSelectedItems() } else { KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(items, this); - connect(dialog, &KIO::RenameFileDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished); - dialog->open(); } @@ -1441,12 +1442,13 @@ void DolphinView::slotJobResult(KJob *job) if (!m_selectedUrls.isEmpty()) { m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls); - updateSelectionState(); - if (!m_selectedUrls.isEmpty()) { + updateViewState(); + if (!m_currentItemUrl.isEmpty() || !m_selectedUrls.isEmpty()) { // not all urls were found, the model may not be up to date connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::onDirectoryLoadingCompletedAfterJob, Qt::SingleShotConnection); } else { m_selectJobCreatedItems = false; + m_currentItemUrl.clear(); m_selectedUrls.clear(); } } @@ -1455,6 +1457,12 @@ void DolphinView::slotJobResult(KJob *job) void DolphinView::slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous) { m_selectNextItem = false; + + if (!m_ignoreSelectionChanges) { + m_selectJobCreatedItems = false; + m_selectedUrls.clear(); + } + const int currentCount = current.count(); const int previousCount = previous.count(); const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) || (currentCount > 0 && previousCount == 0); @@ -1710,47 +1718,16 @@ void DolphinView::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUr } } -void DolphinView::updateSelectionState() +void DolphinView::updateViewState() { - if (!m_selectedUrls.isEmpty()) { + IgnoreSelectionChangesScopeGuard guard(this, true); + + if (!m_currentItemUrl.isEmpty()) { KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); // if there is a selection already, leave it that way // unless some drop/paste job are in the process of creating items if (!selectionManager->hasSelection() || m_selectJobCreatedItems) { - if (m_clearSelectionBeforeSelectingNewItems) { - selectionManager->clearSelection(); - m_clearSelectionBeforeSelectingNewItems = false; - } - - KItemSet selectedItems = selectionManager->selectedItems(); - - QList<QUrl>::iterator it = m_selectedUrls.begin(); - while (it != m_selectedUrls.end()) { - const int index = m_model->index(*it); - if (index >= 0) { - selectedItems.insert(index); - it = m_selectedUrls.erase(it); - } else { - ++it; - } - } - - if (!selectedItems.isEmpty()) { - selectionManager->beginAnchoredSelection(selectionManager->currentItem()); - selectionManager->setSelectedItems(selectedItems); - } - } - } -} - -void DolphinView::updateViewState() -{ - if (m_currentItemUrl != QUrl()) { - KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); - - // if there is a selection already, leave it that way - if (!selectionManager->hasSelection()) { const int currentIndex = m_model->index(m_currentItemUrl); if (currentIndex != -1) { selectionManager->setCurrentItem(currentIndex); @@ -1760,12 +1737,12 @@ void DolphinView::updateViewState() m_view->scrollToItem(currentIndex, KItemListView::ViewItemPosition::Middle); m_scrollToCurrentItem = false; } - m_currentItemUrl = QUrl(); + m_currentItemUrl.clear(); } else { selectionManager->setCurrentItem(0); } } else { - m_currentItemUrl = QUrl(); + m_currentItemUrl.clear(); } } @@ -1778,7 +1755,36 @@ void DolphinView::updateViewState() m_container->verticalScrollBar()->setValue(y); } - updateSelectionState(); + if (!m_selectedUrls.isEmpty()) { + KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); + + // if there is a selection already, leave it that way + // unless some drop/paste job are in the process of creating items + if (!selectionManager->hasSelection() || m_selectJobCreatedItems) { + if (m_clearSelectionBeforeSelectingNewItems) { + selectionManager->clearSelection(); + m_clearSelectionBeforeSelectingNewItems = false; + } + + KItemSet selectedItems = selectionManager->selectedItems(); + + QList<QUrl>::iterator it = m_selectedUrls.begin(); + while (it != m_selectedUrls.end()) { + const int index = m_model->index(*it); + if (index >= 0) { + selectedItems.insert(index); + it = m_selectedUrls.erase(it); + } else { + ++it; + } + } + + if (!selectedItems.isEmpty()) { + selectionManager->beginAnchoredSelection(selectionManager->currentItem()); + selectionManager->setSelectedItems(selectedItems); + } + } + } } void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) @@ -2022,8 +2028,6 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con job->uiDelegate()->setAutoErrorHandlingEnabled(true); if (!newNameExistsAlready) { - forceUrlsSelection(newUrl, {newUrl}); - // Only connect the result signal if there is no item with the new name // in the model yet, see bug 328262. connect(job, &KJob::result, this, &DolphinView::slotRenamingResult); @@ -2258,11 +2262,6 @@ QUrl DolphinView::viewPropertiesUrl() const return url; } -void DolphinView::slotRenameDialogRenamingFinished(const QList<QUrl> &urls) -{ - forceUrlsSelection(urls.first(), urls); -} - void DolphinView::forceUrlsSelection(const QUrl ¤t, const QList<QUrl> &selected) { clearSelection(); diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index b6b3aa4a9667b0e15175b4cf6be1604f26a616e7..6ecc486cb90f6a1b6a700b498e6e2ba1f4c29257 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -684,7 +684,6 @@ private Q_SLOTS: void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event); void slotModelChanged(KItemModelBase *current, KItemModelBase *previous); void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons); - void slotRenameDialogRenamingFinished(const QList<QUrl> &urls); void slotSelectedItemTextPressed(int index); void slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to); void slotIncreaseZoom(); @@ -956,6 +955,27 @@ private: /// Decides whether items created by jobs should automatically be selected. bool m_selectJobCreatedItems; + /// If true, then the selection was changed inside updateViewState() + bool m_ignoreSelectionChanges; + + struct IgnoreSelectionChangesScopeGuard { + explicit IgnoreSelectionChangesScopeGuard(DolphinView *view, bool newValue) + : m_view(view) + , m_prevValue(m_view->m_ignoreSelectionChanges) + { + m_view->m_ignoreSelectionChanges = newValue; + } + + ~IgnoreSelectionChangesScopeGuard() + { + m_view->m_ignoreSelectionChanges = m_prevValue; + } + + private: + DolphinView * const m_view; + const bool m_prevValue; + }; + VersionControlObserver *m_versionControlObserver; QTimer *m_twoClicksRenamingTimer; @@ -974,7 +994,6 @@ private: friend class DolphinDetailsViewTest; friend class DolphinMainWindowTest; friend class DolphinPart; // Accesses m_model - void updateSelectionState(); }; /// Allow using DolphinView::Mode in QVariant
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor