┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt12
-rw-r--r--src/itemactions/movetonewfolderitemaction.cpp54
-rw-r--r--src/itemactions/movetonewfolderitemaction.h28
-rw-r--r--src/itemactions/movetonewfolderitemaction.json14
4 files changed, 108 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 55eda9dcd..0aa369bdb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -616,3 +616,15 @@ install( FILES settings/dolphin_detailsmodesettings.upd
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
+
+# movetonewfolderitemaction plugin
+
+kcoreaddons_add_plugin(movetonewfolderitemaction
+ SOURCES itemactions/movetonewfolderitemaction.cpp itemactions/movetonewfolderitemaction.h
+ INSTALL_NAMESPACE "kf6/kfileitemaction")
+
+target_link_libraries(movetonewfolderitemaction
+ KF6::I18n
+ KF6::KIOCore
+ KF6::KIOWidgets
+ KF6::KIOFileWidgets)
diff --git a/src/itemactions/movetonewfolderitemaction.cpp b/src/itemactions/movetonewfolderitemaction.cpp
new file mode 100644
index 000000000..6d3d6b85b
--- /dev/null
+++ b/src/itemactions/movetonewfolderitemaction.cpp
@@ -0,0 +1,54 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Ahmet Hakan Çelik <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "movetonewfolderitemaction.h"
+
+#include <KFileItem>
+#include <KLocalizedString>
+#include <KPluginFactory>
+#include <KNewFileMenu>
+#include <KIO/CopyJob>
+#include <KIO/JobUiDelegate>
+#include <KIO/FileUndoManager>
+
+#include <QUrl>
+
+K_PLUGIN_CLASS_WITH_JSON(MoveToNewFolderItemAction, "movetonewfolderitemaction.json")
+
+MoveToNewFolderItemAction::MoveToNewFolderItemAction(QObject *parent)
+ : KAbstractFileItemActionPlugin(parent)
+{
+
+}
+
+QList<QAction *> MoveToNewFolderItemAction::actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget)
+{
+ const KFileItemList &selectedItems = fileItemInfos.items();
+
+ QAction *createFolderFromSelected = new QAction(i18nc("@action:inmenu", "Move to New Folder…"), parentWidget);
+ createFolderFromSelected->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
+ connect(createFolderFromSelected, &QAction::triggered, this, [=]() {
+ QString selectedFileDirPath = selectedItems.at(0).url().toString().remove(selectedItems.at(0).name());
+ if (selectedFileDirPath.endsWith(QStringLiteral("/"))) {
+ selectedFileDirPath.removeLast();
+ }
+ const QUrl newFolderDirUrl(selectedFileDirPath);
+
+ auto newFileMenu = new KNewFileMenu(parentWidget);
+ newFileMenu->setWorkingDirectory(newFolderDirUrl);
+ newFileMenu->createDirectory();
+
+ connect(newFileMenu, &KNewFileMenu::directoryCreated, this, [=](const QUrl &createdUrl) {
+ KIO::CopyJob *job = KIO::move(selectedItems.urlList(), createdUrl);
+ KIO::FileUndoManager::self()->recordCopyJob(job);
+ newFileMenu->deleteLater();
+ });
+ });
+
+ return {createFolderFromSelected};
+}
+
+#include "movetonewfolderitemaction.moc"
diff --git a/src/itemactions/movetonewfolderitemaction.h b/src/itemactions/movetonewfolderitemaction.h
new file mode 100644
index 000000000..e690a35e1
--- /dev/null
+++ b/src/itemactions/movetonewfolderitemaction.h
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Ahmet Hakan Çelik <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef MOVETONEWFOLDERITEMACTION_H
+#define MOVETONEWFOLDERITEMACTION_H
+
+#include <KAbstractFileItemActionPlugin>
+#include <KFileItemListProperties>
+
+class QAction;
+class QWidget;
+
+class KNewFileMenu;
+
+class MoveToNewFolderItemAction : public KAbstractFileItemActionPlugin
+{
+ Q_OBJECT
+
+public:
+ MoveToNewFolderItemAction(QObject *parent);
+
+ QList<QAction *> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override;
+};
+
+#endif // MOVETONEWFOLDERITEMACTION_H
diff --git a/src/itemactions/movetonewfolderitemaction.json b/src/itemactions/movetonewfolderitemaction.json
new file mode 100644
index 000000000..069bad6fd
--- /dev/null
+++ b/src/itemactions/movetonewfolderitemaction.json
@@ -0,0 +1,14 @@
+{
+ "KPlugin": {
+ "Icon": "folder-new",
+ "MimeTypes": [
+ "application/octet-stream"
+ ],
+ "Name": "Move to New Folder",
+ "ServiceTypes": [
+ "KFileItemAction/Plugin"
+ ]
+ },
+ "X-KDE-Require": "Write",
+ "X-KDE-Show-In-Submenu": "true"
+}