X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b168f9a98bbe00643e15a49075ed80ac6c82fa74..65d7ef184acf97e7881050df88ddace97bde4b93:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 1f61bcbf2..d42d9cfcd 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,11 +49,6 @@ #include -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) -#include -#endif - #include #include #include @@ -78,6 +73,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) , m_assureVisibleCurrentIndex(false) , m_isFolderWritable(true) , m_dragging(false) + , m_selectNextItem(false) , m_url(url) , m_viewPropertiesContext() , m_mode(DolphinView::IconsView) @@ -87,11 +83,11 @@ 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) , m_restoredContentsPosition() + , m_controlWheelAccumulatedDelta(0) , m_selectedUrls() , m_clearSelectionBeforeSelectingNewItems(false) , m_markFirstNewlySelectedItemAsCurrent(false) @@ -123,6 +119,7 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) KItemListController *controller = new KItemListController(m_model, m_view, this); const int delay = GeneralSettings::autoExpandFolders() ? 750 : -1; controller->setAutoActivationDelay(delay); + connect(controller, &KItemListController::doubleClickViewBackground, this, &DolphinView::doubleClickViewBackground); // The EnlargeSmallPreviews setting can only be changed after the model // has been set in the view by KItemListController. @@ -130,6 +127,9 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); +#ifndef QT_NO_ACCESSIBILITY + m_view->setAccessibleParentsObject(m_container); +#endif setFocusProxy(m_container); connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); @@ -147,11 +147,13 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) // This is made using a heavily-modified QLabel rather than a KTitleWidget // because KTitleWidget can't be told to turn off mouse-selectable text m_placeholderLabel = new QLabel(this); + // Don't consume mouse events + m_placeholderLabel->setAttribute(Qt::WA_TransparentForMouseEvents); + QFont placeholderLabelFont; // To match the size of a level 2 Heading/KTitleWidget placeholderLabelFont.setPointSize(qRound(placeholderLabelFont.pointSize() * 1.3)); m_placeholderLabel->setFont(placeholderLabelFont); - m_placeholderLabel->setTextInteractionFlags(Qt::NoTextInteraction); m_placeholderLabel->setWordWrap(true); m_placeholderLabel->setAlignment(Qt::AlignCenter); // Match opacity of QML placeholder label component @@ -164,10 +166,6 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) auto *centeringLayout = new QVBoxLayout(m_container); centeringLayout->addWidget(m_placeholderLabel); centeringLayout->setAlignment(m_placeholderLabel, Qt::AlignCenter); - m_placeholderLabel->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_placeholderLabel, &QWidget::customContextMenuRequested, this, [this](const QPoint &pos) { - slotViewContextMenuRequested(m_placeholderLabel->mapToGlobal(pos)); - }); controller->setSelectionBehavior(KItemListController::MultiSelection); connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); @@ -201,7 +199,8 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection); connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError); connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged); - connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved); + // #473377: Use a QueuedConnection to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns. + connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved, Qt::QueuedConnection); connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel); @@ -210,6 +209,13 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent) connect(m_view, &DolphinItemListView::sortRoleChanged, this, &DolphinView::slotSortRoleChangedByHeader); connect(m_view, &DolphinItemListView::visibleRolesChanged, this, &DolphinView::slotVisibleRolesChangedByHeader); connect(m_view, &DolphinItemListView::roleEditingCanceled, this, &DolphinView::slotRoleEditingCanceled); + + connect(m_view, &DolphinItemListView::columnHovered, this, [this](int columnIndex) { + m_hoveredColumnHeaderIndex = columnIndex; + }); + 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); @@ -261,7 +267,6 @@ void DolphinView::setActive(bool active) if (active) { m_container->setFocus(); Q_EMIT activated(); - Q_EMIT writeStateChanged(m_isFolderWritable); } } @@ -273,6 +278,10 @@ bool DolphinView::isActive() const void DolphinView::setViewMode(Mode mode) { if (mode != m_mode) { + // Reset scrollbars before changing the view mode. + m_container->horizontalScrollBar()->setValue(0); + m_container->verticalScrollBar()->setValue(0); + ViewProperties props(viewPropertiesUrl()); props.setViewMode(mode); @@ -292,13 +301,15 @@ DolphinView::Mode DolphinView::viewMode() const void DolphinView::setSelectionModeEnabled(const bool enabled) { if (enabled) { - m_proxyStyle = std::make_unique(); + if (!m_proxyStyle) { + m_proxyStyle = std::make_unique(); + } setStyle(m_proxyStyle.get()); m_view->setStyle(m_proxyStyle.get()); m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False); } else { - setStyle(QApplication::style()); - m_view->setStyle(QApplication::style()); + setStyle(nullptr); + m_view->setStyle(nullptr); m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting); } m_container->controller()->setSelectionModeEnabled(enabled); @@ -415,6 +426,7 @@ int DolphinView::selectedItemsCount() const void DolphinView::markUrlsAsSelected(const QList &urls) { m_selectedUrls = urls; + m_selectJobCreatedItems = false; } void DolphinView::markUrlAsCurrent(const QUrl &url) @@ -458,7 +470,13 @@ int DolphinView::zoomLevel() const void DolphinView::setSortRole(const QByteArray &role) { if (role != sortRole()) { - updateSortRole(role); + ViewProperties props(viewPropertiesUrl()); + props.setSortRole(role); + + KItemModelBase *model = m_container->controller()->model(); + model->setSortRole(role); + + Q_EMIT sortRoleChanged(role); } } @@ -471,7 +489,12 @@ QByteArray DolphinView::sortRole() const void DolphinView::setSortOrder(Qt::SortOrder order) { if (sortOrder() != order) { - updateSortOrder(order); + ViewProperties props(viewPropertiesUrl()); + props.setSortOrder(order); + + m_model->setSortOrder(order); + + Q_EMIT sortOrderChanged(order); } } @@ -613,7 +636,7 @@ void DolphinView::requestStatusBarText() return; } - m_statJobForStatusBarText = KIO::statDetails(m_model->rootItem().url(), KIO::StatJob::SourceSide, KIO::StatRecursiveSize, KIO::HideProgressInfo); + m_statJobForStatusBarText = KIO::stat(m_model->rootItem().url(), KIO::StatJob::SourceSide, KIO::StatRecursiveSize, KIO::HideProgressInfo); connect(m_statJobForStatusBarText, &KJob::result, this, &DolphinView::slotStatJobResult); m_statJobForStatusBarText->start(); } @@ -628,11 +651,11 @@ void DolphinView::emitStatusBarText(const int folderCount, const int fileCount, if (selection == HasSelection) { // At least 2 items are selected because the case of 1 selected item is handled in // DolphinView::requestStatusBarText(). - foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount); - filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount); + foldersText = i18ncp("@info:status", "1 folder selected", "%1 folders selected", folderCount); + filesText = i18ncp("@info:status", "1 file selected", "%1 files selected", fileCount); } else { - foldersText = i18ncp("@info:status", "1 Folder", "%1 Folders", folderCount); - filesText = i18ncp("@info:status", "1 File", "%1 Files", fileCount); + foldersText = i18ncp("@info:status", "1 folder", "%1 folders", folderCount); + filesText = i18ncp("@info:status", "1 file", "%1 files", fileCount); } if (fileCount > 0 && folderCount > 0) { @@ -642,7 +665,7 @@ void DolphinView::emitStatusBarText(const int folderCount, const int fileCount, } else if (folderCount > 0) { summary = foldersText; } else { - summary = i18nc("@info:status", "0 Folders, 0 Files"); + summary = i18nc("@info:status", "0 folders, 0 files"); } Q_EMIT statusBarTextChanged(summary); } @@ -702,6 +725,7 @@ void DolphinView::invertSelection() void DolphinView::clearSelection() { + m_selectJobCreatedItems = false; m_selectedUrls.clear(); m_container->controller()->selectionManager()->clearSelection(); } @@ -716,17 +740,18 @@ void DolphinView::renameSelectedItems() if (items.count() == 1 && GeneralSettings::renameInline()) { const int index = m_model->index(items.first()); - QMetaObject::Connection *const connection = new QMetaObject::Connection; - *connection = connect(m_view, &KItemListView::scrollingStopped, this, [=]() { - QObject::disconnect(*connection); - delete connection; - - m_view->editRole(index, "text"); + connect( + m_view, + &KItemListView::scrollingStopped, + this, + [this, index]() { + m_view->editRole(index, "text"); - hideToolTip(); + hideToolTip(); - connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished); - }); + connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished); + }, + Qt::SingleShotConnection); m_view->scrollToItem(index); } else { @@ -746,43 +771,22 @@ void DolphinView::trashSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) 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; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::trash(list); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotTrashFileFinished); - } -#endif } void DolphinView::deleteSelectedItems() { const QList list = simplifiedSelectedUrls(); -#if KIO_VERSION >= QT_VERSION_CHECK(5, 100, 0) 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; - uiDelegate.setWindow(window()); - if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::del(list); - KJobWidgets::setWindow(job, this); - connect(job, &KIO::Job::result, this, &DolphinView::slotDeleteFileFinished); - } -#endif } void DolphinView::cutSelectedItemsToClipboard() @@ -802,21 +806,39 @@ void DolphinView::copySelectedItemsToClipboard() 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); } @@ -842,9 +864,12 @@ void DolphinView::duplicateSelectedItems() const QMimeDatabase db; + m_clearSelectionBeforeSelectingNewItems = true; + m_markFirstNewlySelectedItemAsCurrent = true; + m_selectJobCreatedItems = true; + // Duplicate all selected items and append "copy" to the end of the file name // but before the filename extension, if present - QList newSelection; for (const auto &item : itemList) { const QUrl originalURL = item.url(); const QString originalDirectoryPath = originalURL.adjusted(QUrl::RemoveFilename).path(); @@ -869,15 +894,14 @@ void DolphinView::duplicateSelectedItems() } KIO::CopyJob *job = KIO::copyAs(originalURL, duplicateURL); + job->setAutoRename(true); KJobWidgets::setWindow(job, this); - if (job) { - newSelection << duplicateURL; - KIO::FileUndoManager::self()->recordCopyJob(job); - } + connect(job, &KIO::CopyJob::result, this, &DolphinView::slotJobResult); + connect(job, &KIO::CopyJob::copyingDone, this, &DolphinView::slotItemCreatedFromJob); + connect(job, &KIO::CopyJob::copyingLinkDone, this, &DolphinView::slotItemLinkCreatedFromJob); + KIO::FileUndoManager::self()->recordCopyJob(job); } - - forceUrlsSelection(newSelection.first(), newSelection); } void DolphinView::stopLoading() @@ -961,9 +985,24 @@ bool DolphinView::eventFilter(QObject *watched, QEvent *event) } break; - case QEvent::ToolTip: - tryShowNameToolTip(static_cast(event)); + case QEvent::ToolTip: { + const auto helpEvent = static_cast(event); + if (tryShowNameToolTip(helpEvent)) { + 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; + } default: break; } @@ -1036,24 +1075,14 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes) if (indexes.count() > 5) { QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) - const int answer = KMessageBox::warningTwoActions( + const int answer = KMessageBox::warningContinueCancel( this, question, {}, -#else - const int answer = - KMessageBox::warningYesNo(this, - question, - {}, -#endif KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()), QStringLiteral("document-open")), - KStandardGuiItem::cancel()); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) - if (answer != KMessageBox::PrimaryAction) { -#else - if (answer != KMessageBox::Yes) { -#endif + KStandardGuiItem::cancel(), + QStringLiteral("ConfirmOpenManyFolders")); + if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) { return; } } @@ -1105,6 +1134,8 @@ void DolphinView::slotItemMiddleClicked(int index) } else { Q_EMIT tabRequested(item.url()); } + } else { + Q_EMIT fileMiddleClickActivated(item); } } @@ -1129,7 +1160,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos) { ViewProperties props(viewPropertiesUrl()); - QPointer menu = new QMenu(QApplication::activeWindow()); + QPointer menu = new QMenu(this); KItemListView *view = m_container->controller()->view(); const QList visibleRolesSet = view->visibleRoles(); @@ -1167,6 +1198,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF &pos) action->setCheckable(true); action->setChecked(visibleRolesSet.contains(info.role)); action->setData(info.role); + action->setToolTip(info.tooltip); const bool enable = (!info.requiresBaloo && !info.requiresIndexer) || (info.requiresBaloo) || (info.requiresIndexer && indexingEnabled); action->setEnabled(enable); @@ -1330,7 +1362,17 @@ void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget * // 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); + }); + }); } } } @@ -1377,7 +1419,12 @@ void DolphinView::slotSelectedItemTextPressed(int index) } } -void DolphinView::slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to) +void DolphinView::slotItemCreatedFromJob(KIO::Job *, const QUrl &, const QUrl &to) +{ + slotItemCreated(to); +} + +void DolphinView::slotItemLinkCreatedFromJob(KIO::Job *, const QUrl &, const QString &, const QUrl &to) { slotItemCreated(to); } @@ -1388,7 +1435,19 @@ void DolphinView::slotItemCreated(const QUrl &url) markUrlAsCurrent(url); m_markFirstNewlySelectedItemAsCurrent = false; } - m_selectedUrls << url; + if (m_selectJobCreatedItems && !m_selectedUrls.contains(url)) { + m_selectedUrls << url; + } +} + +void DolphinView::onDirectoryLoadingCompletedAfterJob() +{ + // the model should now contain all the items created by the job + m_selectJobCreatedItems = true; // to make sure we overwrite selection + // update the view: scroll into View and selection + updateViewState(); + m_selectJobCreatedItems = false; + m_selectedUrls.clear(); } void DolphinView::slotJobResult(KJob *job) @@ -1396,8 +1455,21 @@ 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 + connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::onDirectoryLoadingCompletedAfterJob, Qt::SingleShotConnection); + } else { + m_selectJobCreatedItems = false; + m_selectedUrls.clear(); + } } } @@ -1450,27 +1522,6 @@ void DolphinView::slotStatJobResult(KJob *job) emitStatusBarText(folderCount, fileCount, totalFileSize, NoSelection); } -void DolphinView::updateSortRole(const QByteArray &role) -{ - ViewProperties props(viewPropertiesUrl()); - props.setSortRole(role); - - KItemModelBase *model = m_container->controller()->model(); - model->setSortRole(role); - - Q_EMIT sortRoleChanged(role); -} - -void DolphinView::updateSortOrder(Qt::SortOrder order) -{ - ViewProperties props(viewPropertiesUrl()); - props.setSortOrder(order); - - m_model->setSortOrder(order); - - Q_EMIT sortOrderChanged(order); -} - void DolphinView::updateSortFoldersFirst(bool foldersFirst) { ViewProperties props(viewPropertiesUrl()); @@ -1659,6 +1710,45 @@ void DolphinView::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUr } } +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::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); + selectionManager->endAnchoredSelection(); + if (shouldScrollToCurrentItem) { + m_view->scrollToItem(selectedItems.first()); + } + } + } + } +} + void DolphinView::updateViewState() { if (m_currentItemUrl != QUrl()) { @@ -1672,7 +1762,7 @@ void DolphinView::updateViewState() // scroll to current item and reset the state if (m_scrollToCurrentItem) { - m_view->scrollToItem(currentIndex); + m_view->scrollToItem(currentIndex, KItemListView::ViewItemPosition::Middle); m_scrollToCurrentItem = false; } m_currentItemUrl = QUrl(); @@ -1693,35 +1783,7 @@ void DolphinView::updateViewState() 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::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) @@ -1737,6 +1799,11 @@ void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) } } +bool DolphinView::handleSpaceAsNormalKey() const +{ + return !m_container->hasFocus() || m_container->controller()->isSearchAsYouTypeActive(); +} + void DolphinView::slotTwoClicksRenamingTimerTimeout() { const KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); @@ -1776,7 +1843,7 @@ void DolphinView::slotDeleteFileFinished(KJob *job) void DolphinView::selectNextItem() { if (m_active && m_selectNextItem) { - KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); + KItemListSelectionManager *selectionManager = m_container->controller()->selectionManager(); if (selectedItems().isEmpty()) { Q_ASSERT_X(false, "DolphinView", "Selecting the next item failed."); return; @@ -1921,17 +1988,12 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); #ifndef Q_OS_WIN - //Confirm hiding file/directory by renaming inline + // Confirm hiding file/directory by renaming inline if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { KGuiItem yesGuiItem(i18nc("@action:button", "Rename and Hide"), QStringLiteral("view-hidden")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) const auto code = KMessageBox::questionTwoActions(this, -#else - const auto code = - KMessageBox::questionYesNo(this, -#endif oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" "Do you still want to rename it?") : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" @@ -1941,11 +2003,7 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con KStandardGuiItem::cancel(), QStringLiteral("ConfirmHide")); -#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0) if (code == KMessageBox::SecondaryAction) { -#else - if (code == KMessageBox::No) { -#endif return; } } @@ -1968,9 +2026,9 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->uiDelegate()->setAutoErrorHandlingEnabled(true); - forceUrlsSelection(newUrl, {newUrl}); - 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); @@ -2135,7 +2193,17 @@ void DolphinView::pasteToUrl(const QUrl &url) KJobWidgets::setWindow(job, this); m_clearSelectionBeforeSelectingNewItems = true; m_markFirstNewlySelectedItemAsCurrent = true; + m_selectJobCreatedItems = true; connect(job, &KIO::PasteJob::itemCreated, this, &DolphinView::slotItemCreated); + connect(job, &KIO::PasteJob::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); + }); + }); connect(job, &KIO::PasteJob::result, this, &DolphinView::slotJobResult); } @@ -2186,6 +2254,11 @@ void DolphinView::updateWritableState() } } +bool DolphinView::isFolderWritable() const +{ + return m_isFolderWritable; +} + QUrl DolphinView::viewPropertiesUrl() const { if (m_viewPropertiesContext.isEmpty()) { @@ -2226,7 +2299,7 @@ void DolphinView::copyPathToClipboard() if (clipboard == nullptr) { return; } - clipboard->setText(path); + clipboard->setText(QDir::toNativeSeparators(path)); } void DolphinView::slotIncreaseZoom() @@ -2246,7 +2319,7 @@ void DolphinView::slotSwipeUp() void DolphinView::showLoadingPlaceholder() { - m_placeholderLabel->setText(i18n("Loading...")); + m_placeholderLabel->setText(i18n("Loading…")); m_placeholderLabel->setVisible(true); } @@ -2299,13 +2372,13 @@ void DolphinView::updatePlaceholderLabel() m_placeholderLabel->setVisible(true); } -void DolphinView::tryShowNameToolTip(QHelpEvent *event) +bool DolphinView::tryShowNameToolTip(QHelpEvent *event) { if (!GeneralSettings::showToolTips() && m_mode == DolphinView::IconsView) { const std::optional index = m_view->itemAt(event->pos()); if (!index.has_value()) { - return; + return false; } // Check whether the filename has been elided @@ -2316,6 +2389,10 @@ void DolphinView::tryShowNameToolTip(QHelpEvent *event) const QString text = item.text(); const QPoint pos = mapToGlobal(event->pos()); QToolTip::showText(pos, text); + return true; } } + return false; } + +#include "moc_dolphinview.cpp"