-/***************************************************************************
- * Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2006-2010 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "folderspanel.h"
#include "kitemviews/kitemlistcontainer.h"
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistselectionmanager.h"
+#include "kitemviews/private/kitemlistroleeditor.h"
#include "treeviewcontextmenu.h"
#include "views/draganddrophelper.h"
-#include "views/renamedialog.h"
-#include <KJobWidgets>
-#include <KJobUiDelegate>
#include <KIO/CopyJob>
#include <KIO/DropJob>
#include <KIO/FileUndoManager>
+#include <KIO/RenameFileDialog>
+#include <KJobUiDelegate>
+#include <KJobWidgets>
#include <QApplication>
#include <QBoxLayout>
#include <QPropertyAnimation>
#include <QTimer>
-FoldersPanel::FoldersPanel(QWidget* parent) :
- Panel(parent),
- m_updateCurrentItem(false),
- m_controller(nullptr),
- m_model(nullptr)
+FoldersPanel::FoldersPanel(QWidget *parent)
+ : Panel(parent)
+ , m_updateCurrentItem(false)
+ , m_controller(nullptr)
+ , m_model(nullptr)
{
setLayoutDirection(Qt::LeftToRight);
}
FoldersPanelSettings::self()->save();
if (m_controller) {
- KItemListView* view = m_controller->view();
+ KItemListView *view = m_controller->view();
m_controller->setView(nullptr);
delete view;
}
return FoldersPanelSettings::autoScrolling();
}
-void FoldersPanel::rename(const KFileItem& item)
+void FoldersPanel::rename(const KFileItem &item)
{
if (GeneralSettings::renameInline()) {
const int index = m_model->index(item);
m_controller->view()->editRole(index, "text");
} else {
- RenameDialog* dialog = new RenameDialog(this, KFileItemList() << item);
+ KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(KFileItemList({item}), this);
dialog->open();
}
}
}
}
-
-void FoldersPanel::showEvent(QShowEvent* event)
+void FoldersPanel::showEvent(QShowEvent *event)
{
if (event->spontaneous()) {
Panel::showEvent(event);
// Postpone the creating of the controller to the first show 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();
+ KFileItemListView *view = new KFileItemListView();
view->setWidgetCreator(new KItemListWidgetCreator<FoldersItemListWidget>());
view->setSupportsItemExpanding(true);
// Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
// opening the folders panel.
view->setOpacity(0);
- connect(view, &KFileItemListView::roleEditingFinished,
- this, &FoldersPanel::slotRoleEditingFinished);
+ connect(view, &KFileItemListView::roleEditingFinished, this, &FoldersPanel::slotRoleEditingFinished);
m_model = new KFileItemModel(this);
m_model->setShowDirectoriesOnly(true);
m_controller->setSelectionBehavior(KItemListController::SingleSelection);
m_controller->setAutoActivationBehavior(KItemListController::ExpansionOnly);
m_controller->setMouseDoubleClickAction(KItemListController::ActivateAndExpandItem);
- m_controller->setAutoActivationDelay(750);
m_controller->setSingleClickActivationEnforced(true);
connect(m_controller, &KItemListController::itemActivated, this, &FoldersPanel::slotItemActivated);
connect(m_controller, &KItemListController::viewContextMenuRequested, this, &FoldersPanel::slotViewContextMenuRequested);
connect(m_controller, &KItemListController::itemDropEvent, this, &FoldersPanel::slotItemDropEvent);
- KItemListContainer* container = new KItemListContainer(m_controller, this);
+ KItemListContainer *container = new KItemListContainer(m_controller, this);
+#ifndef QT_NO_ACCESSIBILITY
+ view->setAccessibleParentsObject(container);
+#endif
container->setEnabledFrame(false);
- QVBoxLayout* layout = new QVBoxLayout(this);
+ QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(container);
}
Panel::showEvent(event);
}
-void FoldersPanel::keyPressEvent(QKeyEvent* event)
+void FoldersPanel::keyPressEvent(QKeyEvent *event)
{
const int key = event->key();
if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) {
{
const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
- emit folderActivated(item.url());
+ const auto modifiers = QGuiApplication::keyboardModifiers();
+ // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
+ if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier) {
+ Q_EMIT folderInNewActiveTab(item.url());
+ } else if (modifiers & Qt::ControlModifier) {
+ Q_EMIT folderInNewTab(item.url());
+ } else if (modifiers & Qt::ShiftModifier) {
+ // The shift modifier is not considered because it is used to expand the tree view without actually
+ // opening the folder
+ return;
+ } else {
+ Q_EMIT folderActivated(item.url());
+ }
}
}
{
const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
- emit folderMiddleClicked(item.url());
+ const auto modifiers = QGuiApplication::keyboardModifiers();
+ // keep in sync with KUrlNavigator::slotNavigatorButtonClicked
+ if (modifiers & Qt::ShiftModifier) {
+ Q_EMIT folderInNewActiveTab(item.url());
+ } else {
+ Q_EMIT folderInNewTab(item.url());
+ }
}
}
-void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
+void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF &pos)
{
const KFileItem fileItem = m_model->fileItem(index);
}
}
-void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos)
+void FoldersPanel::slotViewContextMenuRequested(const QPointF &pos)
{
QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, KFileItem());
contextMenu.data()->open(pos.toPoint());
}
}
-void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event)
{
if (index >= 0) {
KFileItem destItem = m_model->fileItem(index);
return;
}
- QDropEvent dropEvent(event->pos().toPoint(),
- event->possibleActions(),
- event->mimeData(),
- event->buttons(),
- event->modifiers());
+ QDropEvent dropEvent(event->pos().toPoint(), event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
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()); });
+ connect(job, &KIO::DropJob::result, this, [this](KJob *job) {
+ if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
+ Q_EMIT errorMessage(job->errorString());
+ }
+ });
}
}
}
-void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
+void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value)
{
if (role == "text") {
const KFileItem item = m_model->fileItem(index);
- const QString newName = value.toString();
+ const EditResult retVal = value.value<EditResult>();
+ const QString newName = retVal.newName;
if (!newName.isEmpty() && newName != item.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) {
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);
+ 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);
void FoldersPanel::startFadeInAnimation()
{
- QPropertyAnimation* anim = new QPropertyAnimation(m_controller->view(), "opacity", this);
+ QPropertyAnimation *anim = new QPropertyAnimation(m_controller->view(), "opacity", this);
anim->setStartValue(0);
anim->setEndValue(1);
anim->setEasingCurve(QEasingCurve::InOutQuad);
anim->setDuration(200);
}
-void FoldersPanel::loadTree(const QUrl& url, FoldersPanel::NavigationBehaviour navigationBehaviour)
+void FoldersPanel::loadTree(const QUrl &url, FoldersPanel::NavigationBehaviour navigationBehaviour)
{
Q_ASSERT(m_controller);
baseUrl = url;
baseUrl.setPath(QStringLiteral("/"));
} else if (Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url)) {
- if (FoldersPanelSettings::limitFoldersPanelToHome() ) {
+ if (FoldersPanelSettings::limitFoldersPanelToHome()) {
baseUrl = Dolphin::homeUrl();
} else {
// Use the root directory as base for local URLs (#150941)
const int index = m_model->index(url);
if (jumpHome) {
- emit folderActivated(baseUrl);
+ Q_EMIT folderActivated(baseUrl);
} else if (index >= 0) {
updateCurrentItem(index);
} else if (url == baseUrl) {
void FoldersPanel::updateCurrentItem(int index)
{
- KItemListSelectionManager* selectionManager = m_controller->selectionManager();
+ KItemListSelectionManager *selectionManager = m_controller->selectionManager();
selectionManager->setCurrentItem(index);
selectionManager->clearSelection();
selectionManager->setSelected(index);
m_controller->view()->scrollToItem(index);
}
+#include "moc_folderspanel.cpp"