+void DolphinView::updateSelectionState()
+{
+ if (!m_selectedUrls.isEmpty()) {
+ KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager();
+
+ const bool shouldScrollToCurrentItem = m_clearSelectionBeforeSelectingNewItems;
+ // 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);
+ if (shouldScrollToCurrentItem) {
+ m_view->scrollToItem(selectedItems.first());
+ }
+ }
+ }
+ }
+}
+