connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved);
connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel);
+ connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updateSelectionState);
m_view->installEventFilter(this);
connect(m_view, &DolphinItemListView::sortOrderChanged, this, &DolphinView::slotSortOrderChangedByHeader);
connect(m_view, &DolphinItemListView::visibleRolesChanged, this, &DolphinView::slotVisibleRolesChangedByHeader);
connect(m_view, &DolphinItemListView::roleEditingCanceled, this, &DolphinView::slotRoleEditingCanceled);
- connect(m_view, &DolphinItemListView::columnHovered, this, [this](int roleIndex) {
- m_hoveredColumnHearderRoleIndex = roleIndex;
+ connect(m_view, &DolphinItemListView::columnHovered, this, [this](int columnIndex) {
+ m_hoveredColumnHeaderIndex = columnIndex;
});
- connect(m_view, &DolphinItemListView::columnUnHovered, this, [this](int roleIndex) {
- Q_UNUSED(roleIndex)
- m_hoveredColumnHearderRoleIndex = std::nullopt;
+ connect(m_view, &DolphinItemListView::columnUnHovered, this, [this](int /* columnIndex */) {
+ m_hoveredColumnHeaderIndex = std::nullopt;
});
connect(m_view->header(), &KItemListHeader::columnWidthChangeFinished, this, &DolphinView::slotHeaderColumnWidthChangeFinished);
connect(m_view->header(), &KItemListHeader::sidePaddingChanged, this, &DolphinView::slotSidePaddingWidthChanged);
void DolphinView::setSelectionModeEnabled(const bool enabled)
{
if (enabled) {
- m_proxyStyle = std::make_unique<SelectionMode::SingleClickSelectionProxyStyle>();
+ if (!m_proxyStyle) {
+ m_proxyStyle = std::make_unique<SelectionMode::SingleClickSelectionProxyStyle>();
+ }
setStyle(m_proxyStyle.get());
m_view->setStyle(m_proxyStyle.get());
m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False);
void DolphinView::markUrlsAsSelected(const QList<QUrl> &urls)
{
m_selectedUrls = urls;
+ m_selectJobCreatedItems = false;
}
void DolphinView::markUrlAsCurrent(const QUrl &url)
void DolphinView::clearSelection()
{
+ m_selectJobCreatedItems = false;
m_selectedUrls.clear();
m_container->controller()->selectionManager()->clearSelection();
}
void DolphinView::copySelectedItems(const KFileItemList &selection, const QUrl &destinationUrl)
{
+ if (selection.isEmpty() || !destinationUrl.isValid()) {
+ return;
+ }
+
+ m_clearSelectionBeforeSelectingNewItems = true;
+ m_markFirstNewlySelectedItemAsCurrent = true;
+ m_selectJobCreatedItems = true;
+
KIO::CopyJob *job = KIO::copy(selection.urlList(), destinationUrl, KIO::DefaultFlags);
KJobWidgets::setWindow(job, this);
connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
- connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ connect(job, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob);
KIO::FileUndoManager::self()->recordCopyJob(job);
}
void DolphinView::moveSelectedItems(const KFileItemList &selection, const QUrl &destinationUrl)
{
+ if (selection.isEmpty() || !destinationUrl.isValid()) {
+ return;
+ }
+
+ m_clearSelectionBeforeSelectingNewItems = true;
+ m_markFirstNewlySelectedItemAsCurrent = true;
+ m_selectJobCreatedItems = true;
+
KIO::CopyJob *job = KIO::move(selection.urlList(), destinationUrl, KIO::DefaultFlags);
KJobWidgets::setWindow(job, this);
connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
- connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotCopyingDone);
+ connect(job, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob);
+ connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob);
KIO::FileUndoManager::self()->recordCopyJob(job);
}
if (tryShowNameToolTip(helpEvent)) {
return true;
- } else if (m_hoveredColumnHearderRoleIndex) {
- const auto roleInfo = KFileItemModel::rolesInformation().at(*m_hoveredColumnHearderRoleIndex);
- QToolTip::showText(helpEvent->globalPos(), roleInfo.tooltip, this);
- return true;
+ } else if (m_hoveredColumnHeaderIndex) {
+ const auto rolesInfo = KFileItemModel::rolesInformation();
+ const auto visibleRole = m_visibleRoles.value(*m_hoveredColumnHeaderIndex);
+
+ for (const KFileItemModel::RoleInfo &info : rolesInfo) {
+ if (visibleRole == info.role) {
+ QToolTip::showText(helpEvent->globalPos(), info.tooltip, this);
+ return true;
+ }
+ }
}
break;
}
// Mark the dropped urls as selected.
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
+ m_selectJobCreatedItems = true;
connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+ connect(job, &KIO::DropJob::copyJobStarted, this, [this](const KIO::CopyJob *copyJob) {
+ connect(copyJob, &KIO::CopyJob::copying, this, &DolphinView::slotItemCreatedFromJob);
+ connect(copyJob, &KIO::CopyJob::moving, this, &DolphinView::slotItemCreatedFromJob);
+ connect(copyJob, &KIO::CopyJob::linking, this, [this](KIO::Job *job, const QString &src, const QUrl &dest) {
+ Q_UNUSED(job)
+ Q_UNUSED(src)
+ slotItemCreated(dest);
+ });
+ });
}
}
}
}
}
-void DolphinView::slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to)
+void DolphinView::slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to)
{
slotItemCreated(to);
}
markUrlAsCurrent(url);
m_markFirstNewlySelectedItemAsCurrent = false;
}
- m_selectedUrls << url;
+ if (m_selectJobCreatedItems && !m_selectedUrls.contains(url)) {
+ m_selectedUrls << url;
+ }
}
void DolphinView::slotJobResult(KJob *job)
if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
Q_EMIT errorMessage(job->errorString());
}
+ if (!m_selectJobCreatedItems) {
+ m_selectedUrls.clear();
+ return;
+ }
if (!m_selectedUrls.isEmpty()) {
m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls);
+
+ updateSelectionState();
+ if (!m_selectedUrls.isEmpty()) {
+ // not all urls were found, the model may not be up to date
+ // TODO KF6 replace with Qt::singleShotConnection
+ QMetaObject::Connection *const connection = new QMetaObject::Connection;
+ *connection = connect(
+ m_model,
+ &KFileItemModel::directoryLoadingCompleted,
+ this,
+ [this, connection]() {
+ // the model should now contain all the items created by the job
+ updateSelectionState();
+ m_selectJobCreatedItems = false;
+ m_selectedUrls.clear();
+ QObject::disconnect(*connection);
+ delete connection;
+ },
+ Qt::UniqueConnection);
+ } else {
+ m_selectJobCreatedItems = false;
+ m_selectedUrls.clear();
+ }
}
}
}
}
+void DolphinView::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::updateViewState()
{
if (m_currentItemUrl != QUrl()) {
m_container->verticalScrollBar()->setValue(y);
}
- if (!m_selectedUrls.isEmpty()) {
- KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager();
-
- // if there is a selection already, leave it that way
- if (!selectionManager->hasSelection()) {
- 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);
- }
- }
- }
+ updateSelectionState();
}
void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior)
KJobWidgets::setWindow(job, this);
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
+ m_selectJobCreatedItems = true;
+ // TODO KF6 use KIO::PasteJob::copyJobStarted to hook to earlier events copying/moving
connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated);
connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult);
}