From 794f9ed1c729c00ca7ab7ddb856e4815b9a6a973 Mon Sep 17 00:00:00 2001 From: reionwong Date: Sat, 4 Sep 2021 02:26:01 +0800 Subject: [PATCH] Add delete confirm dialog --- model/foldermodel.cpp | 34 ++++++++++++----- model/foldermodel.h | 1 + qml.qrc | 1 + qml/Dialogs/DeleteDialog.qml | 73 ++++++++++++++++++++++++++++++++++++ translations/en_US.ts | 61 ++++++++++++++++++++---------- translations/zh_CN.ts | 61 ++++++++++++++++++++---------- 6 files changed, 184 insertions(+), 47 deletions(-) create mode 100644 qml/Dialogs/DeleteDialog.qml diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 6708b22..79517e1 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -52,6 +52,7 @@ // Qt Quick #include +#include // KIO #include @@ -871,13 +872,8 @@ void FolderModel::deleteSelected() } } - const QList urls = selectedUrls(); - KIO::JobUiDelegate uiDelegate; - - if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job *job = KIO::del(urls); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } + KIO::DeleteJob *job = KIO::del(selectedUrls()); + job->start(); } void FolderModel::moveSelectedToTrash() @@ -912,7 +908,7 @@ void FolderModel::keyDeletePress() if (!m_selectionModel->hasSelection()) return; - resolvedUrl().scheme() == "trash" ? deleteSelected() : moveSelectedToTrash(); + resolvedUrl().scheme() == "trash" ? openDeleteDialog() : moveSelectedToTrash(); } void FolderModel::setDragHotSpotScrollOffset(int x, int y) @@ -1084,6 +1080,26 @@ void FolderModel::openChangeWallpaperDialog() QProcess::startDetached("cutefish-settings", QStringList() << "-m" << "background"); } +void FolderModel::openDeleteDialog() +{ + QQuickView *view = new QQuickView; + view->setModality(Qt::ApplicationModal); + view->setFlags(Qt::Dialog); + view->setTitle(tr("File Manager")); + view->setResizeMode(QQuickView::SizeRootObjectToView); + view->setSource(QUrl("qrc:/qml/Dialogs/DeleteDialog.qml")); + view->rootContext()->setContextProperty("model", this); + view->rootContext()->setContextProperty("view", view); + + connect(view, &QQuickView::visibleChanged, this, [=] { + if (!view->isVisible()) { + view->deleteLater(); + } + }); + + view->show(); +} + void FolderModel::restoreFromTrash() { if (!m_selectionModel->hasSelection()) @@ -1287,7 +1303,7 @@ void FolderModel::createActions() connect(emptyTrash, &QAction::triggered, this, &FolderModel::emptyTrash); QAction *del = new QAction(tr("Delete"), this); - connect(del, &QAction::triggered, this, &FolderModel::deleteSelected); + connect(del, &QAction::triggered, this, &FolderModel::openDeleteDialog); QAction *rename = new QAction(tr("Rename"), this); connect(rename, &QAction::triggered, this, &FolderModel::requestRename); diff --git a/model/foldermodel.h b/model/foldermodel.h index e1fa0c0..116f2ae 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -196,6 +196,7 @@ public: Q_INVOKABLE void openPropertiesDialog(); Q_INVOKABLE void openInTerminal(); Q_INVOKABLE void openChangeWallpaperDialog(); + Q_INVOKABLE void openDeleteDialog(); void restoreFromTrash(); diff --git a/qml.qrc b/qml.qrc index 2190f34..0e4cf08 100644 --- a/qml.qrc +++ b/qml.qrc @@ -58,5 +58,6 @@ images/dark/drive-optical.svg images/light/drive-optical.svg qml/Dialogs/OpenWithDialog.qml + qml/Dialogs/DeleteDialog.qml diff --git a/qml/Dialogs/DeleteDialog.qml b/qml/Dialogs/DeleteDialog.qml new file mode 100644 index 0000000..58e5306 --- /dev/null +++ b/qml/Dialogs/DeleteDialog.qml @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * 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 3 of the License, or + * 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, see . + */ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Window 2.12 +import QtQuick.Layouts 1.12 +import FishUI 1.0 as FishUI +import Cutefish.FileManager 1.0 + +Item { + id: control + + width: 300 + FishUI.Units.largeSpacing * 2 + height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2 + + Rectangle { + anchors.fill: parent + color: FishUI.Theme.secondBackgroundColor + } + + ColumnLayout { + id: _mainLayout + anchors.fill: parent + anchors.leftMargin: FishUI.Units.largeSpacing + anchors.rightMargin: FishUI.Units.largeSpacing + anchors.bottomMargin: FishUI.Units.smallSpacing + spacing: FishUI.Units.largeSpacing + + Label { + text: qsTr("Do you want to delete it permanently?") + Layout.fillWidth: true + wrapMode: Text.Wrap + } + + RowLayout { + spacing: FishUI.Units.largeSpacing + + Button { + text: qsTr("Cancel") + Layout.fillWidth: true + onClicked: view.close() + } + + Button { + text: qsTr("Delete") + focus: true + Layout.fillWidth: true + onClicked: { + view.close() + model.deleteSelected() + } + flat: true + } + } + } +} diff --git a/translations/en_US.ts b/translations/en_US.ts index dcdcc55..59e1106 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -62,6 +62,24 @@ + + DeleteDialog + + + Do you want to delete it permanently? + + + + + Cancel + + + + + Delete + + + DesktopView @@ -109,97 +127,102 @@ FolderModel - + %1 item - + %1 items - + The file or folder %1 does not exist. - + Select All - + + File Manager + + + + Open - + Open with - + Cut - + Copy - + Paste - + New Folder - + Move To Trash - + Empty Trash - + Delete - + Rename - + Open in Terminal - + Set as Wallpaper - + Properties - + Change background - + Restore diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 2f42e8f..86b8940 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -62,6 +62,24 @@ %1天前 + + DeleteDialog + + + Do you want to delete it permanently? + 是否要永久删除? + + + + Cancel + 取消 + + + + Delete + 删除 + + DesktopView @@ -109,97 +127,102 @@ FolderModel - + %1 item %1 项 - + %1 items %1 项 - + The file or folder %1 does not exist. 文件或文件夹 %1 不存在 - + Select All 全选 - + + File Manager + 文件管理器 + + + Open 打开 - + Open with 打开方式 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + New Folder 新建文件夹 - + Move To Trash 移动到回收站 - + Empty Trash 清空回收站 - + Delete 删除 - + Rename 重命名 - + Open in Terminal 在终端中打开 - + Set as Wallpaper 设置为壁纸 - + Properties 属性 - + Change background 更改桌面背景 - + Restore 恢复