X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/676cdcbbdbea031c1bec56230561bf8a0efcd0f6..ddcca5fb912cd91c7c6c535e01fb963869ccaee9:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index a737dd0a6..f0dc17837 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -20,60 +20,56 @@ #include "dolphinview.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dolphinnewfilemenuobserver.h" #include "dolphin_detailsmodesettings.h" #include "dolphin_generalsettings.h" #include "dolphinitemlistview.h" +#include "dolphinnewfilemenuobserver.h" #include "draganddrophelper.h" -#include "renamedialog.h" +#include "kitemviews/kfileitemlistview.h" +#include "kitemviews/kfileitemmodel.h" +#include "kitemviews/kitemlistcontainer.h" +#include "kitemviews/kitemlistcontroller.h" +#include "kitemviews/kitemlistheader.h" +#include "kitemviews/kitemlistselectionmanager.h" #include "versioncontrol/versioncontrolobserver.h" -#include "viewmodecontroller.h" #include "viewproperties.h" #include "views/tooltips/tooltipmanager.h" #include "zoomlevelinfo.h" #ifdef HAVE_BALOO - #include +#include #endif +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include DolphinView::DolphinView(const QUrl& url, QWidget* parent) : QWidget(parent), @@ -86,23 +82,24 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : m_viewPropertiesContext(), m_mode(DolphinView::IconsView), m_visibleRoles(), - m_topLayout(0), - m_model(0), - m_view(0), - m_container(0), - m_toolTipManager(0), - m_selectionChangedTimer(0), + m_topLayout(nullptr), + m_model(nullptr), + m_view(nullptr), + m_container(nullptr), + m_toolTipManager(nullptr), + m_selectionChangedTimer(nullptr), m_currentItemUrl(), m_scrollToCurrentItem(false), m_restoredContentsPosition(), m_selectedUrls(), m_clearSelectionBeforeSelectingNewItems(false), m_markFirstNewlySelectedItemAsCurrent(false), - m_versionControlObserver(0) + m_versionControlObserver(nullptr), + m_twoClicksRenamingTimer(nullptr) { m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); - m_topLayout->setMargin(0); + m_topLayout->setContentsMargins(0, 0, 0, 0); // When a new item has been created by the "Create New..." menu, the item should // get selected and it must be assured that the item will get visible. As the @@ -133,8 +130,8 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); setFocusProxy(m_container); - connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); - connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); + connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); }); + connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); }); controller->setSelectionBehavior(KItemListController::MultiSelection); connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); @@ -149,6 +146,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : connect(controller, &KItemListController::itemDropEvent, this, &DolphinView::slotItemDropEvent); connect(controller, &KItemListController::escapePressed, this, &DolphinView::stopLoading); connect(controller, &KItemListController::modelChanged, this, &DolphinView::slotModelChanged); + connect(controller, &KItemListController::selectedItemTextPressed, this, &DolphinView::slotSelectedItemTextPressed); connect(m_model, &KFileItemModel::directoryLoadingStarted, this, &DolphinView::slotDirectoryLoadingStarted); connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted); @@ -180,14 +178,22 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : connect(selectionManager, &KItemListSelectionManager::selectionChanged, this, &DolphinView::slotSelectionChanged); +#ifdef HAVE_BALOO m_toolTipManager = new ToolTipManager(this); + connect(m_toolTipManager, &ToolTipManager::urlActivated, this, &DolphinView::urlActivated); +#endif m_versionControlObserver = new VersionControlObserver(this); + m_versionControlObserver->setView(this); m_versionControlObserver->setModel(m_model); connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage); connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage); connect(m_versionControlObserver, &VersionControlObserver::operationCompletedMessage, this, &DolphinView::operationCompletedMessage); + m_twoClicksRenamingTimer = new QTimer(this); + m_twoClicksRenamingTimer->setSingleShot(true); + connect(m_twoClicksRenamingTimer, &QTimer::timeout, this, &DolphinView::slotTwoClicksRenamingTimerTimeout); + applyViewProperties(); m_topLayout->addWidget(m_container); @@ -211,19 +217,7 @@ void DolphinView::setActive(bool active) m_active = active; - QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); - if (!active) { - color.setAlpha(150); - } - - QWidget* viewport = m_container->viewport(); - if (viewport) { - QPalette palette; - palette.setColor(viewport->backgroundRole(), color); - viewport->setPalette(palette); - } - - update(); + updatePalette(); if (active) { m_container->setFocus(); @@ -465,10 +459,6 @@ void DolphinView::reload() QDataStream saveStream(&viewState, QIODevice::WriteOnly); saveState(saveStream); - const KFileItemList itemList = selectedItems(); - m_selectedUrls.clear(); - m_selectedUrls = itemList.urlList(); - setUrl(url()); loadDirectory(url(), true); @@ -596,7 +586,6 @@ void DolphinView::setUrl(const QUrl& url) clearSelection(); - emit urlAboutToBeChanged(url); m_url = url; hideToolTip(); @@ -649,11 +638,11 @@ void DolphinView::renameSelectedItems() connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished); } else { - RenameDialog* dialog = new RenameDialog(this, items); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - dialog->raise(); - dialog->activateWindow(); + KIO::RenameFileDialog* dialog = new KIO::RenameFileDialog(items, this); + connect(dialog, &KIO::RenameFileDialog::renamingFinished, + this, &DolphinView::slotRenameDialogRenamingFinished); + + dialog->open(); } // Assure that the current index remains visible when KFileItemModel @@ -716,14 +705,104 @@ void DolphinView::pasteIntoFolder() } } +void DolphinView::duplicateSelectedItems() +{ + const KFileItemList itemList = selectedItems(); + if (itemList.isEmpty()) { + return; + } + + const QMimeDatabase db; + + // 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(); + const QString originalFileName = item.name(); + + QString extension = db.suffixForFileName(originalFileName); + + QUrl duplicateURL = originalURL; + + // No extension; new filename is " copy" + if (extension.isEmpty()) { + duplicateURL.setPath(originalDirectoryPath + i18nc(" copy", "%1 copy", originalFileName)); + // There's an extension; new filename is " copy." + } else { + // Need to add a dot since QMimeDatabase::suffixForFileName() doesn't include it + extension = QLatin1String(".") + extension; + const QString originalFilenameWithoutExtension = originalFileName.chopped(extension.size()); + // Preserve file's original filename extension in case the casing differs + // from what QMimeDatabase::suffixForFileName() returned + const QString originalExtension = originalFileName.right(extension.size()); + duplicateURL.setPath(originalDirectoryPath + i18nc(" copy", "%1 copy", originalFilenameWithoutExtension) + originalExtension); + } + + KIO::CopyJob* job = KIO::copyAs(originalURL, duplicateURL, KIO::HideProgressInfo); + KJobWidgets::setWindow(job, this); + + if (job) { + newSelection << duplicateURL; + KIO::FileUndoManager::self()->recordCopyJob(job); + } + } + + forceUrlsSelection(newSelection.first(), newSelection); +} + void DolphinView::stopLoading() { m_model->cancelDirectoryLoading(); } +void DolphinView::updatePalette() +{ + QColor color = KColorScheme(isActiveWindow() ? QPalette::Active : QPalette::Inactive, KColorScheme::View).background().color(); + if (!m_active) { + color.setAlpha(150); + } + + QWidget* viewport = m_container->viewport(); + if (viewport) { + QPalette palette; + palette.setColor(viewport->backgroundRole(), color); + viewport->setPalette(palette); + } + + update(); +} + +void DolphinView::abortTwoClicksRenaming() +{ + m_twoClicksRenamingItemUrl.clear(); + m_twoClicksRenamingTimer->stop(); +} + bool DolphinView::eventFilter(QObject* watched, QEvent* event) { switch (event->type()) { + case QEvent::PaletteChange: + updatePalette(); + QPixmapCache::clear(); + break; + + case QEvent::WindowActivate: + case QEvent::WindowDeactivate: + updatePalette(); + break; + + case QEvent::KeyPress: + hideToolTip(ToolTipManager::HideBehavior::Instantly); + if (GeneralSettings::useTabForSwitchingSplitView()) { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) { + emit toggleActiveViewRequested(); + return true; + } + } + break; case QEvent::FocusIn: if (watched == m_container) { setActive(true); @@ -733,6 +812,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event) case QEvent::GraphicsSceneDragEnter: if (watched == m_view) { m_dragging = true; + abortTwoClicksRenaming(); } break; @@ -774,13 +854,14 @@ void DolphinView::hideEvent(QHideEvent* event) bool DolphinView::event(QEvent* event) { - /* See Bug 297355 - * Dolphin leaves file preview tooltips open even when is not visible. - * - * Hide tool-tip when Dolphin loses focus. - */ if (event->type() == QEvent::WindowDeactivate) { + /* See Bug 297355 + * Dolphin leaves file preview tooltips open even when is not visible. + * + * Hide tool-tip when Dolphin loses focus. + */ hideToolTip(); + abortTwoClicksRenaming(); } return QWidget::event(event); @@ -793,6 +874,8 @@ void DolphinView::activate() void DolphinView::slotItemActivated(int index) { + abortTwoClicksRenaming(); + const KFileItem item = m_model->fileItem(index); if (!item.isNull()) { emit itemActivated(item); @@ -803,6 +886,8 @@ void DolphinView::slotItemsActivated(const KItemSet& indexes) { Q_ASSERT(indexes.count() >= 2); + abortTwoClicksRenaming(); + 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()); const int answer = KMessageBox::warningYesNo(this, question); @@ -819,7 +904,7 @@ void DolphinView::slotItemsActivated(const KItemSet& indexes) const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { // Open folders in new tabs - emit tabRequested(url); + emit tabRequested(url, DolphinTabWidget::AfterLastTab); } else { items.append(item); } @@ -837,9 +922,9 @@ void DolphinView::slotItemMiddleClicked(int index) const KFileItem& item = m_model->fileItem(index); const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { - emit tabRequested(url); + emit tabRequested(url, DolphinTabWidget::AfterCurrentTab); } else if (isTabsForFilesEnabled()) { - emit tabRequested(item.url()); + emit tabRequested(item.url(), DolphinTabWidget::AfterCurrentTab); } } @@ -876,7 +961,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) #endif QString groupName; - QMenu* groupMenu = 0; + QMenu* groupMenu = nullptr; // Add all roles to the menu that can be shown or hidden by the user const QList rolesInfo = KFileItemModel::rolesInformation(); @@ -887,7 +972,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) } const QString text = m_model->roleDescription(info.role); - QAction* action = 0; + QAction* action = nullptr; if (info.group.isEmpty()) { action = menu->addAction(text); } else { @@ -1003,7 +1088,9 @@ void DolphinView::slotItemHovered(int index) const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint()); itemRect.moveTo(pos); - m_toolTipManager->showToolTip(item, itemRect); +#ifdef HAVE_BALOO + m_toolTipManager->showToolTip(item, itemRect, nativeParentWidget()->windowHandle()); +#endif } emit requestItemInfo(item); @@ -1011,7 +1098,7 @@ void DolphinView::slotItemHovered(int index) void DolphinView::slotItemUnhovered(int index) { - Q_UNUSED(index); + Q_UNUSED(index) hideToolTip(); emit requestItemInfo(KFileItem()); } @@ -1035,14 +1122,14 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even event->mimeData(), event->buttons(), event->modifiers()); - dropUrls(destUrl, &dropEvent); + dropUrls(destUrl, &dropEvent, this); setActive(true); } -void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent) +void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget) { - KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, this); + KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, dropWidget); if (job) { connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult); @@ -1058,11 +1145,11 @@ void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent) void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous) { - if (previous != 0) { + if (previous != nullptr) { Q_ASSERT(qobject_cast(previous)); KFileItemModel* fileItemModel = static_cast(previous); disconnect(fileItemModel, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted); - m_versionControlObserver->setModel(0); + m_versionControlObserver->setModel(nullptr); } if (current) { @@ -1075,7 +1162,7 @@ void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* prev void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons) { - Q_UNUSED(itemIndex); + Q_UNUSED(itemIndex) hideToolTip(); @@ -1086,6 +1173,18 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons } } +void DolphinView::slotSelectedItemTextPressed(int index) +{ + if (GeneralSettings::renameInline() && !m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) { + const KFileItem item = m_model->fileItem(index); + const KFileItemListProperties capabilities(KFileItemList() << item); + if (capabilities.supportsMoving()) { + m_twoClicksRenamingItemUrl = item.url(); + m_twoClicksRenamingTimer->start(QApplication::doubleClickInterval()); + } + } +} + void DolphinView::slotItemCreated(const QUrl& url) { if (m_markFirstNewlySelectedItemAsCurrent) { @@ -1101,7 +1200,7 @@ void DolphinView::slotPasteJobResult(KJob *job) emit errorMessage(job->errorString()); } if (!m_selectedUrls.isEmpty()) { - m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls); + m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls); } } @@ -1192,6 +1291,9 @@ void DolphinView::restoreState(QDataStream& stream) // Restore the current item that had the keyboard focus stream >> m_currentItemUrl; + // Restore the previously selected items + stream >> m_selectedUrls; + // Restore the view position stream >> m_restoredContentsPosition; @@ -1216,6 +1318,9 @@ void DolphinView::saveState(QDataStream& stream) stream << QUrl(); } + // Save the selected urls + stream << selectedItems().urlList(); + // Save view position const qreal x = m_container->horizontalScrollBar()->value(); const qreal y = m_container->verticalScrollBar()->value(); @@ -1283,12 +1388,24 @@ QUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh return QUrl(); } +void DolphinView::resetZoomLevel() +{ + ViewModeSettings::ViewMode mode; + + switch (m_mode) { + case IconsView: mode = ViewModeSettings::IconsMode; break; + case CompactView: mode = ViewModeSettings::CompactMode; break; + case DetailsView: mode = ViewModeSettings::DetailsMode; break; + } + const ViewModeSettings settings(mode); + const QSize iconSize = QSize(settings.iconSize(), settings.iconSize()); + setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize)); +} + void DolphinView::observeCreatedItem(const QUrl& url) { if (m_active) { - clearSelection(); - markUrlAsCurrent(url); - markUrlsAsSelected({url}); + forceUrlsSelection(url, {url}); } } @@ -1304,17 +1421,21 @@ void DolphinView::updateViewState() { if (m_currentItemUrl != QUrl()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - const int currentIndex = m_model->index(m_currentItemUrl); - if (currentIndex != -1) { - selectionManager->setCurrentItem(currentIndex); - - // scroll to current item and reset the state - if (m_scrollToCurrentItem) { - m_view->scrollToItem(currentIndex); - m_scrollToCurrentItem = false; + + // 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); + + // scroll to current item and reset the state + if (m_scrollToCurrentItem) { + m_view->scrollToItem(currentIndex); + m_scrollToCurrentItem = false; + } + } else { + selectionManager->setCurrentItem(0); } - } else { - selectionManager->setCurrentItem(0); } m_currentItemUrl = QUrl(); @@ -1332,33 +1453,39 @@ void DolphinView::updateViewState() if (!m_selectedUrls.isEmpty()) { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - if (m_clearSelectionBeforeSelectingNewItems) { - selectionManager->clearSelection(); - m_clearSelectionBeforeSelectingNewItems = false; - } + // 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(); + 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; + 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; + } } - } - selectionManager->setSelectedItems(selectedItems); + selectionManager->beginAnchoredSelection(selectionManager->currentItem()); + selectionManager->setSelectedItems(selectedItems); + } } } -void DolphinView::hideToolTip() +void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) { +#ifdef HAVE_BALOO if (GeneralSettings::showToolTips()) { - m_toolTipManager->hideToolTip(); + m_toolTipManager->hideToolTip(behavior); } +#endif } void DolphinView::calculateItemCount(int& fileCount, @@ -1366,13 +1493,43 @@ void DolphinView::calculateItemCount(int& fileCount, KIO::filesize_t& totalFileSize) const { const int itemCount = m_model->count(); + + bool countFileSize = true; + + // In case we have a precomputed value + const auto job = KIO::statDetails(m_model->rootItem().url(), KIO::StatJob::SourceSide, KIO::StatRecursiveSize); + job->exec(); + const auto entry = job->statResult(); + if (entry.contains(KIO::UDSEntry::UDS_RECURSIVE_SIZE)) { + totalFileSize = static_cast(entry.numberValue(KIO::UDSEntry::UDS_RECURSIVE_SIZE)); + countFileSize = false; + } + for (int i = 0; i < itemCount; ++i) { const KFileItem item = m_model->fileItem(i); if (item.isDir()) { ++folderCount; } else { ++fileCount; - totalFileSize += item.size(); + if (countFileSize) { + totalFileSize += item.size(); + } + } + } +} + +void DolphinView::slotTwoClicksRenamingTimerTimeout() +{ + const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); + + // verify that only one item is selected + if (selectionManager->selectedItems().count() == 1) { + const int index = selectionManager->currentItem(); + const QUrl fileItemUrl = m_model->fileItem(index).url(); + + // check if the selected item was the same item that started the twoClicksRenaming + if (fileItemUrl.isValid() && m_twoClicksRenamingItemUrl == fileItemUrl) { + renameSelectedItems(); } } } @@ -1414,7 +1571,7 @@ void DolphinView::slotRenamingResult(KJob* job) void DolphinView::slotDirectoryLoadingStarted() { // Disable the writestate temporary until it can be determined in a fast way - // in DolphinView::slotLoadingCompleted() + // in DolphinView::slotDirectoryLoadingCompleted() if (m_isFolderWritable) { m_isFolderWritable = false; emit writeStateChanged(m_isFolderWritable); @@ -1441,7 +1598,7 @@ void DolphinView::slotItemsChanged() void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOrder previous) { - Q_UNUSED(previous); + Q_UNUSED(previous) Q_ASSERT(m_model->sortOrder() == current); ViewProperties props(viewPropertiesUrl()); @@ -1452,7 +1609,7 @@ void DolphinView::slotSortOrderChangedByHeader(Qt::SortOrder current, Qt::SortOr void DolphinView::slotSortRoleChangedByHeader(const QByteArray& current, const QByteArray& previous) { - Q_UNUSED(previous); + Q_UNUSED(previous) Q_ASSERT(m_model->sortRole() == current); ViewProperties props(viewPropertiesUrl()); @@ -1464,7 +1621,7 @@ void DolphinView::slotSortRoleChangedByHeader(const QByteArray& current, const Q void DolphinView::slotVisibleRolesChangedByHeader(const QList& current, const QList& previous) { - Q_UNUSED(previous); + Q_UNUSED(previous) Q_ASSERT(m_container->controller()->view()->visibleRoles() == current); const QList previousVisibleRoles = m_visibleRoles; @@ -1495,12 +1652,35 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con if (role == "text") { const KFileItem oldItem = m_model->fileItem(index); const QString newName = value.toString(); - if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { + if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) { const QUrl oldUrl = oldItem.url(); QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); +#ifndef Q_OS_WIN + //Confirm hiding file/directory by renaming inline + if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { + KGuiItem yesGuiItem(KStandardGuiItem::yes()); + yesGuiItem.setText(i18nc("@action:button", "Rename and Hide")); + + const auto code = KMessageBox::questionYesNo(this, + 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" + "Do you still want to rename it?"), + oldItem.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"), + yesGuiItem, + KStandardGuiItem::cancel(), + QStringLiteral("ConfirmHide") + ); + + if (code == KMessageBox::No) { + return; + } + } +#endif + const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); if (!newNameExistsAlready) { // Only change the data in the model if no item with the new name @@ -1516,7 +1696,9 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con KIO::Job * job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); - job->ui()->setAutoErrorHandlingEnabled(true); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); + + forceUrlsSelection(newUrl, {newUrl}); if (!newNameExistsAlready) { // Only connect the result signal if there is no item with the new name @@ -1724,3 +1906,16 @@ QUrl DolphinView::viewPropertiesUrl() const url.setPath(m_viewPropertiesContext); return url; } + +void DolphinView::slotRenameDialogRenamingFinished(const QList& urls) +{ + forceUrlsSelection(urls.first(), urls); +} + +void DolphinView::forceUrlsSelection(const QUrl& current, const QList& selected) +{ + clearSelection(); + m_clearSelectionBeforeSelectingNewItems = true; + markUrlAsCurrent(current); + markUrlsAsSelected(selected); +}