Add delete confirm dialog

This commit is contained in:
reionwong 2021-09-04 02:26:01 +08:00
parent 422fc5d6f9
commit 794f9ed1c7
6 changed files with 184 additions and 47 deletions

View file

@ -52,6 +52,7 @@
// Qt Quick
#include <QQuickItem>
#include <QQmlContext>
// KIO
#include <KIO/CopyJob>
@ -871,13 +872,8 @@ void FolderModel::deleteSelected()
}
}
const QList<QUrl> 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);

View file

@ -196,6 +196,7 @@ public:
Q_INVOKABLE void openPropertiesDialog();
Q_INVOKABLE void openInTerminal();
Q_INVOKABLE void openChangeWallpaperDialog();
Q_INVOKABLE void openDeleteDialog();
void restoreFromTrash();

View file

@ -58,5 +58,6 @@
<file>images/dark/drive-optical.svg</file>
<file>images/light/drive-optical.svg</file>
<file>qml/Dialogs/OpenWithDialog.qml</file>
<file>qml/Dialogs/DeleteDialog.qml</file>
</qresource>
</RCC>

View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@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 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 <http://www.gnu.org/licenses/>.
*/
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
}
}
}
}

View file

@ -62,6 +62,24 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DeleteDialog</name>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="47"/>
<source>Do you want to delete it permanently?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="56"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="62"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DesktopView</name>
<message>
@ -109,97 +127,102 @@
<context>
<name>FolderModel</name>
<message>
<location filename="../model/foldermodel.cpp" line="183"/>
<location filename="../model/foldermodel.cpp" line="184"/>
<source>%1 item</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="183"/>
<location filename="../model/foldermodel.cpp" line="184"/>
<source>%1 items</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="248"/>
<location filename="../model/foldermodel.cpp" line="249"/>
<source>The file or folder %1 does not exist.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="985"/>
<location filename="../model/foldermodel.cpp" line="981"/>
<source>Select All</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1265"/>
<location filename="../model/foldermodel.cpp" line="1088"/>
<source>File Manager</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1281"/>
<source>Open</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1268"/>
<location filename="../model/foldermodel.cpp" line="1284"/>
<source>Open with</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1271"/>
<location filename="../model/foldermodel.cpp" line="1287"/>
<source>Cut</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1274"/>
<location filename="../model/foldermodel.cpp" line="1290"/>
<source>Copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1277"/>
<location filename="../model/foldermodel.cpp" line="1293"/>
<source>Paste</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1280"/>
<location filename="../model/foldermodel.cpp" line="1296"/>
<source>New Folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1283"/>
<location filename="../model/foldermodel.cpp" line="1299"/>
<source>Move To Trash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1286"/>
<location filename="../model/foldermodel.cpp" line="1302"/>
<source>Empty Trash</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1289"/>
<location filename="../model/foldermodel.cpp" line="1305"/>
<source>Delete</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1292"/>
<location filename="../model/foldermodel.cpp" line="1308"/>
<source>Rename</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1295"/>
<location filename="../model/foldermodel.cpp" line="1311"/>
<source>Open in Terminal</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1298"/>
<location filename="../model/foldermodel.cpp" line="1314"/>
<source>Set as Wallpaper</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1301"/>
<location filename="../model/foldermodel.cpp" line="1317"/>
<source>Properties</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1304"/>
<location filename="../model/foldermodel.cpp" line="1320"/>
<source>Change background</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1307"/>
<location filename="../model/foldermodel.cpp" line="1323"/>
<source>Restore</source>
<translation type="unfinished"></translation>
</message>

View file

@ -62,6 +62,24 @@
<translation>%1</translation>
</message>
</context>
<context>
<name>DeleteDialog</name>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="47"/>
<source>Do you want to delete it permanently?</source>
<translation></translation>
</message>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="56"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../qml/Dialogs/DeleteDialog.qml" line="62"/>
<source>Delete</source>
<translation></translation>
</message>
</context>
<context>
<name>DesktopView</name>
<message>
@ -109,97 +127,102 @@
<context>
<name>FolderModel</name>
<message>
<location filename="../model/foldermodel.cpp" line="183"/>
<location filename="../model/foldermodel.cpp" line="184"/>
<source>%1 item</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="183"/>
<location filename="../model/foldermodel.cpp" line="184"/>
<source>%1 items</source>
<translation>%1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="248"/>
<location filename="../model/foldermodel.cpp" line="249"/>
<source>The file or folder %1 does not exist.</source>
<translation> %1 </translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="985"/>
<location filename="../model/foldermodel.cpp" line="981"/>
<source>Select All</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1265"/>
<location filename="../model/foldermodel.cpp" line="1088"/>
<source>File Manager</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1281"/>
<source>Open</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1268"/>
<location filename="../model/foldermodel.cpp" line="1284"/>
<source>Open with</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1271"/>
<location filename="../model/foldermodel.cpp" line="1287"/>
<source>Cut</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1274"/>
<location filename="../model/foldermodel.cpp" line="1290"/>
<source>Copy</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1277"/>
<location filename="../model/foldermodel.cpp" line="1293"/>
<source>Paste</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1280"/>
<location filename="../model/foldermodel.cpp" line="1296"/>
<source>New Folder</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1283"/>
<location filename="../model/foldermodel.cpp" line="1299"/>
<source>Move To Trash</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1286"/>
<location filename="../model/foldermodel.cpp" line="1302"/>
<source>Empty Trash</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1289"/>
<location filename="../model/foldermodel.cpp" line="1305"/>
<source>Delete</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1292"/>
<location filename="../model/foldermodel.cpp" line="1308"/>
<source>Rename</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1295"/>
<location filename="../model/foldermodel.cpp" line="1311"/>
<source>Open in Terminal</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1298"/>
<location filename="../model/foldermodel.cpp" line="1314"/>
<source>Set as Wallpaper</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1301"/>
<location filename="../model/foldermodel.cpp" line="1317"/>
<source>Properties</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1304"/>
<location filename="../model/foldermodel.cpp" line="1320"/>
<source>Change background</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1307"/>
<location filename="../model/foldermodel.cpp" line="1323"/>
<source>Restore</source>
<translation></translation>
</message>