X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a46121dc510f987f2d164b43eaf5f84ea8c83cb8..9cd042a86c:/src/panels/folders/folderspanel.cpp diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 0b2ea3888..020c41e55 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -21,48 +21,46 @@ #include "dolphin_folderspanelsettings.h" #include "dolphin_generalsettings.h" -#include "treeviewcontextmenu.h" #include "foldersitemlistwidget.h" +#include "global.h" +#include "kitemviews/kfileitemlistview.h" +#include "kitemviews/kfileitemmodel.h" +#include "kitemviews/kitemlistcontainer.h" +#include "kitemviews/kitemlistcontroller.h" +#include "kitemviews/kitemlistselectionmanager.h" +#include "treeviewcontextmenu.h" +#include "views/draganddrophelper.h" +#include "views/renamedialog.h" -#include -#include -#include -#include -#include -#include -#include - -#include -#include +#include +#include +#include +#include +#include #include #include -#include #include #include #include #include -#include - -#include - FoldersPanel::FoldersPanel(QWidget* parent) : Panel(parent), m_updateCurrentItem(false), - m_controller(0), - m_model(0) + m_controller(nullptr), + m_model(nullptr) { setLayoutDirection(Qt::LeftToRight); } FoldersPanel::~FoldersPanel() { - FoldersPanelSettings::self()->writeConfig(); + FoldersPanelSettings::self()->save(); if (m_controller) { KItemListView* view = m_controller->view(); - m_controller->setView(0); + m_controller->setView(nullptr); delete view; } } @@ -78,6 +76,17 @@ bool FoldersPanel::showHiddenFiles() const return FoldersPanelSettings::hiddenFilesShown(); } +void FoldersPanel::setLimitFoldersPanelToHome(bool enable) +{ + FoldersPanelSettings::setLimitFoldersPanelToHome(enable); + reloadTree(); +} + +bool FoldersPanel::limitFoldersPanelToHome() const +{ + return FoldersPanelSettings::limitFoldersPanelToHome(); +} + void FoldersPanel::setAutoScrolling(bool enable) { // TODO: Not supported yet in Dolphin 2.0 @@ -96,16 +105,13 @@ void FoldersPanel::rename(const KFileItem& 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(); + dialog->open(); } } bool FoldersPanel::urlChanged() { - if (!url().isValid() || url().protocol().contains("search")) { + if (!url().isValid() || url().scheme().contains(QStringLiteral("search"))) { // Skip results shown by a search, as possible identical // directory names are useless without parent-path information. return false; @@ -118,6 +124,14 @@ bool FoldersPanel::urlChanged() return true; } +void FoldersPanel::reloadTree() +{ + if (m_controller) { + loadTree(url(), AllowJumpHome); + } +} + + void FoldersPanel::showEvent(QShowEvent* event) { if (event->spontaneous()) { @@ -164,7 +178,7 @@ void FoldersPanel::showEvent(QShowEvent* event) container->setEnabledFrame(false); QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(container); } @@ -200,12 +214,10 @@ void FoldersPanel::slotItemMiddleClicked(int index) void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) { - Q_UNUSED(pos); - const KFileItem fileItem = m_model->fileItem(index); - QWeakPointer contextMenu = new TreeViewContextMenu(this, fileItem); - contextMenu.data()->open(); + QPointer contextMenu = new TreeViewContextMenu(this, fileItem); + contextMenu.data()->open(pos.toPoint()); if (contextMenu.data()) { delete contextMenu.data(); } @@ -213,10 +225,8 @@ void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) { - Q_UNUSED(pos); - - QWeakPointer contextMenu = new TreeViewContextMenu(this, KFileItem()); - contextMenu.data()->open(); + QPointer contextMenu = new TreeViewContextMenu(this, KFileItem()); + contextMenu.data()->open(pos.toPoint()); if (contextMenu.data()) { delete contextMenu.data(); } @@ -236,10 +246,9 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve event->buttons(), event->modifiers()); - QString error; - DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent, error); - if (!error.isEmpty()) { - emit errorMessage(error); + KIO::DropJob *job = DragAndDropHelper::dropUrls(destItem.mostLocalUrl(), &dropEvent, this); + if (job) { + connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); }); } } } @@ -250,7 +259,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->uiDelegate()->setAutoErrorHandlingEnabled(true); } } } @@ -264,7 +280,7 @@ void FoldersPanel::slotLoadingCompleted() // animations. // TODO: Check whether it makes sense to allow accessing the // view-internal delay for usecases like this. - QTimer::singleShot(250, this, SLOT(startFadeInAnimation())); + QTimer::singleShot(250, this, &FoldersPanel::startFadeInAnimation); } if (!m_updateCurrentItem) { @@ -286,33 +302,50 @@ void FoldersPanel::startFadeInAnimation() anim->setDuration(200); } -void FoldersPanel::loadTree(const KUrl& url) +void FoldersPanel::loadTree(const QUrl& url, FoldersPanel::NavigationBehaviour navigationBehaviour) { Q_ASSERT(m_controller); m_updateCurrentItem = false; + bool jumpHome = false; - KUrl baseUrl; - if (url.isLocalFile()) { - // Use the root directory as base for local URLs (#150941) - baseUrl = QDir::rootPath(); - } else { + QUrl baseUrl; + if (!url.isLocalFile()) { // Clear the path for non-local URLs and use it as base baseUrl = url; - baseUrl.setPath(QString('/')); + baseUrl.setPath(QStringLiteral("/")); + } else if (Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url)) { + if (FoldersPanelSettings::limitFoldersPanelToHome() ) { + baseUrl = Dolphin::homeUrl(); + } else { + // Use the root directory as base for local URLs (#150941) + baseUrl = QUrl::fromLocalFile(QDir::rootPath()); + } + } else if (FoldersPanelSettings::limitFoldersPanelToHome() && navigationBehaviour == AllowJumpHome) { + baseUrl = Dolphin::homeUrl(); + jumpHome = true; + } else { + // Use the root directory as base for local URLs (#150941) + baseUrl = QUrl::fromLocalFile(QDir::rootPath()); } - if (m_model->directory() != baseUrl) { + if (m_model->directory() != baseUrl && !jumpHome) { m_updateCurrentItem = true; m_model->refreshDirectory(baseUrl); } const int index = m_model->index(url); - if (index >= 0) { + if (jumpHome) { + emit folderActivated(baseUrl); + } else if (index >= 0) { updateCurrentItem(index); + } else if (url == baseUrl) { + // clear the selection when visiting the base url + updateCurrentItem(-1); } else { m_updateCurrentItem = true; m_model->expandParentDirectories(url); + // slotLoadingCompleted() will be invoked after the model has // expanded the url } @@ -328,4 +361,3 @@ void FoldersPanel::updateCurrentItem(int index) m_controller->view()->scrollToItem(index); } -#include "folderspanel.moc"