X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/cb1f42a1eb3584742fa33e28759ed8fbab199c5b..119f7a3f:/src/panels/folders/folderspanel.cpp diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 78e437a41..f56f5a139 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -22,7 +22,9 @@ #include "dolphin_folderspanelsettings.h" #include "dolphin_generalsettings.h" #include "treeviewcontextmenu.h" +#include "foldersitemlistwidget.h" +#include #include #include #include @@ -31,7 +33,10 @@ #include #include -#include +#include +#include +#include +#include #include #include @@ -56,7 +61,7 @@ FoldersPanel::FoldersPanel(QWidget* parent) : FoldersPanel::~FoldersPanel() { - FoldersPanelSettings::self()->writeConfig(); + FoldersPanelSettings::self()->save(); if (m_controller) { KItemListView* view = m_controller->view(); @@ -89,13 +94,21 @@ bool FoldersPanel::autoScrolling() const void FoldersPanel::rename(const KFileItem& item) { - const int index = m_model->index(item); - m_controller->view()->editRole(index, "text"); + if (GeneralSettings::renameInline()) { + const int index = m_model->index(item); + m_controller->view()->editRole(index, "text"); + } else { + RenameDialog* dialog = new RenameDialog(this, KFileItemList() << item); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + dialog->raise(); + dialog->activateWindow(); + } } bool FoldersPanel::urlChanged() { - if (!url().isValid() || url().protocol().contains("search")) { + if (!url().isValid() || url().scheme().contains("search")) { // Skip results shown by a search, as possible identical // directory names are useless without parent-path information. return false; @@ -120,32 +133,35 @@ void FoldersPanel::showEvent(QShowEvent* event) // This assures that no performance and memory overhead is given when the folders panel is not // used at all and stays invisible. KFileItemListView* view = new KFileItemListView(); + view->setWidgetCreator(new KItemListWidgetCreator()); view->setSupportsItemExpanding(true); // Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree // has been finished in slotLoadingCompleted(). This prevents an unnecessary animation-mess when // opening the folders panel. view->setOpacity(0); - connect(view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), - this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant))); + connect(view, &KFileItemListView::roleEditingFinished, + this, &FoldersPanel::slotRoleEditingFinished); m_model = new KFileItemModel(this); m_model->setShowDirectoriesOnly(true); m_model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown()); // Use a QueuedConnection to give the view the possibility to react first on the // finished loading. - connect(m_model, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection); + connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &FoldersPanel::slotLoadingCompleted, Qt::QueuedConnection); m_controller = new KItemListController(m_model, view, this); m_controller->setSelectionBehavior(KItemListController::SingleSelection); + m_controller->setAutoActivationBehavior(KItemListController::ExpansionOnly); + m_controller->setMouseDoubleClickAction(KItemListController::ActivateAndExpandItem); m_controller->setAutoActivationDelay(750); - m_controller->setSingleClickActivation(true); + m_controller->setSingleClickActivationEnforced(true); - connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int))); - connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int))); - connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF))); - connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF))); - connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*))); + connect(m_controller, &KItemListController::itemActivated, this, &FoldersPanel::slotItemActivated); + connect(m_controller, &KItemListController::itemMiddleClicked, this, &FoldersPanel::slotItemMiddleClicked); + connect(m_controller, &KItemListController::itemContextMenuRequested, this, &FoldersPanel::slotItemContextMenuRequested); + connect(m_controller, &KItemListController::viewContextMenuRequested, this, &FoldersPanel::slotViewContextMenuRequested); + connect(m_controller, &KItemListController::itemDropEvent, this, &FoldersPanel::slotItemDropEvent); KItemListContainer* container = new KItemListContainer(m_controller, this); container->setEnabledFrame(false); @@ -223,7 +239,8 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve event->buttons(), event->modifiers()); - const QString error = DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent); + QString error; + DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent, error); if (!error.isEmpty()) { emit errorMessage(error); } @@ -236,7 +253,14 @@ void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, co const KFileItem item = m_model->fileItem(index); const QString newName = value.toString(); if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { - KonqOperations::rename(this, item.url(), newName); + const QUrl oldUrl = item.url(); + QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); + newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); + + 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); } } } @@ -272,13 +296,13 @@ void FoldersPanel::startFadeInAnimation() anim->setDuration(200); } -void FoldersPanel::loadTree(const KUrl& url) +void FoldersPanel::loadTree(const QUrl& url) { Q_ASSERT(m_controller); m_updateCurrentItem = false; - KUrl baseUrl; + QUrl baseUrl; if (url.isLocalFile()) { // Use the root directory as base for local URLs (#150941) baseUrl = QDir::rootPath(); @@ -314,4 +338,3 @@ void FoldersPanel::updateCurrentItem(int index) m_controller->view()->scrollToItem(index); } -#include "folderspanel.moc"